%global scm_tag            v2.7.1
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
Name:                jython
Version:             2.7.1
Release:             2
Summary:             A Java implementation of the Python language
License:             ASL 1.1 and BSD 
URL:                 http://www.jython.org/
%bcond_without rpmwheels
Source0:             https://github.com/jython/jython/archive/%{scm_tag}.tar.gz
Patch0:              jython-cachedir.patch
Patch1:              jython-dont-validate-pom.patch
Patch2:              jython-no-carrotsearch-sizeof.patch
Patch3:              jython-launcher.patch
Patch4:              jython-fix-multiprocessing.patch
Patch5:              jython-fix-tty-detection.patch
Patch189:            jython-use-rpm-wheels.patch
Requires:            antlr32-java apache-commons-compress bouncycastle bouncycastle-pkix guava
Requires:            objectweb-asm jctools >= 2.0.2 jnr-constants jnr-ffi jnr-netdb jnr-posix jffi
Requires:            jffi-native jline jansi icu4j netty >= 4.1.13 xerces-j2
BuildRequires:       javapackages-local ant ant-junit glassfish-servlet-api antlr32-tool
BuildRequires:       apache-commons-compress bouncycastle guava objectweb-asm
BuildRequires:       jctools >= 2.0.2 jnr-constants jnr-ffi jnr-netdb jnr-posix jffi jffi-native
BuildRequires:       jline jansi icu4j netty >= 4.1.13 xerces-j2
%if %{with rpmwheels}
BuildRequires:       python-setuptools-wheel python-pip-wheel
Requires:            python-setuptools-wheel python-pip-wheel
%else
Provides:            bundled(python2-pip) = 9.0.1
Provides:            bundled(python2-setuptools) = 28.8.0
%endif
BuildArch:           noarch
%description
Jython is an implementation of the high-level, dynamic, object-oriented
language Python seamlessly integrated with the Java platform. The
predecessor to Jython, JPython, is certified as 100% Pure Java. Jython is
freely available for both commercial and non-commercial use and is
distributed with source code. Jython is complementary to Java and is
especially suited for the following tasks: Embedded scripting - Java
programmers can add the Jython libraries to their system to allow end
users to write simple or complicated scripts that add functionality to the
application. Interactive experimentation - Jython provides an interactive
interpreter that can be used to interact with Java packages or with
running Java applications. This allows programmers to experiment and debug
any Java system using Jython. Rapid application development - Python
programs are typically 2-10X shorter than the equivalent Java program.
This translates directly to increased programmer productivity. The
seamless interaction between Python and Java allows developers to freely
mix the two languages both during development and in shipping products.

%package javadoc
Summary:             Javadoc for %{name}
Obsoletes:           %{name}-manual = %{version}-%{release}
Provides:            %{name}-manual < %{version}-%{release}
%description javadoc
API documentation for %{name}.

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

%prep
%setup -q -n jython-%{version}
%patch2 -R -p1
%patch0
%patch1
%patch3
%patch4 -p1
%patch5

find . -type f -a -name *.jar -delete
find . -type f -a -name *.exe -delete
find . -type f -a -name *.dll -delete
%if %{with rpmwheels}
%patch189 -p1
rm Lib/ensurepip/_bundled/*.whl
rmdir Lib/ensurepip/_bundled
%endif
rm -rf extlibs/*
sed -i -e '/<javadoc/a additionalparam="-Xdoclint:none"' build.xml

%build
build-jar-repository -p -s extlibs \
  antlr32/antlr antlr32/antlr-runtime stringtemplate antlr \
  jffi jffi-native jnr-constants jnr-ffi jnr-netdb jnr-posix jline/jline jansi/jansi icu4j/icu4j \
  glassfish-servlet-api guava objectweb-asm/asm objectweb-asm/asm-commons objectweb-asm/asm-util \
  commons-compress junit hamcrest/core
ant \
  -Djython.dev.jar=jython.jar \
  -Dhas.repositories.connection=false \
  javatest javadoc
find dist -type f -name '*.py' | xargs sed -i "s:#!\s*/usr.*::"
pushd maven
ant -Dproject.version=%{version} install
popd
rm dist/javalib/*.jar
build-jar-repository -p -s dist/javalib antlr32/antlr-runtime-3.2 \
  objectweb-asm/asm objectweb-asm/asm-commons objectweb-asm/asm-util guava icu4j/icu4j \
  jffi jffi-native jnr-constants jnr-ffi jnr-netdb jnr-posix jline/jline jansi/jansi \
  netty/netty-buffer netty/netty-codec netty/netty-common netty/netty-handler netty/netty-resolver netty/netty-transport \
  jctools/jctools-core apache-commons-compress bcprov bcpkix xerces-j2
%mvn_artifact build/maven/jython-%{version}.pom dist/jython.jar
%mvn_alias org.python:jython org.python:jython-standalone

%install
%mvn_install -J dist/Doc/javadoc
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/%{name}
ln -s %{_javadir}/%{name}/jython.jar $RPM_BUILD_ROOT%{_datadir}/%{name}
cp -pr dist/javalib $RPM_BUILD_ROOT%{_datadir}/%{name}
rm dist/bin/jython_regrtest.bat
cp -pr dist/bin $RPM_BUILD_ROOT%{_datadir}/%{name}
install -m 644 dist/registry $RPM_BUILD_ROOT%{_datadir}/%{name}
rm -rf dist/Lib/{distutils/tests,email/test,json/tests,test,unittest/test}
cp -pr dist/Lib $RPM_BUILD_ROOT%{_datadir}/%{name}
cp -pr Demo $RPM_BUILD_ROOT%{_datadir}/%{name}
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/Doc
ln -s %{_javadocdir}/%{name} $RPM_BUILD_ROOT%{_datadir}/%{name}/Doc/javadoc
install -d $RPM_BUILD_ROOT%{_bindir}
ln -s %{_datadir}/%{name}/bin/jython $RPM_BUILD_ROOT%{_bindir}

%files -f .mfiles
%doc ACKNOWLEDGMENTS NEWS README.txt
%license LICENSE.txt
%attr(0755,root,root) %{_bindir}/%{name}
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/bin
%{_datadir}/%{name}/javalib
%{_datadir}/%{name}/jython.jar
%{_datadir}/%{name}/Lib
%{_datadir}/%{name}/registry

%files javadoc -f .mfiles-javadoc
%license LICENSE.txt
%{_datadir}/%{name}/Doc

%files demo
%license LICENSE.txt
%{_datadir}/%{name}/Demo

%changelog
* Mon Nov 13 2023 wangkai <13474090681@163.com> - 2.7.1-2
- Fix build failure caused by guava upgrade

* Mon Aug 3 2020 yanan li <liyanan032@huawei.com> - 2.7.1-1
- Package init
