Skip to content

Commit

Permalink
[Build] Include a compressed DocBook schema in distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8000-0000 committed Apr 26, 2020
1 parent 2b31ba7 commit cab97c3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
38 changes: 29 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -48,10 +47,6 @@ application {
executableDir = 'bin'
}

applicationDistribution.from("src/test/resources/") {
into "test"
}

task createAllStartScripts() {
// just a placeholder
}
Expand Down Expand Up @@ -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
Binary file added src/dist/schemas/docbook.rng.gz
Binary file not shown.
27 changes: 24 additions & 3 deletions src/main/java/net/signbit/samx/ConvertToXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")));

Expand Down

0 comments on commit cab97c3

Please sign in to comment.