Sat, 03 Aug 2019 17:45:03 +0200
add c++ compiler detection
/* * 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.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** * * @author olaf */ public class Project { private String path; private Properties properties = new Properties(); private HashMap<String,List<Dependency>> namedDependencies = new HashMap<>(); private List<Dependency> dependencies = new LinkedList<>(); private List<Target> targets = new LinkedList<>(); private List<Option> options = new LinkedList<>(); private List<Feature> features = new LinkedList<>(); private HashMap<String,ConfigVar> configVars = new HashMap<>(); private List<ConfigVar> configVarsList = new LinkedList<>(); public Project(File file) throws ParserConfigurationException, SAXException, IOException, Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(file); Element root = doc.getDocumentElement(); NodeList dependency_nodes = root.getElementsByTagName("dependency"); NodeList target_nodes = root.getElementsByTagName("target"); NodeList property_nodes = root.getElementsByTagName("property"); NodeList config_nodes = root.getElementsByTagName("config"); for(int i=0;i<config_nodes.getLength();i++) { Element p = (Element)config_nodes.item(i); NodeList cfgs = p.getChildNodes(); for(int c=0;c<cfgs.getLength();c++) { Node node = cfgs.item(c); if (node.getNodeType() == Node.ELEMENT_NODE) { if(node.getNodeName().equals("var")) { ConfigVar var = ConfigVar.parse((Element)node); if(var != null) { configVarsList.add(var); configVars.put(var.getName(), var); } } } } } for(int i=0;i<dependency_nodes.getLength();i++) { addDependency(Dependency.parse((Element)dependency_nodes.item(i))); } for(int i=0;i<target_nodes.getLength();i++) { targets.add(Target.parse(this, (Element)target_nodes.item(i))); } for(int i=0;i<property_nodes.getLength();i++) { Element p = (Element)property_nodes.item(i); String name = p.getAttribute("name"); String value = p.getAttribute("value"); if(name != null && value != null) { properties.setProperty(name, value); } else { throw new Exception("Missing property name or value"); } } if(targets.size() == 0) { createDefaultTarget(); } } private void createDefaultTarget() { Target t = new Target(); t.setAllDependencies(true); t.setName("default"); addTarget(t); } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public List<NamedDependency> getNamedDependencies() { List<NamedDependency> ret = new LinkedList<>(); for(Map.Entry<String,List<Dependency>> entry : namedDependencies.entrySet()) { NamedDependency d = new NamedDependency(); d.setName(entry.getKey()); d.setSubdependencies(entry.getValue()); ret.add(d); } return ret; } public List<Dependency> getDependencies() { return dependencies; } public List<Target> getTargets() { return targets; } public void addDependency(Dependency dependency) { if(dependency.getName() != null) { List<Dependency> l = namedDependencies.get(dependency.getName()); if(l == null) { l = new LinkedList<>(); namedDependencies.put(dependency.getName(), l); } dependency.setNum(l.size()); l.add(dependency); } else { dependencies.add(dependency); } } public void addTarget(Target target) { targets.add(target); } public void addOption(Option o) { options.add(o); } public List<Option> getOptions() { return options; } public void addFeature(Feature feature) { features.add(feature); } public List<Feature> getFeatures() { return features; } public List<ConfigVar> getVars() { return configVarsList; } public boolean hasVar(String varName) { return configVars.containsKey(varName); } }