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

Sat, 20 Jan 2024 15:37:16 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 20 Jan 2024 15:37:16 +0100
changeset 104
ea36fd802446
parent 103
01ec9f32835e
child 113
24f32dbd88cd
permissions
-rw-r--r--

adds documentation for new toolchain attr to XSD

relates to #346

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
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
7 import java.util.*;
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
8 import java.util.stream.Collectors;
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
9
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
10 import static de.unixwork.uwproj.Util.isNullOrBlank;
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
11
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 public class Dependency {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 private String name;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 private String platform;
103
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
15 private String toolchain;
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
16 private String not;
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
17
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
18 private final List<ConfigVar> flags = new LinkedList<>();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
19 private final List<PkgConfigPackage> pkgconfig = new LinkedList<>();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
20 private final List<String> tests = new LinkedList<>();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
21 private final StringBuilder make = new StringBuilder();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
22
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
23 private final List<String> lang = new LinkedList<>();
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
24
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 private int num = 0;
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
26
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 public static Dependency parse(Element element) throws Exception {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 Dependency d = new Dependency();
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
29
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 String name = element.getAttribute("name");
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 String platform = element.getAttribute("platform");
103
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
32 String toolchain = element.getAttribute("toolchain");
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
33 String not = element.getAttribute("not");
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
34 if (!name.isEmpty()) {
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 d.setName(name);
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
37 if (!platform.isEmpty()) {
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 d.setPlatform(platform);
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 }
103
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
40 if (!toolchain.isEmpty()) {
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
41 d.setToolchain(toolchain);
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
42 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
43 if (!not.isEmpty()) {
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
44 d.setNotString(not);
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
45 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
46
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 NodeList nodes = element.getChildNodes();
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
48 for (int i = 0; i < nodes.getLength(); i++) {
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 Node node = nodes.item(i);
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 if (node.getNodeType() == Node.ELEMENT_NODE) {
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
51 Element elm = (Element) node;
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 String n = elm.getNodeName();
65
6db50c6df6e3 add support for cxxflags and fix lang parser
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
53 if (n.equals("cflags") || n.equals("cxxflags") || n.equals("ldflags")) {
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
54 Optional.ofNullable(ConfigVar.parse(elm, true)).ifPresent(d::addFlags);
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
55 } else if (n.equals("pkgconfig")) {
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 PkgConfigPackage pcp = PkgConfigPackage.parse(elm);
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 d.addPkgconfig(pcp);
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
58 } else if (n.equals("test")) {
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
59 d.tests.add(Util.getContent(elm));
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
60 } else if (n.equals("make")) {
65
6db50c6df6e3 add support for cxxflags and fix lang parser
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
61 d.addMake(Util.getContent(elm));
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
62 } else if (n.equals("lang")) {
96
eb9152e5f1b6 trim all contents by default - relates to #317
Mike Becker <universe@uap-core.de>
parents: 65
diff changeset
63 d.lang.add(Util.getContent(elm).toLowerCase());
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
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 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
67
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 return d;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
70
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 public String getName() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 return name;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
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 public void setName(String name) {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 this.name = name;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 public String getPlatform() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 return platform;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
82
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
83 public String getFullName() {
103
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
84 String fname = name;
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
85 if (!isNullOrBlank(platform)) {
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
86 fname += " platform=\"" + platform + '"';
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
103
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
88 if (!isNullOrBlank(toolchain)) {
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
89 fname += " toolchain=\"" + toolchain + '"';
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
90 }
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
91 return fname;
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
93
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
94 public void setNotString(String not) {
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
95 this.not = not;
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
96 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
97
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
98 public List<String> getNotList() {
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
99 return isNullOrBlank(not) ?
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
100 Collections.emptyList() :
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
101 Arrays.stream(not.split(",")).map(String::trim).collect(Collectors.toList());
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
102 }
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 public void setPlatform(String platform) {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 this.platform = platform;
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
103
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
108 public void setToolchain(String toolchain) {
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
109 this.toolchain = toolchain;
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
110 }
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
111
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
112 public String getToolchain() { return toolchain; }
01ec9f32835e add toolchain attribute - relates to #346
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
113
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
114 public List<ConfigVar> getFlags() {
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return flags;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
118 public void addFlags(ConfigVar var) {
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
119 this.flags.add(var);
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 public List<PkgConfigPackage> getPkgconfig() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 return pkgconfig;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 public void addPkgconfig(PkgConfigPackage pkgconfig) {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 this.pkgconfig.add(pkgconfig);
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 public int getNum() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 return num;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
133
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 public void setNum(int num) {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 this.num = num;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
137
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 public List<String> getTests() {
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 return tests;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
141
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
142 public void addMake(String m) {
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
143 make.append(m.trim());
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
144 make.append('\n');
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
145 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
146
5
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
147 public String getMake() {
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
148 return make.toString();
895bf81d3b6e add missing source changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
149 }
40
b42bfc9e9983 first minor code improvements
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
150
8
82cd9f1d94cb add c++ compiler detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
151 public List<String> getLang() {
82cd9f1d94cb add c++ compiler detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
152 return lang;
82cd9f1d94cb add c++ compiler detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
153 }
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 }

mercurial