src/main/java/de/unixwork/uwproj/TargetData.java

Sun, 17 Sep 2023 12:15:14 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 17 Sep 2023 12:15:14 +0200
branch
configure-evo
changeset 57
df03772f7429
parent 41
75ee588d5d9e
child 78
c3a62e0baa9e
permissions
-rw-r--r--

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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
16 public static TargetData parse(Element element) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
17 var target = new TargetData();
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
18
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 NodeList nodes = element.getChildNodes();
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
25 if (n.equals("define")) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
26 target.addDefine(
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
27 elm.getAttribute("name"),
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
28 elm.getAttribute("value")
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
29 );
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
30 } else if (n.equals("dependencies")) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
31 Arrays.stream(Util.getContent(elm).split(","))
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
32 .map(String::trim)
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
33 .forEach(target::addDependency);
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
34 } else if (n.equals("make")) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
39
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
40 return target;
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 }
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
54
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
55 public void addDefine(String name, String value) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
56 if (name.isBlank()) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
57 throw new IllegalArgumentException("define element requires name attribute");
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
58 }
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
59 defines.add(new Define(name, value));
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
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 }

mercurial