-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMain.java
More file actions
108 lines (91 loc) · 3.65 KB
/
Copy pathMain.java
File metadata and controls
108 lines (91 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package edu.rit.se.testsmells;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
if (args == null) {
System.out.println("Please provide the file containing the paths to the collection of test files");
return;
}
if(!args[0].isEmpty()){
File inputFile = new File(args[0]);
if(!inputFile.exists() || inputFile.isDirectory()) {
System.out.println("Please provide a valid file containing the paths to the collection of test files");
return;
}
}
TestSmellDetector testSmellDetector = TestSmellDetector.createTestSmellDetector();
/*
Read the input file and build the TestFile objects
*/
BufferedReader in = new BufferedReader(new FileReader(args[0]));
String str;
String[] lineItem;
TestFile testFile;
List<TestFile> testFiles = new ArrayList<>();
while ((str = in.readLine()) != null) {
// use comma as separator
lineItem = str.split(",");
//check if the test file has an associated production file
if(lineItem.length ==2){
testFile = new TestFile(lineItem[0], lineItem[1], "");
}
else{
testFile = new TestFile(lineItem[0], lineItem[1], lineItem[2]);
}
testFiles.add(testFile);
}
/*
Initialize the output file - Create the output file and add the column names
*/
ResultsWriter resultsWriter = ResultsWriter.createResultsWriter();
List<String> columnNames;
List<String> columnValues;
columnNames = testSmellDetector.getTestSmellNames();
columnNames.add(0, "App");
columnNames.add(1, "Version");
columnNames.add(2, "TestFilePath");
columnNames.add(3, "ProductionFilePath");
columnNames.add(4, "RelativeTestFilePath");
columnNames.add(5, "RelativeProductionFilePath");
resultsWriter.writeColumnName(columnNames);
/*
Iterate through all test files to detect smells and then write the output
*/
TestFile tempFile;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date;
for (TestFile file : testFiles) {
date = new Date();
System.out.println(dateFormat.format(date) + " Processing: "+file.getTestFilePath());
System.out.println("Processing: "+file.getTestFilePath());
//detect smells
tempFile = testSmellDetector.detectSmells(file);
//write output
columnValues = new ArrayList<>();
columnValues.add(file.getApp());
columnValues.add(file.getTagName());
columnValues.add(file.getTestFilePath());
columnValues.add(file.getProductionFilePath());
columnValues.add(file.getRelativeTestFilePath());
columnValues.add(file.getRelativeProductionFilePath());
for (AbstractSmell smell : tempFile.getTestSmells()) {
try {
columnValues.add(String.valueOf(smell.getHasSmell()));
}
catch (NullPointerException e){
columnValues.add("");
}
}
resultsWriter.writeLine(columnValues);
}
System.out.println("end");
}
}