Fri, 22 Sep 2023 22:08:34 +0200
simplify code which computes the required languages
src/main/java/de/unixwork/uwproj/Project.java | file | annotate | diff | comparison | revisions | |
src/test/resources/golden-sample/configure | file | annotate | diff | comparison | revisions |
--- a/src/main/java/de/unixwork/uwproj/Project.java Thu Sep 21 18:24:37 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Project.java Fri Sep 22 22:08:34 2023 +0200 @@ -6,10 +6,9 @@ import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class Project { private final HashMap<String, List<Dependency>> namedDependencies = new HashMap<>(); @@ -21,7 +20,7 @@ private final HashMap<String, ConfigVar> configVars = new HashMap<>(); private final List<ConfigVar> configVarsList = new LinkedList<>(); - private final List<String> langList = new LinkedList<>(); + private final Set<String> lang; public Project(File file) throws Exception { var root = DocumentBuilderFactory. @@ -60,22 +59,10 @@ } // create a list of all languages that are used - for (Dependency d : dependencies) { - for (String lang : d.getLang()) { - if(!langList.contains(lang)) { - langList.add(lang); - } - } - } - for (var nd : namedDependencies.entrySet()) { - for (var d : nd.getValue()) { - for (String lang : d.getLang()) { - if(!langList.contains(lang)) { - langList.add(lang); - } - } - } - } + lang = Stream.concat( + namedDependencies.values().stream().flatMap(Collection::stream), + dependencies.stream() + ).flatMap(d -> d.getLang().stream()).collect(Collectors.toSet()); } private void createDefaultTarget() { @@ -139,7 +126,7 @@ return configVarsList; } - public List<String> getLang() { - return langList; + public Collection<String> getLang() { + return lang; } }
--- a/src/test/resources/golden-sample/configure Thu Sep 21 18:24:37 2023 +0200 +++ b/src/test/resources/golden-sample/configure Fri Sep 22 22:08:34 2023 +0200 @@ -199,12 +199,12 @@ # check languages lang_c= lang_cpp= +if detect_cpp_compiler ; then + lang_cpp=1 +fi if detect_c_compiler ; then lang_c=1 fi -if detect_cpp_compiler ; then - lang_cpp=1 -fi # create buffer for make variables required by dependencies echo > "$TEMP_DIR/make.mk"