%global debug_package %{nil}
%global debug_package %{nil}
%define kafka_home /opt/kafka

Name: kafka
Version: 2.4.0
Release: 4
Summary: A Distributed Streaming Platform.

License: Apache License, Version 2.0
Source0: https://archive.apache.org/dist/%{name}/%{version}/%{name}-%{version}-src.tgz
Source1: kafka.service
Source2: https://raw.githubusercontent.com/gradle/gradle/v5.6.2/gradle/wrapper/gradle-wrapper.jar
patch1:  Modify-gradle-wrapper-to-local-source.patch
patch2:  Modify-maven-url-to-huaweicloud.patch
patch3:  Modify-gradle-url-to-huaweicloud.patch

BuildRequires: systemd java-1.8.0-openjdk-devel
Provides: kafka = %{version}
Requires: java-1.8.0-openjdk
# To ensure that Zookeeper is included,deploy Kafka using your own Zookeeper
Provides: zookeeper = 3.5.6
Conflicts: zookeeper = 3.6.1

%description
Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.

%pre
getent group %{name} >/dev/null || groupadd -r %{name}
getent passwd %{name} >/dev/null || \
    useradd -r -g %{name} -d %{_sharedstatedir}/%{name} -s /sbin/nologin \
    -c "User for Kafka services" %{name}
exit 0

%prep
%setup -q -n %{name}-%{version}-src
%patch1 -p1
%patch2 -p1
%patch3 -p1
cp %{SOURCE2} ./
echo `pwd` > absolute_prefix.log
sed -i 's/\//\\\//g' absolute_prefix.log
absolute_prefix=`head -n 1 absolute_prefix.log`
sed -i 's/absolute-prefix/'"$absolute_prefix"'/g' wrapper.gradle
sed -i 's/absolute-prefix/'"$absolute_prefix"'/g' gradlew


%build
./gradlew jar

%install
mkdir -p $RPM_BUILD_ROOT%{kafka_home}/{libs,bin,config}

install -p -D -m 755 bin/*.sh $RPM_BUILD_ROOT%{kafka_home}/bin
install -p -D -m 644 config/* $RPM_BUILD_ROOT%{kafka_home}/config
cp -n */build/libs/* $RPM_BUILD_ROOT%{kafka_home}/libs
cp -n */build/dependant-libs*/* $RPM_BUILD_ROOT%{kafka_home}/libs
cp -n */*/build/libs/* $RPM_BUILD_ROOT%{kafka_home}/libs
cp -n */*/build/dependant-libs*/* $RPM_BUILD_ROOT%{kafka_home}/libs

%files
%defattr(-,root,root)

%{kafka_home}
%doc NOTICE
%doc LICENSE


%clean
rm -rf %{buildroot}

%changelog
* Thu Jul 15 2021 liyanan <liyanan32@huawei.com> - 2.4.0-4
- fix gradle url to huaweicloud
- fix gradle wrapper to local source
- fix maven url to huaweicloud

* Thu Apr 2 2021 huanghaitao <huanghaitao8@huawei.com> 2.4.0 - 3
- Declare kafka already include zookeeper

* Thu Mar 25 2021 huanghaitao <huanghaitao8@huawei.com> 2.4.0 - 2
- Remove dist macros

* Sat Mar 20 2021 huanghaitao <huanghaitao8@huawei.com> 2.4.0 - 1
- Rebase to 2.4.0

* Sat Aug 15 2020 Hao Zhang <unioah@isrc.iscas.ac.cn>
- init
* Sat Oct 04 2020 Hao Zhang <unioah@isrc.iscas.ac.cn>
- add service
