Skip to content

Commit

Permalink
Merge pull request #107 from ndw/dev
Browse files Browse the repository at this point in the history
Add extension functions to the distribution
  • Loading branch information
ndw authored Mar 11, 2018
2 parents 250f16c + dae1f6b commit b86ba54
Show file tree
Hide file tree
Showing 289 changed files with 1,227 additions and 482 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/tools/lib/cachedir/
/.gradle/
/build/
/out/
/buildSrc/.gradle/
/buildSrc/build/
# Local libraries that should not be committed or distributed
/lib/
/out/
18 changes: 13 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ buildscript {
classpath group: 'com.xmlcalabash', name: 'xmlcalabash', version: xmlCalabashVersion
classpath group: 'com.xmlcalabash', name: 'xmlcalabash1-gradle', version: '1.3.3'
classpath group: 'com.xmlcalabash', name: 'xmlcalabash1-deltaxml', version: '1.1.4'
classpath group: 'org.docbook', name: 'docbook-xsl-java-saxon', version: '1.2.1-95'
classpath group: 'org.docbook', name: 'docbook-schemas', version: '5.1-1'
}
}
Expand Down Expand Up @@ -59,7 +58,6 @@ dependencies {
compile (
[group: 'net.sf.saxon', name: 'Saxon-HE', version: saxonVersion],
[group: 'com.thaiopensource', name: 'jing', version: '20091111', transitive: false],
[group: 'org.docbook', name: 'docbook-xsl-java-saxon', version: '1.2.1-95'],
[group: 'com.xmlcalabash', name: 'xmlcalabash', version: xmlCalabashVersion],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-gradle', version: '1.3.3'],

Expand Down Expand Up @@ -233,17 +231,17 @@ schemas.each { String rnc ->
// ======================================================================
// Run tests

task test_html() {
task test_html(dependsOn: [ "setupTestResources" ]) {
// just a task to hang dependencies on
};
test.dependsOn test_html

task test_print_css() {
task test_print_css(dependsOn: [ "setupTestResources" ]) {
// just a task to hang dependencies on
};
test.dependsOn test_print_css

task test_print_fo() {
task test_print_fo(dependsOn: [ "setupTestResources" ]) {
// just a task to hang dependencies on
};
test.dependsOn test_print_fo
Expand Down Expand Up @@ -311,6 +309,16 @@ tests.each { File file ->
test_print_fo.dependsOn "test_print_fo_$testname"
}

task setupTestResources(type: Copy, dependsOn: [ "setupResources" ]) {
from "build/docbook-xslt20-resources-" + resourcesVersion
into "build/test/resources"
rename ("build/test/resources/docbook-xslt20-resources-" + resourcesVersion,
"build/test/resources")
doFirst {
mkdir("build/test/resources")
}
}

// ======================================================================
// Make test report(s)

Expand Down
19 changes: 19 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This Gradle script builds the extension functions for the build process

plugins {
id "java"
}

repositories {
maven { url uri('/tmp/repo') }
mavenLocal()
mavenCentral()
maven { url "http://maven.restlet.org" }
}

dependencies {
compile (
[group: 'com.nwalsh', name: 'nwalsh-annotations', version: '1.0.0'],
[group: 'net.sf.saxon', name: 'Saxon-HE', version: "9.8.0-8"],
)
}
70 changes: 70 additions & 0 deletions buildSrc/src/main/java/org/docbook/extensions/xslt20/Cwd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.docbook.extensions.xslt20;


import com.nwalsh.annotations.SaxonExtensionFunction;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.AnyURIValue;
import net.sf.saxon.value.SequenceType;

/**
* Saxon extension to get the current working directory.
*
* This class provides a
* <a href="http://saxonica.com/">Saxon</a>
* extension to return the current working directory (the user.dir system property).
*
* <p>Copyright © 2011-2018 Norman Walsh.
*
* @author Norman Walsh
* <a href="mailto:[email protected]">[email protected]</a>
*/
@SaxonExtensionFunction
public class Cwd extends ExtensionFunctionDefinition {
private static final StructuredQName qName =
new StructuredQName("", "http://docbook.org/extensions/xslt20", "cwd");

@Override
public StructuredQName getFunctionQName() {
return qName;
}

@Override
public int getMinimumNumberOfArguments() {
return 0;
}

@Override
public int getMaximumNumberOfArguments() {
return 0;
}

@Override
public SequenceType[] getArgumentTypes() {
// If it takes no arguments, what's this for?
return new SequenceType[]{SequenceType.OPTIONAL_NUMERIC};
}

@Override
public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
return SequenceType.SINGLE_ATOMIC;
}

public ExtensionFunctionCall makeCallExpression() {
return new CwdCall();
}

private class CwdCall extends ExtensionFunctionCall {
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
String dir = System.getProperty("user.dir");
if (!dir.endsWith("/")) {
dir += "/";
}
return new AnyURIValue(dir);
}
}
}
Loading

0 comments on commit b86ba54

Please sign in to comment.