Name:           groovy
Version:        2.4.8
Release:        10
Summary:        Dynamic language for the Java Platform
License:        ASL 2.0 and BSD and EPL-1.0 and Public Domain and ANTLR-PD and MIT
URL:            http://groovy-lang.org
Source0:        https://dl.bintray.com/groovy/maven/apache-groovy-src-%{version}.zip
Source1:        groovy-script.sh
Source3:        groovy.desktop
Source4:        cpl-v10.txt
Source5:        epl-v10.txt
Source6:        http://central.maven.org/maven2/org/codehaus/groovy/groovy-all/%{version}/groovy-all-%{version}.pom
Patch0:         0001-Port-to-Servlet-API-3.1.patch
Patch1:         0002-Gradle-local-mode.patch
Patch2:         0003-Bintray.patch
Patch3:         0004-Remove-android-support.patch
Patch4:         0005-Update-to-QDox-2.0.patch
Patch5:         0006-Disable-artifactory-publish.patch
Patch6:         0007-Fix-missing-extension-definitions.patch
Patch7:         CVE-2020-17521.patch
Patch8:         Speed-up-class-loading-of-groovy-all-files.patch

BuildRequires:  gradle-local >= 2.1-0.9 javapackages-local java-devel >= 1.8 ant antlr-tool ant-antlr
BuildRequires:  aqute-bnd gpars multiverse apache-parent testng jline apache-commons-cli apache-commons-beanutils
BuildRequires:  apache-commons-collections checkstyle jarjar glassfish-jsp-api glassfish-servlet-api
BuildRequires:  objectweb-asm3 bsf apache-ivy jansi junit xstream desktop-file-utils unzip qdox
BuildRequires:  mvn(org.apache.ant:ant-junit) mvn(org.apache.ant:ant-launcher) mvn(javax.servlet:servlet-api) mvn(javax.servlet:jsp-api)
Requires:       xpp3-minimal
BuildArch:      noarch

Obsoletes:      groovy-lib < %{version}-%{release}
Obsoletes:      groovy-ant < %{version}-%{release}
Obsoletes:      groovy-bsf < %{version}-%{release}
Obsoletes:      groovy-console < %{version}-%{release}
Obsoletes:      groovy-docgenerator < %{version}-%{release}
Obsoletes:      groovy-groovydoc < %{version}-%{release}
Obsoletes:      groovy-groovysh < %{version}-%{release}
Obsoletes:      groovy-jmx < %{version}-%{release}
Obsoletes:      groovy-json < %{version}-%{release}
Obsoletes:      groovy-jsr223 < %{version}-%{release}
Obsoletes:      groovy-nio < %{version}-%{release}
Obsoletes:      groovy-servlet < %{version}-%{release}
Obsoletes:      groovy-sql < %{version}-%{release}
Obsoletes:      groovy-swing < %{version}-%{release}
Obsoletes:      groovy-templates < %{version}-%{release}
Obsoletes:      groovy-test < %{version}-%{release}
Obsoletes:      groovy-testng < %{version}-%{release}
Obsoletes:      groovy-xml < %{version}-%{release}

Provides:       groovy-lib = %{version}-%{release}
Provides:       groovy-ant = %{version}-%{release}
Provides:       groovy-bsf = %{version}-%{release}
Provides:       groovy-console = %{version}-%{release}
Provides:       groovy-docgenerator = %{version}-%{release}
Provides:       groovy-groovydoc = %{version}-%{release}
Provides:       groovy-groovysh = %{version}-%{release}
Provides:       groovy-jmx = %{version}-%{release}
Provides:       groovy-json = %{version}-%{release}
Provides:       groovy-jsr223 = %{version}-%{release}
Provides:       groovy-nio = %{version}-%{release}
Provides:       groovy-servlet = %{version}-%{release}
Provides:       groovy-sql = %{version}-%{release}
Provides:       groovy-swing = %{version}-%{release}
Provides:       groovy-templates = %{version}-%{release}
Provides:       groovy-test = %{version}-%{release}
Provides:       groovy-testng = %{version}-%{release}
Provides:       groovy-xml = %{version}-%{release}

%description
Groovy is an agile and dynamic language for the Java Virtual Machine,
built upon Java with features inspired by languages like Python, Ruby and
Smalltalk.

%prep
%autosetup -p1
cp %{SOURCE4} %{SOURCE5} .
find \( -name *.jar -o -name *.class \) -delete
%mvn_package ':groovy::indy:'
%mvn_package ':groovy-{*}' @1
%mvn_package ':groovy-{*}::indy:' @1

%build
%gradle_build -f -G jarAll -- -x groovydoc -x javadoc -Pindy=true
%gradle_build -f -G distBin -- -x groovydoc -x javadoc -x jarAllWithIndy

%install
%mvn_artifact %{SOURCE6} target/libs/groovy-all-%{version}-indy.jar
%mvn_install

unzip -o target/distributions/apache-groovy-binary-%{version}.zip
rm -rf groovy-%{version}/{*LICENSE.txt,NOTICE.txt,bin/*.bat,META-INF}
install -d -m 755 %{buildroot}%{_datadir}/
cp -a groovy-%{version} %{buildroot}%{_datadir}/groovy

for mod in groovy groovy-ant groovy-bsf groovy-console groovy-docgenerator \
           groovy-groovydoc groovy-groovysh groovy-jmx groovy-json \
           groovy-jsr223 groovy-nio groovy-servlet groovy-sql groovy-swing \
           groovy-templates groovy-test groovy-testng groovy-xml; do
    ln -sf ../../java/groovy/$mod.jar %{buildroot}%{_datadir}/groovy/lib/$mod-%{version}.jar
    ln -sf ../../java/groovy/$mod-indy.jar %{buildroot}%{_datadir}/groovy/indy/$mod-%{version}.jar
done

ln -sf ../../java/groovy/groovy-all.jar %{buildroot}%{_datadir}/groovy/embeddable/groovy-all-%{version}.jar
ln -sf ../../java/groovy/groovy-all.jar %{buildroot}%{_datadir}/groovy/embeddable/groovy-all-%{version}-indy.jar

find %{buildroot}%{_datadir}/groovy/lib/ ! -name "groovy*" -type f -print -delete
xmvn-subst %{buildroot}%{_datadir}/groovy/

ln -sf `build-classpath ant/ant` %{buildroot}%{_datadir}/groovy/lib/ant.jar
ln -sf `build-classpath ant/ant-antlr` %{buildroot}%{_datadir}/groovy/lib/ant-antlr.jar
ln -sf `build-classpath ant/ant-junit` %{buildroot}%{_datadir}/groovy/lib/ant-junit.jar
ln -sf `build-classpath ant/ant-launcher` %{buildroot}%{_datadir}/groovy/lib/ant-launcher.jar
ln -sf `build-classpath bsf` %{buildroot}%{_datadir}/groovy/lib/bsf.jar
ln -sf `build-classpath commons-cli` %{buildroot}%{_datadir}/groovy/lib/commons-cli.jar
ln -sf `build-classpath commons-logging` %{buildroot}%{_datadir}/groovy/lib/commons-logging.jar
ln -sf `build-classpath gpars/gpars` %{buildroot}%{_datadir}/groovy/lib/gpars.jar
ln -sf `build-classpath hamcrest/core` %{buildroot}%{_datadir}/groovy/lib/hamcrest-core.jar
ln -sf `build-classpath apache-ivy/ivy` %{buildroot}%{_datadir}/groovy/lib/ivy.jar
ln -sf `build-classpath jansi/jansi` %{buildroot}%{_datadir}/groovy/lib/jansi.jar
ln -sf `build-classpath beust-jcommander` %{buildroot}%{_datadir}/groovy/lib/jcommander.jar
ln -sf `build-classpath jline/jline` %{buildroot}%{_datadir}/groovy/lib/jline.jar
ln -sf `build-classpath glassfish-jsp-api` %{buildroot}%{_datadir}/groovy/lib/jsp-api.jar
ln -sf `build-classpath junit` %{buildroot}%{_datadir}/groovy/lib/junit.jar
ln -sf `build-classpath multiverse/multiverse-core` %{buildroot}%{_datadir}/groovy/lib/multiverse-core.jar
ln -sf `build-classpath qdox` %{buildroot}%{_datadir}/groovy/lib/qdox.jar
ln -sf `build-classpath glassfish-servlet-api` %{buildroot}%{_datadir}/groovy/lib/servlet-api.jar
ln -sf `build-classpath testng` %{buildroot}%{_datadir}/groovy/lib/testng.jar
ln -sf `build-classpath xpp3-minimal` %{buildroot}%{_datadir}/groovy/lib/xpp3-minimal.jar
ln -sf `build-classpath xstream/xstream` %{buildroot}%{_datadir}/groovy/lib/xstream.jar
ln -sf `build-classpath extra166y` %{buildroot}%{_datadir}/groovy/lib/extra166y.jar

install -d -m 755 %{buildroot}%{_bindir}/
for cmd in grape groovy groovyc groovyConsole groovydoc groovysh java2groovy; do
    class=$(awk '/^startGroovy/{print$2}' %{buildroot}%{_datadir}/groovy/bin/$cmd)
    install -p -m 755 %{SOURCE1} %{buildroot}%{_bindir}/$cmd
    sed -i "s/@CLASS@/$class/" %{buildroot}%{_bindir}/$cmd
    ln -sf %{_bindir}/$cmd %{buildroot}%{_datadir}/groovy/bin/$cmd
done

install -d -m 755 %{buildroot}%{_sysconfdir}/
mv %{buildroot}%{_datadir}/groovy/conf/groovy-starter.conf %{buildroot}%{_sysconfdir}/
ln -s %{_sysconfdir}/groovy-starter.conf %{buildroot}%{_datadir}/groovy/conf/

install -d %{buildroot}%{_datadir}/pixmaps
install -d %{buildroot}%{_datadir}/applications
install -p -m644 subprojects/groovy-console/src/main/resources/groovy/ui/ConsoleIcon.png \
        %{buildroot}%{_datadir}/pixmaps/groovy.png
desktop-file-install --dir %{buildroot}%{_datadir}/applications \
        %{SOURCE3}

mkdir -p $RPM_BUILD_ROOT%{_datadir}/appdata
cat > $RPM_BUILD_ROOT%{_datadir}/appdata/groovy.appdata.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2014 Ryan Lerch <rlerch@redhat.com> -->
<!--
SentUpstream: No public bugtracker
-->
<application>
  <id type="desktop">groovy.desktop</id>
  <metadata_license>CC0-1.0</metadata_license>
  <summary>Interactive console for the Groovy programming language</summary>
  <description>
    <p>
      Groovy is a dynamic programming language that is commonly used as a
      scripting language for the Java platform. This application provides an
      interactive console for evaluating scripts in the Groovy language.
    </p>
  </description>
  <url type="homepage">http://groovy-lang.org/</url>
  <screenshots>
    <screenshot type="default">https://raw.githubusercontent.com/hughsie/fedora-appstream/master/screenshots-extra/groovy/a.png</screenshot>
  </screenshots>
  <!-- FIXME: change this to an upstream email address for spec updates
  <updatecontact>someone_who_cares@upstream_project.org</updatecontact>
  -->
</application>
EOF

%files
%{_datadir}/groovy
%{_bindir}/*
%{_datadir}/pixmaps/*
%{_datadir}/appdata/*.appdata.xml
%{_datadir}/applications/*
%config(noreplace) %{_sysconfdir}/*
%attr(0755,root,root) %dir /usr/share/java/groovy
%attr(0644,root,root) %{_datadir}/java/groovy/*.jar
%attr(0644,root,root) %{_datadir}/maven-metadata/*.xml
%attr(0755,root,root) %dir /usr/share/maven-poms/groovy
%attr(0644,root,root) %{_datadir}/maven-poms/groovy/groovy-all.pom
%doc LICENSE NOTICE README.adoc

%changelog
* Mon Aug 09 2021 lingsheng <lingsheng@huawei.com> - 2.4.8-10
- Speed up class loading of groovy-all files

* Thu Feb 04 2021 wangyue <wangyue92@huawei.com> - 2.4.8-9
- fix CVE-2020-17521

* Tue Dec 17 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.4.8-8
- Package init
