%global majorversion 1.8
%global archiver 1_8_9
Name:                groovy18
Version:             1.8.9
Release:             4
Summary:             Dynamic language for the Java Platform
License:             ASL 2.0 and BSD and EPL-1.0 and Public Domain and CPL-1.0
URL:                 http://groovy-lang.org
Source0:             https://github.com/groovy/groovy-core/archive/GROOVY_%{archiver}.zip
Source1:             groovy18-script
Source2:             groovy18-starter.conf
Source4:             cpl-v10.txt
Source5:             epl-v10.txt
Source6:             http://www.apache.org/licenses/LICENSE-2.0.txt
Patch0:              groovy-inner-interface-annotations.patch
Patch1:              groovy-build-with-java8.patch
Patch2:              groovy-servlet31.patch
Patch3:              groovy-commons-cli-1.3.patch
Patch4:              groovy-CVE-2015-3253-and-CVE-2016-6814.patch
BuildRequires:       ant antlr-tool ant-antlr objectweb-asm3 bsf apache-ivy jansi jline1
BuildRequires:       glassfish-jsp-api junit glassfish-servlet-api xstream java-devel >= 1.8
BuildRequires:       desktop-file-utils jpackage-utils apache-commons-cli unzip javapackages-local
BuildRequires:       mvn(org.apache.ant:ant-junit) mvn(org.apache.ant:ant-launcher)
BuildRequires:       mvn(javax.servlet:servlet-api) mvn(javax.servlet:jsp-api)
Requires:            %{name}-lib = %{version}-%{release} mvn(junit:junit)
Requires:            mvn(commons-cli:commons-cli) mvn(org.apache.ant:ant)
Requires:            mvn(org.apache.ant:ant-antlr) mvn(org.apache.ant:ant-launcher)
Requires:            mvn(org.apache.ant:ant-junit) mvn(bsf:bsf) mvn(commons-logging:commons-logging)
Requires:            glassfish-jsp-api glassfish-servlet-api mvn(com.thoughtworks.xstream:xstream)
Requires:            mvn(jline:jline:1) mvn(org.fusesource.jansi:jansi) mvn(org.apache.ivy:ivy)
Requires:            mvn(org.codehaus.gpars:gpars)
Suggests:            java-devel
BuildArch:           noarch
%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.  It seamlessly integrates with all existing Java objects and
libraries and compiles straight to Java byte-code so you can use it anywhere
you can use Java.

%package lib
Summary:             Groovy JAR artifact
%description lib
This package contains Groovy JAR artifact.

%package javadoc
Summary:             API Documentation for %{name}
%description javadoc
JavaDoc documentation for %{name}

%prep
%setup -q -n groovy-core-GROOVY_%{archiver}
find . -name "*.class" -delete
find . -name "*.jar" -delete
cp %{SOURCE4} %{SOURCE5} %{SOURCE6} .
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
sed -i "s| depends=\"-excludeLegacyAntVersion\"||" build.xml
%pom_xpath_replace "pom:dependency[pom:optional[text()='true']]/pom:scope" "<scope>provided</scope>"
%pom_remove_dep org.livetribe:livetribe-jsr223
sed -i "s|<groupId>javax.servlet</groupId>|<groupId>org.apache.tomcat</groupId>|" pom.xml
sed -i "s|<artifactId>jsp-api</artifactId>|<artifactId>tomcat-jsp-api</artifactId>|" pom.xml
sed -i "s|<version>2.0</version>|<version>any</version>|" pom.xml
sed -i "s|<artifactId>servlet-api</artifactId>|<artifactId>tomcat-servlet-api</artifactId>|" pom.xml
sed -i "s|<version>2.4</version>|<version>any</version>|" pom.xml
for s in src/main/groovy/transform/NotYetImplemented.java\
  src/main/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java;do
  native2ascii -encoding UTF8 ${s} ${s}
done
find . -name "*.java" -exec sed -i 's|org.objectweb.asm|org.objectweb.distroshaded.asm|g' {} +
find . -name "*.groovy" -exec sed -i 's|org.objectweb.asm|org.objectweb.distroshaded.asm|g' {} +
%pom_change_dep :asm :asm-distroshaded
%pom_change_dep :asm-commons :asm-commons-distroshaded
%pom_change_dep :asm-util :asm-util-distroshaded
%pom_change_dep :asm-analysis :asm-analysis-distroshaded
%pom_change_dep :asm-tree :asm-tree-distroshaded
%mvn_package : %{name}-lib
%mvn_file : groovy %{name}
%mvn_alias : :groovy-all :%{name}-all :%{name}
%mvn_compat_version : "1.8" "1.8.9"

%build
mkdir -p target/lib/{compile,tools}
build-jar-repository target/lib/compile glassfish-servlet-api glassfish-jsp-api/javax.servlet.jsp-api \
        objectweb-asm3/asm-tree-distroshaded objectweb-asm3/asm-distroshaded \
        objectweb-asm3/asm-util-distroshaded objectweb-asm3/asm-analysis-distroshaded \
        antlr ant/ant-antlr antlr \
        bsf jline1/jline-1 xstream ant junit apache-ivy commons-cli \
        jansi
export CLASSPATH=$(build-classpath ant/ant-antlr)
ant -DskipTests=on -DskipExamples=on -DskipFetch=on -DskipEmbeddable=on \
        createJars javadoc

%install
%mvn_artifact pom.xml target/dist/groovy.jar
%mvn_install -J target/html/api/
install -d $RPM_BUILD_ROOT%{_bindir}
install -p -m755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/%{name}
for TOOL in grape18 %{name}c %{name}Console java2%{name} %{name}sh
do
        ln $RPM_BUILD_ROOT%{_bindir}/%{name} \
                $RPM_BUILD_ROOT%{_bindir}/$TOOL
done
install -d $RPM_BUILD_ROOT%{_sysconfdir}
install -p -m644 %{SOURCE2} \
        $RPM_BUILD_ROOT%{_sysconfdir}/%{name}-starter.conf

%files
%{_bindir}/*
%config(noreplace) %{_sysconfdir}/%{name}-starter.conf
%doc README.md
%license LICENSE.txt LICENSE-2.0.txt NOTICE.txt cpl-v10.txt epl-v10.txt

%files lib -f .mfiles-%{name}-lib
%license LICENSE.txt LICENSE-2.0.txt NOTICE.txt cpl-v10.txt epl-v10.txt

%files javadoc
%{_javadocdir}/%{name}
%license LICENSE.txt LICENSE-2.0.txt NOTICE.txt cpl-v10.txt epl-v10.txt

%changelog
* Mon Mar 11 2024 Ge Wang <wang__ge@126.com> - 1.8.9-4
- Add command line parser separator recogonition

* Mon Feb 26 2024 xu_ping <707078654@qq.com> - 1.8.9-3
- fix help information is consistent due to the singularity of the class method.

* Tue Feb 20 2024 Ge Wang <wang__ge@126.com> - 1.8.9-2
- Replace run with exec

* Sat Aug 15 2020 zhanghua <zhanghua40@huawei.com> - 1.8.9-1
- Package init
