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

mercurial