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

Sat, 27 Jan 2024 14:28:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 27 Jan 2024 14:28:09 +0100
changeset 109
1e852be12654
parent 93
df47e083139b
child 112
206e91a8dd18
permissions
-rw-r--r--

adds schema validation - fixes #291

0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 package de.unixwork.uwproj;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 import org.apache.velocity.VelocityContext;
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 import org.apache.velocity.app.VelocityEngine;
109
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
5 import org.xml.sax.SAXException;
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
6
109
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
7 import javax.xml.XMLConstants;
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
8 import javax.xml.parsers.DocumentBuilderFactory;
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
9 import javax.xml.transform.dom.DOMSource;
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
10 import javax.xml.transform.stream.StreamSource;
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
11 import javax.xml.validation.SchemaFactory;
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
12 import java.io.*;
93
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
13 import java.nio.file.Files;
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
14 import java.nio.file.Path;
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
15 import java.nio.file.Paths;
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
16 import java.nio.file.StandardCopyOption;
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
17 import java.nio.file.attribute.PosixFilePermissions;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
18 import java.util.Arrays;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
19 import java.util.Objects;
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
20
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
21 public class Main {
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
22
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
23 public final static String IN_FILE_DEFAULT = "make/project.xml";
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
24 public final static String TPL_FILE_DEFAULT = "make/configure.vm";
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
25 public final static String OUT_FILE_DEFAULT = "configure";
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
26
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
27 static Project loadProjectFile(String fileName) {
109
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
28 try (final var xsdResource = Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream("make/uwproj.xsd"))) {
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
29 // Create the XSD validator
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
30 final var factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
31 final var schema = factory.newSchema(new StreamSource(xsdResource));
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
32 final var validator = schema.newValidator();
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
33
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
34 // Load the DOM from the input file
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
35 final var dom = DocumentBuilderFactory.
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
36 newDefaultNSInstance().
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
37 newDocumentBuilder().
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
38 parse(fileName).
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
39 getDocumentElement();
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
40
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
41 // Validate the XML
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
42 validator.validate(new DOMSource(dom));
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
43
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
44 // Parse the XML
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
45 return new Project(dom);
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
46 } catch (SAXException saxerror) {
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
47 System.err.println(saxerror.getMessage());
1e852be12654 adds schema validation - fixes #291
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
48 throw new RuntimeException("XML validation failed.");
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
49 } catch (Exception e) {
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
50 throw new RuntimeException(e);
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
51 }
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
52 }
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
54 static void writeConfigureScript(Writer out, String tplFileName, Project project) {
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
55 var context = new VelocityContext();
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
56 context.put("targets", project.getTargets());
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
57 context.put("namedDependencies", project.getNamedDependencies());
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
58 context.put("dependencies", project.getDependencies());
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
59 context.put("options", project.getOptions());
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
60 context.put("features", project.getFeatures());
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
61 context.put("project", project);
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
62 context.put("vars", project.getVars());
67
e43d30273f74 check compilers before any dependency checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
63 context.put("languages", project.getLang());
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
64 new VelocityEngine().getTemplate(tplFileName).merge(context, out);
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
65 }
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
66
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
67 private static void abort() {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
68 System.err.println("Abort.");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
69 System.exit(1);
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
70 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
71
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
72 private static void printUsage() {
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
73 System.err.println("Usage: uwproj [OPTIONS]");
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
74 System.err.println();
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
75 System.err.println("OPTIONS:");
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
76 System.err.println(" -h --help Print help text and exit");
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
77 System.err.println(" --init Creates default files in directory 'make'");
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
78 System.err.println(" -o --output <file> Path to the output file");
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
79 System.err.printf(" (default: %s)\n", OUT_FILE_DEFAULT);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
80 System.err.println(" -p --project <file> Path to the project.xml file");
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
81 System.err.printf(" (default: %s)\n", IN_FILE_DEFAULT);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
82 System.err.println(" -t --template <file> Path to the velocity template");
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
83 System.err.printf(" (default: %s)\n", TPL_FILE_DEFAULT);
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
84 System.err.println(" --update Same as --init, but overwrites existing files");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
85 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
86
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
87 private static void extract(Path path) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
88 try (final var res = Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream(path.toString()))) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
89 Files.copy(res, path, StandardCopyOption.REPLACE_EXISTING);
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
90 } catch (Throwable t) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
91 System.err.printf("Cannot extract '%s': %s\n", path, t.getMessage());
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
92 abort();
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
93 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
94 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
95
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
96 private static void init(boolean force) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
97 final var files = new String[]{
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
98 "cc.mk", "gcc.mk", "clang.mk", "suncc.mk",
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
99 "configure.vm", "toolchain.sh", "uwproj.xsd"
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
100 };
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
101
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
102 // (1) create the make dir if it does not exist
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
103 final var make = Paths.get("make");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
104 if (Files.exists(make)) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
105 if (!Files.isDirectory(make)) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
106 System.err.println("A file with name 'make' already exists, but it's not a directory.");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
107 abort();
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
108 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
109 if (!force) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
110 System.err.println("uwproj files already exist. You can use --update instead.");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
111 abort();
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
112 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
113 } else {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
114 try {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
115 Files.createDirectory(make);
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
116 } catch (Throwable t) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
117 System.err.printf("Creating directory failed: %s\n", t.getMessage());
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
118 abort();
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
119 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
120 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
121
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
122 // (2) create project.xml ONLY if it does not exist
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
123 final var project = make.resolve("project.xml");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
124 if (Files.notExists(project)) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
125 extract(project);
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
126 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
127
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
128 // (3) create or update remaining uwproj files
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
129 Arrays.stream(files).map(make::resolve).forEach(Main::extract);
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
130
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
131 // (4) stop
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
132 System.out.printf("uwproj files %s.\n", force ? "updated" : "created");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
133 System.exit(0);
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
134 }
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
135
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
136 private static void checkOneMoreArg(int i, int length) {
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
137 if (i+1 >= length) {
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
138 printUsage();
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
139 System.exit(1);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
140 }
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
141 }
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
142
42
becfbf7af928 add simple SLF4J provider - fixes #292
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
143 public static void main(String[] args) {
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
144 var inFileName = IN_FILE_DEFAULT;
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
145 var tplFileName = TPL_FILE_DEFAULT;
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
146 var outFileName = OUT_FILE_DEFAULT;
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
147 boolean opsOptionsUsed = false;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
148 boolean doInit = false;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
149 boolean forceInit = false;
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
150
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
151 for (int i = 0 ; i < args.length ; i++) {
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
152 switch (args[i]) {
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
153 case "-o":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
154 case "--output":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
155 checkOneMoreArg(i, args.length);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
156 outFileName = args[++i];
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
157 opsOptionsUsed = true;
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
158 break;
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
159 case "-p":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
160 case "--project":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
161 checkOneMoreArg(i, args.length);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
162 inFileName = args[++i];
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
163 opsOptionsUsed = true;
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
164 break;
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
165
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
166 case "-t":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
167 case "--template":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
168 checkOneMoreArg(i, args.length);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
169 tplFileName = args[++i];
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
170 opsOptionsUsed = true;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
171 break;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
172 case "--init":
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
173 doInit = true;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
174 break;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
175 case "--update":
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
176 doInit = true;
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
177 forceInit = true;
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
178 break;
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
179 case "--help":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
180 case "-h":
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
181 printUsage();
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
182 System.exit(0);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
183 default:
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
184 printUsage();
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
185 System.exit(1);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
186 }
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
187 }
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
188
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
189 if (opsOptionsUsed && doInit) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
190 System.err.println("Cannot use --init or --update with other options.");
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
191 abort();
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
192 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
193
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
194 if (doInit) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
195 init(forceInit);
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
196 }
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
197
81
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
198 System.out.println("In: " + inFileName);
ea79a383ad75 add command line options - fixes #303
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
199 System.out.println("Tpl: " + tplFileName);
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
200
93
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
201 final var outFilePath = Path.of(outFileName);
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
202 try {
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
203 final var tmp = File.createTempFile("uwproj", null);
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
204 try (var out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmp)))) {
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
205 writeConfigureScript(out, tplFileName, loadProjectFile(inFileName));
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
206 }
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
207 Files.copy(tmp.toPath(), outFilePath, StandardCopyOption.REPLACE_EXISTING);
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
208 } catch (Throwable t) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
209 System.err.printf("Unexpected error: %s\n", t.getMessage());
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
210 abort();
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 }
39
3ca85da78515 add RegressionTest - fixes #264
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
212
42
becfbf7af928 add simple SLF4J provider - fixes #292
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
213 System.out.println("Out: " + outFileName);
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
214 try {
93
df47e083139b fix that a broken configure file is left over when something goes wrong
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
215 Files.setPosixFilePermissions(outFilePath, PosixFilePermissions.fromString("rwxr-xr-x"));
90
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
216 } catch (Throwable t) {
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
217 System.err.printf("WARN: Setting file permissions failed: %s\n", t.getMessage());
a13789dd1cfb add --init and --update options
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
218 }
0
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 }
38775db5fdf5 add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 }

mercurial