2 |
2 |
3 import org.w3c.dom.Element; |
3 import org.w3c.dom.Element; |
4 |
4 |
5 import java.util.List; |
5 import java.util.List; |
6 |
6 |
|
7 import static de.unixwork.uwproj.Util.isNotNullOrBlank; |
|
8 |
7 public class Feature { |
9 public class Feature { |
8 private String name; |
10 private String name; |
9 private String arg; |
11 private String arg; |
10 private boolean def; |
12 private boolean def; |
11 |
13 |
12 private TargetData targetData; |
14 private TargetData targetData; |
13 |
15 |
14 public static Feature parse(Project project, Element e) throws Exception { |
16 public static Feature parse(Project project, Element e) throws Exception { |
15 Feature feature = new Feature(); |
17 Feature feature = new Feature(); |
16 String name = e.getAttribute("name"); |
18 String name = e.getAttribute("name"); |
17 String arg = e.getAttribute("arg"); |
19 String arg = e.getAttribute("arg"); |
18 String def = e.getAttribute("default"); |
20 String def = e.getAttribute("default"); |
19 |
21 |
20 if(name.isEmpty()) { |
22 if (name.isBlank()) { |
21 throw new Exception("feature element requires name attribute"); |
23 throw new Exception("feature element requires name attribute"); |
22 } |
24 } |
23 |
25 |
24 String ld = def.toLowerCase(); |
26 String ld = def.toLowerCase(); |
25 boolean on = ld.equals("on") || ld.equals("true"); |
27 boolean on = ld.equals("on") || ld.equals("true"); |
26 feature.setName(name); |
28 feature.setName(name); |
27 feature.setDefault(on); |
29 feature.setDefault(on); |
28 if(arg.isEmpty()) { |
30 if (arg.isBlank()) { |
29 feature.setArg(name); |
31 feature.setArg(name); |
30 } else { |
32 } else { |
31 feature.setArg(arg); |
33 feature.setArg(arg); |
32 } |
34 } |
33 |
35 |
34 feature.setTargetData(TargetData.parse(e)); |
36 feature.setTargetData(TargetData.parse(e)); |
35 project.addFeature(feature); |
37 project.addFeature(feature); |
36 return feature; |
38 return feature; |
37 } |
39 } |
38 |
40 |
39 public String getVarName() { |
41 public String getVarName() { |
40 return "FEATURE_"+name.toUpperCase(); |
42 return "FEATURE_" + name.toUpperCase(); |
41 } |
43 } |
42 |
44 |
43 public List<String> getDependencies() { |
45 public List<String> getDependencies() { |
44 return getTargetData().getDependencies(); |
46 return getTargetData().getDependencies(); |
45 } |
47 } |
46 |
48 |
47 public List<Define> getDefines() { |
49 public List<Define> getDefines() { |
48 return getTargetData().getDefines(); |
50 return getTargetData().getDefines(); |
49 } |
51 } |
50 |
52 |
51 public String getMake() { |
53 public String getMake() { |
52 return targetData.getMake(); |
54 return targetData.getMake(); |
53 } |
55 } |
54 |
56 |
55 public boolean hasMake() { |
57 public boolean hasMake() { |
56 return !targetData.getMake().trim().isEmpty(); |
58 return isNotNullOrBlank(targetData.getMake()); |
57 } |
59 } |
58 |
60 |
59 public String getName() { |
61 public String getName() { |
60 return name; |
62 return name; |
61 } |
63 } |