%global oname jamon
Name:                jamonapi
Version:             2.74
Release:             1
Summary:             A Java monitoring API
License:             BSD
URL:                 http://jamonapi.sourceforge.net/
Source0:             https://sourceforge.net/projects/%{name}/files/%{name}/v2_74/jamonall-%{version}.zip
Source1:             https://repo1.maven.org/maven2/com/%{name}/%{oname}/2.75/%{oname}-2.75.pom
#git clone https://git.code.sf.net/p/jamonapi/jamonapi jamonapi-jamonapi
#cd jamonapi-jamonapi/src
#tar -cvf jamonapi-JAMonUsersGuide.tar.gz JAMonUsersGuide
Source2:             jamonapi-JAMonUsersGuide.tar.gz
Patch0:              0001-fix-pom.xml.patch
Patch1:              %{name}-jetty8.patch
Patch2:              %{name}-jetty93.patch
BuildRequires:       maven-local jetty-util tomcat
BuildRequires:       mvn(org.apache.maven.plugins:maven-javadoc-plugin)
Requires:            geronimo-interceptor log4j12
BuildArch:           noarch
%description
JAMon API is a free, simple, high performance, thread safe,
Java API that allows developers to easily monitor the
performance and scalability of production applications. JAMon
tracks hits, execution times (total, avg, min, max, std dev),
and more.

%package javadoc
Summary:             API documentation for %{name}
%description javadoc
This package contains API documentation for Java monitoring API.

%prep
%setup -q -c -n %{name}
rm -rf binaries
rm -rf javadoc
mkdir -p ./src/
mv ./java ./src/
mv ./osmon ./src/
cp %{SOURCE1} ./pom.xml
cp %{SOURCE2} ./src/
pushd ./src
tar -xvf %{name}-JAMonUsersGuide.tar.gz
rm -f %{name}-JAMonUsersGuide.tar.gz
popd
%patch0 -p1
%patch1 -p1
%patch2 -p1

%build
%mvn_build

%install
%mvn_install
cp %{buildroot}%{_datadir}/maven-poms/jamonapi/jamon.pom %{buildroot}%{_datadir}/maven-poms/jamonapi.pom
mv %{buildroot}%{_datadir}/maven-poms/jamonapi/jamon.pom %{buildroot}%{_datadir}/maven-poms/
rm -rf %{buildroot}/maven-poms/jamonapi/
cp %{buildroot}%{_javadir}/jamonapi/jamon.jar %{buildroot}%{_javadir}/jamonapi.jar
mv %{buildroot}%{_javadir}/jamonapi/jamon.jar %{buildroot}%{_javadir}/
rm -rf %{buildroot}%{_javadir}/jamonapi/
mkdir -p %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/http/ 
mkdir -p %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/log4j/
mkdir -p %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/proxy/
mkdir -p %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/utils/
install -D -p -m -r %{_builddir}/%{name}/javadocs/*.* %{buildroot}%{_javadocdir}/jamonapi/
chmod 644 %{buildroot}%{_javadocdir}/jamonapi/*.*
install -D -p -m -r %{_builddir}/%{name}/javadocs/com/jamonapi/*.* %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/
chmod 644 %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/*.*
install -D -p -m -r %{_builddir}/%{name}/javadocs/com/jamonapi/http/*.* %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/http/
chmod 644 %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/http/*.*
install -D -p -m -r %{_builddir}/%{name}/javadocs/com/jamonapi/log4j/*.* %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/log4j/
chmod 644 %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/log4j/*.*
install -D -p -m -r %{_builddir}/%{name}/javadocs/com/jamonapi/proxy/*.* %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/proxy/
chmod 644 %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/proxy/*.*
install -D -p -m -r %{_builddir}/%{name}/javadocs/com/jamonapi/utils/*.* %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/utils/ 
chmod 644 %{buildroot}%{_javadocdir}/jamonapi/com/jamonapi/utils/*.*

%files 
%attr(0644,root,root) /usr/share/maven-metadata/jamonapi.xml
%attr(0755,root,root) /usr/share/java/jamon.jar
%attr(0755,root,root) /usr/share/java/jamonapi.jar
%attr(0644,root,root) /usr/share/maven-poms/jamon.pom
%attr(0644,root,root) /usr/share/maven-poms/jamonapi.pom
%doc src/JAMonUsersGuide
%license src/JAMonUsersGuide/JAMonLicense.html

%files javadoc
%defattr (-,root,root,0755) 
/usr/share/javadoc/jamonapi
%license src/JAMonUsersGuide/JAMonLicense.html

%changelog
* Sat Sep 5 2020 Ge Wang <wangge20@huawei.com> - 2.74-1
- Package init
