Sat, 20 Jan 2024 15:47:39 +0100
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 | 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 | 19 | public static TargetData parse(Element element) { |
20 | var target = new TargetData(); | |
21 | ||
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | NodeList nodes = element.getChildNodes(); |
41 | 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 | 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 | 28 | if (n.equals("define")) { |
29 | target.addDefine( | |
30 | elm.getAttribute("name"), | |
31 | elm.getAttribute("value") | |
32 | ); | |
33 | } else if (n.equals("dependencies")) { | |
34 | Arrays.stream(Util.getContent(elm).split(",")) | |
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 | 37 | .forEach(target::addDependency); |
38 | } else if (n.equals("make")) { | |
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 | 43 | |
44 | return target; | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | } |
41 | 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 | 58 | |
59 | public void addDefine(String name, String value) { | |
60 | if (name.isBlank()) { | |
61 | throw new IllegalArgumentException("define element requires name attribute"); | |
62 | } | |
63 | defines.add(new Define(name, value)); | |
0
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 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 | 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 | } |