%define debug_package %{nil}
%define pulsar_ver 2.10.4
%define pkg_ver 4
%define _prefix /opt/pulsar
Summary: Cloud-Native, Distributed Messaging and Streaming
Name: pulsar
Version: %{pulsar_ver}
Release: %{pkg_ver}
License: Apache-2.0
Group: Applications/Message
URL: https://pulsar.apache.org
Source0: https://archive.apache.org/dist/pulsar/pulsar-2.10.4/apache-pulsar-2.10.4-src.tar.gz
Patch0001: 0001-use-huawei-repository.patch
Patch0002: 0002-resolve-cve-2023-32697.patch
Patch0003: 0003-CVE-2023-2976.patch
Patch0004: 0004-netty-to-4.1.89.patch
BuildRoot: /root/rpmbuild/BUILDROOT/
BuildRequires: java-1.8.0-openjdk-devel,maven,systemd
Requires: java-1.8.0-openjdk,systemd
Provides: apache-pulsar
Provides: mvn(org.apche.pulsar:pulsar)

%description
Pulsar is a distributed pub-sub messaging platform with a very flexible messaging model and an intuitive client API.

%prep
%setup -q -n apache-pulsar-%{version}-src

%patch0001 -p1
%patch0002 -p1
%patch0003 -p1
%patch0004 -p1

%build
mvn clean install -Pcore-modules,-main -DskipTests

%install
mkdir -p $RPM_BUILD_ROOT%{_prefix}/{lib,bin,conf,examples,instances,licenses}
cd %{_builddir}/apache-pulsar-%{version}-src/distribution/server/target/
tar -xvf apache-pulsar-%{version}-bin.tar.gz
cd apache-pulsar-%{version}
cp -pr * $RPM_BUILD_ROOT%{_prefix}

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%attr(-,pulsar,pulsar) %{_prefix}
%dir %attr(755, pulsar, pulsar) %{_prefix}

%pre
getent group pulsar >/dev/null || groupadd -r pulsar
getent passwd pulsar >/dev/null || useradd -r -g pulsar -d / -s /sbin/nologin pulsar
exit 0

%changelog
* Fri Dec 1 2023 Dapeng Sun <sundapeng@cmss.chinamobile.com> - 2.10.4-4
- upgrade netty to 4.1.89
* Mon Nov 27 2023 Dapeng Sun <sundapeng@cmss.chinamobile.com> - 2.10.4-3
- resolve CVE-2023-2976
* Thu Aug 24 2023 Jialing Wang <wangjialing@cmss.chinamobile.com> - 2.10.4-2
- resovle Cve-2023-32697
* Fri Aug 11 2023 Jialing Wang <wangjialing@cmss.chinamobile.com> - 2.10.4-1
- init puslar spec
