Accepting request 186712 from 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 (forwarded request 186711 from mvyskocil)

OBS-URL: https://build.opensuse.org/request/show/186712
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/saxon6?expand=0&rev=4
This commit is contained in:
Tomáš Chvátal 2013-08-18 20:24:00 +00:00 committed by Git OBS Bridge
commit e7786f478f
4 changed files with 227 additions and 2 deletions

169
saxon6-batch.patch Normal file
View File

@ -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 <B>StyleSheetBatch</B> 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<p>
+ *
+ * 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<String> 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<String> alist = null;
+ List<String> 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 <filename> -style <file.xsl> arguments");
+ System.exit(1);
+ }
+
+ // remove -batch <filename> from args
+ alist = new Vector<String>(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<String>(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;
+ }
+
+ }
+
+}

View File

@ -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 Thu Jul 11 13:48:28 UTC 2013 - toms@opensuse.org

41
saxon6.saxon-batch.script Normal file
View File

@ -0,0 +1,41 @@
#!/bin/sh
#
# saxon script
# JPackage Project <http://www.jpackage.org/>
. /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 "$@"

View File

@ -31,12 +31,16 @@ Source1: %{name}.saxon.script
Source2: %{name}.build.script Source2: %{name}.build.script
Source3: %{name}.1 Source3: %{name}.1
Source4: http://www.xml.com/2000/08/09/xslt/StructXmlParser.java 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 Patch2: %{name}-cmdlinefix.patch
#PATCH-FIX-OPENSUSE: jdk7+ assumes ASCII as default encoding, so iso-8859-1 does not work by default #PATCH-FIX-OPENSUSE: jdk7+ assumes ASCII as default encoding, so iso-8859-1 does not work by default
Patch3: saxon-javac-encoding.patch Patch3: saxon-javac-encoding.patch
#PATCH-FIX-OPENSUSE: bnc#739498 - backport changes from com/icl/saxon/aelfred/XmlParser.java #PATCH-FIX-OPENSUSE: bnc#739498 - backport changes from com/icl/saxon/aelfred/XmlParser.java
# to older version released under more permissive license # to older version released under more permissive license
Patch4: saxon-add-fixes-from-com-isl-saxon-aelfred.patch 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: fop >= 0.20.1
BuildRequires: jdom >= 1.0 BuildRequires: jdom >= 1.0
BuildRequires: jpackage-utils >= 1.6 BuildRequires: jpackage-utils >= 1.6
@ -52,8 +56,6 @@ BuildRequires: unzip
%endif %endif
Requires: /usr/sbin/update-alternatives Requires: /usr/sbin/update-alternatives
Requires: jaxp_parser_impl Requires: jaxp_parser_impl
Recommends: %{name}-scripts
Recommends: xml-commons-resolver
Provides: jaxp_transform_impl = %{name}-%{version} Provides: jaxp_transform_impl = %{name}-%{version}
# bnc#780666 # bnc#780666
Provides: saxon Provides: saxon
@ -159,6 +161,7 @@ cp -p %{SOURCE4} XmlParser.java
%patch2 -p0 %patch2 -p0
%patch3 -p1 %patch3 -p1
%patch4 -p0 %patch4 -p0
%patch5 -p1
cp XmlParser.java com/icl/saxon/aelfred/XmlParser.java cp XmlParser.java com/icl/saxon/aelfred/XmlParser.java
# cleanup unnecessary stuff we'll build ourselves # cleanup unnecessary stuff we'll build ourselves
rm -rf *.jar docs/api rm -rf *.jar docs/api
@ -193,6 +196,8 @@ mkdir -p %{buildroot}%{_bindir}
sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE1} \ sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE1} \
> %{buildroot}%{_bindir}/%{name} > %{buildroot}%{_bindir}/%{name}
ln -s %{name} %{buildroot}%{_bindir}/saxon ln -s %{name} %{buildroot}%{_bindir}/saxon
sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE5} \
> %{buildroot}%{_bindir}/%{name}-batch
mkdir -p %{buildroot}%{_mandir}/man1 mkdir -p %{buildroot}%{_mandir}/man1
sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE3} \ sed 's,__RESOLVERDIR__,%{resolverdir},' < %{SOURCE3} \
@ -251,6 +256,7 @@ update-alternatives --install %{_javadir}/jaxp_transform_impl.jar \
%files scripts %files scripts
%defattr(0755,root,root,0755) %defattr(0755,root,root,0755)
%{_bindir}/%{name} %{_bindir}/%{name}
%{_bindir}/%{name}-batch
%{_bindir}/saxon %{_bindir}/saxon
%attr(0644,root,root) %{_mandir}/man1/%{name}.1* %attr(0644,root,root) %{_mandir}/man1/%{name}.1*