%global bootstrap 0
%global bootstrap_version 3.1.3
Name:                antlr32
Version:             3.2
Release:             2
Summary:             ANother Tool for Language Recognition
License:             BSD-3-Clause
URL:                 http://www.antlr3.org/
Source0:             http://www.antlr3.org/download/antlr-%{version}.tar.gz
%if %{bootstrap}
Source1:             https://repo1.maven.org/maven2/org/antlr/antlr-master/%{bootstrap_version}/antlr-master-%{bootstrap_version}.pom
Source2:             https://repo1.maven.org/maven2/org/antlr/antlr/%{bootstrap_version}/antlr-%{bootstrap_version}.jar
Source3:             https://repo1.maven.org/maven2/org/antlr/antlr/%{bootstrap_version}/antlr-%{bootstrap_version}.pom
Source4:             https://repo1.maven.org/maven2/org/antlr/antlr-runtime/%{bootstrap_version}/antlr-runtime-%{bootstrap_version}.jar
Source5:             https://repo1.maven.org/maven2/org/antlr/antlr-runtime/%{bootstrap_version}/antlr-runtime-%{bootstrap_version}.pom
Source6:             https://repo1.maven.org/maven2/org/antlr/antlr3-maven-plugin/%{bootstrap_version}-1/antlr3-maven-plugin-%{bootstrap_version}-1.jar
Source7:             https://repo1.maven.org/maven2/org/antlr/antlr3-maven-plugin/%{bootstrap_version}-1/antlr3-maven-plugin-%{bootstrap_version}-1.pom
%endif
Patch0:              java8-compat.patch
Patch1:              osgi-manifest.patch
Patch2:              antlr2-usage.patch
BuildRequires:       maven-local ant-antlr exec-maven-plugin maven-plugin-build-helper
BuildRequires:       maven-plugin-bundle maven-plugin-plugin stringtemplate >= 3.2
%if ! %{bootstrap}
BuildRequires:       %{name}-maven-plugin = %{version}
%endif
BuildArch:           noarch
%description
ANother Tool for Language Recognition, is a grammar parser generator.
This package is compatibility package containing an older version of
in order to support jython. No other packages should declare a
dependency on this one.

%package     maven-plugin
Summary:             Maven plug-in for creating ANTLR-generated parsers
Requires:            %{name}-tool = %{version}-%{release}
%description maven-plugin
Maven plug-in for creating ANTLR-generated parsers.

%package     tool
Summary:             Command line tool for creating ANTLR-generated parsers
Requires:            %{name}-java = %{version}-%{release}
%description tool
Command line tool for creating ANTLR-generated parsers.

%package     java
Summary:             Java run-time support for ANTLR-generated parsers
Requires:            stringtemplate >= 3.2
%description java
Java run-time support for ANTLR-generated parsers.

%package     javadoc
Summary:             API documentation for ANTLR
%description javadoc
%{summary}.

%prep
%setup -q -n antlr-%{version}
%patch0 -b .orig
%patch1 -b .orig
%patch2 -b .orig
find -type f -a -name *.jar -delete
find -type f -a -name *.class -delete
find -name "._*" -delete
%pom_disable_module gunit
%pom_disable_module gunit-maven-plugin
%pom_remove_plugin org.codehaus.mojo:buildnumber-maven-plugin
%pom_xpath_remove pom:build/pom:extensions
%pom_xpath_remove pom:build/pom:extensions runtime/Java
%pom_xpath_remove pom:build/pom:extensions antlr3-maven-plugin
%mvn_package :antlr tool
%mvn_package :antlr-master java
%mvn_package :antlr-runtime java
%mvn_package :antlr3-maven-plugin maven-plugin
find -name "pom.xml" | xargs sed -i -e "s|>jsr14<|>1.5<|"
sed -i -e "s|\${buildNumber}|%{release}|" tool/src/main/resources/org/antlr/antlr.properties
%mvn_compat_version 'org.antlr:antlr3-maven-plugin' %{version} %{bootstrap_version}-1
%mvn_compat_version 'org.antlr:antlr{,-master,-runtime}' %{version} %{bootstrap_version}

%build
mkdir -p .m2/org/antlr/antlr-master/%{version}/
cp -p pom.xml .m2/org/antlr/antlr-master/%{version}/antlr-master-%{version}.pom
%if %{bootstrap}
mkdir -p .m2/org/antlr/antlr-master/%{bootstrap_version}/
cp -p %{SOURCE1} .m2/org/antlr/antlr-master/%{bootstrap_version}/.
mkdir -p .m2/org/antlr/antlr/%{bootstrap_version}/
cp -p %{SOURCE2} %{SOURCE3} .m2/org/antlr/antlr/%{bootstrap_version}/.
mkdir -p .m2/org/antlr/antlr-runtime/%{bootstrap_version}/
cp -p %{SOURCE4} %{SOURCE5} .m2/org/antlr/antlr-runtime/%{bootstrap_version}/.
mkdir -p .m2/org/antlr/antlr3-maven-plugin/%{bootstrap_version}/
cp -p %{SOURCE6} %{SOURCE7} .m2/org/antlr/antlr3-maven-plugin/%{bootstrap_version}/.
%endif
%mvn_build -f

%install
%mvn_install

%files tool -f .mfiles-tool
%doc tool/LICENSE.txt

%files maven-plugin -f .mfiles-maven-plugin
%doc tool/LICENSE.txt

%files java -f .mfiles-java
%doc tool/LICENSE.txt
%dir %{_datadir}/java/antlr32

%files javadoc -f .mfiles-javadoc
%doc tool/LICENSE.txt

%changelog
* Mon May 9 2022 caodongxia <caodongxia@h-partners.com> - 3.2-2
- License compliance rectification

* Wed Jul 22 2020 Jeffery.Gao <gaojianxing@huawei.com> - 3.2-1
- Package init
