From 924e6b827a7c21ca99db02bfc0d65cb015500877995000252b5fc6466ebc282d Mon Sep 17 00:00:00 2001 From: Michal Vyskocil Date: Mon, 12 Aug 2013 08:58:12 +0000 Subject: [PATCH] Accepting request 186711 from home:mvyskocil:branches:Java:packages - implement batch support for saxon: saxon-batch * requested by docu team * adds saxon6-batch script with new -batch/-style arguments, which allows to proceed more XML files per one JVM launch removing the bootleneck in docu build OBS-URL: https://build.opensuse.org/request/show/186711 OBS-URL: https://build.opensuse.org/package/show/Java:packages/saxon6?expand=0&rev=9 --- saxon6-batch.patch | 169 ++++++++++++++++++++++++++++++++++++++ saxon6.changes | 9 ++ saxon6.saxon-batch.script | 41 +++++++++ saxon6.spec | 10 ++- 4 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 saxon6-batch.patch create mode 100644 saxon6.saxon-batch.script diff --git a/saxon6-batch.patch b/saxon6-batch.patch new file mode 100644 index 0000000..a607461 --- /dev/null +++ b/saxon6-batch.patch @@ -0,0 +1,169 @@ +--- + com/icl/saxon/StyleSheetBatch.java | 160 +++++++++++++++++++++++++++++++++++++ + 1 file changed, 160 insertions(+) + +Index: saxon6-6.5.5/com/icl/saxon/StyleSheetBatch.java +=================================================================== +--- /dev/null ++++ saxon6-6.5.5/com/icl/saxon/StyleSheetBatch.java +@@ -0,0 +1,160 @@ ++/** ++ * This StyleSheetBatch class supports multiple input/output files proceed by StyleSheet.main(). ++ * It does work around the performance problems when running an extra saxon/JVM process for each file

++ * ++ * The XSLT syntax supported conforms to the W3C XSLT 1.0 and XPath 1.0 recommendation. ++ * Only the transformation language is implemented (not the formatting objects). ++ * Saxon extensions are documented in the file extensions.html ++ * ++ * @author Michal Vyskocil ++ */ ++ ++package com.icl.saxon; ++ ++import java.io.BufferedReader; ++import java.io.IOException; ++import java.io.File; ++import java.io.FileReader; ++import java.io.FileNotFoundException; ++ ++import java.util.Arrays; ++import java.util.List; ++import java.util.Vector; ++ ++public class StyleSheetBatch { ++ ++ protected static String toString(List lst) { ++ StringBuilder sb = new StringBuilder(); ++ for (String s: lst) { ++ sb.append(s); ++ sb.append(", "); ++ } ++ return sb.toString(); ++ } ++ ++ public static void main (String args[]) ++ throws java.lang.Exception { ++ ++ int i = -1; ++ int bi = -1; // -batch index ++ int si = -1; // -style index ++ int pi = 65536; // param=value lowest index ++ String batchFileName = null; ++ String styleFileName = null; ++ String line = null; ++ String foo[] = null; ++ List alist = null; ++ List arglist = null; ++ File batchFile = null; ++ BufferedReader batchReader = null; ++ ++ Boolean have_params = false; ++ ++ if (args.length == 0) { ++ System.err.println("All arguments are missing, type saxon6 for help"); ++ System.exit(1); ++ } ++ ++ for(i = 0; i != args.length; i++) { ++ if (args[i].equals("-batch")) { ++ bi = i; ++ i++; ++ if (args.length < i+1) { ++ System.err.println("No batch file specified after -batch argument"); ++ System.exit(1); ++ } ++ batchFileName = args[i]; ++ } ++ if (args[i].equals("-style")) { ++ si = i; ++ i++; ++ if (args.length < i+1) { ++ System.err.println("No xsl file specified after -style argument"); ++ System.exit(1); ++ } ++ styleFileName = args[i]; ++ } ++ } ++ ++ if (batchFileName == null) { ++ System.err.println("No batch file specified, call saxon6-batch with -batch -style arguments"); ++ System.exit(1); ++ } ++ ++ // remove -batch from args ++ alist = new Vector(args.length - 4); ++ for(i = 0; i != args.length; i++) { ++ //System.err.println(String.format("DEBUG: processing args[%d]: %s", i, args[i])); ++ if ((i == bi) || (i == bi + 1) || (i == si) || (i == si + 1)) { ++ //System.err.println(String.format("DEBUG: skipped args[%d]: %s", i, args[i])); ++ continue; ++ } ++ //System.err.println(String.format("DEBUG: added args[%d]: %s", i, args[i])); ++ alist.add(args[i]); ++ } ++ ++ // get the index of first param ++ i = 0; ++ for (String s: alist) { ++ if (s.indexOf('=') != -1) { ++ pi = i; ++ have_params = true; ++ break; ++ } ++ i++; ++ } ++ ++ batchFile = new File(batchFileName); ++ ++ if (!batchFile.canRead()) { ++ System.err.println(String.format("Cannot read batch-file ``%s''", batchFileName)); ++ return; ++ } ++ ++ try { ++ batchReader = new BufferedReader(new FileReader(batchFile)); ++ } catch (FileNotFoundException fnfe) { ++ System.err.println(String.format("Cannot read batch-file ``%s''", batchFileName)); ++ return; ++ } ++ ++ try { ++ ++ while ((line = batchReader.readLine()) != null) { ++ ++ foo = line.split(";", 2); ++ arglist = new Vector(4+alist.size()); ++ //output file ++ arglist.add("-o"); ++ arglist.add(foo[1]); ++ if (have_params) { ++ //System.err.println(String.format("DEBUG: arglist.addAll(alist.subList(0, %d))", pi-1)); ++ // everything up to first property ++ arglist.addAll(alist.subList(0, pi-1)); ++ } ++ else { ++ arglist.addAll(alist); ++ } ++ // add inp file ++ arglist.add(foo[0]); ++ // add stylesheet ++ arglist.add(styleFileName); ++ if (have_params) { ++ // add all properties ++ arglist.addAll(alist.subList(pi, alist.size())); ++ } ++ ++ //System.err.println("DEBUG: call com.icl.saxon.StyleSheet.main(" + toString(arglist)); ++ ++ StyleSheet.main(arglist.toArray(new String[0])); ++ ++ } ++ ++ } catch (IOException ioe) { ++ System.err.println(String.format("Can't read from ``%s''", batchFileName)); ++ return; ++ } ++ ++ } ++ ++} diff --git a/saxon6.changes b/saxon6.changes index 102c90a..7d6e1a0 100644 --- a/saxon6.changes +++ b/saxon6.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Mon Aug 12 08:55:15 UTC 2013 - mvyskocil@suse.com + +- implement batch support for saxon: saxon-batch + * requested by docu team + * adds saxon6-batch script with new -batch/-style arguments, which + allows to proceed more XML files per one JVM launch removing the + bootleneck in docu build + ------------------------------------------------------------------- Thu Jul 11 13:48:28 UTC 2013 - toms@opensuse.org diff --git a/saxon6.saxon-batch.script b/saxon6.saxon-batch.script new file mode 100644 index 0000000..dd7e9f5 --- /dev/null +++ b/saxon6.saxon-batch.script @@ -0,0 +1,41 @@ +#!/bin/sh +# +# saxon script +# JPackage Project + +. /usr/share/java-utils/java-functions + +MAIN_CLASS=com.icl.saxon.StyleSheetBatch + +BASE_JARS="saxon6.jar xml-commons-apis.jar jaxp_parser_impl.jar" + +# Optional jars +CLASSPATH="$CLASSPATH:"$(build-classpath docbook-xsl-saxon saxon-fop \ + avalon-logkit xml-commons-resolver 2>/dev/null) || : + +# If we have resolver, add the CatalogManager.properties dir to CLASSPATH, +# and tweak command line options so that it's used. +args= +if echo "$CLASSPATH" | grep xml-commons-resolver >/dev/null 2>&1 ; then + CLASSPATH="$CLASSPATH:__RESOLVERDIR__" + # Tune options to use resolver. + r=org.apache.xml.resolver.tools.ResolvingXMLReader + for opt in -x -y ; do + if ! echo $@ | grep "\\$opt " >/dev/null 2>&1 ; then + args="$args $opt $r" + fi + done + r=org.apache.xml.resolver.tools.CatalogResolver + if ! echo $@ | grep "\\-r " >/dev/null 2>&1 ; then + args="$args -r $r" + fi +fi + +# Set parameters +set_jvm +set_classpath $BASE_JARS +set_flags $BASE_FLAGS +set_options $BASE_OPTIONS + +# Let's start +run $args "$@" diff --git a/saxon6.spec b/saxon6.spec index b3dd345..cb859ed 100644 --- a/saxon6.spec +++ b/saxon6.spec @@ -31,12 +31,16 @@ Source1: %{name}.saxon.script Source2: %{name}.build.script Source3: %{name}.1 Source4: http://www.xml.com/2000/08/09/xslt/StructXmlParser.java +# implementes batch based interface to saxon6, SUSE specific +Source5: saxon6.saxon-batch.script Patch2: %{name}-cmdlinefix.patch #PATCH-FIX-OPENSUSE: jdk7+ assumes ASCII as default encoding, so iso-8859-1 does not work by default Patch3: saxon-javac-encoding.patch #PATCH-FIX-OPENSUSE: bnc#739498 - backport changes from com/icl/saxon/aelfred/XmlParser.java # to older version released under more permissive license Patch4: saxon-add-fixes-from-com-isl-saxon-aelfred.patch +#PATCH-FIX-OPENSUSE: implements batch mode in which saxon is capable to proceed more files per one JVM launch +Patch5: saxon6-batch.patch BuildRequires: fop >= 0.20.1 BuildRequires: jdom >= 1.0 BuildRequires: jpackage-utils >= 1.6 @@ -52,8 +56,6 @@ BuildRequires: unzip %endif Requires: /usr/sbin/update-alternatives Requires: jaxp_parser_impl -Recommends: %{name}-scripts -Recommends: xml-commons-resolver Provides: jaxp_transform_impl = %{name}-%{version} # bnc#780666 Provides: saxon @@ -159,6 +161,7 @@ cp -p %{SOURCE4} XmlParser.java %patch2 -p0 %patch3 -p1 %patch4 -p0 +%patch5 -p1 cp XmlParser.java com/icl/saxon/aelfred/XmlParser.java # cleanup unnecessary stuff we'll build ourselves rm -rf *.jar docs/api @@ -193,6 +196,8 @@ mkdir -p %{buildroot}%{_bindir} sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE1} \ > %{buildroot}%{_bindir}/%{name} ln -s %{name} %{buildroot}%{_bindir}/saxon +sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE5} \ + > %{buildroot}%{_bindir}/%{name}-batch mkdir -p %{buildroot}%{_mandir}/man1 sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE3} \ @@ -251,6 +256,7 @@ update-alternatives --install %{_javadir}/jaxp_transform_impl.jar \ %files scripts %defattr(0755,root,root,0755) %{_bindir}/%{name} +%{_bindir}/%{name}-batch %{_bindir}/saxon %attr(0644,root,root) %{_mandir}/man1/%{name}.1*