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

Sat, 03 Aug 2019 13:46:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 03 Aug 2019 13:46:43 +0200
changeset 7
686991ae6e2f
parent 0
38775db5fdf5
child 39
3ca85da78515
permissions
-rw-r--r--

add configureable make variables

/*
 * 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.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.xml.sax.SAXException;

/**
 *
 * @author olaf
 */
public class Main {
    public static void main(String[] args){
        File f = new File("make/project.xml");
        Project p = null;
        try {
            p = new Project(f);
        } catch (SAXException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(p == null) {
            System.exit(1);
        }
        
        VelocityEngine ve = new VelocityEngine();
        Template t = ve.getTemplate("make/configure.vm");
        VelocityContext context = new VelocityContext();
        context.put("targets", p.getTargets());
        context.put("namedDependencies", p.getNamedDependencies());
        context.put("dependencies", p.getDependencies());
        context.put("options", p.getOptions());
        context.put("features", p.getFeatures());
        context.put("project", p);
        context.put("vars", p.getVars());
        
        int ret = 1;
        try {
            FileOutputStream fout = new FileOutputStream(new File("configure"));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fout));
            t.merge(context, out);
            out.close();
            ret = 0;
            System.out.println("Out: configure");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.exit(ret);
    }
}

mercurial