Name:          xerces-j2
Version:       2.12.2
Release:       1
Summary:       Java XML parser
License:       ASL 2.0 and W3C
URL:           http://xerces.apache.org/xerces2-j/

Source0:       http://mirror.ox.ac.uk/sites/rsync.apache.org/xerces/j/source/Xerces-J-src.%{version}.tar.gz
Source11:      %{name}-version.1
Source12:      %{name}-constants.1
Source3:       https://svn.apache.org/repos/asf/xerces/java/tags/Xerces-J_2_12_2/tools/src/XJavac.java
Source5:       https://svn.apache.org/repos/asf/xerces/java/tags/Xerces-J_2_12_2/tools/src/ExperimentalTaglet.java
Source6:       https://svn.apache.org/repos/asf/xerces/java/tags/Xerces-J_2_12_2/tools/src/InternalTaglet.java
Source7:       %{name}-pom.xml

Patch0:        %{name}-build.patch
Patch1:        %{name}-manifest.patch

BuildRequires: javapackages-local ant apache-parent xalan-j2 >= 2.7.1
BuildRequires: xml-commons-apis >= 1.4.01 xml-commons-resolver >= 1.2
BuildRequires: java-1.8.0-openjdk-devel

Requires:      xalan-j2 >= 2.7.1 xml-commons-resolver >= 1.2
Requires:      xml-commons-apis >= 1.4.01 javapackages-tools

Provides:      jaxp_parser_impl = 1.4
Provides:      %{name}-scripts = %{version}-%{release}

Obsoletes:     %{name}-scripts < 2.11.0-6
Obsoletes:     %{name}-javadoc-apis < %{version}-%{release}
Obsoletes:     %{name}-manual < %{version}-%{release}

Provides:       %{name}-demo = %{version}-%{release}
Obsoletes:      %{name}-demo < %{version}-%{release}

BuildArch:     noarch

%description
Welcome to the future! Xerces2 is the next generation of high
performance, fully compliant XML parsers in the Apache Xerces family.
This new version of Xerces introduces the Xerces Native Interface (XNI),
a complete framework for building parser components and configurations
that is extremely modular and easy to program.

The Apache Xerces2 parser is the reference implementation of XNI but
other parser components, configurations, and parsers can be written
using the Xerces Native Interface. For complete design and
implementation documents, refer to the XNI Manual.

Xerces 2 is a fully conforming XML Schema processor. For more
information, refer to the XML Schema page.

Xerces 2 also provides a partial implementation of Document Object Model
Level 3 Core, Load and Save and Abstract Schemas [deprecated] Working
Drafts. For more information, refer to the DOM Level 3 Implementation
page.

%package        help
Summary:        Documents for %{name}
Buildarch:      noarch
Requires:		man info
Provides:       %{name}-javadoc = %{version}-%{release}
Obsoletes:      %{name}-javadoc < %{version}-%{release}
Obsoletes:      %{name}-javadoc-impl < %{version}-%{release}
Obsoletes:      %{name}-javadoc-xs < %{version}-%{release}
Obsoletes:      %{name}-javadoc-xni < %{version}-%{release}
Obsoletes:      %{name}-javadoc-other < %{version}-%{release}

%description help
Man pages and other related documents for %{name}.

%prep
%autosetup -p1 -n xerces-2_12_2
install -d tools/org/apache/xerces/util
install -d tools/bin
cp -a %{SOURCE3} %{SOURCE5} %{SOURCE6} tools/org/apache/xerces/util
find -name '*.class' -exec rm -f '{}' \;
find -name '*.jar' -exec rm -f '{}' \;
sed -i 's/\r//' LICENSE README NOTICE
sed -i -e "s|additionalparam='|additionalparam='-Xdoclint:none |" build.xml
%mvn_alias : xerces:xerces xerces:xmlParserAPIs apache:%{name}
%mvn_file : %{name} jaxp_parser_impl

%build
pushd tools
javac -classpath $(build-classpath ant) org/apache/xerces/util/XJavac.java
jar cf bin/xjavac.jar org/apache/xerces/util/XJavac.class
javac -classpath /usr/lib/jvm/java/lib/tools.jar org/apache/xerces/util/*Taglet.java
jar cf bin/xerces2taglets.jar org/apache/xerces/util/*Taglet.class
ln -sf $(build-classpath xalan-j2-serializer) serializer.jar
ln -sf $(build-classpath xml-commons-apis) xml-apis.jar
ln -sf $(build-classpath xml-commons-resolver) resolver.jar
ln -sf $(build-classpath %{name}) x.jar
popd
export ANT_OPTS="-Xmx512m -Djava.awt.headless=true -Dbuild.sysclasspath=first -Ddisconnected=true"
%ant -Djavac.source=1.6 -Djavac.target=1.6 -Dbuild.compiler=modern clean jars javadocs
%mvn_artifact %{SOURCE7} build/xercesImpl.jar

%install
%mvn_install

install -d $RPM_BUILD_ROOT%{_javadocdir}/%{name}
install -d $RPM_BUILD_ROOT%{_javadocdir}/%{name}/impl
install -d $RPM_BUILD_ROOT%{_javadocdir}/%{name}/xs
install -d $RPM_BUILD_ROOT%{_javadocdir}/%{name}/xni
install -d $RPM_BUILD_ROOT%{_javadocdir}/%{name}/other
cp -pr build/docs/javadocs/xerces2/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}/impl
cp -pr build/docs/javadocs/api/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}/xs
cp -pr build/docs/javadocs/xni/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}/xni
cp -pr build/docs/javadocs/other/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}/other
%jpackage_script org.apache.xerces.impl.Version "" "" %{name} %{name}-version 1
%jpackage_script org.apache.xerces.impl.Constants "" "" %{name} %{name}-constants 1
install -d -m 755 $RPM_BUILD_ROOT%{_mandir}/man1
install -p -m 644 %{SOURCE11} $RPM_BUILD_ROOT%{_mandir}/man1
install -p -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man1
install -pD -T build/xercesSamples.jar $RPM_BUILD_ROOT%{_datadir}/%{name}/%{name}-samples.jar
cp -pr data $RPM_BUILD_ROOT%{_datadir}/%{name}

%post
update-alternatives --remove jaxp_parser_impl %{_javadir}/%{name}.jar >/dev/null 2>&1 || :
ln -sf %{name}.jar %{_javadir}/jaxp_parser_impl.jar

%files -f .mfiles
%doc LICENSE
%{_bindir}/*
%{_datadir}/%{name}

%files help
%doc NOTICE README
%{_javadocdir}/%{name}
%{_mandir}/*/*

%changelog
* Wed Apr 27 2022 yaoxin <yaoxin30@h-partners.com> - 2.12.2-1
- Upgrade to 2.12.2 for fix CVE-2022-23437

* Sat Sep 19 2020 wangxiao<wangxiao65@huawei.com> - 2.11.0-37
- fix CVE-2012-0881
* Mon Feb 17 2020 zhouyihang<zhouyihang1@huawei.com> - 2.11.0-36
- Package init
