forked from tushartushar/DesigniteJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputArgs.java
More file actions
130 lines (115 loc) · 3.16 KB
/
InputArgs.java
File metadata and controls
130 lines (115 loc) · 3.16 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package Designite;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import Designite.utils.Constants;
public class InputArgs {
private static final String SOURCE = "[SOURCE FOLDER]";
private static final String OUTPUT = "[OUTPUT FOLDER]";
private String batchFilePath;
private String sourceFolder;
private String outputFolder;
public InputArgs(String batchFilePath) {
this.batchFilePath = batchFilePath;
outputFolder = "";
readInputArgs();
checkEssentialInputs();
setCsvDirectoryPath();
}
public String getSourceFolder() {
return sourceFolder;
}
public String getOutputFolder() {
return outputFolder;
}
//At least, the source folder must be specified
private void checkEssentialInputs() {
if (sourceFolder==null)
{
System.out.println("Input source folder is not specified.");
throw new IllegalArgumentException();
}
File file = new File(sourceFolder);
if (!(file.exists() && file.isDirectory()))
{
System.out.println("Input source folder path is not valid.");
throw new IllegalArgumentException();
}
}
private void readInputArgs() {
File file = new File(batchFilePath);
if(file.exists() && !file.isDirectory()) {
readInputArgsFromFile(file);
}
else
{
System.out.println("The specified file doesn't exists. Please provide absolute path of batch input file.");
throw new IllegalArgumentException();
}
}
private void readInputArgsFromFile(File file) {
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
String line = null;
InputStates presentState = InputStates.DEFAULT;
while ((line = br.readLine()) != null) {
switch(line.trim().toUpperCase()){
case SOURCE:
presentState = InputStates.SOURCE;
break;
case OUTPUT:
presentState = InputStates.OUTPUT;
break;
default:
if (presentState.equals(InputStates.SOURCE)){
if(line.trim().length()>0)
sourceFolder = line.trim();
}
if (presentState.equals(InputStates.OUTPUT)){
if(line.trim().length()>0)
outputFolder = line.trim();
}
}
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}
}
/***
* Sets the value of the directory name
* where the output CSVs will be stored.
*/
private void setCsvDirectoryPath() {
Constants.CSV_DIRECTORY_PATH =
getOutputFolder() +
File.separator + this.getProjectName() +
"_csv";
}
/***
* Analyzes the provided <b>sourceFolder</b> variable and
* extracts the name of the project.
* @return A String with the name of the project.
* When the given sourceFolder has a value of <i>src</i>
* or <i>source</i> then the method returns
* the name of the direct parent directory
*/
public String getProjectName() {
File temp = new File(sourceFolder);
if (temp.getName().equals("src") || temp.getName().equals("source")) {
return new File(temp.getParent()).getName();
} else {
return new File(sourceFolder).getName();
}
}
private enum InputStates{
SOURCE,
OUTPUT,
DEFAULT
}
}