1 /* |
|
2 * To change this license header, choose License Headers in Project Properties. |
|
3 * To change this template file, choose Tools | Templates |
|
4 * and open the template in the editor. |
|
5 */ |
|
6 package de.unixwork.uwproj; |
1 package de.unixwork.uwproj; |
7 |
2 |
8 import org.w3c.dom.Element; |
3 import org.w3c.dom.Element; |
9 import org.w3c.dom.Node; |
4 import org.w3c.dom.Node; |
10 import org.w3c.dom.NodeList; |
5 import org.w3c.dom.NodeList; |
11 |
6 |
12 import java.util.LinkedList; |
7 import java.util.*; |
13 import java.util.List; |
8 import java.util.stream.Collectors; |
14 |
9 |
15 /** |
10 import static de.unixwork.uwproj.Util.isNullOrBlank; |
16 * |
11 |
17 * @author olaf |
|
18 */ |
|
19 public class Dependency { |
12 public class Dependency { |
20 private String name; |
13 private String name; |
21 private String platform; |
14 private String platform; |
22 private String not; |
15 private String not; |
23 |
16 |
24 private List<Flags> flags = new LinkedList<>(); |
17 private final List<ConfigVar> flags = new LinkedList<>(); |
25 private List<PkgConfigPackage> pkgconfig = new LinkedList<>(); |
18 private final List<PkgConfigPackage> pkgconfig = new LinkedList<>(); |
26 private List<String> tests = new LinkedList<>(); |
19 private final List<String> tests = new LinkedList<>(); |
27 private StringBuilder make = new StringBuilder(); |
20 private final StringBuilder make = new StringBuilder(); |
28 |
21 |
29 private List<String> lang = new LinkedList<>(); |
22 private final List<String> lang = new LinkedList<>(); |
30 |
23 |
31 private boolean abortOnError = false; |
24 private boolean abortOnError = false; |
32 |
25 |
33 private int num = 0; |
26 private int num = 0; |
34 |
27 |
35 public static Dependency parse(Element element) throws Exception { |
28 public static Dependency parse(Element element) throws Exception { |
36 Dependency d = new Dependency(); |
29 Dependency d = new Dependency(); |
37 |
30 |
38 String name = element.getAttribute("name"); |
31 String name = element.getAttribute("name"); |
39 String platform = element.getAttribute("platform"); |
32 String platform = element.getAttribute("platform"); |
40 String not = element.getAttribute("not"); |
33 String not = element.getAttribute("not"); |
41 if(name.length() > 0) { |
34 if (!name.isEmpty()) { |
42 d.setName(name); |
35 d.setName(name); |
43 } |
36 } |
44 if(platform.length() > 0) { |
37 if (!platform.isEmpty()) { |
45 d.setPlatform(platform); |
38 d.setPlatform(platform); |
46 } |
39 } |
47 if(not.length() > 0) { |
40 if (!not.isEmpty()) { |
48 d.setNotString(not); |
41 d.setNotString(not); |
49 } |
42 } |
50 |
43 |
51 NodeList nodes = element.getChildNodes(); |
44 NodeList nodes = element.getChildNodes(); |
52 for(int i=0;i<nodes.getLength();i++) { |
45 for (int i = 0; i < nodes.getLength(); i++) { |
53 Node node = nodes.item(i); |
46 Node node = nodes.item(i); |
54 if (node.getNodeType() == Node.ELEMENT_NODE) { |
47 if (node.getNodeType() == Node.ELEMENT_NODE) { |
55 Element elm = (Element)node; |
48 Element elm = (Element) node; |
56 String n = elm.getNodeName(); |
49 String n = elm.getNodeName(); |
57 if(n.equals("cflags") || n.equals("ldflags")) { |
50 if (n.equals("cflags") || n.equals("ldflags")) { |
58 Flags f = Flags.parse(elm); |
51 Optional.ofNullable(ConfigVar.parse(elm, true)).ifPresent(d::addFlags); |
59 d.addFlags(f); |
52 } else if (n.equals("pkgconfig")) { |
60 } else if(n.equals("pkgconfig")) { |
|
61 PkgConfigPackage pcp = PkgConfigPackage.parse(elm); |
53 PkgConfigPackage pcp = PkgConfigPackage.parse(elm); |
62 d.addPkgconfig(pcp); |
54 d.addPkgconfig(pcp); |
63 } else if(n.equals("test")) { |
55 } else if (n.equals("test")) { |
64 d.tests.add(Xml.getContent(elm)); |
56 d.tests.add(Util.getContent(elm)); |
65 } else if(n.equals("make")) { |
57 } else if (n.equals("make")) { |
66 String m = Xml.getContent(elm); |
58 String m = Util.getContent(elm); |
67 d.addMake(m); |
59 d.addMake(m); |
68 } else if(n.equals("lang")) { |
60 } else if (n.equals("lang")) { |
69 d.lang.add(n.trim().toLowerCase()); |
61 d.lang.add(n.trim().toLowerCase()); |
70 } |
62 } |
71 } |
63 } |
72 } |
64 } |
73 |
65 |
74 return d; |
66 return d; |
75 } |
67 } |
76 |
68 |
77 public String getName() { |
69 public String getName() { |
78 return name; |
70 return name; |
79 } |
71 } |
80 |
72 |
81 public void setName(String name) { |
73 public void setName(String name) { |
83 } |
75 } |
84 |
76 |
85 public String getPlatform() { |
77 public String getPlatform() { |
86 return platform; |
78 return platform; |
87 } |
79 } |
88 |
80 |
89 public String getFullName() { |
81 public String getFullName() { |
90 if(platform == null || platform.length() == 0) { |
82 if (isNullOrBlank(platform)) { |
91 return name; |
83 return name; |
92 } else { |
84 } else { |
93 return name+" platform=\""+platform+'"'; |
85 return name + " platform=\"" + platform + '"'; |
94 } |
86 } |
95 } |
87 } |
96 |
88 |
97 public void setNotString(String not) { |
89 public void setNotString(String not) { |
98 this.not = not; |
90 this.not = not; |
99 } |
91 } |
100 |
92 |
101 public List<String> getNotList() { |
93 public List<String> getNotList() { |
102 List<String> notPlatforms = new LinkedList<>(); |
94 return isNullOrBlank(not) ? |
103 if(not != null) { |
95 Collections.emptyList() : |
104 String[] n = not.split(","); |
96 Arrays.stream(not.split(",")).map(String::trim).collect(Collectors.toList()); |
105 for(String s : n) { |
|
106 notPlatforms.add(s); |
|
107 } |
|
108 } |
|
109 return notPlatforms; |
|
110 } |
97 } |
111 |
98 |
112 public void setPlatform(String platform) { |
99 public void setPlatform(String platform) { |
113 this.platform = platform; |
100 this.platform = platform; |
114 } |
101 } |
115 |
102 |
116 public List<Flags> getFlags() { |
103 public List<ConfigVar> getFlags() { |
117 return flags; |
104 return flags; |
118 } |
105 } |
119 |
106 |
120 public void addFlags(Flags flags) { |
107 public void addFlags(ConfigVar var) { |
121 this.flags.add(flags); |
108 this.flags.add(var); |
122 } |
109 } |
123 |
110 |
124 public List<PkgConfigPackage> getPkgconfig() { |
111 public List<PkgConfigPackage> getPkgconfig() { |
125 return pkgconfig; |
112 return pkgconfig; |
126 } |
113 } |
134 } |
121 } |
135 |
122 |
136 public void setAbortOnError(boolean abortOnError) { |
123 public void setAbortOnError(boolean abortOnError) { |
137 this.abortOnError = abortOnError; |
124 this.abortOnError = abortOnError; |
138 } |
125 } |
139 |
126 |
140 public int getNum() { |
127 public int getNum() { |
141 return num; |
128 return num; |
142 } |
129 } |
143 |
130 |
144 public void setNum(int num) { |
131 public void setNum(int num) { |
145 this.num = num; |
132 this.num = num; |
146 } |
133 } |
147 |
134 |
148 public List<String> getTests() { |
135 public List<String> getTests() { |
149 return tests; |
136 return tests; |
150 } |
137 } |
151 |
138 |
152 public void addMake(String m) { |
139 public void addMake(String m) { |
153 make.append(m.trim()); |
140 make.append(m.trim()); |
154 make.append('\n'); |
141 make.append('\n'); |
155 } |
142 } |
156 |
143 |
157 public String getMake() { |
144 public String getMake() { |
158 return make.toString(); |
145 return make.toString(); |
159 } |
146 } |
160 |
147 |
161 public List<String> getLang() { |
148 public List<String> getLang() { |
162 return lang; |
149 return lang; |
163 } |
150 } |
164 } |
151 } |