# HG changeset patch # User Mike Becker # Date 1694033742 -7200 # Node ID b42bfc9e99830aec8e991384c71af5d8cd10a69d # Parent 3ca85da785150d9702781a539f0877a29be59ed6 first minor code improvements diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/ConfigVar.java --- a/src/main/java/de/unixwork/uwproj/ConfigVar.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/ConfigVar.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,58 +1,44 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; import org.w3c.dom.Element; -/** - * - * @author olaf - */ public class ConfigVar { - String name; - String value; + private String varName; + private String value; private boolean exec = false; - + public static ConfigVar parse(Element e) { + return parse(e, false); + } + + public static ConfigVar parse(Element e, boolean varNameIsElemName) { ConfigVar var = new ConfigVar(); - - String name = e.getAttribute("name"); - if(name == null || name.length() == 0) { - System.err.println("-element: name attribute required"); - return null; + + if (varNameIsElemName) { + var.varName = e.getNodeName().toUpperCase(); + } else { + String name = e.getAttribute("name"); + if (name.isBlank()) { + System.err.println("-element: name attribute required"); + return null; + } + var.varName = name; } - var.name = name; - - String value = Xml.getContent(e); - var.value = value == null ? "" : value; - - String type = e.getAttribute("type"); - if(type != null && type.equals("exec")) { - var.exec = true; - } - + + var.value = Util.getContent(e); + var.exec = e.getAttribute("type").equals("exec"); + return var; } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; + public String getVarName() { + return varName; } public String getValue() { return value; } - public void setValue(String value) { - this.value = value; - } - public boolean isExec() { return exec; } diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/Define.java --- a/src/main/java/de/unixwork/uwproj/Define.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Define.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,15 +1,5 @@ package de.unixwork.uwproj; -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author olaf - */ public class Define { private String name; private String value; diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/Dependency.java --- a/src/main/java/de/unixwork/uwproj/Dependency.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Dependency.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,79 +1,71 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.util.LinkedList; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; -/** - * - * @author olaf - */ +import static de.unixwork.uwproj.Util.isNullOrBlank; + public class Dependency { private String name; private String platform; private String not; - - private List flags = new LinkedList<>(); - private List pkgconfig = new LinkedList<>(); - private List tests = new LinkedList<>(); - private StringBuilder make = new StringBuilder(); - - private List lang = new LinkedList<>(); - + + private final List flags = new LinkedList<>(); + private final List pkgconfig = new LinkedList<>(); + private final List tests = new LinkedList<>(); + private final StringBuilder make = new StringBuilder(); + + private final List lang = new LinkedList<>(); + private boolean abortOnError = false; - + private int num = 0; - + public static Dependency parse(Element element) throws Exception { Dependency d = new Dependency(); - + String name = element.getAttribute("name"); String platform = element.getAttribute("platform"); String not = element.getAttribute("not"); - if(name.length() > 0) { + if (!name.isEmpty()) { d.setName(name); } - if(platform.length() > 0) { + if (!platform.isEmpty()) { d.setPlatform(platform); } - if(not.length() > 0) { + if (!not.isEmpty()) { d.setNotString(not); } - + NodeList nodes = element.getChildNodes(); - for(int i=0;i getNotList() { - List notPlatforms = new LinkedList<>(); - if(not != null) { - String[] n = not.split(","); - for(String s : n) { - notPlatforms.add(s); - } - } - return notPlatforms; + return isNullOrBlank(not) ? + Collections.emptyList() : + Arrays.stream(not.split(",")).map(String::trim).collect(Collectors.toList()); } public void setPlatform(String platform) { this.platform = platform; } - public List getFlags() { + public List getFlags() { return flags; } - public void addFlags(Flags flags) { - this.flags.add(flags); + public void addFlags(ConfigVar var) { + this.flags.add(var); } public List getPkgconfig() { @@ -136,28 +123,28 @@ public void setAbortOnError(boolean abortOnError) { this.abortOnError = abortOnError; } - + public int getNum() { return num; } - + public void setNum(int num) { this.num = num; } - + public List getTests() { return tests; } - + public void addMake(String m) { make.append(m.trim()); make.append('\n'); } - + public String getMake() { return make.toString(); } - + public List getLang() { return lang; } diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/Feature.java --- a/src/main/java/de/unixwork/uwproj/Feature.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Feature.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,18 +1,9 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; -import java.util.LinkedList; -import java.util.List; import org.w3c.dom.Element; -/** - * - * @author olaf - */ +import java.util.List; + public class Feature { private String name; private String arg; @@ -26,7 +17,7 @@ String arg = e.getAttribute("arg"); String def = e.getAttribute("default"); - if(name.length() == 0) { + if(name.isEmpty()) { throw new Exception("feature element requires name attribute"); } @@ -34,7 +25,7 @@ boolean on = ld.equals("on") || ld.equals("true"); feature.setName(name); feature.setDefault(on); - if(arg.length() == 0) { + if(arg.isEmpty()) { feature.setArg(name); } else { feature.setArg(arg); @@ -62,7 +53,7 @@ } public boolean hasMake() { - return targetData.getMake().trim().length() > 0; + return !targetData.getMake().trim().isEmpty(); } public String getName() { diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/Flags.java --- a/src/main/java/de/unixwork/uwproj/Flags.java Wed Sep 06 21:08:04 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package de.unixwork.uwproj; - -import org.w3c.dom.Element; - -/** - * - * @author olaf - */ -public class Flags { - private String varName; - private String value; - private boolean exec = false; - - public static Flags parse(Element e) { - Flags f = new Flags(); - f.varName = e.getNodeName().toUpperCase(); - String value = Xml.getContent(e); - f.value = value == null ? "" : value; - - String type = e.getAttribute("type"); - if(type != null && type.equals("exec")) { - f.exec = true; - } - - return f; - } - - public String getVarName() { - return varName; - } - - public void setVarName(String varName) { - this.varName = varName; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public boolean isExec() { - return exec; - } - - public void setExec(boolean exec) { - this.exec = exec; - } -} diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/NamedDependency.java --- a/src/main/java/de/unixwork/uwproj/NamedDependency.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/NamedDependency.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,16 +1,7 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; import java.util.List; -/** - * - * @author olaf - */ public class NamedDependency { private String name; private List subdependencies; diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/Option.java --- a/src/main/java/de/unixwork/uwproj/Option.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Option.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,20 +1,12 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; -import java.util.LinkedList; -import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -/** - * - * @author olaf - */ +import java.util.LinkedList; +import java.util.List; + public class Option { private String arg; @@ -24,7 +16,7 @@ public static Option parse(Project project, Element element) throws Exception { Option opt = new Option(); String arg = element.getAttribute("arg"); - if(arg.length() == 0) { + if(arg.isEmpty()) { throw new Exception("Option has no argument string"); } opt.setArgument(arg); @@ -45,7 +37,7 @@ String defPlatform = elm.getAttribute(("platform")); OptionDefault def = new OptionDefault(opt); def.setValueName(defValue); - if(defPlatform.length() > 0) { + if(!defPlatform.isEmpty()) { def.setPlatform(defPlatform); } opt.defaults.add(def); @@ -85,7 +77,7 @@ } public String getValuesString() { - if(values.size() == 0) { + if(values.isEmpty()) { return "()"; } else if(values.size() == 1) { return values.get(0).getValue(); diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/OptionDefault.java --- a/src/main/java/de/unixwork/uwproj/OptionDefault.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/OptionDefault.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,23 +1,14 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; -/** - * - * @author olaf - */ public class OptionDefault { - private Option option; + private final Option option; private String value; private String platform; public OptionDefault(Option opt) { option = opt; } - + public String getValueName() { return value; } @@ -33,14 +24,14 @@ public void setPlatform(String platform) { this.platform = platform; } - + public String getFunc() { return option.getValueFunc(value); } - + public OptionValue getValue() { - for(OptionValue val : option.getValues()) { - if(val.getValue().equals(value)) { + for (OptionValue val : option.getValues()) { + if (val.getValue().equals(value)) { return val; } } diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/OptionValue.java --- a/src/main/java/de/unixwork/uwproj/OptionValue.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/OptionValue.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,17 +1,7 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; import java.util.List; -import java.util.LinkedList; -/** - * - * @author olaf - */ public class OptionValue { Option option; @@ -52,6 +42,6 @@ } public boolean hasMake() { - return targetData.getMake().trim().length() > 0; + return !targetData.getMake().trim().isEmpty(); } } diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/PkgConfigPackage.java --- a/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,16 +1,7 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; import org.w3c.dom.Element; -/** - * - * @author olaf - */ public class PkgConfigPackage { private String name; private String atleast; @@ -18,7 +9,7 @@ public static PkgConfigPackage parse(Element e) throws Exception { PkgConfigPackage p = new PkgConfigPackage(); - String name = Xml.getContent(e); + String name = Util.getContent(e); if(name != null) { p.setName(name); } else { diff -r 3ca85da78515 -r b42bfc9e9983 src/main/java/de/unixwork/uwproj/Project.java --- a/src/main/java/de/unixwork/uwproj/Project.java Wed Sep 06 21:08:04 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Project.java Wed Sep 06 22:55:42 2023 +0200 @@ -1,115 +1,93 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.unixwork.uwproj; -import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; import java.util.*; -/** - * - * @author olaf - */ public class Project { - private String path; - private Properties properties = new Properties(); - - private HashMap> namedDependencies = new HashMap<>(); - private List dependencies = new LinkedList<>(); - private List targets = new LinkedList<>(); - private List