support to scan once with multi-level granularities outputs
This commit is contained in:
parent
877c1ac1d3
commit
27f1206a1a
|
@ -24,15 +24,15 @@ SOFTWARE.
|
|||
|
||||
package depends;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import depends.deptypes.DependencyType;
|
||||
import depends.extractor.LangProcessorRegistration;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.Parameters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Command(name = "depends")
|
||||
public class DependsCommand {
|
||||
public static class SupportedLangs extends ArrayList<String> {
|
||||
|
@ -62,8 +62,8 @@ public class DependsCommand {
|
|||
@Option(names = {"--strip-paths"}, split=",", description = "The path(s) to be stripped. if -s enabled, the path(s) start after <src>. "
|
||||
+ "Otherwise, the path(s) should be valid.")
|
||||
private String[] strippedPaths = new String[]{};
|
||||
@Option(names = {"-g", "--granularity"}, description = "Granularity of dependency.[file(default),method,structure,L#(the level of folder. e.g. L1=1st level folder)]")
|
||||
private String granularity="file";
|
||||
@Option(names = {"-g", "--granularity"}, split=",", description = "Granularity of dependency.[file(default),method,structure]")
|
||||
private String[] granularity=new String[]{"file"};
|
||||
@Option(names = {"-p", "--namepattern"}, description = "The name path pattern.[dot(.), unix(/) or windows(\\)")
|
||||
private String namePathPattern="";
|
||||
@Option(names = {"-i","--includes"},split=",", description = "The files of searching path")
|
||||
|
@ -120,7 +120,7 @@ public class DependsCommand {
|
|||
public boolean isHelp() {
|
||||
return help;
|
||||
}
|
||||
public String getGranularity() {
|
||||
public String[] getGranularity() {
|
||||
return granularity;
|
||||
}
|
||||
public String getNamePathPattern() {
|
||||
|
|
|
@ -36,7 +36,6 @@ import depends.generator.FileDependencyGenerator;
|
|||
import depends.generator.FunctionDependencyGenerator;
|
||||
import depends.generator.StructureDependencyGenerator;
|
||||
import depends.matrix.core.DependencyMatrix;
|
||||
import depends.matrix.transform.MatrixLevelReducer;
|
||||
import depends.relations.BindingResolver;
|
||||
import depends.relations.IBindingResolver;
|
||||
import depends.relations.RelationCounter;
|
||||
|
@ -52,6 +51,7 @@ import picocli.CommandLine;
|
|||
import picocli.CommandLine.PicocliException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -69,6 +69,7 @@ public class Main {
|
|||
CommandLine.usage(new DependsCommand(), System.out);
|
||||
System.exit(0);
|
||||
}
|
||||
verifyParameters(appArgs);
|
||||
executeCommand(appArgs);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof PicocliException) {
|
||||
|
@ -83,6 +84,16 @@ public class Main {
|
|||
}
|
||||
}
|
||||
|
||||
private static void verifyParameters(DependsCommand args) throws ParameterException {
|
||||
String[] granularities = args.getGranularity();
|
||||
List<String> validGranularities = Arrays.asList(new String[]{"file", "method", "structure"});
|
||||
for (String g:granularities){
|
||||
if (!validGranularities.contains(g)){
|
||||
throw new ParameterException("granularity is invalid:"+g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void executeCommand(DependsCommand args) throws ParameterException {
|
||||
String lang = args.getLang();
|
||||
|
@ -114,14 +125,13 @@ public class Main {
|
|||
System.out.println("Dependency done....");
|
||||
|
||||
//step2: generate dependencies matrix
|
||||
DependencyGenerator dependencyGenerator = getDependencyGenerator(args, inputDir);
|
||||
DependencyMatrix matrix = dependencyGenerator.identifyDependencies(entityRepo,args.getTypeFilter());
|
||||
//step3: output
|
||||
if (args.getGranularity().startsWith("L")) {
|
||||
matrix = new MatrixLevelReducer(matrix,args.getGranularity().substring(1)).shrinkToLevel();
|
||||
List<DependencyGenerator> dependencyGenerators = getDependencyGenerators(args, inputDir);
|
||||
for (DependencyGenerator dependencyGenerator:dependencyGenerators) {
|
||||
DependencyMatrix matrix = dependencyGenerator.identifyDependencies(entityRepo, args.getTypeFilter());
|
||||
DependencyDumper output = new DependencyDumper(matrix);
|
||||
output.outputResult(outputName+"-"+dependencyGenerator.getType(), outputDir, outputFormat);
|
||||
}
|
||||
DependencyDumper output = new DependencyDumper(matrix);
|
||||
output.outputResult(outputName,outputDir,outputFormat);
|
||||
|
||||
if (args.isOutputExternalDependencies()) {
|
||||
Set<UnsolvedBindings> unsolved = langProcessor.getExternalDependencies();
|
||||
UnsolvedSymbolDumper unsolvedSymbolDumper = new UnsolvedSymbolDumper(unsolved,args.getOutputName(),args.getOutputDir(),
|
||||
|
@ -147,7 +157,7 @@ public class Main {
|
|||
return includeDir;
|
||||
}
|
||||
|
||||
private static DependencyGenerator getDependencyGenerator(DependsCommand app, String inputDir) throws ParameterException {
|
||||
private static List<DependencyGenerator> getDependencyGenerators(DependsCommand app, String inputDir) throws ParameterException {
|
||||
FilenameWritter filenameWritter = new EmptyFilenameWritter();
|
||||
if (!StringUtils.isEmpty(app.getNamePathPattern())) {
|
||||
if (app.getNamePathPattern().equals("dot")||
|
||||
|
@ -164,34 +174,29 @@ public class Main {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* by default use file dependency generator */
|
||||
DependencyGenerator dependencyGenerator = new FileDependencyGenerator();
|
||||
if (!StringUtils.isEmpty(app.getGranularity())) {
|
||||
List<DependencyGenerator> dependencyGenerators = new ArrayList<>();
|
||||
for (int i=0;i<app.getGranularity().length;i++) {
|
||||
/* by default use file dependency generator */
|
||||
DependencyGenerator dependencyGenerator = null;
|
||||
/* method parameter means use method generator */
|
||||
if (app.getGranularity().equals("method"))
|
||||
if (app.getGranularity()[i].equals("method"))
|
||||
dependencyGenerator = new FunctionDependencyGenerator();
|
||||
else if (app.getGranularity().equals("structure"))
|
||||
else if (app.getGranularity()[i].equals("file"))
|
||||
dependencyGenerator = new FileDependencyGenerator();
|
||||
else if (app.getGranularity()[i].equals("structure"))
|
||||
dependencyGenerator = new StructureDependencyGenerator();
|
||||
else if (app.getGranularity().equals("file"))
|
||||
/*no action*/;
|
||||
else if (app.getGranularity().startsWith("L"))
|
||||
/*no action*/;
|
||||
else
|
||||
throw new ParameterException("Unknown granularity parameter:" + app.getGranularity());
|
||||
}
|
||||
|
||||
if (app.isStripLeadingPath() ||
|
||||
app.getStrippedPaths().length>0) {
|
||||
dependencyGenerator.setLeadingStripper(new LeadingNameStripper(app.isStripLeadingPath(), inputDir, app.getStrippedPaths()));
|
||||
dependencyGenerators.add(dependencyGenerator);
|
||||
if (app.isStripLeadingPath() ||
|
||||
app.getStrippedPaths().length > 0) {
|
||||
dependencyGenerator.setLeadingStripper(new LeadingNameStripper(app.isStripLeadingPath(), inputDir, app.getStrippedPaths()));
|
||||
}
|
||||
if (app.isDetail()) {
|
||||
dependencyGenerator.setGenerateDetail(true);
|
||||
}
|
||||
dependencyGenerator.setFilenameRewritter(filenameWritter);
|
||||
}
|
||||
|
||||
if (app.isDetail()) {
|
||||
dependencyGenerator.setGenerateDetail(true);
|
||||
}
|
||||
|
||||
dependencyGenerator.setFilenameRewritter(filenameWritter);
|
||||
return dependencyGenerator;
|
||||
return dependencyGenerators;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,11 +51,10 @@ import static depends.deptypes.DependencyType.POSSIBLE_DEP;
|
|||
public abstract class DependencyGenerator {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DependencyGenerator.class);
|
||||
|
||||
public abstract String getType();
|
||||
public DependencyMatrix identifyDependencies(EntityRepo entityRepo, List<String> typeFilter) {
|
||||
System.out.println("dependencie data generating...");
|
||||
DependencyMatrix dependencyMatrix = build(entityRepo, typeFilter);
|
||||
entityRepo.clear();
|
||||
System.out.println("reorder dependency matrix...");
|
||||
dependencyMatrix = new OrderedMatrixGenerator(dependencyMatrix).build();
|
||||
System.out.println("Dependencies data generating done successfully...");
|
||||
|
|
|
@ -40,6 +40,11 @@ public class FileDependencyGenerator extends DependencyGenerator{
|
|||
return (entity instanceof FileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "file";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int upToOutputLevelEntityId(EntityRepo entityRepo, Entity entity) {
|
||||
Entity ancestor = entity.getAncestorOfType(FileEntity.class);
|
||||
|
|
|
@ -56,4 +56,9 @@ public class FunctionDependencyGenerator extends DependencyGenerator {
|
|||
return ancestor.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "method";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,11 @@ public class StructureDependencyGenerator extends DependencyGenerator{
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "structure";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int upToOutputLevelEntityId(EntityRepo entityRepo, Entity entity) {
|
||||
Entity ancestor = getAncestorOfType(entity);
|
||||
|
|
Loading…
Reference in New Issue