%bcond_with bootstrap
%{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{name}-%{version}}
Name:                xmlbeans
Version:             2.6.0
Release:             2
Summary:             XML-Java binding tool
URL:                 http://xmlbeans.apache.org/
Source0:             http://archive.apache.org/dist/xmlbeans/source/%{name}-%{version}-src.tgz
Source1:             https://repo1.maven.org/maven2/org/apache/%{name}/%{name}/%{version}/%{name}-%{version}.pom
Source2:             https://repo1.maven.org/maven2/org/apache/%{name}/%{name}-xpath/%{version}/%{name}-xpath-%{version}.pom
Source3:             https://repo1.maven.org/maven2/org/apache/%{name}/%{name}-xmlpublic/%{version}/%{name}-xmlpublic-%{version}.pom
Patch0:              xmlbeans-2.6.0-nodownload.patch
Patch1:              0001-Update-to-newer-saxon-API.patch
Patch2:              xmlbeans-2.6.0-iso-8859-1-encoding.patch
Patch3:              xmlbeans-2.6.0-jsr-bundle.patch
Patch4:              xmlbeans-scripts-classpath.patch
Patch5:              xmlbeans-2.6.0-java8.patch
Patch6:              CVE-2021-23926-pre.patch
Patch7:              CVE-2021-23926-1.patch
Patch8:              CVE-2021-23926-2.patch
License:             Apache-2.0 and CPL-1.0
%if %without bootstrap
BuildRequires:       xmlbeans
%endif
BuildRequires:       java-devel jpackage-utils >= 0:1.5 javapackages-local
BuildRequires:       ant >= 0:1.6, ant-junit, ant-contrib, junit xml-commons-resolver >= 0:1.1
BuildRequires:       bea-stax-api saxon >= 8
Requires:            jpackage-utils >= 0:1.6 java-headless
BuildArch:           noarch
%description
XMLBeans is a tool that allows you to access the full power
of XML in a Java friendly way. It is an XML-Java binding tool.
The idea is that you can take advantage the richness and
features of XML and XML Schema and have these features mapped
as naturally as possible to the equivalent Java language and
typing constructs. XMLBeans uses XML Schema to compile Java
interfaces and classes that you can then use to access and
modify XML instance data. Using XMLBeans is similar to using
any other Java interface/class, you will see things like
getFoo or setFoo just as you would expect when working with
Java. While a major use of XMLBeans is to access your XML
instance data with strongly typed Java classes there are also
API's that allow you access to the full XML infoset (XMLBeans
keeps full XML Infoset fidelity) as well as to allow you to
reflect into the XML schema itself through an XML Schema
Object model.

%package javadoc
Summary:             Javadoc for %{name}
%description javadoc
%{summary}.

%package manual
Summary:             Documents for %{name}
%description manual
%{summary}.

%package scripts
Summary:             Scripts for %{name}
Requires:            %{name} = %{version}-%{release}
%description scripts
%{summary}.

%prep
%setup -q -n %{name}-%{version}
%patch0 -p1 -b .nodownload
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p0
%patch6 -p1
%patch7 -p1
%patch8 -p1

%build
find . \( -name '*.jar' -o -name '*.zip' \) \
        -not -name 'piccolo*.jar' -not -name 'jam*.jar' \
        %{?with_bootstrap:-not -name 'oldxbean.jar' } \
        -print -delete
mkdir -p build/lib
ln -sf $(build-classpath xml-commons-resolver) build/lib/resolver.jar
ln -sf $(build-classpath xmlbeans/xbean) external/lib/oldxbean.jar
ln -sf $(build-classpath bea-stax-api) external/lib/jsr173_1.0_api.jar
ln -sf $(build-classpath saxon/saxon) external/lib/saxon9.jar
ln -sf $(build-classpath saxon/saxon) external/lib/saxon9-dom.jar
sed 's/\r//' -i LICENSE.txt NOTICE.txt README.txt docs/stylesheet.css docs/xmlbeans.css docs/guide/tools.html
ant -Djavac.source=1.6 -Djavac.target=1.6 default docs

%install
install -d -m 0755 $RPM_BUILD_ROOT%{_javadir}/%{name}
install -p -m 0644 build/lib/xmlpublic.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/xmlpublic.jar
install -p -m 0644 build/lib/xbean_xpath.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/xbean_xpath.jar
install -p -m 0644 build/lib/xbean.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/xbean.jar
mkdir -p $RPM_BUILD_ROOT%{_mavenpomdir}
install -pm 644 %{SOURCE1} $RPM_BUILD_ROOT%{_mavenpomdir}/JPP.%{name}-xbean.pom
%add_maven_depmap JPP.%{name}-xbean.pom %{name}/xbean.jar
install -pm 644 %{SOURCE2} $RPM_BUILD_ROOT%{_mavenpomdir}/JPP.%{name}-xbean_xpath.pom
%add_maven_depmap JPP.%{name}-xbean_xpath.pom %{name}/xbean_xpath.jar
install -pm 644 %{SOURCE3} $RPM_BUILD_ROOT%{_mavenpomdir}/JPP.%{name}-xmlpublic.pom
%add_maven_depmap JPP.%{name}-xmlpublic.pom %{name}/xmlpublic.jar
install -d -m 0755 $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/dumpxsb   $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/inst2xsd  $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/scomp     $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/sdownload $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/sfactor   $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/svalidate $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/validate  $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/xpretty   $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/xsd2inst  $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/xsdtree   $RPM_BUILD_ROOT%{_bindir}
install -p -m 0755 bin/xstc      $RPM_BUILD_ROOT%{_bindir}
install -d -m 755 $RPM_BUILD_ROOT%{_javadocdir}/%{name}
cp -pr build/docs/reference/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}
rm -rf build/docs/reference
install -d -m 755 $RPM_BUILD_ROOT%{_pkgdocdir}
cp -pr build/docs/* README.txt $RPM_BUILD_ROOT%{_pkgdocdir}

%files -f .mfiles
%dir %{_pkgdocdir}
%doc %{_pkgdocdir}/README.txt
%license LICENSE.txt NOTICE.txt

%files javadoc
%dir %{_pkgdocdir}
%doc %{_pkgdocdir}/README.txt
%doc %{_javadocdir}/%{name}
%license LICENSE.txt NOTICE.txt

%files manual
%{_pkgdocdir}

%files scripts
%attr(0755,root,root) %{_bindir}/*

%changelog
* Mon Feb 8 2021 wangxiao <wangxiao65@huawei.com> - 2.6.0-2
- Fix CVE-2021-23926

* Thu Aug 20 2020 maminjie <maminjie1@huawei.com> - 2.6.0-1
- package init
