Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ant build support for Schematron #160

Merged
merged 59 commits into from Feb 4, 2018
Merged

Add Ant build support for Schematron #160

merged 59 commits into from Feb 4, 2018

Conversation

cirulls
Copy link
Member

@cirulls cirulls commented Jan 24, 2018

Summary

This pull request integrates #138 submitted by @markdunnoup and allows to run XSpec tests for Schematron using the ant build script. For further detail, please see conversation in #138.

This pull request also adds two bats tests checking that the ant build script works correctly for XSLT and Schematron.

As this was approved by @markdunnoup and me in #138 (comment), I'm merging into master.

Further work

I will update the documentation in the wiki.

@AirQuick: would you be able to add similar tests for the batch script? Note that ant is installed by default in Travis but I had to install additional ant libraries in .travis.yaml. Ant may not be installed by default on AppVeyor.

Copy link
Member

@AirQuick AirQuick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions.
I didn't track the original PR in details. Sorry if they're already answered.

build.xml Outdated
</antcall>
</sequential>
</macrodef>
<!-- OXYGEN PATCH needed to create a custom Saxon, for example -warnings:recover -strip:none -opt:10 -dtd:off -l:off -versionmsg:off -expand:on -outval:fatal -val:lax -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These OXYGEN PATCH phrases are confusing. As the changes are being committed here, they aren't patches anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the OXYGEN PATCH title but kept the comment for documentation purposes in 3b1a6f4

build.xml Outdated
name="http://saxon.sf.net/feature/allow-external-functions"
value="true"/>
</factory>
</xslt>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saxon.custom.options is defined before, but not used here. Why? (Is it possible in the first place?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess saxon.custom.options is used by oXygen. I can see it is defined with this comment:

  <!-- OXYGEN PATCH needed to create a custom Saxon, for example  -warnings:recover -strip:none -opt:10 -dtd:off -l:off -versionmsg:off -expand:on -outval:fatal -val:lax -->
  <property name="saxon.custom.options" value=""/>
  <!-- OXYGEN PATCH END -->

I wonder if it is is worth removing oXygen customizations that are currently not needed for this feature and work with oXygen for a smooth integration of XSpec. This should also address #138 (comment) raised by @markdunnoup.

Shall we just remove the saxon.custom.options if not used? Do you see any side effect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may just remove it, but...
This PR changes <java> to <xslt>. Is it easy to implement the feature of saxon.custom.options in <xslt>? I'm afraid not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reintroduced the use of <java> instead of <xslt> in 3bcb2cd#diff-2cccd7bf48b7a9cc113ff564acd802a8R227. I have kept saxon.custom.options as a result.

build.xml Outdated
force="true"
>
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oXygen's build.xml enables XML catalog here and in other places. Whey are they not incorporated in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reintroduced XML catalog in various places in 3bcb2cd following the current version of build.xml packaged with oXygen 19. I had to add xml-resolver.jar as additional jar library in .travis.yaml and appveyor.yaml otherwise tests failed on my local machine with the following error message:

[java] Transformation failed: Failed to load Apache catalog resolver library [java]

Tests are passing on Travis but failing on AppVeyor. The culprit is the ant test for Schematron which fails with this error:

[java] Error on line 12 column 87 of demo-03.xsl:
     [java]   Malformed URL C:/projects/xspec/tutorial/schematron/demo-03-sch-compiled.xsl(base
     [java]   file:/C:/projects/xspec/tutorial/schematron/xspec/demo-03.xsl): unknown protocol: c
     [java] Malformed URL C:/projects/xspec/tutorial/schematron/demo-03-sch-compiled.xsl(base file:/C:/projects/xspec/tutorial/schematron/xspec/demo-03.xsl)

The issue is the path file:/C, I suspect the XML resolver or the java command may have caused this. I also wonder if this is a similar problem I described in #138 (review) (see where I talk about file:/ in Unix and Windows) but this time it's problematic for Windows.

I won't have more time today to debug this and unfortunately Windows is not my forte. Could you have a look at this failing test in case you spot any glaring error I made?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements!
I looked at the intermediate file (demo-03.xsl) and found a fake URI:

   <xsl:import href="c:/xspec/tutorial/schematron/demo-03-sch-compiled.xsl"/>
...
   <xsl:variable name="x:stylesheet-uri"
                 as="xs:string"
                 select="'c:/xspec/tutorial/schematron/demo-03-sch-compiled.xsl'"/>

Probably 4e2ed51#diff-2cccd7bf48b7a9cc113ff564acd802a8R129 makes it.
I'm fixing it.

build.xml Outdated
xspec.phase Required if XSpec describes a Schematron file, with value "#ALL"
xspec.compiled.xsl.dir Folder in which to place the compiled XSLT file generated from a Schematron file
[Optional; the default is a subfolder "xspec" of the folder containing the XSpec file]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all parameters are explained. Are they missed? Or, will be explained only in Wiki?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more documentation in e9861f8. This will be used to update the wiki. I left the documentation on how to run it in oXygen as it will be useful for the oXygen integration and for all those who want to use it before this feature is fully integrated in oXygen.

build.xml Outdated

<!-- Copy of original XSpec file
will be overwritten if XSpec applies to Schematron -->
<property name="xspec.compiled.xml" location="${xspec.base.dir}/${xspec.base}-compiled-oxygen.xspec"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this file name have -oxygen?
It was puzzling to find such a file when I ran build.xml outside oXygen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the -oxygen from the file name in 3b1a6f4#diff-2cccd7bf48b7a9cc113ff564acd802a8R113. This should be unnecessary once we fully integrate with the oXygen ant build file.

test/xspec.bats Outdated


@test "running XSpec via ant for XSLT support" {
run ant -buildfile ${PWD}/../build.xml -Dxspec.xml=${PWD}/../tutorial/escape-for-regex.xspec -lib /tmp/xspec/saxon/saxon9he.jar -lib /tmp/ant/lib/xmltask.jar -lib /tmp/ant/lib/ant-contrib.jar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • -lib /tmp/xspec/saxon/saxon9he.jar should be -lib ${SAXON_CP} to coordinate with other tests and help changing Saxon versions/editions.
  • -lib /tmp/ant/lib/xmltask.jar -lib /tmp/ant/lib/ant-contrib.jar may be shortened to -lib /tmp/ant/lib
  • -Dclean.output.dir=true should be added, otherwise git status finds a temp file after testing locally.

Copy link
Member Author

@cirulls cirulls Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this feedback in this branch in cd32771

test/xspec.bats Outdated

@test "running XSpec via ant for Schematron support" {
echo ${PWD}
run ant -buildfile ${PWD}/../build.xml -Dxspec.xml=${PWD}/../tutorial/schematron/demo-03.xspec -lib /tmp/xspec/saxon/saxon9he.jar -lib /tmp/ant/lib/xmltask.jar -lib /tmp/ant/lib/ant-contrib.jar -Dtest.type=s -Dxspec.project.dir=${PWD}/../ -Dxspec.compiled.xsl.dir=${PWD}/../tutorial/schematron -Dxspec.phase=#ALL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After running this command line locally, git status finds tutorial/schematron/demo-03-sch-compiled.xsl even with -Dclean.output.dir=true. Is it a bug of clean.output.dir?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember @markdunnoup mentioning this in #138 (comment):

The "cleanup" target is not fully compatible with XSpec for Schematron yet. When ${clean.output.dir} is set to true, it removes SVRL files which the HTML report links to if the XSPec fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that a file is not removed. The known problem in the cited comment is that a file is removed. Are they the same thing?
Anyway, if cleanup is incomplete, it would be nice if known issues or remaining tasks are commented in the file.

Copy link
Member Author

@cirulls cirulls Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the removal of the temporary file in 3b1a6f4#diff-2cccd7bf48b7a9cc113ff564acd802a8R252, the XSL compiled file was missing. I tested it locally and it removes the temporary files when the option clean.output.dir is set to true via the command line.

@AirQuick
Copy link
Member

@AirQuick: would you be able to add similar tests for the batch script?

I pushed the tests to this branch.

  • appveyor.yml on AppVeyor defines an environment variable XSPEC_ANT_LIB and installs external Jar files there.
  • xspec-bat.cmd runs Ant tests only when the XSPEC_ANT_LIB is defined. (XSLT and Schematron)

I made so, because I usually run xspec-bat.cmd on a local computer where Ant and libraries are not readily available.

- See comment in #160 (review)
- Use SAXON_CP instead of path to Saxon
- Shorten path to ant libraries
- Add clean option to remove temp file
test/xspec.bats Outdated


@test "running XSpec via ant for XSLT support" {
run ant -buildfile ${PWD}/../build.xml -Dxspec.xml=${PWD}/../tutorial/escape-for-regex.xspec -lib ${SAXON_CP} -lib /tmp/ant/lib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, -Dclean.output.dir=true is necessary here too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I added it in ab86e9f

Sandro Cirulli and others added 10 commits January 25, 2018 17:56
- Remove comments OXYGEN_PATCH
- Remove misleading -oxygen from compiled file name
- Add removal of temporary compiled file
- Add clean option in test for XSLT support
- Add clean option in test for XSLT support
- Use <java> instead of <xslt>
- Enable XML catalog
- Add xml-resolver.jar to CI configuration
- Format and indent code
This build.xml expects Saxon Jar to be specified by the -lib command line option
because makeurl/@Validate=true by default.

Also rename the property to better represent its nature.
@AirQuick
Copy link
Member

The issue encountered on Travis was not reproduced locally even with the same version (1.9.3) of Ant. Something may be special on Travis's Ant or environment, I don't know. So I had to install a cleaner Ant on Travis.

While doing so, I noticed Bats was readily available on Travis. So I removed its installation process from .travis.yml.

As we've put some installation processes, .travis.yml and appveyor.yml are getting crowded. So I tidied them up a bit.

<fail> is reinstated in 52c123c.
With <fail>, I added a few more tests in xspec.bats and xspec-bat.cmd. In the course of adding the tests, I had to inject a test failure into tutorial/schematron/demo-04.xspec.

I hope I'm done. Please review the changes which have been accumulated unexpectedly. Beware; I'm not familiar with Ant :)

this would be the last pull request to be merged before the new release. Is this fine with you?

No problem.

@AirQuick
Copy link
Member

AirQuick commented Jan 30, 2018

I hope I'm really done now :(

Various changes have been made since the initial commit. For writing the usage in Wiki, you might want to take a look at xspec.bats and xspec-bat.cmd in test/ and an AppVeyor build log (actual command lines are printed there) as well as the usage comment in build.xml.

@cirulls
Copy link
Member Author

cirulls commented Jan 30, 2018

Thanks for your work and the many improvements. I'll review your changes this week and let you know. If everything is fine, I'll approve it and merge this branch into master.

@AirQuick
Copy link
Member

Sorry for adding commits. They are supposed to just augment tests and simplify build.xml.

@cirulls
Copy link
Member Author

cirulls commented Feb 1, 2018

@AirQuick: Thanks a lot for your work, it's amazing how you improved this original pull request! Thanks for adding additional tests (always appreciated!), for removing unncessary dependencies, and simplifying the build script. Thanks also for making the Travis and AppVeyor configurations closer and for standardizing on tools like curl.

I checked your commits and they look good to me. I just have few questions:

  1. I saw you installed Ant 1.9.8 as it is the Ant version installed in oXygen. I read your comment about the trouble you had with Ant installed by default on Travis. For documentation purposes, I'd like to know if we should state that XSpec has been tested with v1.9.8 or if XSpec actually requires Ant v1.9.8. I think the former but it would be good if you can confirm.
  2. I'll update the documentation on Ant and will ask you to review it.
  3. I noticed you introduced some JavaScript in make-path.js which is called in the build file. Was it problematic to do this with <makeurl>? I'm just a bit concerned about introducing another programming language in the code base for maintainability reasons and wonder if the same result could be achieved differently. This shouldn't stop this pull request being merged (which is my priority) but I just wanted to mention it.

Let me know what you think. I'm aiming to merge this pull request during the weekend and then working on #139 for releasing XSpec v1.0.0.

@cirulls cirulls added this to the v1.0.0 milestone Feb 1, 2018
@AirQuick
Copy link
Member

AirQuick commented Feb 2, 2018

Based on the Ant manual, the new build.xml requires Ant 1.9.1. I tested with Ant 1.9.1 and it worked. You can confirm it here. So only 1.9.1 or later should be required.
I still do not know why the preinstalled Ant (1.9.3) on Travis fails. The error message is weird. If I install the same version of Ant separately on Travis, it works.

<makeurl> converts file path to URL. What we need is a reverse function (converts URL to file path). I couldn't find a smarter way of achieving it without external language.

@cirulls
Copy link
Member Author

cirulls commented Feb 2, 2018

Thanks for your replies. I'll mention in the documentation that Ant 1.9.1 is the minimum requirement (I didn't know about if and unless in Ant, I'm glad they have been introduced so we don't have to use the ant-contrib library).

I can see the rationale for using a scripting programming language and I can see it is also one of the suggested solutions for a similar question on StackOverflow. It makes sense.

I'll merge this pull request during the weekend and review the documentation on the wiki.

@cirulls cirulls merged commit 63cf95d into master Feb 4, 2018
@cirulls cirulls deleted the review/138 branch February 4, 2018 21:30
@cirulls
Copy link
Member Author

cirulls commented Feb 4, 2018

@AirQuick: I merged this pull request into master and deleted branch review/138 (if you think of other changes, please use a new branch and open a new pull request). I updated the documentation on the wiki, in particular the section Running XSpec's Ant build file from the command line. Could you please have a look at some point? Feel free to add changes in the documentation as we can't open pull request there.

@AirQuick
Copy link
Member

AirQuick commented Feb 5, 2018

Updated the wiki:

  • Removed the section Using the xspec macro, because the macro has been removed.
  • Moved lib from the section Useful Properties to its own section, because lib is not a property.
  • Removed the phrase and are passed to the Ant build script as option using the syntax -Dproperty-value unless otherwise specified, because it is included in the list of You can override the defaults by predefining the property:.
  • Other minor fixes.

@markdunnoup
Copy link

Thanks very much to both @AirQuick and @cirulls for your efforts in improving and locking down this request!

@cirulls
Copy link
Member Author

cirulls commented Feb 5, 2018

@AirQuick: thanks for updating the wiki, it's much clearer now.
@markdunnoup: I'll close #138.

AirQuick added a commit to AirQuick/xspec that referenced this pull request Mar 26, 2018
* 'master' of git://github.com/xspec/xspec:
  Add a pom file to publish XSpec as a Maven artifact (xspec#156)
  Add Ant build support for Schematron (xspec#160)
  Add tests for CSS inline (xspec#159)
  Improvements to HTML report (xspec#135)
  Run tests with Saxon 9.8.0.7, 9.7.0.21 and 9.7.0.19 (xspec#157)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants