1 package de.unixwork.uwproj; |
1 package de.unixwork.uwproj; |
2 |
2 |
3 import org.w3c.dom.Element; |
3 import org.w3c.dom.Element; |
4 |
4 |
5 import java.util.ArrayList; |
|
6 import java.util.stream.Collectors; |
|
7 |
|
8 import static de.unixwork.uwproj.Util.isNotNullOrBlank; |
|
9 |
|
10 public class PkgConfigPackage { |
5 public class PkgConfigPackage { |
11 private String name; |
6 private String name; |
12 private String atLeastVersion; |
7 private String atleast; |
13 private String exactVersion; |
8 private String exact; |
14 private String maxVersion; |
9 private String max; |
15 |
10 |
16 public static PkgConfigPackage parse(Element e) throws Exception { |
11 public static PkgConfigPackage parse(Element e) throws Exception { |
17 var p = new PkgConfigPackage(); |
12 var p = new PkgConfigPackage(); |
18 String name = Util.getContent(e); |
13 String name = Util.getContent(e); |
19 if (name.isBlank()) { |
14 if (name.isBlank()) { |
20 throw new Exception("pkgconfig element: value required"); |
15 throw new Exception("pkgconfig element: value required"); |
21 } else { |
16 } else { |
22 p.setName(name); |
17 p.setName(name); |
23 } |
18 } |
24 p.setAtLeastVersion(e.getAttribute("atleast")); |
19 p.setAtleast(e.getAttribute("atleast")); |
25 p.setExactVersion(e.getAttribute("exact")); |
20 p.setExact(e.getAttribute("exact")); |
26 p.setMaxVersion(e.getAttribute("max")); |
21 p.setMax(e.getAttribute("max")); |
27 return p; |
22 return p; |
28 } |
23 } |
29 |
24 |
30 public String getName() { |
25 public String getName() { |
31 return name; |
26 return name; |
33 |
28 |
34 public void setName(String name) { |
29 public void setName(String name) { |
35 this.name = name; |
30 this.name = name; |
36 } |
31 } |
37 |
32 |
38 public String getAtLeastVersion() { |
33 public String getAtleast() { |
39 return atLeastVersion; |
34 return atleast; |
40 } |
35 } |
41 |
36 |
42 public void setAtLeastVersion(String atLeastVersion) { |
37 public void setAtleast(String atleast) { |
43 this.atLeastVersion = atLeastVersion; |
38 this.atleast = atleast; |
44 } |
39 } |
45 |
40 |
46 public String getMaxVersion() { |
41 public String getMax() { |
47 return maxVersion; |
42 return max; |
48 } |
43 } |
49 |
44 |
50 public void setMaxVersion(String maxVersion) { |
45 public void setMax(String max) { |
51 this.maxVersion = maxVersion; |
46 this.max = max; |
52 } |
47 } |
53 |
48 |
54 public String getExactVersion() { |
49 public String getExact() { |
55 return exactVersion; |
50 return exact; |
56 } |
51 } |
57 |
52 |
58 public void setExactVersion(String exactVersion) { |
53 public void setExact(String exact) { |
59 this.exactVersion = exactVersion; |
54 this.exact = exact; |
60 } |
|
61 |
|
62 public String getPkgConfigTestQuery() { |
|
63 // pkg-config is a more broken piece of software than we thought |
|
64 // it is not possible to combine any flags |
|
65 // e.g. --atleast-version and --max-version together will return true, |
|
66 // even when the max-version is violated |
|
67 // or other example: combining any version flag with --cflags or |
|
68 // --libs does not print the flags |
|
69 // therefore we have to execute multiple query first, and obtain the flags later |
|
70 |
|
71 final var commands = new ArrayList<String>(); |
|
72 if (isNotNullOrBlank(atLeastVersion)) { |
|
73 commands.add("$PKG_CONFIG --atleast-version="+atLeastVersion+" "+name); |
|
74 } |
|
75 if (isNotNullOrBlank(exactVersion)) { |
|
76 commands.add("$PKG_CONFIG --exact-version="+exactVersion+" "+name); |
|
77 } |
|
78 if (isNotNullOrBlank(maxVersion)) { |
|
79 commands.add("$PKG_CONFIG --max-version="+maxVersion+" "+name); |
|
80 } |
|
81 if (commands.isEmpty()) { |
|
82 commands.add("$PKG_CONFIG "+name); |
|
83 } |
|
84 return String.join(" && ", commands); |
|
85 } |
55 } |
86 } |
56 } |