Skip to content

Commit

Permalink
Revert "Merge branch 'asl'"
Browse files Browse the repository at this point in the history
This reverts commit 6553fea, reversing
changes made to d516023.
  • Loading branch information
f43nd1r committed Dec 21, 2018
1 parent 20f7589 commit 33b0951
Show file tree
Hide file tree
Showing 53 changed files with 91 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.support.annotation.NonNull;
import androidx.work.Constraints;
import androidx.work.OneTimeWorkRequest;
import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;
import org.acra.config.ConfigUtils;
import org.acra.config.CoreConfiguration;
import org.acra.config.SchedulerConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.content.Intent;
import android.support.annotation.NonNull;
import androidx.work.*;
import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;
import org.acra.ACRA;
import org.acra.builder.LastActivityManager;
import org.acra.config.ConfigUtils;
Expand Down
2 changes: 1 addition & 1 deletion acra-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-fragment'
}
api project(':acra-javacore')
implementation "com.faendir.asl:serviceloader:$aslVersion"
compileOnly "com.google.auto.service:auto-service:$autoServiceVersion"
annotationProcessor project(':annotationprocessor')
compileOnly project(':annotations')
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ReportExecutor(@NonNull Context context, @NonNull CoreConfiguration confi
this.crashReportDataFactory = crashReportDataFactory;
this.defaultExceptionHandler = defaultExceptionHandler;
this.processFinisher = processFinisher;
reportingAdministrators = config.pluginLoader().loadEnabled(context, config, ReportingAdministrator.class);
reportingAdministrators = config.pluginLoader().loadEnabled(config, ReportingAdministrator.class);
this.schedulerStarter = schedulerStarter;
this.lastActivityManager = lastActivityManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.support.annotation.Nullable;
import android.util.SparseArray;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import android.view.Display;
import android.view.Surface;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.os.DropBoxManager;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;
import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import android.support.annotation.Nullable;
import android.util.SparseArray;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.content.pm.PackageInfo;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.os.Environment;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.os.Build;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ReportField;
import org.acra.builder.ReportBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;

import org.acra.ACRAConstants;
import org.acra.ReportField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class BaseCoreConfigurationBuilder {

private List<ConfigurationBuilder> configurationBuilders() {
if (configurationBuilders == null) {
List<ConfigurationBuilderFactory> factories = pluginLoader.load(app, ConfigurationBuilderFactory.class);
List<ConfigurationBuilderFactory> factories = pluginLoader.load(ConfigurationBuilderFactory.class);
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Found ConfigurationBuilderFactories : " + factories);
configurationBuilders = new ArrayList<>(factories.size());
for (ConfigurationBuilderFactory factory : factories) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class CrashReportDataFactory {
public CrashReportDataFactory(@NonNull Context context, @NonNull CoreConfiguration config) {
this.context = context;
this.config = config;
collectors = config.pluginLoader().loadEnabled(context, config, Collector.class);
collectors = config.pluginLoader().loadEnabled(config, Collector.class);
//noinspection Java8ListSort
Collections.sort(collectors, (c1, c2) -> {
Collector.Order o1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ReportInteractionExecutor {
public ReportInteractionExecutor(@NonNull final Context context, @NonNull final CoreConfiguration config) {
this.context = context;
this.config = config;
reportInteractions = config.pluginLoader().loadEnabled(context, config, ReportInteraction.class);
reportInteractions = config.pluginLoader().loadEnabled(config, ReportInteraction.class);
}

public boolean hasInteractions() {
Expand Down
5 changes: 2 additions & 3 deletions acra-core/src/main/java/org/acra/plugins/PluginLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.acra.plugins;

import android.content.Context;
import android.support.annotation.NonNull;
import org.acra.config.CoreConfiguration;

Expand All @@ -28,7 +27,7 @@
* @since 01.07.18
*/
public interface PluginLoader extends Serializable {
<T extends Plugin> List<T> load(@NonNull Context context, @NonNull Class<T> clazz);
<T extends Plugin> List<T> load(@NonNull Class<T> clazz);

<T extends Plugin> List<T> loadEnabled(@NonNull Context context, @NonNull CoreConfiguration config, @NonNull Class<T> clazz);
<T extends Plugin> List<T> loadEnabled(@NonNull CoreConfiguration config, @NonNull Class<T> clazz);
}
22 changes: 7 additions & 15 deletions acra-core/src/main/java/org/acra/plugins/ServicePluginLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.acra.plugins;

import android.content.Context;
import android.support.annotation.NonNull;
import org.acra.ACRA;
import org.acra.config.CoreConfiguration;
Expand All @@ -35,26 +34,19 @@
public class ServicePluginLoader implements PluginLoader {

@Override
public <T extends Plugin> List<T> load(@NonNull Context context, @NonNull Class<T> clazz) {
return loadInternal(context, clazz, plugin -> true);
public <T extends Plugin> List<T> load(@NonNull Class<T> clazz) {
return loadInternal(clazz, plugin -> true);
}

@Override
public <T extends Plugin> List<T> loadEnabled(@NonNull Context context, @NonNull CoreConfiguration config, @NonNull Class<T> clazz) {
return loadInternal(context, clazz, plugin -> plugin.enabled(config));
public <T extends Plugin> List<T> loadEnabled(@NonNull CoreConfiguration config, @NonNull Class<T> clazz) {
return loadInternal(clazz, plugin -> plugin.enabled(config));
}

private <T extends Plugin> List<T> loadInternal(@NonNull Context context, @NonNull Class<T> clazz, Predicate<T> shouldLoadPredicate) {
List<T> plugins = new ArrayList<>(new com.faendir.asl.serviceloader.ServiceLoader(context).load(clazz));
for (Iterator<T> iterator = plugins.iterator(); iterator.hasNext(); ) {
T plugin = iterator.next();
if (!shouldLoadPredicate.apply(plugin)) {
iterator.remove();
} else if (ACRA.DEV_LOGGING) ACRA.log.d(ACRA.LOG_TAG, "Loaded " + clazz.getSimpleName() + " of type " + plugin.getClass().getName());
}
//legacy
private <T extends Plugin> List<T> loadInternal(@NonNull Class<T> clazz, Predicate<T> shouldLoadPredicate) {
List<T> plugins = new ArrayList<>();
//noinspection ForLoopReplaceableByForEach
final ServiceLoader<T> serviceLoader = ServiceLoader.load(clazz, context.getClassLoader());
final ServiceLoader<T> serviceLoader = ServiceLoader.load(clazz, getClass().getClassLoader());
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "ServicePluginLoader loading services from ServiceLoader : " + serviceLoader);

for (final Iterator<T> iterator = serviceLoader.iterator(); iterator.hasNext(); ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.acra.plugins;

import android.content.Context;
import android.support.annotation.NonNull;
import org.acra.ACRA;
import org.acra.config.CoreConfiguration;
Expand All @@ -41,7 +40,7 @@ public SimplePluginLoader(@NonNull Class<? extends Plugin>... plugins) {
}

@Override
public <T extends Plugin> List<T> load(@NonNull Context context, @NonNull Class<T> clazz) {
public <T extends Plugin> List<T> load(@NonNull Class<T> clazz) {
List<T> list = new ArrayList<>();
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "SimplePluginLoader loading services from plugin classes : " + plugins);
for (Class<? extends Plugin> plugin : plugins) {
Expand All @@ -59,8 +58,8 @@ public <T extends Plugin> List<T> load(@NonNull Context context, @NonNull Class<
}

@Override
public <T extends Plugin> List<T> loadEnabled(@NonNull Context context, @NonNull CoreConfiguration config, @NonNull Class<T> clazz) {
List<T> list = load(context, clazz);
public <T extends Plugin> List<T> loadEnabled(@NonNull CoreConfiguration config, @NonNull Class<T> clazz) {
List<T> list = load(clazz);
//noinspection Java8CollectionRemoveIf
for (Iterator<T> iterator = list.iterator(); iterator.hasNext(); ) {
T plugin = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SchedulerStarter {

public SchedulerStarter(@NonNull Context context, @NonNull CoreConfiguration config) {
locator = new ReportLocator(context);
List<SenderSchedulerFactory> schedulerFactories = config.pluginLoader().loadEnabled(context, config, SenderSchedulerFactory.class);
List<SenderSchedulerFactory> schedulerFactories = config.pluginLoader().loadEnabled(config, SenderSchedulerFactory.class);
if (schedulerFactories.isEmpty()) {
senderScheduler = new DefaultSenderScheduler(context, config);
} else {
Expand Down
16 changes: 14 additions & 2 deletions acra-core/src/main/java/org/acra/sender/SenderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,21 @@ private void sendReports(@NonNull CoreConfiguration config, boolean onlySendSile
@NonNull
private List<ReportSender> getSenderInstances(@NonNull CoreConfiguration config) {
List<Class<? extends ReportSenderFactory>> factoryClasses = config.reportSenderFactoryClasses();
List<ReportSenderFactory> factories = !factoryClasses.isEmpty() ? new InstanceCreator().create(factoryClasses) : config.pluginLoader()
.loadEnabled(this, config, ReportSenderFactory.class);

if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "config#reportSenderFactoryClasses : " + factoryClasses);

final List<ReportSenderFactory> factories;
if (factoryClasses.isEmpty()) {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Using PluginLoader to find ReportSender factories");
final PluginLoader loader = config.pluginLoader();
factories = loader.loadEnabled(config, ReportSenderFactory.class);
} else {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Creating reportSenderFactories for reportSenderFactory config");
factories = new InstanceCreator().create(factoryClasses);
}
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "reportSenderFactories : " + factories);


final List<ReportSender> reportSenders = new ArrayList<>();
for (ReportSenderFactory factory : factories) {
final ReportSender sender = factory.create(this.getApplication(), config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void processReports(boolean isAcraEnabled) {
for (File r : reportLocator.getApprovedReports()) {
reports.add(new Report(r, true));
}
final List<StartupProcessor> startupProcessors = config.pluginLoader().loadEnabled(context, config, StartupProcessor.class);
final List<StartupProcessor> startupProcessors = config.pluginLoader().loadEnabled(config, StartupProcessor.class);
for (StartupProcessor processor : startupProcessors) {
processor.processReports(context, config, reports);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import android.content.Context;
import android.support.annotation.NonNull;
import com.faendir.asl.annotation.AutoService;
import com.google.auto.service.AutoService;
import org.acra.config.CoreConfiguration;
import org.acra.file.LastModifiedComparator;

Expand Down
6 changes: 3 additions & 3 deletions acra-core/src/test/java/org/acra/ACRATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;
import org.acra.builder.ReportBuilder;
import org.acra.collector.StacktraceCollector;
import org.acra.config.CoreConfiguration;
Expand All @@ -30,6 +29,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;
Expand All @@ -43,15 +43,15 @@ public class ACRATest {

@Test
public void init() {
Application application = ApplicationProvider.getApplicationContext();
Application application = RuntimeEnvironment.application;
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(application).setPluginLoader(new SimplePluginLoader(StacktraceCollector.class, TestAdministrator.class));
ACRA.init(application, builder);
ACRA.getErrorReporter().handleException(new RuntimeException());
}

@Test(expected = AssertionError.class)
public void failing() {
Application application = ApplicationProvider.getApplicationContext();
Application application = RuntimeEnvironment.application;
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(application).setPluginLoader(new SimplePluginLoader(FailingTestAdministrator.class));
ACRA.init(application, builder);
ACRA.getErrorReporter().handleException(new RuntimeException());
Expand Down
Loading

0 comments on commit 33b0951

Please sign in to comment.