src/main/java/de/unixwork/uwproj/Target.java

Sat, 03 Aug 2019 11:15:03 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 03 Aug 2019 11:15:03 +0200
changeset 5
895bf81d3b6e
parent 0
38775db5fdf5
child 40
b42bfc9e9983
permissions
-rw-r--r--

add missing source changes

/*
 * 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
 */
public class Target {
    private String name;
    private String prefix;
    
    private List<String> dependencies = new LinkedList<>();
    private List<String> optionalDependencies = new LinkedList<>();
    private List<Define> defines = new LinkedList<>();
    private List<Feature> features = new LinkedList<>();
    private List<Option> options = new LinkedList<>();
    
    private boolean allDependencies = false;
    
    public static Target parse(Project project, Element element) throws Exception {
        Target target = new Target();
        
        String name = element.getAttribute("name");
        if(name.length() > 0) {
            target.setName(name);
        }
        
        NodeList nodes = element.getChildNodes();
        for(int i=0;i<nodes.getLength();i++) {
            Node node = nodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element elm = (Element)node;
                String n = elm.getNodeName();
                if(n.equals("feature")) {
                    Feature feature = Feature.parse(project, elm);
                    target.addFeature(feature);
                } else if(n.equals("define")) {
                    String def = elm.getAttribute("name");
                    String defval = elm.getAttribute("value");
                    if(def == null) {
                        throw new Exception("define element requires name attribute");
                    }
                    target.addDefine(def, defval);
                } else if(n.equals("dependencies")) {
                    String deps = Xml.getContent(elm);                   
                    String[] dependencies = deps.split(",");
                    for(String dependency : dependencies) {
                        dependency = dependency.trim();
                        target.addDependency(dependency, false);
                    }
                } else if(n.equals("alldependencies")) {
                    target.setAllDependencies(true);
                } else if(n.equals("option")) {
                    Option opt = Option.parse(project, elm);
                    target.addOption(opt);
                    project.addOption(opt);
                }
            }
        }
        
        if (target.prefix == null && target.name != null) {
            target.setPrefix(name.toUpperCase());
        }
        
        return target;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }
    
    public String getCFlags() {
        return prefix == null ? "CFLAGS" : prefix + "_CFLAGS";
    }
    
    public String getLDFlags() {
        return prefix == null ? "LDFLAGS" : prefix + "_LDFLAGS";
    }
    
    public String getCXXFlags() {
        return prefix == null ? "CXXFLAGS" : prefix + "_CXXFLAGS";
    }

    public List<String> getDependencies() {
        return dependencies;
    }

    public void addDependency(String dependency, boolean optional) {
        if(optional) {
            optionalDependencies.add(dependency);
        } else {
            dependencies.add(dependency);
        }
    }

    public List<String> getOptionalDependencies() {
        return optionalDependencies;
    }

    public boolean isAllDependencies() {
        return allDependencies;
    }

    public void setAllDependencies(boolean allDependencies) {
        this.allDependencies = allDependencies;
    }
    
    public void addDefine(String name, String value) {
        Define def = new Define();
        def.setName(name);
        def.setValue(value);
        defines.add(def);
    }
    
    public List<Define> getDefines() {
        return defines;
    }
    
    public void addFeature(Feature f) {
        features.add(f);
    }
    
    public List<Feature> getFeatures() {
        return features;
    }
    
    public void addOption(Option o) {
        options.add(o);
    }
    
    public List<Option> getOptions() {
        return options;
    }
}

mercurial