Skip to content

Commit 64ac4ff

Browse files
refactor main classes
1 parent c35f69e commit 64ac4ff

File tree

3 files changed

+87
-94
lines changed

3 files changed

+87
-94
lines changed

src/main/java/Main.java

+56-43
Original file line numberDiff line numberDiff line change
@@ -24,84 +24,97 @@ public static void main(String[] args) throws IOException {
2424
XmlFileAnalyzer xmlfileAnalyzer = XmlFileAnalyzer.createFileAnalyzer();
2525

2626
ResultsWriter resultsWriter = ResultsWriter.createResultsWriter();
27-
ClassEntity classEntity;
28-
XmlEntity xmlEntity;
2927

3028

31-
File rootDirectory = new File("G:\\Android\\Apps");
32-
FileFilter filter = new FileFilter() {
33-
@Override
34-
public boolean accept(File pathname) {
35-
return pathname.isDirectory();
36-
}
37-
};
38-
File[] directorie = rootDirectory.listFiles( filter);
39-
// System.out.println(directorie.length);
40-
//
41-
File[] p1 = Arrays.copyOfRange(directorie, Integer.valueOf(args[0]), Integer.valueOf(args[1]));
29+
File[] dictList = getDirectoriesList();
30+
4231

43-
File[] directories = p1;
32+
33+
File[] RangeOfDirectoriesList = Arrays.copyOfRange(dictList, Integer.valueOf(args[0]), Integer.valueOf(args[1]));
34+
35+
File[] directories = RangeOfDirectoriesList;
4436

4537
for (File dir: directories){
4638

4739
//recursively identify all files with the specified extension in the specified directory
4840

49-
Util.writeOperationLogEntry("Identify all '"+fileExtension+"' test files", Util.OperationStatus.Started);
41+
Util.writeOperationLogEntry("Identify all '"+fileExtension+"' java files", Util.OperationStatus.Started);
5042
FileWalker fw = new FileWalker();
5143
List<List<Path>> files = fw.getFiles(dir.getPath(),true,fileExtension,secondFileExtension);
52-
Util.writeOperationLogEntry("Identify all '"+fileExtension+"' test files", Util.OperationStatus.Completed);
44+
Util.writeOperationLogEntry("Identify all '"+fileExtension+"' java files", Util.OperationStatus.Completed);
45+
46+
47+
// foreach of the identified 'java' files, obtain details about the methods that they contain
48+
Util.writeOperationLogEntry("Obtain method details", Util.OperationStatus.Started);
49+
for (Path file : files.get(0)) {
5350

51+
checkJavaFiles(fileAnalyzer, resultsWriter, file);
52+
53+
}
54+
Util.writeOperationLogEntry("Obtain method details", Util.OperationStatus.Completed);
5455

55-
//foreach of the identified 'java' files, obtain details about the methods that they contain
56-
// Util.writeOperationLogEntry("Obtain method details", Util.OperationStatus.Started);
57-
// for (Path file : files.get(0)) {
58-
// try {
59-
// classEntity = fileAnalyzer.runAnalysis(file);
60-
// resultsWriter.outputToCSV(classEntity);
61-
// } catch (Exception e) {
62-
// Util.writeException(e, "File: " + file.toAbsolutePath().toString());
63-
// }
64-
// }
65-
// Util.writeOperationLogEntry("Obtain method details", Util.OperationStatus.Completed);
6656

6757
Util.writeOperationLogEntry("Obtain Xml details"+files.get(1).size(), Util.OperationStatus.Started);
6858
for (Path file : files.get(1)) {
69-
try {
7059

60+
checkXmlFiles(xmlfileAnalyzer, resultsWriter, file);
61+
}
62+
Util.writeOperationLogEntry("Obtain Xml details", Util.OperationStatus.Completed);
7163

72-
if (file.toAbsolutePath().toString().toLowerCase().contains("\\res\\")
73-
|| file.getFileName().toString().equalsIgnoreCase("AndroidManifest.xml")
74-
|| file.toAbsolutePath().toString().toLowerCase().contains("\\resources\\")) {
7564

65+
}
7666

77-
if (file.toAbsolutePath().toString().toLowerCase().contains("\\layout\\")
78-
|| file.getFileName().toString().equalsIgnoreCase("AndroidManifest.xml")){
7967

80-
xmlEntity = xmlfileAnalyzer.runAnalysis(file);
8168

82-
resultsWriter.outputXmlToCSV(xmlEntity);
8369

84-
}
8570

86-
}
8771

8872

89-
} catch (Exception e) {
90-
Util.writeException(e, "XML: " + file.toAbsolutePath().toString());
91-
}
92-
}
93-
Util.writeOperationLogEntry("Obtain Xml details", Util.OperationStatus.Completed);
9473

74+
resultsWriter.closeOutputFiles();
75+
}
76+
77+
public static File[] getDirectoriesList() {
78+
File rootDirectory = new File("E:\\P");
79+
FileFilter filter = pathname -> pathname.isDirectory();
80+
81+
return rootDirectory.listFiles( filter);
82+
}
9583

84+
private static void checkJavaFiles(FileAnalyzer fileAnalyzer, ResultsWriter resultsWriter, Path file) throws IOException {
85+
ClassEntity classEntity;
86+
try {
87+
classEntity = fileAnalyzer.runAnalysis(file);
88+
resultsWriter.outputToCSV(classEntity);
89+
} catch (Exception e) {
90+
Util.writeException(e, "File: " + file.toAbsolutePath().toString());
9691
}
92+
}
9793

94+
private static void checkXmlFiles(XmlFileAnalyzer xmlfileAnalyzer, ResultsWriter resultsWriter, Path file) throws IOException {
95+
XmlEntity xmlEntity;
96+
try {
9897

9998

99+
if (file.toAbsolutePath().toString().toLowerCase().contains("\\res\\")
100+
|| file.getFileName().toString().equalsIgnoreCase("AndroidManifest.xml")
101+
|| file.toAbsolutePath().toString().toLowerCase().contains("\\resources\\")) {
100102

101103

104+
if (file.toAbsolutePath().toString().toLowerCase().contains("\\layout\\")
105+
|| file.getFileName().toString().equalsIgnoreCase("AndroidManifest.xml")){
102106

107+
xmlEntity = xmlfileAnalyzer.runAnalysis(file);
103108

109+
resultsWriter.outputXmlToCSV(xmlEntity);
104110

105-
resultsWriter.closeOutputFiles();
111+
}
112+
113+
}
114+
115+
116+
} catch (Exception e) {
117+
Util.writeException(e, "XML: " + file.toAbsolutePath().toString());
118+
}
106119
}
107120
}

src/main/java/MainMultipleThread.java

+28-48
Original file line numberDiff line numberDiff line change
@@ -25,75 +25,55 @@ public static void main(String[] args) throws Exception {
2525
// System.out.println(files.get(0).size());
2626

2727

28-
Thread t = new Thread() {
29-
@Override
30-
public void run() { // override the run() to specify the running behavior
28+
File[] dictList = Main.getDirectoriesList();
3129

32-
Process p = null;
33-
try {
34-
p = Runtime.getRuntime().exec("java -jar C:\\Users\\khalid\\Documents\\GitHub\\FileDetector\\classes\\artifacts\\FileDetector_jar\\FileDetector.jar 0 662");
35-
BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
36-
String line;
30+
int len = dictList.length;
31+
int diffByFive = len /4;
3732

38-
while ((line = is.readLine()) != null)
39-
System.out.println("p "+line);
33+
int starRange = 0;
34+
int endRange = diffByFive;
35+
for (int i = 0; i <4; i++) {
4036

41-
} catch (IOException e) {
42-
e.printStackTrace();
43-
}
4437

38+
System.out.println("run process start"+starRange+" end "+endRange);
4539

40+
runFileDetector( String.valueOf(starRange), String.valueOf(endRange));
4641

47-
}
48-
};
49-
t.start(); // call back run()
50-
42+
Thread.sleep(400);
5143

52-
Thread t1 = new Thread() {
53-
@Override
54-
public void run() { // override the run() to specify the running behavior
55-
try {
56-
Process p1 = Runtime.getRuntime().exec("java -jar C:\\Users\\khalid\\Documents\\GitHub\\FileDetector\\classes\\artifacts\\FileDetector_jar\\FileDetector.jar 663 1324");
57-
BufferedReader is1 = new BufferedReader(new InputStreamReader(p1.getInputStream()));
58-
String line1;
44+
starRange = endRange+1;
45+
endRange = endRange+diffByFive;
5946

60-
while ((line1 = is1.readLine()) != null)
61-
System.out.println("p1 "+line1);
62-
} catch (IOException e) {
63-
e.printStackTrace();
64-
}
6547

48+
}
6649

67-
}
68-
};
69-
t1.start(); // call back run()
70-
71-
Thread t2 = new Thread() {
72-
@Override
73-
public void run() { // override the run() to specify the running behavior
7450

75-
try {
76-
Process p2 = Runtime.getRuntime().exec("java -jar C:\\Users\\khalid\\Documents\\GitHub\\FileDetector\\classes\\artifacts\\FileDetector_jar\\FileDetector.jar 1325 1986");
77-
BufferedReader is2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));
78-
String line2;
7951

80-
while ((line2 = is2.readLine()) != null)
81-
System.out.println("p2 "+line2);
82-
} catch (IOException e) {
83-
e.printStackTrace();
84-
}
8552

8653

87-
}
88-
};
89-
t2.start(); // call back run()
54+
}
9055

56+
private static void runFileDetector(String start, String end) {
57+
String jarURl = "E:\\Khalid\\GitHub\\FileDetector\\classes\\artifacts\\FileDetector_jar\\FileDetector.jar";
58+
Thread t = new Thread(() -> { // override the run() to specify the running behavior
9159

60+
Process p = null;
61+
try {
62+
p = Runtime.getRuntime().exec("java -jar "+jarURl+" "+start+" "+end+"");
63+
BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
64+
String line;
9265

66+
while ((line = is.readLine()) != null)
67+
System.out.println("Process "+start+" end "+end+" output ");
9368

69+
} catch (IOException e) {
70+
e.printStackTrace();
71+
}
9472

9573

9674

75+
});
76+
t.start(); // call back run()
9777
}
9878

9979

src/main/java/entity/ClassEntity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ public String getRelativeFilePath() {
7373
String filePath = path.toAbsolutePath().toString();
7474
String[] splitString = filePath.split("\\\\");
7575
StringBuilder stringBuilder = new StringBuilder();
76-
for (int i = 0; i < 5; i++) {
76+
for (int i = 0; i < 4; i++) {
7777
stringBuilder.append(splitString[i] + "\\");
7878
}
7979
return filePath.substring(stringBuilder.toString().length()).replace("\\", "/");
8080
}
8181

8282
public String getAppName() {
8383
String filePath = path.toAbsolutePath().toString();
84-
return filePath.split("\\\\")[3];
84+
return filePath.split("\\\\")[2];
8585
}
8686

8787
public String getTagName() {
8888
String filePath = path.toAbsolutePath().toString();
8989

90-
return filePath.split("\\\\")[4];
90+
return filePath.split("\\\\")[3];
9191
}
9292
}

0 commit comments

Comments
 (0)