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

Tue, 19 Sep 2023 19:29:19 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 19 Sep 2023 19:29:19 +0200
changeset 67
e43d30273f74
parent 42
becfbf7af928
child 81
ea79a383ad75
permissions
-rw-r--r--

check compilers before any dependency checks

package de.unixwork.uwproj;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.slf4j.LoggerFactory;

import java.io.*;

public class Main {

    static Project loadProjectFile(String fileName) {
        try {
            return new Project(new File(fileName));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    static void writeConfigureScript(Writer out, String tplFileName, Project project) {
        var context = new VelocityContext();
        context.put("targets", project.getTargets());
        context.put("namedDependencies", project.getNamedDependencies());
        context.put("dependencies", project.getDependencies());
        context.put("options", project.getOptions());
        context.put("features", project.getFeatures());
        context.put("project", project);
        context.put("vars", project.getVars());
        context.put("languages", project.getLang());
        new VelocityEngine().getTemplate(tplFileName).merge(context, out);
    }

    public static void main(String[] args) {
        final var inFileName = "make/project.xml";
        final var tplFileName = "make/configure.vm";
        final var outFileName = "configure";

        try (var out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName)))) {
            writeConfigureScript(out, tplFileName, loadProjectFile(inFileName));
        } catch (Exception ex) {
            LoggerFactory.getLogger(Main.class).error(
                    "Uncaught Exception",
                    ex
            );
        }

        System.out.println("Out: " + outFileName);
    }
}

mercurial