6: Extract Analyser to another package
This commit is contained in:
@@ -1,26 +1,19 @@
|
||||
package com.bartek.esa.core.analyser;
|
||||
package com.bartek.esa.analyser.core;
|
||||
|
||||
import com.bartek.esa.core.archetype.Plugin;
|
||||
import com.bartek.esa.core.executor.PluginExecutor;
|
||||
import com.bartek.esa.core.model.object.Issue;
|
||||
import com.bartek.esa.error.EsaException;
|
||||
import com.bartek.esa.file.provider.FileProvider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Analyser {
|
||||
private final FileProvider fileProvider;
|
||||
public abstract class Analyser {
|
||||
private final PluginExecutor pluginExecutor;
|
||||
private final Set<Plugin> plugins;
|
||||
|
||||
@Inject
|
||||
public Analyser(FileProvider fileProvider, PluginExecutor pluginExecutor, Set<Plugin> plugins) {
|
||||
this.fileProvider = fileProvider;
|
||||
public Analyser(PluginExecutor pluginExecutor, Set<Plugin> plugins) {
|
||||
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.plugins = plugins;
|
||||
@@ -34,28 +27,9 @@ public class Analyser {
|
||||
return pluginExecutor.executeForFiles(manifest, files, selectedPlugins);
|
||||
}
|
||||
|
||||
private File getManifest(String source) {
|
||||
Set<File> manifests = fileProvider.getGlobMatchedFiles(source, "**/AndroidManifest.xml");
|
||||
if (manifests.isEmpty()) {
|
||||
throw new EsaException("No AndroidManifest.xml file found. Interrupting...");
|
||||
}
|
||||
protected abstract File getManifest(String source);
|
||||
|
||||
if (manifests.size() > 1) {
|
||||
throw new EsaException("Found multiple AndroidManifest.xml files. Interrupting...");
|
||||
}
|
||||
|
||||
return (File) (manifests.toArray())[0];
|
||||
}
|
||||
|
||||
private Set<File> getFiles(String source) {
|
||||
Set<File> javaFiles = fileProvider.getGlobMatchedFiles(source, "**/*.java");
|
||||
Set<File> androidManifest = fileProvider.getGlobMatchedFiles(source, "**/AndroidManifest.xml");
|
||||
Set<File> layoutFiles = fileProvider.getGlobMatchedFiles(source, "**/res/layout*/**.xml");
|
||||
|
||||
return Stream.of(javaFiles, androidManifest, layoutFiles)
|
||||
.flatMap(Set::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
protected abstract Set<File> getFiles(String source);
|
||||
|
||||
private Set<Plugin> getPlugins(Set<String> pluginCodes, Set<String> excludeCodes) {
|
||||
Set<Plugin> outputPlugins = plugins;
|
||||
19
src/main/java/com/bartek/esa/analyser/di/AnalyserModule.java
Normal file
19
src/main/java/com/bartek/esa/analyser/di/AnalyserModule.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.bartek.esa.analyser.di;
|
||||
|
||||
import com.bartek.esa.analyser.source.SourceAnalyser;
|
||||
import com.bartek.esa.core.archetype.Plugin;
|
||||
import com.bartek.esa.core.executor.PluginExecutor;
|
||||
import com.bartek.esa.file.provider.FileProvider;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Module
|
||||
public class AnalyserModule {
|
||||
|
||||
@Provides
|
||||
public SourceAnalyser sourceAnalyser(PluginExecutor pluginExecutor, Set<Plugin> plugins, FileProvider fileProvider) {
|
||||
return new SourceAnalyser(pluginExecutor, plugins, fileProvider);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.bartek.esa.analyser.source;
|
||||
|
||||
import com.bartek.esa.analyser.core.Analyser;
|
||||
import com.bartek.esa.core.archetype.Plugin;
|
||||
import com.bartek.esa.core.executor.PluginExecutor;
|
||||
import com.bartek.esa.error.EsaException;
|
||||
import com.bartek.esa.file.provider.FileProvider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SourceAnalyser extends Analyser {
|
||||
private final FileProvider fileProvider;
|
||||
|
||||
@Inject
|
||||
public SourceAnalyser(PluginExecutor pluginExecutor, Set<Plugin> plugins, FileProvider fileProvider) {
|
||||
super(pluginExecutor, plugins);
|
||||
this.fileProvider = fileProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File getManifest(String source) {
|
||||
Set<File> manifests = fileProvider.getGlobMatchedFilesRecursively(source, "**/AndroidManifest.xml");
|
||||
if (manifests.isEmpty()) {
|
||||
throw new EsaException("No AndroidManifest.xml file found. Interrupting...");
|
||||
}
|
||||
|
||||
if (manifests.size() > 1) {
|
||||
throw new EsaException("Found multiple AndroidManifest.xml files. Interrupting...");
|
||||
}
|
||||
|
||||
return (File) (manifests.toArray())[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<File> getFiles(String source) {
|
||||
Set<File> javaFiles = fileProvider.getGlobMatchedFilesRecursively(source, "**/*.java");
|
||||
System.out.println(javaFiles);
|
||||
Set<File> layoutFiles = fileProvider.getGlobMatchedFilesRecursively(source, "**/res/layout*/**.xml");
|
||||
System.out.println(layoutFiles);
|
||||
Set<File> androidManifest = Collections.singleton(getManifest(source));
|
||||
System.out.println(androidManifest);
|
||||
|
||||
return Stream.of(javaFiles, androidManifest, layoutFiles)
|
||||
.flatMap(Set::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.bartek.esa.core.di;
|
||||
|
||||
import com.bartek.esa.core.analyser.Analyser;
|
||||
import com.bartek.esa.core.archetype.Plugin;
|
||||
import com.bartek.esa.core.desc.provider.DescriptionProvider;
|
||||
import com.bartek.esa.core.executor.PluginExecutor;
|
||||
import com.bartek.esa.core.java.JavaSyntaxRegexProvider;
|
||||
import com.bartek.esa.core.xml.XmlHelper;
|
||||
import com.bartek.esa.file.provider.FileProvider;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Module
|
||||
public class CoreModule {
|
||||
|
||||
@@ -34,9 +29,4 @@ public class CoreModule {
|
||||
public XmlHelper xmlHelper() {
|
||||
return new XmlHelper();
|
||||
}
|
||||
|
||||
@Provides
|
||||
public Analyser analyser(FileProvider fileProvider, PluginExecutor pluginExecutor, Set<Plugin> plugins) {
|
||||
return new Analyser(fileProvider, pluginExecutor, plugins);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartek.esa.di;
|
||||
|
||||
import com.bartek.esa.EsaMain;
|
||||
import com.bartek.esa.analyser.di.AnalyserModule;
|
||||
import com.bartek.esa.cli.di.CliModule;
|
||||
import com.bartek.esa.core.di.CoreModule;
|
||||
import com.bartek.esa.core.di.PluginModule;
|
||||
@@ -15,7 +16,8 @@ import dagger.Component;
|
||||
FileModule.class,
|
||||
DecompilerModule.class,
|
||||
CoreModule.class,
|
||||
PluginModule.class
|
||||
PluginModule.class,
|
||||
AnalyserModule.class
|
||||
})
|
||||
public interface DependencyInjector {
|
||||
EsaMain esa();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class FileProvider {
|
||||
.toFile();
|
||||
}
|
||||
|
||||
public Set<File> getGlobMatchedFiles(String path, String globPattern) {
|
||||
public Set<File> getGlobMatchedFilesRecursively(String path, String globPattern) {
|
||||
return Try.of(() -> Files.walk(Paths.get(path))
|
||||
.filter(p -> globMatcher.pathMatchesGlobPattern(p, globPattern))
|
||||
.map(Path::toFile)
|
||||
|
||||
Reference in New Issue
Block a user