Subject: [PATCH 16/31] gnu: Add java-xerces.

From: Julien Lepiller <[email-masked]>
Date: Sun, 19 Nov 2017 18:57:50 +0100

* gnu/packages/java.scm (java-xerces): New variable.
* gnu/packages/patches/java-xerces-bootclasspath.patch: New file.
* gnu/packages/patches/java-xerces-build_dont_unzip.patch: New file.
* gnu/packages/patches/java-xerces-xjavac_taskdef.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add them.
---
 gnu/local.mk                                       |  3 +
 gnu/packages/java.scm                              | 74 ++++++++++++++++++++++
 .../patches/java-xerces-bootclasspath.patch        | 38 +++++++++++
 .../patches/java-xerces-build_dont_unzip.patch     | 44 +++++++++++++
 .../patches/java-xerces-xjavac_taskdef.patch       | 45 +++++++++++++
 5 files changed, 204 insertions(+)
 create mode 100644 gnu/packages/patches/java-xerces-bootclasspath.patch
 create mode 100644 gnu/packages/patches/java-xerces-build_dont_unzip.patch
 create mode 100644 gnu/packages/patches/java-xerces-xjavac_taskdef.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 2fbafe118..6094ddfc4 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -757,6 +757,9 @@ dist_patch_DATA =						\
   %D%/packages/patches/isl-0.11.1-aarch64-support.patch	\
   %D%/packages/patches/jacal-fix-texinfo.patch			\
   %D%/packages/patches/java-powermock-fix-java-files.patch		\
+  %D%/packages/patches/java-xerces-bootclasspath.patch	\
+  %D%/packages/patches/java-xerces-build_dont_unzip.patch	\
+  %D%/packages/patches/java-xerces-xjavac_taskdef.patch	\
   %D%/packages/patches/jbig2dec-ignore-testtest.patch		\
   %D%/packages/patches/jbig2dec-CVE-2016-9601.patch		\
   %D%/packages/patches/jbig2dec-CVE-2017-7885.patch		\
diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 886a71f23..873226aca 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -7992,3 +7992,77 @@ the Xerces-J XML parser and Xalan-J XSLT processor and specifies these APIs:
 to other xml.apache.org projects instead of shipping it's own \"standalone\"
 project.")
     (license license:asl2.0)))
+
+(define-public java-xerces
+  (package
+    (name "java-xerces")
+    (version "2.11.0")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "mirror://apache/xerces/j/source/"
+                           "Xerces-J-src." version ".tar.gz"))
+       (sha256
+        (base32 "1006igwy2lqrmjvdk64v8dg6qbk9c29pm8xxx7r87n0vnpvmx6pm"))
+       (patches (search-patches
+                 "java-xerces-xjavac_taskdef.patch"
+                 "java-xerces-build_dont_unzip.patch"
+                 "java-xerces-bootclasspath.patch"))))
+    (build-system ant-build-system)
+    (arguments
+     `(#:tests? #f;; Test files are not present
+       #:test-target "test"
+       #:jdk ,icedtea-8
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'create-build.properties
+          (lambda* (#:key inputs #:allow-other-keys)
+            (let ((jaxp (assoc-ref inputs "java-jaxp"))
+                  (resolver (assoc-ref inputs "java-apache-xml-commons-resolver")))
+              (with-output-to-file "build.properties"
+                (lambda _
+                  (format #t
+                   "jar.jaxp = ~a/share/java/jaxp.jar~@
+                   jar.apis-ext = ~a/share/java/jaxp.jar~@
+                   jar.resolver = ~a/share/java/xml-resolver.jar~%"
+                   jaxp jaxp resolver)))
+              ;; Make xerces use our version of jaxp in tests
+              (substitute* "build.xml"
+                (("xml-apis.jar")
+                 (string-append jaxp "/share/java/jaxp.jar"))
+                (("\\$\\{tools.dir\\}/\\$\\{jar.apis\\}")
+                 "${jar.apis}")))
+            #t))
+         (replace 'install (install-jars "build")))))
+    (inputs
+     `(("java-apache-xml-commons-resolver" ,java-apache-xml-commons-resolver)
+       ("java-jaxp" ,java-jaxp)))
+    (home-page "https://xerces.apache.org/xerces2-j/")
+    (synopsis "Validating XML parser for Java with DOM level 3 support")
+    (description "The Xerces2 Java parser is the reference implementation of
+XNI, the Xerces Native Interface, and also a fully conforming XML Schema
+processor.
+
+Xerces2-J supports the following standards and APIs:
+
+@itemize
+@item eXtensible Markup Language (XML) 1.0 Second Edition Recommendation
+@item Namespaces in XML Recommendation
+@item Document Object Model (DOM) Level 2 Core, Events, and Traversal and
+      Range Recommendations
+@item Simple API for XML (SAX) 2.0.1 Core and Extension
+@item Java APIs for XML Processing (JAXP) 1.2.01
+@item XML Schema 1.0 Structures and Datatypes Recommendations
+@item Experimental implementation of the Document Object Model (DOM) Level 3
+      Core and Load/Save Working Drafts
+@item Provides a partial implementation of the XML Inclusions (XInclude) W3C
+      Candidate Recommendation
+@end itemize
+
+Xerces is now able to parse documents written according to the XML 1.1
+Candidate Recommendation, except that it does not yet provide an option to
+enable normalization checking as described in section 2.13 of this
+specification.  It also handles namespaces according to the XML Namespaces 1.1
+Candidate Recommendation, and will correctly serialize XML 1.1 documents if
+the DOM level 3 load/save API's are in use.")
+    (license license:asl2.0)))
diff --git a/gnu/packages/patches/java-xerces-bootclasspath.patch b/gnu/packages/patches/java-xerces-bootclasspath.patch
new file mode 100644
index 000000000..efaa548a6
--- /dev/null
+++ b/gnu/packages/patches/java-xerces-bootclasspath.patch
@@ -0,0 +1,38 @@
+Based on https://anonscm.debian.org/viewvc/pkg-java/trunk/libxerces2-java/debian/patches/03_bootclasspath.patch?revision=14509, adopted for guix
+
+--- xerces-2_11_0/build.xml.orig	2010-11-26 21:42:11.000000000 +0100
++++ xerces-2_11_0/build.xml	2017-03-28 14:04:41.946606996 +0200
+@@ -290,13 +290,14 @@
+            destdir="${build.dest}"
+            source="${javac.source}"
+            target="${javac.target}"
+-           classpath="${build.dir}/classes:${tools.dir}/${jar.apis}:${tools.dir}/${jar.resolver}:${tools.dir}/${jar.serializer}"
++           classpath="${build.dir}/classes:${jar.jaxp}:${jar.apis-ext}:${jar.resolver}"
+            debug="${debug}" nowarn="true"
+            debuglevel="${debuglevel}"
+            deprecation="${deprecation}"
+            optimize="${optimize}"
+            includeAntRuntime="false"
+-           includeJavaRuntime="false"
++           includeJavaRuntime="true"
++           bootclasspath="${jar.jaxp}:${jar.apis-ext}:${jar.resolver}"
+            excludes="org/xml/sax/** 
+                 javax/xml/**
+                 org/w3c/dom/*
+@@ -1451,13 +1452,14 @@
+                destdir="${build.dest}"
+                source="${javac.source}"
+                target="${javac.target}"
+-               classpath="${build.dir}/classes:${tools.dir}/${jar.apis}:${tools.dir}/${jar.resolver}:${tools.dir}/${jar.serializer}"
++               classpath="${build.dir}/classes:${jar.jaxp}:${jar.apis-ext}:${jar.resolver}"
+                debug="${debug}"
+                debuglevel="${debuglevel}"
+                deprecation="${deprecation}"
+                optimize="${optimize}"
+                includeAntRuntime="false"
+-               includeJavaRuntime="false"
++               includeJavaRuntime="true"
++               bootclasspath="${jar.jaxp}:${jar.apis-ext}:${jar.resolver}"
+                excludes="org/xml/sax/** 
+                     javax/xml/**
+                     org/w3c/dom/*
diff --git a/gnu/packages/patches/java-xerces-build_dont_unzip.patch b/gnu/packages/patches/java-xerces-build_dont_unzip.patch
new file mode 100644
index 000000000..2ff562886
--- /dev/null
+++ b/gnu/packages/patches/java-xerces-build_dont_unzip.patch
@@ -0,0 +1,44 @@
+Don't unzip the sources which were bundled originally. Guix strips them from
+the source and uses pre-build packages.
+
+Taken from https://anonscm.debian.org/viewvc/pkg-java/trunk/libxerces2-java/debian/patches/02_build_dont_unzip.patch?revision=14507
+
+Index: b/build.xml
+===================================================================
+--- a/build.xml
++++ b/build.xml
+@@ -247,7 +247,7 @@
+     <copy file="${src.dir}/org/apache/xerces/impl/xpath/regex/message.properties"
+       tofile="${build.src}/org/apache/xerces/impl/xpath/regex/message_en.properties"/>
+ 
+-    <!-- now deal with API's:  -->
++    <!-- not needed for Debian
+     <unzip src="${src.apis.zip}" dest="${build.src}">
+         <patternset
+             includes="org/xml/sax/** 
+@@ -270,6 +270,7 @@
+                 org/w3c/dom/xpath/**"
+         />
+     </unzip>
++    -->
+     
+     <!-- substitute tokens as needed -->
+     <replace file="${build.dir}/src/org/apache/xerces/impl/Version.java" 
+@@ -1232,7 +1233,7 @@
+     <replace file="${build.dir}/src/org/apache/xerces/parsers/AbstractSAXParser.java"
+              token="return (fConfiguration instanceof XML11Configurable);" value="return false;"/>
+  
+-    <!-- now deal with API's:  -->
++    <!-- not needed for Debian
+     <unzip src="${src.apis.zip}" dest="${build.src}">
+         <patternset
+             includes="org/xml/sax/** 
+@@ -1255,7 +1256,7 @@
+                 org/w3c/dom/xpath/**"
+         />
+     </unzip>
+-
++    -->
+ 
+     <!-- substitute tokens as needed -->
+     <replace file="${build.dir}/src/org/apache/xerces/impl/Version.java" 
diff --git a/gnu/packages/patches/java-xerces-xjavac_taskdef.patch b/gnu/packages/patches/java-xerces-xjavac_taskdef.patch
new file mode 100644
index 000000000..4f5d008c2
--- /dev/null
+++ b/gnu/packages/patches/java-xerces-xjavac_taskdef.patch
@@ -0,0 +1,45 @@
+This patch eliminates the need for providing "xjavac", which saves building a
+package for the unmaintained "xerces-tools".
+
+Taken from https://anonscm.debian.org/viewvc/pkg-java/trunk/libxerces2-java/debian/patches/01_xjavac_taskdef.patch?revision=14507
+
+Index: b/build.xml
+===================================================================
+--- a/build.xml
++++ b/build.xml
+@@ -39,7 +39,7 @@
+   <property name="tools.dir" value="./tools"/>
+ 
+   <!-- enable compilation under JDK 1.4 and above -->
+-  <taskdef name="xjavac" classname="org.apache.xerces.util.XJavac">
++  <taskdef name="xjavac" classname="org.apache.tools.ant.taskdefs.Javac">
+     <classpath>
+       <pathelement location="${tools.dir}/bin/xjavac.jar"/>
+     </classpath>
+@@ -291,7 +291,7 @@
+            source="${javac.source}"
+            target="${javac.target}"
+            classpath="${build.dir}/classes:${tools.dir}/${jar.apis}:${tools.dir}/${jar.resolver}:${tools.dir}/${jar.serializer}"
+-           debug="${debug}"
++           debug="${debug}" nowarn="true"
+            debuglevel="${debuglevel}"
+            deprecation="${deprecation}"
+            optimize="${optimize}"
+@@ -359,7 +359,7 @@
+            source="${javac.source}"
+            target="${javac.target}"
+            classpath="${build.dir}/classes:${tools.dir}/${jar.apis}"
+-           debug="${debug}"
++           debug="${debug}" nowarn="true"
+            debuglevel="${debuglevel}"
+            includeAntRuntime="false"
+            includeJavaRuntime="true"/>
+@@ -379,7 +379,7 @@
+            source="${javac.source}"
+            target="${javac.target}"
+            classpath="${tools.dir}/${jar.apis}:${build.dir}/classes:./tools/junit.jar"
+-           debug="${debug}"
++           debug="${debug}" nowarn="true"
+            debuglevel="${debuglevel}"
+            includeAntRuntime="false"
+            includeJavaRuntime="true"/>
-- 
2.15.0