Name:           checkstyle
Version:        8.0
Release:        4.2
Summary:        Java source code inspection tool
URL:            http://checkstyle.sourceforge.net/
License:        LGPLv2+ and GPLv2+ and BSD
BuildArch:      noarch

Source0:        http://download.sf.net/checkstyle/checkstyle-%{version}-src.tar.gz
Source1:        %{name}.catalog

#This patch fixed CVE-2019-9658: Checkstyle loads external DTDs by default
Patch0000:      0001-Do-not-load-external-DTDs-by-default.patch

BuildRequires:  maven-local mvn(antlr:antlr) mvn(com.google.guava:guava) mvn(commons-beanutils:commons-beanutils)
BuildRequires:  mvn(commons-cli:commons-cli) mvn(com.sun:tools) mvn(org.antlr:antlr4-maven-plugin)
BuildRequires:  mvn(org.antlr:antlr4-runtime) mvn(org.apache.ant:ant) mvn(org.apache.ant:ant-nodeps)
BuildRequires:  mvn(org.apache.maven.plugins:maven-antrun-plugin) mvn(org.apache.maven.plugins:maven-failsafe-plugin)
BuildRequires:  mvn(org.codehaus.mojo:antlr-maven-plugin) mvn(org.codehaus.mojo:build-helper-maven-plugin)

Obsoletes:      %{name}-optional < %{version}-%{release} %{name}-demo < %{version}-%{release}
Obsoletes:      %{name}-manual < %{version}-%{release}

%description
A tool to help Java developers comply with certain coding standards

%package        help
Summary:        Help documents for checkstyle
Provides:       %{name}-javadoc = %{version}-%{release}
Obsoletes:      %{name}-javadoc < %{version}-%{release}

%description    help
Help documents for checkstyle

%prep
%autosetup -n %{name}-%{version} -p1

%pom_remove_parent

sed -i s/guava-jdk5/guava/ pom.xml

for file in maven-eclipse-plugin maven-site-plugin nexus-staging-maven-plugin maven-enforcer-plugin cobertura-maven-plugin maven-linkcheck-plugin maven-pmd-plugin findbugs-maven-plugin xml-maven-plugin forbiddenapis spotbugs-maven-plugin;do
%pom_remove_plugin :$file
done

%pom_remove_dep com.sun:tools
%pom_add_dep com.sun:tools

sed -i '/testLoadFromURL/s/ *.*/    @org.junit.Ignore&/' src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionsLoaderTest.java

sed -i '/testUnexpectedChar/s/./@org.junit.Ignore/' src/test/java/com/puppycrawl/tools/checkstyle/grammars/GeneratedJava14LexerTest.java

%build
%mvn_file : %{name}
%mvn_build -f

%install
%mvn_install

%jpackage_script com.puppycrawl.tools.checkstyle.Main "" "" checkstyle:antlr:apache-commons-beanutils:apache-commons-cli:apache-commons-logging:apache-commons-collections:guava checkstyle true

install -Dm 644 %{SOURCE1} %{buildroot}%{_datadir}/xml/%{name}/catalog
cp -pa src/main/resources/com/puppycrawl/tools/checkstyle/*.dtd \
  %{buildroot}%{_datadir}/xml/%{name}

install -dm 755  %{buildroot}%{_sysconfdir}/ant.d
cat > %{buildroot}%{_sysconfdir}/ant.d/%{name} << EOF
checkstyle antlr apache-commons-beanutils apache-commons-cli apache-commons-logging guava
EOF

%post
if [ -x %{_bindir}/install-catalog -a -d %{_sysconfdir}/sgml ]; then
  %{_bindir}/install-catalog --add \
    %{_sysconfdir}/sgml/%{name}-%{version}-%{release}.cat \
    %{_datadir}/xml/%{name}/catalog > /dev/null || :
fi

%postun
if [ -x %{_bindir}/install-catalog -a -d %{_sysconfdir}/sgml ]; then
  %{_bindir}/install-catalog --remove \
    %{_sysconfdir}/sgml/%{name}-%{version}-%{release}.cat \
    %{_datadir}/xml/%{name}/catalog > /dev/null || :
fi

%files -f .mfiles
%license LICENSE
%doc README.md
%{_datadir}/xml/%{name}
%{_bindir}/%{name}
%config(noreplace) %{_sysconfdir}/ant.d/%{name}

%files help -f .mfiles-javadoc

%changelog
* Wed Mar 4 2020 tangjing <tangjing30@huawei.com> - 8.0-4.2
- Package init
