Commit 9416ebfb authored by Claus Nagel's avatar Claus Nagel
Browse files

switched to Gradle

parent e248ab95
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* ade-xjc is part of the citygml4j project * ade-xjc is part of the citygml4j project
* *
* Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com> * Copyright 2013-2018 Claus Nagel <claus.nagel@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
--> -->
<xs:schema xmlns="http://www.igg.tu-berlin.de/citygml4j/ade_hooks" xmlns:xs="http://www.w3.org/2001/XMLSchema" <xs:schema xmlns="http://www.citygml4j.org/ade_hooks" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.igg.tu-berlin.de/citygml4j/ade_hooks" targetNamespace="http://www.citygml4j.org/ade_hooks"
xmlns:core1="http://www.opengis.net/citygml/1.0" xmlns:app1="http://www.opengis.net/citygml/appearance/1.0" xmlns:core1="http://www.opengis.net/citygml/1.0" xmlns:app1="http://www.opengis.net/citygml/appearance/1.0"
xmlns:bldg1="http://www.opengis.net/citygml/building/1.0" xmlns:frn1="http://www.opengis.net/citygml/cityfurniture/1.0" xmlns:bldg1="http://www.opengis.net/citygml/building/1.0" xmlns:frn1="http://www.opengis.net/citygml/cityfurniture/1.0"
xmlns:grp1="http://www.opengis.net/citygml/cityobjectgroup/1.0" xmlns:luse1="http://www.opengis.net/citygml/landuse/1.0" xmlns:grp1="http://www.opengis.net/citygml/cityobjectgroup/1.0" xmlns:luse1="http://www.opengis.net/citygml/landuse/1.0"
......
...@@ -46,5 +46,5 @@ ...@@ -46,5 +46,5 @@
<xs:import namespace="http://www.opengis.net/citygml/waterbody/2.0" schemaLocation="2.0.0/waterBody.xsd"/> <xs:import namespace="http://www.opengis.net/citygml/waterbody/2.0" schemaLocation="2.0.0/waterBody.xsd"/>
<xs:import namespace="http://www.opengis.net/citygml/texturedsurface/2.0" schemaLocation="2.0.0/texturedSurface.xsd"/> <xs:import namespace="http://www.opengis.net/citygml/texturedsurface/2.0" schemaLocation="2.0.0/texturedSurface.xsd"/>
<!-- ade hooks --> <!-- ade hooks -->
<xs:import namespace="http://www.igg.tu-berlin.de/citygml4j/ade_hooks" schemaLocation="ade_hooks/ade_hooks.xsd"/> <xs:import namespace="http://www.citygml4j.org/ade_hooks" schemaLocation="ade_hooks/ade_hooks.xsd"/>
</xs:schema> </xs:schema>
rootProject.name = 'ade-xjc'
/* /*
* ade-xjc - XML Schema binding compiler for CityGML ADEs * ade-xjc - XML Schema binding compiler for CityGML ADEs
* https://github.com/citygml4j/ade-xjc * https://github.com/citygml4j/ade-xjc
* *
* ade-xjc is part of the citygml4j project * ade-xjc is part of the citygml4j project
* *
* Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com> * Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.citygml4j.ade_xjc; package org.citygml4j.ade_xjc;
import java.io.File; import com.sun.codemodel.JCodeModel;
import java.io.FileNotFoundException; import com.sun.codemodel.writer.FileCodeWriter;
import java.io.IOException; import com.sun.codemodel.writer.PrologCodeWriter;
import java.io.PrintStream; import com.sun.tools.xjc.Options;
import java.math.BigInteger; import com.sun.tools.xjc.Plugin;
import java.nio.file.Files; import com.sun.tools.xjc.api.S2JJAXBModel;
import java.nio.file.Path; import com.sun.tools.xjc.api.SchemaCompiler;
import java.nio.file.Paths; import com.sun.tools.xjc.api.XJC;
import java.security.NoSuchAlgorithmException; import com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl;
import java.text.SimpleDateFormat; import org.citygml4j.ade_xjc.Util.URLClassLoader;
import java.util.ArrayList; import org.kohsuke.args4j.Argument;
import java.util.Arrays; import org.kohsuke.args4j.CmdLineException;
import java.util.Date; import org.kohsuke.args4j.CmdLineParser;
import java.util.List; import org.kohsuke.args4j.Option;
import java.util.Map; import org.kohsuke.args4j.ParserProperties;
import java.util.ServiceLoader; import org.xml.sax.InputSource;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.io.File;
import java.io.FileNotFoundException;
import org.citygml4j.ade_xjc.Util.URLClassLoader; import java.io.IOException;
import org.kohsuke.args4j.Argument; import java.io.PrintStream;
import org.kohsuke.args4j.CmdLineException; import java.math.BigInteger;
import org.kohsuke.args4j.CmdLineParser; import java.nio.file.Files;
import org.kohsuke.args4j.Option; import java.nio.file.Path;
import org.kohsuke.args4j.ParserProperties; import java.nio.file.Paths;
import org.xml.sax.InputSource; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import com.sun.codemodel.JCodeModel; import java.util.Arrays;
import com.sun.codemodel.writer.FileCodeWriter; import java.util.Date;
import com.sun.codemodel.writer.PrologCodeWriter; import java.util.List;
import com.sun.tools.xjc.Options; import java.util.Map;
import com.sun.tools.xjc.Plugin; import java.util.ServiceLoader;
import com.sun.tools.xjc.api.S2JJAXBModel; import java.util.stream.Collectors;
import com.sun.tools.xjc.api.SchemaCompiler; import java.util.stream.Stream;
import com.sun.tools.xjc.api.XJC;
import com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl; public class ADESchemaCompiler {
private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
public class ADE_XJC { private Path appHome;
private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); private Path workDir;
// some dirs we will need @Argument
private Path schema_dir = Paths.get("schemas"); private List<String> adeSchemaFileList = new ArrayList<>();
private Path plugins_dir = Paths.get("jaxb-plugins");
@Option(name="-package", usage="package for the ADE JAXB classes", metaVar="<packageName>")
// some files we will need private String packageName = "ade";
private Path baseProfileFile = schema_dir.resolve("CityGML/citygml4j_profile.xsd");
private Path bindingFile = schema_dir.resolve("CityGML/binding.xjb"); @Option(name="-binding", usage="optional JAXB binding file for ADE XML Schema", metaVar="<fileName>")
private Path adeSchemaFile = null; private Path adeBindingFile;
// args @Option(name="-output", usage="output folder", metaVar="<folderName>")
@Argument private Path outputFolder = Paths.get("src-gen");
private List<String> adeSchemaFileList = new ArrayList<String>();
@Option(name="-non-strict", usage="allow changes to contents of subfolder 'schemas'")
@Option(name="-package", usage="package for the ADE JAXB classes", metaVar="<packageName>") private boolean nonStrict = false;
private String packageName = "ade";
@Option(name="-clean", usage="clean output folder")
@Option(name="-binding", usage="optional JAXB binding file for ADE XML Schema", metaVar="<fileName>") private boolean clean;
private File adeBindingFile = null;
@Option(name="-help", aliases={"-h"}, usage="print this help message and exit")
@Option(name="-output", usage="output folder", metaVar="<folderName>") private boolean help;
private File outputFolder = new File("src-gen");
@Option(name="-version", aliases={"-v"}, usage="print product version and exit")
@Option(name="-non-strict", usage="allow changes to contents of subfolder 'schemas'") private boolean version;
private boolean nonStrict = false;
@Option(name="-X{arg}", usage="one or more arguments for JAXB plugins")
@Option(name="-clean", usage="clean output folder") private Boolean dummy;
private boolean clean;
public static void main(String[] args) {
@Option(name="-h", aliases={"-help"}, usage="print this help message and exit") new ADESchemaCompiler().doMain(args);
private boolean help; }
@Option(name="-version", usage="print product version and exit") private void doMain(String[] _args) {
private boolean version; CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
Map<Boolean, List<String>> args = Arrays.stream(_args)
@Option(name="-X{arg}", usage="one or more arguments for JAXB plugins") .flatMap(arg -> Arrays.stream(arg.split("\\s+")))
private Boolean dummy = null; .collect(Collectors.partitioningBy(arg -> !arg.startsWith("-X")));
public static void main(String[] args) { try {
new ADE_XJC().doMain(args); parser.parseArgument(args.get(Boolean.TRUE));
} } catch (CmdLineException e) {
System.err.println(e.getMessage());
private void doMain(String[] _args) { printUsage(parser, System.err);
List<String> tmp = new ArrayList<String>(); System.exit(1);
for (String arg : _args) }
tmp.addAll(Arrays.asList(arg.split(" +")));
if (help) {
Map<Boolean, List<String>> args = tmp.stream().collect(Collectors.partitioningBy(arg -> !arg.startsWith("-X"))); printUsage(parser, System.out);
CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); System.exit(0);
}
try {
parser.parseArgument(args.get(Boolean.TRUE)); if (version) {
} catch (CmdLineException e) { System.out.println(getClass().getPackage().getImplementationTitle() + " version " + getClass().getPackage().getImplementationVersion());
System.err.println(e.getMessage()); System.out.println("XML Schema binding compiler for CityGML ADEs; use with citygml4j version " + getClass().getPackage().getImplementationVersion());
printUsage(parser, System.err); System.exit(0);
System.exit(1); }
}
if (adeSchemaFileList.isEmpty()) {
if (help) { System.out.println("Provide the ADE XML Schema definition file to be compiled as argument");
printUsage(parser, System.out); printUsage(parser, System.out);
System.exit(0); System.exit(1);
} }
if (version) { if (adeSchemaFileList.size() > 1) {
System.out.println("ade-xjc version " + this.getClass().getPackage().getImplementationVersion()); System.out.println("Just provide one ADE XML Schema definition file at a time");
System.out.println(this.getClass().getPackage().getImplementationTitle()); printUsage(parser, System.out);
System.exit(0); System.exit(1);
} }
if (adeSchemaFileList.isEmpty()) { log(LogLevel.INFO, "Starting ade-xjc compiler");
System.out.println("Provide the ADE XML Schema definition file to be compiled as argument"); int status = 0;
printUsage(parser, System.out); initialize();
System.exit(1);
} try {
log(LogLevel.INFO, "Setting up build environment");
if (adeSchemaFileList.size() > 1) { Path schemaDir = appHome.resolve("schemas");
System.out.println("Just provide one ADE XML Schema definition file at a time"); Path pluginsDir = appHome.resolve("jaxb-plugins");
printUsage(parser, System.out);
System.exit(1); Path adeSchemaFile = Paths.get(adeSchemaFileList.get(0));
} if (!adeSchemaFile.isAbsolute())
adeSchemaFile = workDir.resolve(adeSchemaFile);
log(LogLevel.INFO, "Starting ade-xjc compiler");
adeSchemaFile = Paths.get(adeSchemaFileList.get(0)); if (!adeBindingFile.isAbsolute())
int status = 0; adeBindingFile = workDir.resolve(adeBindingFile);
try { if (!outputFolder.isAbsolute())
log(LogLevel.INFO, "Setting up build environment"); outputFolder = workDir.resolve(outputFolder);
checkBuildEnvironment();
checkBuildEnvironment(schemaDir, adeSchemaFile);
if (clean && Files.exists(outputFolder.toPath())) {
log(LogLevel.INFO, "Cleaning output folder"); if (clean && Files.exists(outputFolder)) {
Files.walkFileTree(outputFolder.toPath(), new FileDeleter(true)); log(LogLevel.INFO, "Cleaning output folder");
} Files.walkFileTree(outputFolder, new FileDeleter(true));
}
createBuildEnvironment();
createBuildEnvironment();
if (packageName.startsWith("org.citygml4j")) {
log(LogLevel.ERROR, "The package " + packageName + " is not allowed for the ADE classes"); if (packageName.startsWith("org.citygml4j")) {
log(LogLevel.ERROR, "Choose a package which is not a subpackage of org.citygml4j. Aborting."); log(LogLevel.ERROR, "The package " + packageName + " is not allowed for the ADE classes");
System.exit(1); log(LogLevel.ERROR, "Choose a package which is not a subpackage of org.citygml4j. Aborting.");
} System.exit(1);
}
log(LogLevel.INFO, "Using ADE schema " + adeSchemaFile.toAbsolutePath().toString());
if (adeBindingFile != null) log(LogLevel.INFO, "Using ADE schema " + adeSchemaFile.toAbsolutePath().toString());
log(LogLevel.INFO, "Using JAXB binding " + adeBindingFile.getCanonicalFile()); if (adeBindingFile != null)
log(LogLevel.INFO, "Using JAXB binding " + adeBindingFile.toAbsolutePath());
log(LogLevel.INFO, "Using Java package " + packageName + " for JAXB classes");
log(LogLevel.INFO, "Using Java package " + packageName + " for JAXB classes");
SchemaCompiler sc = XJC.createSchemaCompiler();
sc.setDefaultPackageName(packageName); SchemaCompiler sc = XJC.createSchemaCompiler();
sc.setDefaultPackageName(packageName);
if (!args.get(Boolean.FALSE).isEmpty() && Files.exists(plugins_dir)) {
log(LogLevel.INFO, "Loading and configuring JAXB plugins"); if (!args.get(Boolean.FALSE).isEmpty() && Files.exists(pluginsDir)) {
String[] pluginArgs = args.get(Boolean.FALSE).stream().toArray(String[]::new); log(LogLevel.INFO, "Loading and configuring JAXB plugins");
Options options = ((SchemaCompilerImpl)sc).getOptions(); String[] pluginArgs = args.get(Boolean.FALSE).toArray(new String[0]);
Options options = ((SchemaCompilerImpl)sc).getOptions();
URLClassLoader loader = new URLClassLoader();
try (Stream<Path> stream = Files.walk(plugins_dir).filter(path -> path.getFileName().toString().toLowerCase().endsWith(".jar"))) { URLClassLoader loader = new URLClassLoader();
stream.forEach(path -> loader.addPath(path)); try (Stream<Path> stream = Files.walk(pluginsDir).filter(path -> path.getFileName().toString().toLowerCase().endsWith(".jar"))) {
} stream.forEach(loader::addPath);
}
ServiceLoader<Plugin> plugins = ServiceLoader.load(Plugin.class, loader);
for (Plugin plugin : plugins) { ServiceLoader<Plugin> plugins = ServiceLoader.load(Plugin.class, loader);
for (int i = 0; i < pluginArgs.length; i++) { for (Plugin plugin : plugins) {
if (('-' + plugin.getOptionName()).equals(pluginArgs[i])) { for (int i = 0; i < pluginArgs.length; i++) {
log(LogLevel.INFO, "Found JAXB plugin for option '-" + plugin.getOptionName() + "'"); if (('-' + plugin.getOptionName()).equals(pluginArgs[i])) {
options.activePlugins.add(plugin); log(LogLevel.INFO, "Found JAXB plugin for option '-" + plugin.getOptionName() + "'");
plugin.onActivated(options); options.activePlugins.add(plugin);
} plugin.onActivated(options);
}
plugin.parseArgument(options, pluginArgs, i);
} plugin.parseArgument(options, pluginArgs, i);
} }
} }
}
XJCErrorListener listener = new XJCErrorListener();
sc.setErrorListener(listener); XJCErrorListener listener = new XJCErrorListener();
sc.setErrorListener(listener);
log(LogLevel.INFO, "Generating JAXB classes. This may take some time...");
sc.parseSchema(new InputSource(baseProfileFile.toUri().toString())); log(LogLevel.INFO, "Generating JAXB classes. This may take some time...");
sc.parseSchema(new InputSource(bindingFile.toUri().toString())); sc.parseSchema(new InputSource(schemaDir.resolve("CityGML").resolve("citygml4j_profile.xsd").toUri().toString()));
sc.parseSchema(new InputSource(adeSchemaFile.toUri().toString())); sc.parseSchema(new InputSource(schemaDir.resolve("CityGML").resolve("binding.xjb").toUri().toString()));
sc.parseSchema(new InputSource(adeSchemaFile.toUri().toString()));
if (adeBindingFile != null)
sc.parseSchema(new InputSource(adeBindingFile.toURI().toString())); if (adeBindingFile != null)
sc.parseSchema(new InputSource(adeBindingFile.toUri().toString()));
S2JJAXBModel model = sc.bind();
JCodeModel code = model.generateCode(null, listener); S2JJAXBModel model = sc.bind();
JCodeModel code = model.generateCode(null, listener);
// write classes using a header comment
PrologCodeWriter writer = new PrologCodeWriter(new FileCodeWriter(outputFolder, "UTF-8"), // write classes using a header comment
"Generated with ade-xjc - XML Schema binding compiler for CityGML ADEs, version " + this.getClass().getPackage().getImplementationVersion() + "\n" PrologCodeWriter writer = new PrologCodeWriter(new FileCodeWriter(outputFolder.toFile(), "UTF-8"),
+ "ade-xjc is part of the citygml4j project, see https://github.com/citygml4j\n" "Generated with ade-xjc - XML Schema binding compiler for CityGML ADEs, version " + this.getClass().getPackage().getImplementationVersion() + "\n"
+ "Any modifications to this file will be lost upon recompilation of the source\n" + "ade-xjc is part of the citygml4j project, see https://github.com/citygml4j\n"
+ "Generated: " + new Date().toString() + "\n"); + "Any modifications to this file will be lost upon recompilation of the source\n"
code.build(writer); + "Generated: " + new Date().toString() + "\n");
code.build(writer);
File packageDir = new File(outputFolder.getAbsolutePath());
log(LogLevel.INFO, "JAXB classes successfully written to " + packageDir.getCanonicalPath()); log(LogLevel.INFO, "JAXB classes successfully written to " + outputFolder.toAbsolutePath());
} catch (Exception e) { } catch (Exception e) {
if (e.getMessage() != null) if (e.getMessage() != null)
log(LogLevel.ERROR, e.getMessage()); log(LogLevel.ERROR, e.getMessage());
else
log(LogLevel.ERROR, "Unable to recover from previous error(s). Aborting."); log(LogLevel.ERROR, "An unexpected " + e + " occurred.");
status = 1;
} finally { log(LogLevel.ERROR, "Unable to recover from previous error(s). Aborting.");
try { status = 1;
cleanBuildEnvironment(status == 1); } finally {
} catch (IOException e) { try {
log(LogLevel.ERROR, "Failed to clean build environment."); cleanBuildEnvironment(status == 1);
status = 1; } catch (IOException e) {
} log(LogLevel.ERROR, "Failed to clean build environment.");
} status = 1;
}
System.exit(status); }
}
System.exit(status);
private void createBuildEnvironment() throws Exception { }
boolean success = true;
private void initialize() {
if (success && !outputFolder.exists()) { String appHomeName = System.getenv("APP_HOME");
success = outputFolder.mkdirs(); String workDirName = System.getenv("WORKING_DIR");
if (!success)
throw new Exception("Could not create directory " + outputFolder.getAbsolutePath()); if (appHomeName == null) {
} else if (!outputFolder.isDirectory()) { log(LogLevel.WARN, "Environment variable APP_HOME not set. Using current working directory.");
success = outputFolder.delete(); appHomeName = ".";
if (success) }
success = outputFolder.mkdirs();
else if (workDirName == null) {
throw new Exception("Could not create directory " + outputFolder.getAbsolutePath()); log(LogLevel.WARN, "Environment variable WORKING_DIR not set. Using current working directory.");
} workDirName = ".";
} }
private void checkBuildEnvironment() throws Exception, FileNotFoundException, NoSuchAlgorithmException { appHome = Paths.get(appHomeName).normalize().toAbsolutePath();
if (!Files.exists(schema_dir)) if (!Files.exists(appHome)) {
throw new FileNotFoundException("Failed to open folder " + schema_dir.toAbsolutePath().toString()); log(LogLevel.ERROR, "Invalid working directory '" + appHomeName + "'.");
System.exit(1);
if (!nonStrict) { }
log(LogLevel.INFO, "Running in strict mode. Checking sanity of subfolder 'schemas'");
workDir = Paths.get(workDirName).normalize().toAbsolutePath();
BigInteger md5 = new BigInteger("0"); if (!Files.exists(workDir)) {
md5 = Util.dir2md5(schema_dir.toFile(), md5); log(LogLevel.ERROR, "Invalid working directory '" + workDirName + "'.");
System.exit(1);
if (!md5.toString(16).equals("79facf9d68ad19afacf8d51a58c5f8b6")) }
throw new Exception("Contents of subfolder 'schemas' have been altered. Please restore its original state."); }
}
private void createBuildEnvironment() throws Exception {
if (!Files.exists(adeSchemaFile) || !Files.isRegularFile(adeSchemaFile) || !Files.isReadable(adeSchemaFile)) if (!Files.exists(outputFolder))
throw new Exception("Could not open ADE schema file " + adeSchemaFile.toAbsolutePath().toString()); Files.createDirectories(outputFolder);
else if (!Files.isDirectory(outputFolder)) {
if (adeBindingFile != null && (!adeBindingFile.exists() || !adeBindingFile.isFile() || !adeBindingFile.canRead())) Files.delete(outputFolder);
throw new Exception("Could not open ADE binding file " + adeBindingFile.getAbsolutePath()); Files.createDirectories(outputFolder);
} }
}
private void cleanBuildEnvironment(boolean cleanAll) throws IOException {
if (!cleanAll) { private void checkBuildEnvironment(Path schemaDir, Path adeSchemaFile) throws Exception {
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "net/opengis/citygml"), new FileDeleter(true)); if (!Files.exists(schemaDir))
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "net/opengis/gml"), new FileDeleter(true)); throw new FileNotFoundException("Failed to open folder " + schemaDir.toAbsolutePath().toString());
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "oasis/names/tc/ciq/xsdschema/xal/_2"), new FileDeleter(true));
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "org/citygml4j"), new FileDeleter(true)); if (!nonStrict) {
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "org/w3/_1999/xlink"), new FileDeleter(true)); log(LogLevel.INFO, "Running in strict mode. Checking sanity of subfolder 'schemas'");
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "org/w3/_2001/smil20"), new FileDeleter(true));
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "net"), new FileDeleter(true, true)); BigInteger md5 = new BigInteger("0");
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "org"), new FileDeleter(true, true)); md5 = Util.dir2md5(schemaDir.toFile(), md5);
Files.walkFileTree(Paths.get(outputFolder.getAbsolutePath(), "oasis"), new FileDeleter(true, true));
} else if (!md5.toString(16).equals("64fffffdb208ef0382a769611d2ab54"))
Files.walkFileTree(outputFolder.toPath(), new FileDeleter(true)); throw new Exception("Contents of subfolder 'schemas' have been altered. Please restore its original state.");
} }
private void printUsage(CmdLineParser parser, PrintStream out) { if (!Files.exists(adeSchemaFile) || !Files.isRegularFile(adeSchemaFile) || !Files.isReadable(adeSchemaFile))
out.println("Usage: java -jar ade-xjc.jar [-options] ade.xsd"); throw new Exception("Could not open ADE schema file " + adeSchemaFile.toAbsolutePath().toString());
out.println();
out.println("where options include:"); if (adeBindingFile != null && (!Files.exists(adeBindingFile)
parser.printUsage(System.out); || !Files.isRegularFile(adeBindingFile)
out.println(); || !Files.isReadable(adeBindingFile)))
} throw new Exception("Could not open ADE binding file " + adeBindingFile.toAbsolutePath());
}
private void log(LogLevel level, String msg) {
StringBuilder builder = new StringBuilder(); private void cleanBuildEnvironment(boolean cleanAll) throws IOException {
builder.append("[") if (!cleanAll) {
.append(df.format(new Date())) Files.walkFileTree(outputFolder.resolve("net/opengis/citygml"), new FileDeleter(true));
.append(" ") Files.walkFileTree(outputFolder.resolve("net/opengis/gml"), new FileDeleter(true));
.append(level.toString()) Files.walkFileTree(outputFolder.resolve("oasis/names/tc/ciq/xsdschema/xal/_2"), new FileDeleter(true));
.append("] ") Files.walkFileTree(outputFolder.resolve("org/citygml4j"), new FileDeleter(true));
.append(msg); Files.walkFileTree(outputFolder.resolve("org/w3/_1999/xlink"), new FileDeleter(true));
Files.walkFileTree(outputFolder.resolve("org/w3/_2001/smil20"), new FileDeleter(true));
System.out.println(builder.toString()); Files.walkFileTree(outputFolder.resolve("net"), new FileDeleter(true, true));
} Files.walkFileTree(outputFolder.resolve("org"), new FileDeleter(true, true));
Files.walkFileTree(outputFolder.resolve("oasis"), new FileDeleter(true, true));
private enum LogLevel { } else
INFO("info"), Files.walkFileTree(outputFolder, new FileDeleter(true));
WARN("warn"), }
ERROR("error");
private void printUsage(CmdLineParser parser, PrintStream out) {
private String value; out.println("Usage: " + getClass().getPackage().getImplementationTitle() + " [-options] ade.xsd");
out.println();
LogLevel(String value) { out.println("where options include:");
this.value = value; parser.printUsage(System.out);
} out.println();
}
public String toString() {
return value; private void log(LogLevel level, String msg) {
} System.out.println("[" + df.format(new Date()) + " " + level.toString() + "] " + msg);
} }
} private enum LogLevel {
INFO("info"),
WARN("warn"),
ERROR("error");
private String value;
LogLevel(String value) {
this.value = value;
}
public String toString() {
return value;
}
}
}
...@@ -32,17 +32,17 @@ public class FileDeleter extends SimpleFileVisitor<Path> { ...@@ -32,17 +32,17 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
private boolean recursive; private boolean recursive;
private boolean onlyEmptyDirs; private boolean onlyEmptyDirs;
public FileDeleter(boolean recursive) { FileDeleter(boolean recursive) {
this(recursive, false); this(recursive, false);
} }
public FileDeleter(boolean recursive, boolean onlyEmptyDirs) { FileDeleter(boolean recursive, boolean onlyEmptyDirs) {
this.recursive = recursive; this.recursive = recursive;
this.onlyEmptyDirs = onlyEmptyDirs; this.onlyEmptyDirs = onlyEmptyDirs;
} }
boolean deleteFile(Path file) throws IOException { private void deleteFile(Path file) throws IOException {
return Files.deleteIfExists(file); Files.deleteIfExists(file);
} }
@Override @Override
...@@ -54,7 +54,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> { ...@@ -54,7 +54,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
} }
@Override @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
...@@ -77,7 +77,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> { ...@@ -77,7 +77,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
} }
@Override @Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { public FileVisitResult visitFileFailed(Path file, IOException exc) {
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
......
/* /*
* ade-xjc - XML Schema binding compiler for CityGML ADEs * ade-xjc - XML Schema binding compiler for CityGML ADEs
* https://github.com/citygml4j/ade-xjc * https://github.com/citygml4j/ade-xjc
* *
* ade-xjc is part of the citygml4j project * ade-xjc is part of the citygml4j project
* *
* Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com> * Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.citygml4j.ade_xjc; package org.citygml4j.ade_xjc;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileInputStream;
import java.io.FileInputStream; import java.io.IOException;
import java.io.FileNotFoundException; import java.io.InputStream;
import java.io.IOException; import java.math.BigInteger;
import java.io.InputStream; import java.net.MalformedURLException;
import java.math.BigInteger; import java.net.URL;
import java.net.MalformedURLException; import java.nio.file.Path;
import java.net.URL; import java.security.MessageDigest;
import java.nio.file.Path; import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; public class Util {
public class Util { public static BigInteger dir2md5(File file, BigInteger md5) throws NoSuchAlgorithmException {
md5 = string2md5(file.getName(), md5);
public static BigInteger dir2md5(File file, BigInteger md5) throws NoSuchAlgorithmException, FileNotFoundException {
md5 = string2md5(file.getName(), md5); if (file.isDirectory()) {
File[] children = file.listFiles(pathname -> pathname.isDirectory()
if (file.isDirectory()) { || pathname.getName().endsWith("xsd")
File[] children = file.listFiles(new FileFilter() { || pathname.getName().endsWith("xjb"));
public boolean accept(File pathname) {
if (pathname.isDirectory()) if (children != null) {
return true; for (File next : children)
md5 = dir2md5(next, md5);
if (pathname.getName().endsWith("xsd") || pathname.getName().endsWith("xjb")) }
return true; } else
md5 = file2md5(file.getAbsolutePath(), md5);
return false;
} return md5;
}); }
for (File next : children) private static BigInteger file2md5(String fileName, BigInteger md5) throws NoSuchAlgorithmException {
md5 = dir2md5(next, md5); MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] buffer = new byte[8192];
} else int read;
md5 = file2md5(file.getAbsolutePath(), md5);
try (InputStream is = new FileInputStream(new File(fileName))) {
return md5; while( (read = is.read(buffer)) > 0)
} digest.update(buffer, 0, read);
public static BigInteger file2md5(String fileName, BigInteger md5) throws NoSuchAlgorithmException, FileNotFoundException { byte[] md5sum = digest.digest();
MessageDigest digest = MessageDigest.getInstance("MD5");
InputStream is = new FileInputStream(new File(fileName)); return md5.xor(new BigInteger(1, md5sum));
byte[] buffer = new byte[8192]; } catch(IOException e) {
int read = 0; throw new RuntimeException("Unable to process file for MD5", e);
}
try { }
while( (read = is.read(buffer)) > 0)
digest.update(buffer, 0, read); private static BigInteger string2md5(String input, BigInteger md5) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] md5sum = digest.digest(); byte[] md5sum = digest.digest(input.getBytes());
return md5.xor(new BigInteger(1, md5sum)); return md5.xor(new BigInteger(1, md5sum));
} catch(IOException e) { }
throw new RuntimeException("Unable to process file for MD5", e);
} finally { public static class URLClassLoader extends java.net.URLClassLoader {
try { URLClassLoader() {
is.close(); super(new URL[]{}, ADESchemaCompiler.class.getClassLoader());
} }
catch(IOException e) {
throw new RuntimeException("Unable to close input stream for MD5 calculation", e); @Override
} protected void addURL(URL url) {
} super.addURL(url);
} }
private static BigInteger string2md5(String input, BigInteger md5) throws NoSuchAlgorithmException { void addPath(Path path) {
MessageDigest digest = MessageDigest.getInstance("MD5"); try {
byte[] md5sum = digest.digest(input.getBytes()); super.addURL(path.toUri().toURL());
} catch (MalformedURLException e) {
return md5.xor(new BigInteger(1, md5sum)); //
} }
}
public static class URLClassLoader extends java.net.URLClassLoader { }
protected URLClassLoader() {
super(new URL[]{}, Util.class.getClassLoader()); }
}
@Override
protected void addURL(URL url) {
super.addURL(url);
}
protected void addPath(Path path) {
try {
super.addURL(path.toUri().toURL());
} catch (MalformedURLException e) {
//
}
}
}
}
/* /*
* ade-xjc - XML Schema binding compiler for CityGML ADEs * ade-xjc - XML Schema binding compiler for CityGML ADEs
* https://github.com/citygml4j/ade-xjc * https://github.com/citygml4j/ade-xjc
* *
* ade-xjc is part of the citygml4j project * ade-xjc is part of the citygml4j project
* *
* Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com> * Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.citygml4j.ade_xjc; package org.citygml4j.ade_xjc;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import com.sun.tools.xjc.api.ErrorListener; import com.sun.tools.xjc.api.ErrorListener;
public class XJCErrorListener implements ErrorListener { public class XJCErrorListener implements ErrorListener {
public void error(SAXParseException ex) { public void error(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
public void fatalError(SAXParseException ex) { public void fatalError(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
public void info(SAXParseException ex) { public void info(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
public void warning(SAXParseException ex) { public void warning(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment