diff --git a/build.gradle b/build.gradle index c1874a3..f9663b6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id 'java-library' id 'antlr' - id 'distribution' id 'application' id 'maven-publish' id "de.undercouch.download" version "4.0.4" @@ -48,10 +47,6 @@ application { executableDir = 'bin' } -applicationDistribution.from("src/test/resources/") { - into "test" -} - task createAllStartScripts() { // just a placeholder } @@ -96,17 +91,42 @@ task downloadRelaxSchema(type: Download) { overwrite false } +task createDocs { + def docs = file("$buildDir/docs") + outputs.dir docs + doLast { + docs.mkdirs() + } +} + task generateBook(type: JavaExec) { description = 'Generates the documentation in DocBook format' group = 'verification' classpath = sourceSets.main.runtimeClasspath main = 'net.signbit.samx.ConvertToXml' - args = ['-i', 'doc/samx_language.samx', '-o', 'build/samx_language.dbk', '-b'] + args = ['-i', 'doc/samx_language.samx', '-o', 'build/docs/samx_language.dbk', '-b', '-s', 'src/dist/schemas/docbook.rng.gz'] mustRunAfter test } -tasks.build.dependsOn downloadRelaxSchema +tasks.generateBook.dependsOn createDocs -tasks.generateBook.dependsOn downloadRelaxSchema +check.dependsOn generateBook + +distributions { + main { + contents { + from 'README.md' + + from("src/test/resources/") { + into "examples" + } + from(createDocs) { + into 'docs' + } + from(generateBook) { + into 'docs' + } + } + } +} -check.dependsOn generateBook \ No newline at end of file diff --git a/src/dist/schemas/docbook.rng.gz b/src/dist/schemas/docbook.rng.gz new file mode 100644 index 0000000..af666a2 Binary files /dev/null and b/src/dist/schemas/docbook.rng.gz differ diff --git a/src/main/java/net/signbit/samx/ConvertToXml.java b/src/main/java/net/signbit/samx/ConvertToXml.java index bcbdfb0..017631e 100644 --- a/src/main/java/net/signbit/samx/ConvertToXml.java +++ b/src/main/java/net/signbit/samx/ConvertToXml.java @@ -19,6 +19,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.*; +import java.util.zip.GZIPInputStream; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -60,6 +61,9 @@ protected void addCustomOptions(Options options) Option rootElementVersion = new Option("v", "version", true, "root element version (default null)"); options.addOption(rootElementVersion); + + Option schemaPath = new Option("s", "schema", true, "RelaxNG schema"); + options.addOption(schemaPath); } @Override @@ -114,10 +118,20 @@ protected void addCustomOptions(CommandLine cmd) private File findSchemaFile(CommandLine cmd) { + File schemaFile = null; + + if (cmd.getOptionValue("schema") != null) + { + schemaFile = new File(cmd.getOptionValue("schema")); + if (schemaFile.exists()) + { + return schemaFile; + } + } + final File outputFile = new File(cmd.getOptionValue("output")); final File outputFileParent = outputFile.getParentFile(); - - File schemaFile = new File(outputFileParent, "docbook.rng"); + schemaFile = new File(outputFileParent, "docbook.rng"); if (schemaFile.exists()) { return schemaFile; @@ -153,7 +167,14 @@ protected void performCheck(CommandLine cmd) try { final ValidationDriver vd = new ValidationDriver(); - vd.loadSchema(new InputSource(new FileInputStream(schemaFile))); + + InputStream schemaStream = new FileInputStream(schemaFile); + if (schemaFile.getName().endsWith(".gz")) + { + schemaStream = new GZIPInputStream(schemaStream); + } + + vd.loadSchema(new InputSource(schemaStream)); final boolean isValid = vd.validate(new InputSource(cmd.getOptionValue("output")));