-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathBuildTools.java
More file actions
157 lines (149 loc) · 4.18 KB
/
Copy pathBuildTools.java
File metadata and controls
157 lines (149 loc) · 4.18 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package javaforce.utils;
import java.io.*;
import java.util.*;
import javaforce.*;
/** Build Tools
*
* @author pquiring
*/
public class BuildTools {
private XML xml;
private Properties versions;
private String file;
private boolean debug = false;
public boolean loadXML(String xmlfile) {
this.file = xmlfile;
xml = new XML();
try {
xml.read(new FileInputStream(xmlfile));
return true;
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
return false;
}
public String getTag(String name) {
XML.XMLTag tag = xml.getTag(new String[] {"project", name});
if (tag == null) return "";
return tag.content;
}
public String getTag(String[] path) {
XML.XMLTag tag = xml.getTag(path);
if (tag == null) return "";
return tag.content;
}
public String getProperty(String name) {
//<project> <property name="name" value="value">
int cnt = xml.root.getChildCount();
for(int a=0;a<cnt;a++) {
XML.XMLTag tag = xml.root.getChildAt(a);
if (!tag.name.equals("property")) continue;
int attrs = tag.attrs.size();
String attrName = null;
String attrValue = null;
for(int b=0;b<attrs;b++) {
XML.XMLAttr attr = tag.attrs.get(b);
if (attr.name.equals("name")) {
attrName = attr.value;
}
if (attr.name.equals("value")) {
attrValue = attr.value;
}
if (attr.name.equals("location")) {
attrValue = attr.value;
}
}
if (attrName != null && attrName.equals(name)) {
//TODO : expand ${} tags
if (attrValue.equals("${javaforce-version}")) {
attrValue = getVersion("javaforce-version");
}
return attrValue;
}
}
if (debug) JFLog.log("error:property not found:" + name + ":file=" + file);
return "";
}
public String getVersion(String name) {
String home = getProperty("home");
if (versions == null) {
try {
versions = new Properties();
FileInputStream fis = new FileInputStream(home + "/versions.properties");
versions.load(fis);
fis.close();
} catch (Exception e) {
JFLog.log(e);
return null;
}
}
return versions.getProperty(name);
}
public static void chmod_x(String file) {
new File(file).setExecutable(true);
}
public static boolean checkFiles(String files_lst) {
try {
File files = new File(files_lst);
if (!files.exists()) {
JFLog.log("Error:" + files_lst + " not found");
return false;
}
cleanFiles(files_lst);
FileInputStream fis = new FileInputStream(files);
String[] lns = new String(fis.readAllBytes()).split("\n");
fis.close();
for(String ln : lns) {
if (ln.length() == 0) continue;
File file = new File(ln);
if (!file.exists()) {
JFLog.log("Error:File not found:" + ln);
return false;
}
}
return true;
} catch (Exception e) {
JFLog.log(e);
return false;
}
}
public String[] getSubProjects() {
if (!file.endsWith(File.separator + "build.xml")) {
return new String[0];
}
if (!new File("projects.lst").exists()) {
return new String[0];
}
try {
byte[] data = JF.readFile("projects.lst");
String[] subs = new String(data).replaceAll("\r", "").split("\n");
//remove empty lines
ArrayList<String> list = new ArrayList<>();
for(String sub : subs) {
sub = sub.trim();
if (sub.length() == 0) continue;
if (sub.equals("build")) continue;
list.add(sub);
}
return list.toArray(JF.StringArrayType);
} catch (Exception e) {
return new String[0];
}
}
public static void cleanFiles(String files) {
//remove \r from files
try {
FileInputStream fis = new FileInputStream(files);
String content = new String(fis.readAllBytes());
fis.close();
String clean = content.replaceAll("\r", "");
if (content.equals(clean)) return;
FileOutputStream fos = new FileOutputStream(files);
fos.write(clean.getBytes());
fos.close();
} catch (Exception e) {
JFLog.log(e);
}
}
}