Fri, 29 Nov 2024 21:43:32 +0100
add draft for website
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 | |
41 | 5 | import java.util.Arrays; |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
6 | import java.util.Collection; |
40
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
7 | import java.util.LinkedList; |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
8 | import java.util.List; |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
9 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
10 | 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:
79
diff
changeset
|
11 | import static java.util.function.Predicate.not; |
41 | 12 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
13 | public final class Target { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
14 | private final String name; |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
15 | private final String prefix; |
41 | 16 | |
40
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
17 | private final List<String> dependencies = new LinkedList<>(); |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
18 | private final List<Define> defines = new LinkedList<>(); |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
19 | private final List<Feature> features = new LinkedList<>(); |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
20 | private final List<Option> options = new LinkedList<>(); |
41 | 21 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | private boolean allDependencies = false; |
41 | 23 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
24 | public static Target defaultTarget() { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
25 | return new Target(); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
26 | } |
41 | 27 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
28 | private Target() { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
29 | name = "default"; |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
30 | prefix = ""; |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
31 | allDependencies = true; |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
32 | } |
41 | 33 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
34 | public Target(Element element) { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
35 | this.name = element.getAttribute("name").trim(); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
36 | if (this.name.isEmpty()) { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
37 | prefix = ""; |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
38 | } else { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
39 | prefix = shId(name.toUpperCase()); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
40 | } |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
41 | Util.getChildElements(element).forEach(elm -> { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
42 | switch (elm.getNodeName()) { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
43 | case "feature" -> features.add(new Feature(elm)); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
44 | case "define" -> defines.add(new Define( |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
45 | elm.getAttribute("name"), |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
46 | elm.getAttribute("value") |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
47 | )); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
48 | case "dependencies" -> Arrays.stream(Util.getContent(elm).split(",")) |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
49 | .map(String::trim) |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
50 | .filter(not(String::isBlank)) |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
51 | .map(Util::shId) |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
52 | .forEach(dependencies::add); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
53 | case "alldependencies" -> this.allDependencies = true; |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
54 | case "option" -> options.add(new Option(elm)); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
56 | }); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | } |
41 | 58 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | public String getName() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | return name; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | public String getPrefix() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | return prefix; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | |
41 | 67 | private String withPrefix(String id) { |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
68 | return prefix.isEmpty() ? id : String.format("%s_%s", prefix, id); |
41 | 69 | } |
70 | ||
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | public String getCFlags() { |
41 | 72 | return withPrefix("CFLAGS"); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | } |
41 | 74 | |
79
ef0635b78b7b
remove explicit calls of getters in velocity template
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
75 | public String getLdFlags() { |
41 | 76 | return withPrefix("LDFLAGS"); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
41 | 78 | |
79
ef0635b78b7b
remove explicit calls of getters in velocity template
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
79 | public String getCxxFlags() { |
41 | 80 | return withPrefix("CXXFLAGS"); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | public List<String> getDependencies() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | return dependencies; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
87 | public void replaceAllDependencies(Collection<String> deps) { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
88 | dependencies.clear(); |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
89 | dependencies.addAll(deps); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
113
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
92 | public boolean wantsAllDependencies() { |
24f32dbd88cd
minimize application code
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
93 | return allDependencies; |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | } |
41 | 95 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | public List<Define> getDefines() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | return defines; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | } |
41 | 99 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | public List<Feature> getFeatures() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | return features; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | } |
41 | 103 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | public List<Option> getOptions() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | return options; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |