%global version_str %(sed -e 's/\\./-/g' <<<"%{version}")
%global version_major_minor %(sed -e 's/\\([0-9]*\\.[0-9]*\\)\\..*/\\1/g' <<<"%{version}")
%global version_major_minor_str %(sed -e 's/\\./-/g' <<<"%{version_major_minor}")
%global version_maven %(sed -e 's/\\(.*\\)\\.\\([0-9]*\\)/\\1-\\2/g' <<<"%{version}")
%global artifact_id Saxon-HE
Summary:             Java XPath, XSLT 2.0 and XQuery implementation
Name:                saxon
Version:             9.4.0.9
Release:             2
License:             MPLv1.0 and MPLv1.1 and ASL 1.1 and UCD and MIT
URL:                 http://saxon.sourceforge.net/
Source0:             https://downloads.sourceforge.net/project/saxon/Saxon-HE/%{version_major_minor}/saxon%{version_str}source.zip
Source1:             %{name}.saxon.script
Source2:             %{name}.saxonq.script
Source3:             %{name}.build.script
Source4:             %{name}.1
Source5:             %{name}q.1
Source6:             https://downloads.sourceforge.net/project/saxon/Saxon-HE/%{version_major_minor}/saxon-resources%{version_major_minor_str}.zip
Source8:             http://www.mozilla.org/MPL/1.0/index.txt#/mpl-1.0.txt
Source9:             http://www.mozilla.org/MPL/1.0/index.txt#/mpl-1.1.txt
BuildRequires:       unzip java-devel >= 1:1.6.0 ant javapackages-local bea-stax-api
BuildRequires:       xml-commons-apis xml-commons-resolver xom java-javadoc jdom >= 0:1.0-0.b7
BuildRequires:       jdom-javadoc >= 0:1.0-0.b9.3jpp jdom2 dom4j
Requires:            bea-stax-api bea-stax
Obsoletes:           %{name}-xpath < %{version}-%{release}
Provides:            %{name}-xpath = %{version}-%{release}
Obsoletes:           %{name}-xom < %{version}-%{release}
Provides:            %{name}-xom = %{version}-%{release}
Obsoletes:           %{name}-sql < %{version}-%{release}
Provides:            %{name}-sql = %{version}-%{release}
Obsoletes:           %{name}-jdom < %{version}-%{release}
Provides:            %{name}-jdom = %{version}-%{release}
Obsoletes:           %{name}-dom < %{version}-%{release}
Provides:            %{name}-dom = %{version}-%{release}
BuildArch:           noarch
%description
Saxon HE is Saxonica's non-schema-aware implementation of the XPath 2.0,
XSLT 2.0, and XQuery 1.0 specifications aligned with the W3C Candidate
Recommendation published on 3 November 2005. It is a complete and
conformant implementation, providing all the mandatory features of
those specifications and nearly all the optional features.

%package        manual
Summary:             Manual for %{name}
%description    manual
Manual for %{name}.

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

%package        demo
Summary:             Demos for %{name}
Requires:            %{name} = %{version}-%{release}
%description    demo
Demonstrations and samples for %{name}.

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

%prep
%setup -q -c
unzip -q %{SOURCE6}
cp -p %{SOURCE3} ./build.xml
rm -rf net/sf/saxon/dotnet samples/cs
rm -rf net/sf/saxon/xqj
rm -rf net/sf/saxon/option/sql/SQLElementFactory.java
rm -rf docs/api
find . \( -name "*.jar" -name "*.pyc" \) -delete
cp %{SOURCE8} %{SOURCE9} .
cat >%{artifact_id}-%{version_maven}.pom <<POM_XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.sf.saxon</groupId>
  <artifactId>%{artifact_id}</artifactId>
  <version>%{version_maven}</version>
  <packaging>jar</packaging>
  <name>%{artifact_id}</name>
  <url>http://saxon.sf.net/</url>
  <description>The XSLT and XQuery Processor</description>
  <licenses>
    <license>
      <name>Mozilla Public License Version 2.0</name>
      <url>http://www.mozilla.org/MPL/2.0/</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <scm>
    <connection>scm:svn:https://dev.saxonica.com/repos/archive/opensource/latest%{version_major_minor}/</connection>
    <developerConnection>scm:svn:https://dev.saxonica.com/repos/archive/opensource/latest%{version_major_minor}/</developerConnection>
    <url>https://saxon.svn.sourceforge.net/svnroot/saxon/latest%{version_major_minor}/</url>
  </scm>
</project>
POM_XML

%build
mkdir -p build/classes
cat >build/classes/edition.properties <<EOF
config=net.sf.saxon.Configuration
platform=net.sf.saxon.java.JavaPlatform
EOF
export CLASSPATH=$(build-classpath axiom xml-commons-apis xml-commons-resolver jdom jdom2 xom bea-stax-api dom4j)
ant \
  -Dj2se.javadoc=%{_javadocdir}/java \
  -Djdom.javadoc=%{_javadocdir}/jdom
%mvn_artifact %{artifact_id}-%{version_maven}.pom build/lib/saxon.jar
%mvn_alias : :saxon
%mvn_alias : net.sf.saxon:saxon::dom:

%install
%mvn_install
ln -s %{artifact_id}.jar $RPM_BUILD_ROOT/%{_javadir}/saxon/saxon.jar
mkdir -p $RPM_BUILD_ROOT%{_javadocdir}/%{name}
cp -pr build/api/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}
mkdir -p $RPM_BUILD_ROOT%{_datadir}/%{name}
cp -pr samples/* $RPM_BUILD_ROOT%{_datadir}/%{name}
mkdir -p $RPM_BUILD_ROOT%{_bindir}
install -p -m755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/%{name}
install -p -m755 %{SOURCE2} $RPM_BUILD_ROOT%{_bindir}/%{name}q
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
install -p -m644 %{SOURCE4} $RPM_BUILD_ROOT%{_mandir}/man1/%{name}.1
install -p -m644 %{SOURCE5} $RPM_BUILD_ROOT%{_mandir}/man1/%{name}q.1

%post
if [ -f "%{_javadir}/jaxp_transform_impl.jar" ]; then
    mv %{_javadir}/jaxp_transform_impl.jar{,.tmp} || :
fi
update-alternatives --remove jaxp_transform_impl %{_javadir}/saxon/%{artifact_id}.jar &>/dev/null || :
if [ -f "%{_javadir}/jaxp_transform_impl.jar.tmp" ]; then
   mv %{_javadir}/jaxp_transform_impl.jar{.tmp,} || :
fi

%files -f .mfiles
%license mpl-1.0.txt mpl-1.1.txt
%{_javadir}/%{name}/saxon.jar

%files manual
%doc doc/*

%files javadoc
%doc mpl-1.0.txt mpl-1.1.txt
%{_javadocdir}/%{name}

%files demo
%{_datadir}/%{name}

%files scripts
%{_bindir}/%{name}
%{_bindir}/%{name}q
%{_mandir}/man1/%{name}.1*
%{_mandir}/man1/%{name}q.1*

%changelog
* Mon Jul 18 2022 liyanan <liyanan32@h-partners.com> - 9.4.0.9-2
- fix install error

* Thu Jul 23 2020 Jeffery.Gao <gaojianxing@huawei.com> - 9.4.0.9-1
- Package init
