forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildTools.java
More file actions
104 lines (97 loc) · 2.7 KB
/
Copy pathBuildTools.java
File metadata and controls
104 lines (97 loc) · 2.7 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
package javaforce.utils;
/** Build Tools
*
* @author pquiring
*/
import java.io.*;
import javaforce.*;
public class BuildTools {
private XML xml;
private BuildTools 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 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) {
versions = new BuildTools();
versions.loadXML(home + "/versions.xml");
}
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;
}
FileInputStream fis = new FileInputStream(files);
byte[] lst = fis.readAllBytes();
String[] lns = new String(lst).replaceAll("\r","").split("\n");
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;
}
}
}