Sun, 17 Sep 2023 12:15:14 +0200
invert logic of dependency check
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | package de.unixwork.uwproj; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | import org.w3c.dom.Element; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | import org.w3c.dom.Node; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | import org.w3c.dom.NodeList; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | |
41 | 7 | import java.util.Arrays; |
40
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
8 | import java.util.LinkedList; |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
9 | import java.util.List; |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
10 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | public class TargetData { |
40
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
12 | private final List<Define> defines = new LinkedList<>(); |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
13 | private final List<String> dependencies = new LinkedList<>(); |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
14 | private final StringBuilder make = new StringBuilder(); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | |
41 | 16 | public static TargetData parse(Element element) { |
17 | var target = new TargetData(); | |
18 | ||
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | NodeList nodes = element.getChildNodes(); |
41 | 20 | for (int i = 0; i < nodes.getLength(); i++) { |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | Node node = nodes.item(i); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | if (node.getNodeType() == Node.ELEMENT_NODE) { |
41 | 23 | Element elm = (Element) node; |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | String n = elm.getNodeName(); |
41 | 25 | if (n.equals("define")) { |
26 | target.addDefine( | |
27 | elm.getAttribute("name"), | |
28 | elm.getAttribute("value") | |
29 | ); | |
30 | } else if (n.equals("dependencies")) { | |
31 | Arrays.stream(Util.getContent(elm).split(",")) | |
32 | .map(String::trim) | |
33 | .forEach(target::addDependency); | |
34 | } else if (n.equals("make")) { | |
35 | target.addMake(Util.getContent(elm)); | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | } |
41 | 39 | |
40 | return target; | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | } |
41 | 42 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | public List<Define> getDefines() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | return defines; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | public List<String> getDependencies() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | return dependencies; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | public String getMake() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | return make.toString(); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | } |
41 | 54 | |
55 | public void addDefine(String name, String value) { | |
56 | if (name.isBlank()) { | |
57 | throw new IllegalArgumentException("define element requires name attribute"); | |
58 | } | |
59 | defines.add(new Define(name, value)); | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | } |
41 | 61 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | public void addDependency(String d) { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | dependencies.add(d); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | } |
41 | 65 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | public void addMake(String m) { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | make.append(m.trim()); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | make.append('\n'); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | } |