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 |
5 public class PkgConfigPackage { |
10 public class PkgConfigPackage { |
6 private String name; |
11 private String name; |
7 private String atleast; |
12 private String atLeastVersion; |
|
13 private String exactVersion; |
8 private String maxVersion; |
14 private String maxVersion; |
9 |
15 |
10 public static PkgConfigPackage parse(Element e) throws Exception { |
16 public static PkgConfigPackage parse(Element e) throws Exception { |
11 var p = new PkgConfigPackage(); |
17 var p = new PkgConfigPackage(); |
12 String name = Util.getContent(e); |
18 String name = Util.getContent(e); |
13 if (name.isBlank()) { |
19 if (name.isBlank()) { |
14 throw new Exception("pkgconfig element: value required"); |
20 throw new Exception("pkgconfig element: value required"); |
15 } else { |
21 } else { |
16 p.setName(name); |
22 p.setName(name); |
17 } |
23 } |
|
24 p.setAtLeastVersion(e.getAttribute("atleast")); |
|
25 p.setExactVersion(e.getAttribute("exact")); |
|
26 p.setMaxVersion(e.getAttribute("max")); |
18 return p; |
27 return p; |
19 } |
28 } |
20 |
29 |
21 public String getName() { |
30 public String getName() { |
22 return name; |
31 return name; |
24 |
33 |
25 public void setName(String name) { |
34 public void setName(String name) { |
26 this.name = name; |
35 this.name = name; |
27 } |
36 } |
28 |
37 |
29 public String getAtleast() { |
38 public String getAtLeastVersion() { |
30 return atleast; |
39 return atLeastVersion; |
31 } |
40 } |
32 |
41 |
33 public void setAtleast(String atleast) { |
42 public void setAtLeastVersion(String atLeastVersion) { |
34 this.atleast = atleast; |
43 this.atLeastVersion = atLeastVersion; |
35 } |
44 } |
36 |
45 |
37 public String getMaxVersion() { |
46 public String getMaxVersion() { |
38 return maxVersion; |
47 return maxVersion; |
39 } |
48 } |
40 |
49 |
41 public void setMaxVersion(String maxVersion) { |
50 public void setMaxVersion(String maxVersion) { |
42 this.maxVersion = maxVersion; |
51 this.maxVersion = maxVersion; |
43 } |
52 } |
44 |
53 |
45 public String getPkgConfigParam() { |
54 public String getExactVersion() { |
46 return name; |
55 return exactVersion; |
|
56 } |
|
57 |
|
58 public void setExactVersion(String exactVersion) { |
|
59 this.exactVersion = exactVersion; |
|
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); |
47 } |
85 } |
48 } |
86 } |