%global noupdatechecks_version 20140707gitcce19ac

Name:           findbugs
Version:        3.0.1
Release:        18
Summary:        Find Bugs in Java Programs
License:        LGPLv2+
URL:            http://findbugs.sourceforge.net/
Source0:        http://downloads.sourceforge.net/%{name}/%{name}-%{version}-source.zip
Source1:        findbugs-ant
Source2:        findbugs-tools-README
Source3:        http://repo1.maven.org/maven2/com/google/code/findbugs/findbugs/3.0.1/findbugs-3.0.1.pom
Source4:        http://repo1.maven.org/maven2/com/google/code/findbugs/annotations/3.0.0/annotations-3.0.0.pom

# This archive contains the source for the noUpdateChecks plugin.
# It was created with:
#   $ git clone --bare https://code.google.com/p/findbugs
#   $ git --git-dir=findbugs.git archive --format tgz cce19ac plugins/noUpdateChecks -o noUpdateChecks-plugin-20140707gitcce19ac.tgz
Source5:        noUpdateChecks-plugin-%{noupdatechecks_version}.tgz
Source6:        http://repo1.maven.org/maven2/com/google/code/findbugs/findbugs-ant/3.0.0/findbugs-ant-3.0.0.pom
# It looks in /usr/share/java for jar files at compile time, instead of in findbugs' lib directory.
Patch0000:         findbugs-build.patch
# Set xsl.stylesheet.home to the directory containing the DocBook Modular XSL Stylesheets from http://docbook.sourceforge.net/projects/xsl/ 
Patch0001:         findbugs-manual.patch
# Port to dom4j 2.0
Patch0002:         findbugs-dom4j.patch
BuildArch:      noarch
BuildRequires:  ant findbugs-bcel docbook-style-xsl apache-commons-lang dom4j jaxen jcip-annotations jdepend jFormatString
BuildRequires:  javapackages-local jsr-305 junit make objectweb-asm perl-interpreter perl-generators
BuildRequires:  docbook-style-xsl tex(latex) texlive-preprint libxslt java-devel >= 1:1.6.0 jpackage-utils
Requires:       apache-commons-lang findbugs-bcel dom4j jaxen jcip-annotations objectweb-asm
Requires:       junit jsr-305 jpackage-utils jFormatString java >= 1:1.6.0

%description
Findbugs is a program which uses static analysis to look for bugs in Java code.

%package -n ant-findbugs
Summary:        findbugs used for Ant task
Requires:       %{name} = %{version}-%{release}
Requires:       ant

%description -n ant-findbugs
The ant-findbugs package contain an ant task for integration of findbugs easily into ant-controlled project.

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

%description help
Help documentation for findbugs.

%package tools
Summary:        Addon tools for findbugs
Requires:       %{name} = %{version}-%{release}
Requires:       junit

%description tools
Provide additional tools for use with findbugs. See README.openEuler for more information.

%prep
%autosetup -p1 -a 5
install -p %{SOURCE2} README.tools
find lib -name ".jar" -exec rm {} \;
find src/gui/edu/umd/cs/findbugs/gui2 -name "OSXAdapter.java" -exec rm {} \;
cp %{SOURCE3} ./
%pom_remove_dep com.apple:AppleJavaExtensions findbugs-3.0.1.pom

%build
ant docs build
ant apiJavadoc
cd $RPM_BUILD_DIR/%{name}-%{version}/design/architecture
make depend
make
jar fc $RPM_BUILD_DIR/%{name}-%{version}/lib/findbugs-tools.jar \
       $RPM_BUILD_DIR/%{name}-%{version}/build/classes/edu/umd/cs/findbugs/tools

cd $RPM_BUILD_DIR/%{name}-%{version}/plugins/noUpdateChecks
ant plugin-jar

%install

for dir in %{_javadir}/ant %{_javadocdir} %{_datadir}/%{name}/lib %{_bindir} %{_mavenpomdir};
do
  mkdir -p $RPM_BUILD_ROOT$dir
done

cp -Rdp apiJavaDoc $RPM_BUILD_ROOT%{_javadocdir}/%{name}
cp -Rdp etc plugin $RPM_BUILD_ROOT%{_datadir}/%{name}
cp -p plugins/noUpdateChecks/build/noUpdateChecks.jar $RPM_BUILD_ROOT%{_datadir}/%{name}/plugin
install -pD %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/ant.d/%{name}

mv lib/annotations.jar lib/%{name}-annotations.jar
for file in %{name}-annotations %{name}-tools %{name} %{name}-ant;
do
  cp -p lib/$file.jar $RPM_BUILD_ROOT%{_javadir}/$file.jar
done
mv $RPM_BUILD_ROOT%{_javadir}/%{name}-ant.jar $RPM_BUILD_ROOT%{_javadir}/ant/ant-%{name}.jar

for f in $(find bin -maxdepth 1 -type f \! -name '*.bat' \! -name '*.ico');
do
  cp -p $f $RPM_BUILD_ROOT%{_bindir}
done

for i in findbugs findbugs-bcel dom4j jaxen objectweb-asm/asm-all jsr-305 jFormatString apache-commons-lang;
do
  ln -s %{_javadir}/$i.jar $RPM_BUILD_ROOT%{_datadir}/%{name}/lib
done

rm -f build/doc/manual*.xml build/doc/manual*.xsl

sed -i 's/3\.0\.0/3\.0\.1/g' %{SOURCE4} %{SOURCE6}
sed -i '/<parent>/,/<\/parent>/d' findbugs-3.0.1.pom
cp findbugs-3.0.1.pom $RPM_BUILD_ROOT%{_mavenpomdir}/JPP-%{name}.pom
cp %{SOURCE4} $RPM_BUILD_ROOT%{_mavenpomdir}/JPP-%{name}-annotations.pom
cp %{SOURCE6} $RPM_BUILD_ROOT%{_mavenpomdir}/JPP.ant-ant-%{name}.pom

%add_maven_depmap -a net.sourceforge.findbugs:findbugs JPP-%{name}.pom %{name}.jar
%add_maven_depmap -a net.sourceforge.findbugs:annotations JPP-%{name}-annotations.pom %{name}-annotations.jar
%add_maven_depmap -a net.sourceforge.findbugs:findbugs-ant JPP.ant-ant-%{name}.pom ant/ant-findbugs.jar -f ant

%pretrans help -p <lua>
path = "%{_javadocdir}/%{name}"
st = posix.stat(path)
if st and st.type == "link" then
  os.remove(path)
end

%files -f .mfiles
%doc licenses/LICENSE.txt design/DecouplingFromBCEL.txt design/VisitingAndCaching.txt
%doc README.txt "design/eclipse findbugs plugin features.sxw"
%doc design/architecture/architecture.pdf build/doc
%{_bindir}/*
%{_datadir}/%{name}

%files -n ant-findbugs -f .mfiles-ant
%config(noreplace) %{_sysconfdir}/ant.d/%{name}

%files help
%{_javadocdir}/*

%files tools
%doc README.tools
%{_javadir}/findbugs-tools.jar

%changelog
* Wed Mar 10 2021 chengzihan <chengzihan2@huawei.com> - 3.0.1-18
- modify the duplicate of Source3 instead of itself

* Fri Sep 04 2020 yaokai <yaokai13@huawei.com> - 3.0.1-17
- Remove parent tag in pom file

* Tue Mar 03 2020 wangyiru <wangyiru1@huawei.com> - 3.0.1-16
- Package init
