add file path re-writter
This commit is contained in:
parent
ffd57d6b1d
commit
a7a5e763fe
19
pom.xml
19
pom.xml
|
@ -134,14 +134,19 @@
|
|||
<version>3.8.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -18,8 +18,12 @@ public class DependsCommand {
|
|||
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")
|
||||
|
@ -63,5 +67,10 @@ public class DependsCommand {
|
|||
public String getGranularity() {
|
||||
return granularity;
|
||||
}
|
||||
|
||||
public String getNamePathPattern() {
|
||||
return namePathPattern;
|
||||
}
|
||||
public boolean isStripLeadingPath() {
|
||||
return stripLeadingPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,11 @@ 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;
|
||||
|
@ -62,6 +65,15 @@ public class Main {
|
|||
(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();
|
||||
|
|
|
@ -57,7 +57,6 @@ abstract public class AbstractLangWorker {
|
|||
System.out.println("dependencie data generating...");
|
||||
dependencyMatrix = dependencyGenerator.build(entityRepo);
|
||||
dependencyMatrix.remapIds(entityRepo);
|
||||
dependencyMatrix.stripFilenames(inputSrcPath);
|
||||
System.out.println("dependencie data generating done successfully...");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package depends.format.path;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import depends.matrix.FilenameWritter;
|
||||
|
||||
public class DotPathFilenameWritter implements FilenameWritter {
|
||||
@Override
|
||||
public String reWrite(String originalPath) {
|
||||
String ext = FilenameUtils.getExtension(originalPath);
|
||||
String path = replaceExt(originalPath,ext);
|
||||
path = path.replace('/', '.');
|
||||
path = path.replace('\\', '.');
|
||||
return path;
|
||||
}
|
||||
|
||||
private String replaceExt(String path, String ext) {
|
||||
if (ext==null) return path;
|
||||
if (ext.length()==0) return path;
|
||||
if (!path.endsWith(ext)) return path;
|
||||
path = path.substring(0,path.length()-ext.length()-1) + "_" + ext;
|
||||
return path;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package depends.format.path;
|
||||
|
||||
import depends.matrix.FilenameWritter;
|
||||
|
||||
public class EmptyFilenameWritter implements FilenameWritter {
|
||||
@Override
|
||||
public String reWrite(String originalPath) {
|
||||
return originalPath;
|
||||
}
|
||||
}
|
|
@ -77,4 +77,10 @@ public class DependencyMatrix {
|
|||
reMappedNodes.set(i, shortPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void reWriteFilenamePattern(FilenameWritter filenameRewritter) {
|
||||
for (int i=0;i<reMappedNodes.size();i++) {
|
||||
reMappedNodes.set(i, filenameRewritter.reWrite(reMappedNodes.get(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package depends.matrix;
|
||||
|
||||
public interface FilenameWritter {
|
||||
String reWrite(String originalPath);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package depends.format.path;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DotPathFilenameWritterTest {
|
||||
|
||||
@Test
|
||||
public void testRewriteFilename() {
|
||||
DotPathFilenameWritter r = new DotPathFilenameWritter();
|
||||
assertEquals(".abc.123_cpp",r.reWrite("/abc/123.cpp"));
|
||||
assertEquals("..abc.123_cpp",r.reWrite("./abc/123.cpp"));
|
||||
assertEquals("..abc.123.1_cpp",r.reWrite("./abc/123.1.cpp"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue