forked from multilang-depends/depends
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
191 changed files
with
7,150 additions
and
4,810 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*.log | ||
.idea/ | ||
out/ | ||
data/ | ||
*.DS_Store | ||
/target/ | ||
.classpath | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package depends; | ||
|
||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = "depends") | ||
public class DependsCommand { | ||
@Parameters(index = "0", description = "The lanauge of project files: [java, cpp]") | ||
private String lang; | ||
@Parameters(index = "1", description = "The directory to be analyzed") | ||
private String src; | ||
@Parameters(index = "2", description = "The output file name") | ||
private String output; | ||
@Option(names = {"-f", "--format"},split=",", description = "the output format: [json(default),xml,excel,detail(text format),dot]") | ||
private String[] format=new String[]{"json"}; | ||
@Option(names = {"-d", "--dir"}, description = "The output directory") | ||
private String dir; | ||
@Option(names = {"-m", "--map"}, description = "Output DV8 dependency map file.") | ||
private boolean dv8map = true; | ||
@Option(names = {"-s", "--strip-leading-path"}, description = "Strip the leading path.") | ||
private boolean stripLeadingPath = false; | ||
@Option(names = {"-g", "--granularity"}, description = "Granularity of dependency.[file(default),method]") | ||
private String granularity="file"; | ||
@Option(names = {"-p", "--namepattern"}, description = "The name path pattern.[default(/),dot(.)") | ||
private String namePathPattern="default"; | ||
@Option(names = {"-i","--includes"},split=",", description = "The files of searching path") | ||
private String[] includes = new String[] {}; | ||
@Option(names = {"-h","--help"}, usageHelp = true, description = "display this help and exit") | ||
boolean help; | ||
public String getLang() { | ||
return lang; | ||
} | ||
public void setLang(String lang) { | ||
this.lang = lang; | ||
} | ||
public String getSrc() { | ||
return src; | ||
} | ||
public void setSrc(String src) { | ||
this.src = src; | ||
} | ||
public String getOutputName() { | ||
return output; | ||
} | ||
public void setOutput(String output) { | ||
this.output = output; | ||
} | ||
public String[] getFormat() { | ||
return format; | ||
} | ||
public String getOutputDir() { | ||
if (dir==null) { | ||
dir = System.getProperty("user.dir"); | ||
} | ||
return dir; | ||
} | ||
public boolean isDv8map() { | ||
return dv8map; | ||
} | ||
public String[] getIncludes() { | ||
return includes; | ||
} | ||
public boolean isHelp() { | ||
return help; | ||
} | ||
public String getGranularity() { | ||
return granularity; | ||
} | ||
public String getNamePathPattern() { | ||
return namePathPattern; | ||
} | ||
public boolean isStripLeadingPath() { | ||
return stripLeadingPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package depends; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
|
||
import depends.addons.DV8MappingFileBuilder; | ||
import depends.extractor.AbstractLangWorker; | ||
import depends.extractor.LangWorkers; | ||
import depends.extractor.cpp.CppWorker; | ||
import depends.extractor.java.JavaWorker; | ||
import depends.extractor.ruby.RubyWorker; | ||
import depends.format.DependencyDumper; | ||
import depends.format.path.DotPathFilenameWritter; | ||
import depends.format.path.EmptyFilenameWritter; | ||
import depends.matrix.DependencyGenerator; | ||
import depends.matrix.FileDependencyGenerator; | ||
import depends.matrix.FilenameWritter; | ||
import depends.matrix.FunctionDependencyGenerator; | ||
import depends.util.FileUtil; | ||
import picocli.CommandLine; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
try { | ||
DependsCommand app = CommandLine.populateCommand(new DependsCommand(), args); | ||
if (app.help) { | ||
CommandLine.usage(new DependsCommand(), System.out); | ||
System.exit(0); | ||
} | ||
executeCommand(app); | ||
} catch (Exception e) { | ||
System.err.println("Exception encountered"); | ||
CommandLine.usage(new DependsCommand(), System.out); | ||
System.exit(0); | ||
} | ||
|
||
} | ||
|
||
private static void executeCommand(DependsCommand app) { | ||
String lang = app.getLang(); | ||
String inputDir = app.getSrc(); | ||
String[] includeDir = app.getIncludes(); | ||
String outputName = app.getOutputName(); | ||
String outputDir = app.getOutputDir(); | ||
String[] outputFormat = app.getFormat(); | ||
if ( app.isDv8map()) { | ||
DV8MappingFileBuilder dv8MapfileBuilder = new DV8MappingFileBuilder(); | ||
dv8MapfileBuilder.create(outputDir+File.separator+"depends-dv8map.json"); | ||
} | ||
|
||
inputDir = FileUtil.uniqFilePath(inputDir); | ||
LangWorkers.getRegistry().register(new JavaWorker(inputDir, includeDir)); | ||
LangWorkers.getRegistry().register(new CppWorker(inputDir, includeDir)); | ||
LangWorkers.getRegistry().register(new RubyWorker(inputDir, includeDir)); | ||
|
||
AbstractLangWorker worker = LangWorkers.getRegistry().getWorkerOf(lang); | ||
if (worker == null) { | ||
System.out.println("Not support this language: " + lang); | ||
return; | ||
} | ||
|
||
long startTime = System.currentTimeMillis(); | ||
DependencyGenerator dependencyGenerator = app.getGranularity().equals("file")? | ||
(new FileDependencyGenerator()):(new FunctionDependencyGenerator()); | ||
worker.setDependencyGenerator(dependencyGenerator); | ||
worker.work(); | ||
if (app.isStripLeadingPath()) { | ||
worker.getDependencies().stripFilenames(inputDir); | ||
} | ||
|
||
FilenameWritter filenameWritter = new EmptyFilenameWritter(); | ||
if (app.getNamePathPattern().equals("dot")) { | ||
filenameWritter = new DotPathFilenameWritter(); | ||
} | ||
worker.getDependencies().reWriteFilenamePattern(filenameWritter ); | ||
DependencyDumper output = new DependencyDumper(worker.getDependencies(),worker.getErrors()); | ||
output.outputResult(outputName,outputDir,outputFormat); | ||
long endTime = System.currentTimeMillis(); | ||
System.out.println("Consumed time: " + (float) ((endTime - startTime) / 1000.00) + " s, or " | ||
+ (float) ((endTime - startTime) / 60000.00) + " min."); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
data/undertestsrc/java/depends/addons/DV8MappingFileBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package depends.addons; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import depends.deptypes.DependencyType; | ||
|
||
class MappingValue{ | ||
int family = 0; | ||
int vendor = 2; | ||
int type = 0; | ||
MappingValue(String orginalName, int typeId){ | ||
this.type = typeId; | ||
} | ||
public int getFamily() { | ||
return family; | ||
} | ||
public void setFamily(int family) { | ||
this.family = family; | ||
} | ||
public int getVendor() { | ||
return vendor; | ||
} | ||
public void setVendor(int vendor) { | ||
this.vendor = vendor; | ||
} | ||
public int getType() { | ||
return type; | ||
} | ||
public void setType(int type) { | ||
this.type = type; | ||
} | ||
} | ||
|
||
class MappingItem { | ||
String name; | ||
MappingValue id; | ||
public MappingItem(String dv8Name, int typeId) { | ||
this.name = dv8Name; | ||
String orginalName = dv8Name; | ||
this.id = new MappingValue(orginalName, typeId); | ||
} | ||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public MappingValue getId() { | ||
return id; | ||
} | ||
public void setId(MappingValue id) { | ||
this.id = id; | ||
} | ||
|
||
} | ||
|
||
public class DV8MappingFileBuilder { | ||
|
||
public void create(String fileName) { | ||
Map<String,MappingItem> values = new HashMap<>(); | ||
ArrayList<String> dependencies = DependencyType.allDependencies(); | ||
for (int i=0;i<dependencies.size();i++) { | ||
String dep = dependencies.get(i); | ||
values.put(dep,new MappingItem(dep,i)); | ||
} | ||
ObjectMapper mapper = new ObjectMapper(); | ||
try { | ||
mapper.writerWithDefaultPrettyPrinter().writeValue(new File(fileName), values); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
data/undertestsrc/java/depends/deptypes/DependencyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package depends.deptypes; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DependencyType { | ||
public static final String IMPORT = "Import"; | ||
public static final String CONTAIN = "Contain"; | ||
public static final String IMPLEMENT = "Implement"; | ||
public static final String INHERIT = "Extend"; | ||
public static final String CALL = "Call"; | ||
public static final String PARAMETER = "Parameter"; | ||
public static final String RETURN = "Return"; | ||
public static final String SET = "Set"; | ||
public static final String USE = "Use"; | ||
public static final String RECEIVE = "Receive"; | ||
public static final String CREATE = "Create"; | ||
public static final String CAST = "Cast"; | ||
public static final String THROW = "Throw"; | ||
public static final String ANNOTATION = "Annotation"; | ||
|
||
public static ArrayList<String> allDependencies() { | ||
ArrayList<String> depedencyTypes = new ArrayList<String>(); | ||
depedencyTypes.add(IMPORT); | ||
depedencyTypes.add(CONTAIN); | ||
depedencyTypes.add(IMPLEMENT); | ||
depedencyTypes.add(INHERIT); | ||
depedencyTypes.add(CALL); | ||
depedencyTypes.add(PARAMETER); | ||
depedencyTypes.add(RETURN); | ||
depedencyTypes.add(SET); | ||
depedencyTypes.add(CREATE); | ||
depedencyTypes.add(USE); | ||
depedencyTypes.add(RECEIVE); | ||
depedencyTypes.add(CAST); | ||
depedencyTypes.add(THROW); | ||
depedencyTypes.add(ANNOTATION); | ||
return depedencyTypes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package depends.entity; | ||
|
||
import java.util.UUID; | ||
|
||
public class AnonymousBlock extends ContainerEntity{ | ||
public AnonymousBlock(Entity parent, Integer id) { | ||
super(UUID.randomUUID().toString(), parent, id); | ||
} | ||
} |
Oops, something went wrong.