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

Sat, 20 Jan 2024 15:47:39 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 20 Jan 2024 15:47:39 +0100
changeset 105
4b3e655339cb
parent 92
5a32534f2604
child 113
24f32dbd88cd
permissions
-rw-r--r--

improve toolchain detection

relates to #347

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
78
c3a62e0baa9e fix special chars in dependency names are breaking configure - fixes #312
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
11 import static de.unixwork.uwproj.Util.shId;
92
5a32534f2604 fix empty dependencies element producing broken configure script - fixes #336
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
12 import static java.util.function.Predicate.not;
78
c3a62e0baa9e fix special chars in dependency names are breaking configure - fixes #312
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
13
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 public class TargetData {
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
15 private final List<Define> defines = new LinkedList<>();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
16 private final List<String> dependencies = new LinkedList<>();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
17 private final StringBuilder make = new StringBuilder();
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
19 public static TargetData parse(Element element) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
20 var target = new TargetData();
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
21
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 NodeList nodes = element.getChildNodes();
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
23 for (int i = 0; i < nodes.getLength(); i++) {
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 Node node = nodes.item(i);
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 if (node.getNodeType() == Node.ELEMENT_NODE) {
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
26 Element elm = (Element) node;
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 String n = elm.getNodeName();
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
28 if (n.equals("define")) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
29 target.addDefine(
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
30 elm.getAttribute("name"),
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
31 elm.getAttribute("value")
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
32 );
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
33 } else if (n.equals("dependencies")) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
34 Arrays.stream(Util.getContent(elm).split(","))
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
35 .map(String::trim)
92
5a32534f2604 fix empty dependencies element producing broken configure script - fixes #336
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
36 .filter(not(String::isBlank))
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
37 .forEach(target::addDependency);
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
38 } else if (n.equals("make")) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
39 target.addMake(Util.getContent(elm));
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 }
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
43
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
44 return target;
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
46
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 public List<Define> getDefines() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 return defines;
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 List<String> getDependencies() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 return dependencies;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 public String getMake() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 return make.toString();
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
41
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 public void addDefine(String name, String value) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
60 if (name.isBlank()) {
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
61 throw new IllegalArgumentException("define element requires name attribute");
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
62 }
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
63 defines.add(new Define(name, value));
0
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 addDependency(String d) {
78
c3a62e0baa9e fix special chars in dependency names are breaking configure - fixes #312
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
67 // we have to add the sanitized identifier to the list of dependencies
c3a62e0baa9e fix special chars in dependency names are breaking configure - fixes #312
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
68 dependencies.add(shId(d));
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
41
75ee588d5d9e some more code cleanup
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
70
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 public void addMake(String m) {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 make.append(m.trim());
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 make.append('\n');
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 }

mercurial