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

Sat, 02 Nov 2024 14:23:45 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 02 Nov 2024 14:23:45 +0100
changeset 121
155cd224b51d
parent 113
24f32dbd88cd
permissions
-rw-r--r--

fix incorrect compatibility check for major versions

package de.unixwork.uwproj;

import org.w3c.dom.Element;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import static de.unixwork.uwproj.Util.shId;
import static java.util.function.Predicate.not;

public final class Target {
    private final String name;
    private final String prefix;

    private final List<String> dependencies = new LinkedList<>();
    private final List<Define> defines = new LinkedList<>();
    private final List<Feature> features = new LinkedList<>();
    private final List<Option> options = new LinkedList<>();

    private boolean allDependencies = false;

    public static Target defaultTarget() {
        return new Target();
    }

    private Target() {
        name = "default";
        prefix = "";
        allDependencies = true;
    }

    public Target(Element element) {
        this.name = element.getAttribute("name").trim();
        if (this.name.isEmpty()) {
            prefix = "";
        } else {
            prefix = shId(name.toUpperCase());
        }
        Util.getChildElements(element).forEach(elm -> {
            switch (elm.getNodeName()) {
                case "feature" -> features.add(new Feature(elm));
                case "define" -> defines.add(new Define(
                        elm.getAttribute("name"),
                        elm.getAttribute("value")
                ));
                case "dependencies" -> Arrays.stream(Util.getContent(elm).split(","))
                        .map(String::trim)
                        .filter(not(String::isBlank))
                        .map(Util::shId)
                        .forEach(dependencies::add);
                case "alldependencies" -> this.allDependencies = true;
                case "option" -> options.add(new Option(elm));
            }
        });
    }

    public String getName() {
        return name;
    }

    public String getPrefix() {
        return prefix;
    }

    private String withPrefix(String id) {
        return prefix.isEmpty() ? id : String.format("%s_%s", prefix, id);
    }

    public String getCFlags() {
        return withPrefix("CFLAGS");
    }

    public String getLdFlags() {
        return withPrefix("LDFLAGS");
    }

    public String getCxxFlags() {
        return withPrefix("CXXFLAGS");
    }

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

    public void replaceAllDependencies(Collection<String> deps) {
        dependencies.clear();
        dependencies.addAll(deps);
    }

    public boolean wantsAllDependencies() {
        return allDependencies;
    }

    public List<Define> getDefines() {
        return defines;
    }

    public List<Feature> getFeatures() {
        return features;
    }

    public List<Option> getOptions() {
        return options;
    }
}

mercurial