4 import org.w3c.dom.Node; |
4 import org.w3c.dom.Node; |
5 import org.w3c.dom.NodeList; |
5 import org.w3c.dom.NodeList; |
6 |
6 |
7 import javax.xml.parsers.DocumentBuilderFactory; |
7 import javax.xml.parsers.DocumentBuilderFactory; |
8 import java.io.File; |
8 import java.io.File; |
9 import java.util.HashMap; |
9 import java.util.*; |
10 import java.util.LinkedList; |
10 import java.util.stream.Collectors; |
11 import java.util.List; |
11 import java.util.stream.Stream; |
12 import java.util.Optional; |
|
13 |
12 |
14 public class Project { |
13 public class Project { |
15 private final HashMap<String, List<Dependency>> namedDependencies = new HashMap<>(); |
14 private final HashMap<String, List<Dependency>> namedDependencies = new HashMap<>(); |
16 private final List<Dependency> dependencies = new LinkedList<>(); |
15 private final List<Dependency> dependencies = new LinkedList<>(); |
17 private final List<Target> targets = new LinkedList<>(); |
16 private final List<Target> targets = new LinkedList<>(); |
19 private final List<Feature> features = new LinkedList<>(); |
18 private final List<Feature> features = new LinkedList<>(); |
20 |
19 |
21 private final HashMap<String, ConfigVar> configVars = new HashMap<>(); |
20 private final HashMap<String, ConfigVar> configVars = new HashMap<>(); |
22 private final List<ConfigVar> configVarsList = new LinkedList<>(); |
21 private final List<ConfigVar> configVarsList = new LinkedList<>(); |
23 |
22 |
24 private final List<String> langList = new LinkedList<>(); |
23 private final Set<String> lang; |
25 |
24 |
26 public Project(File file) throws Exception { |
25 public Project(File file) throws Exception { |
27 var root = DocumentBuilderFactory. |
26 var root = DocumentBuilderFactory. |
28 newDefaultNSInstance(). |
27 newDefaultNSInstance(). |
29 newDocumentBuilder(). |
28 newDocumentBuilder(). |
58 if (targets.isEmpty()) { |
57 if (targets.isEmpty()) { |
59 createDefaultTarget(); |
58 createDefaultTarget(); |
60 } |
59 } |
61 |
60 |
62 // create a list of all languages that are used |
61 // create a list of all languages that are used |
63 for (Dependency d : dependencies) { |
62 lang = Stream.concat( |
64 for (String lang : d.getLang()) { |
63 namedDependencies.values().stream().flatMap(Collection::stream), |
65 if(!langList.contains(lang)) { |
64 dependencies.stream() |
66 langList.add(lang); |
65 ).flatMap(d -> d.getLang().stream()).collect(Collectors.toSet()); |
67 } |
|
68 } |
|
69 } |
|
70 for (var nd : namedDependencies.entrySet()) { |
|
71 for (var d : nd.getValue()) { |
|
72 for (String lang : d.getLang()) { |
|
73 if(!langList.contains(lang)) { |
|
74 langList.add(lang); |
|
75 } |
|
76 } |
|
77 } |
|
78 } |
|
79 } |
66 } |
80 |
67 |
81 private void createDefaultTarget() { |
68 private void createDefaultTarget() { |
82 var t = new Target(); |
69 var t = new Target(); |
83 t.setAllDependencies(true); |
70 t.setAllDependencies(true); |