%define HADOOP_VERSION 3.2.1
%global debug_package %{nil}

Name:             avro
Version:          1.10.2
Release:          4
Summary:          Data serialization system
License:          Apache-2.0
URL:              http://avro.apache.org

Source0:          https://github.com/apache/avro/archive/refs/tags/release-1.10.2.tar.gz
# file xmvn-reactor required by mvn_install to specify which jar package should be put in rpm
Source1:          xmvn-reactor
Patch0:           CVE-2021-43045.patch

ExclusiveArch:	  aarch64 x86_64

BuildRequires:    maven maven-local java-1.8.0-openjdk-devel
Requires:         java-1.8.0-openjdk

%description
Apache Avro is a data serialization system.

Avro provides:

* Rich data structures.
* A compact, fast, binary data format.
* A container file, to store persistent data.
* Remote procedure call (RPC).
* Simple integration with dynamic languages. Code generation is not required
  to read or write data files nor to use or implement RPC protocols. Code
  generation as an optional optimization, only worth implementing for
  statically typed languages.

%prep
%autosetup -n avro-release-1.10.2 -p1
cp %{SOURCE1} ./.xmvn-reactor
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' .xmvn-reactor

%build
for module in avro compiler maven-plugin ipc ipc-jetty ipc-netty tools mapred protobuf thrift archetypes grpc integration-test perf;do
    pushd lang/java/${module}
      mvn package -Dcheckstyle.skip=true -Dmaven.test.skip=true -Dhadoop.version=%{HADOOP_VERSION} -P hadoop2
    popd
done 

pushd lang/java/trevni/avro
    mvn package -Dcheckstyle.skip=true -Dmaven.test.skip=true -Dhadoop.version=%{HADOOP_VERSION} -P hadoop2
popd

pushd lang/java/trevni
    mvn package -Dcheckstyle.skip=true -Dmaven.test.skip=true -Dhadoop.versio=%{HADOOP_VERSION} -P hadoop2
popd

pushd lang/java/tools/target
  mkdir -p tmp
  mv avro-tools-%{version}.jar tmp
  cd tmp
    jar -xvf avro-tools-%{version}.jar
    #delete unsupported architecture dynamic lib
    rm -rf aix/ppc64
    rm -rf org/xerial/snappy/native/Linux/ppc64
    rm -rf org/xerial/snappy/native/Linux/ppc
    rm -rf org/xerial/snappy/native/Linux/s390x
    rm -rf org/xerial/snappy/native/Linux/ppc64le
    rm -rf org/xerial/snappy/native/SunOS/sparc
    rm -rf linux/ppc64
    rm -rf linux/s390x
    rm -rf linux/ppc64le
%ifarch x86_64
    rm -rf org/xerial/snappy/native/Linux/aarch64
    rm -rf org/xerial/snappy/native/Linux/armv6
    rm -rf org/xerial/snappy/native/Linux/armv7
    rm -rf org/xerial/snappy/native/Linux/arm
    rm -rf org/xerial/snappy/native/Linux/android-arm
    rm -rf linux/aarch64
    rm -rf linux/arm
%endif
%ifarch aarch64
    rm -rf freebsd/i386
    rm -rf linux/mips64
    rm -rf linux/i386
    rm -rf linux/amd64
    rm -rf freebsd/amd64
    rm -rf org/xerial/snappy/native/SunOS/x86_64
    rm -rf org/xerial/snappy/native/SunOS/x86
    rm -rf org/xerial/snappy/native/Linux/x86_64
    rm -rf org/xerial/snappy/native/Linux/x86
    rm -rf org/xerial/snappy/native/FreeBSD/x86_64
%endif
    find . -name *.so | for line in `xargs`;do strip $line;done
    rm -rf avro-tools-%{version}.jar
    jar -cvf avro-tools-%{version}.jar ./*
    mv avro-tools-%{version}.jar ../
  cd ..
  rm -rf tmp
popd

%install
%mvn_install
install -d -m 0755 %{buildroot}%{_datadir}/java/%{name}
install -m 0755 lang/java/tools/target/avro-tools-1.10.2-nodeps.jar %{buildroot}%{_datadir}/java/%{name}/avro-tools-nodeps.jar

%files -f .mfiles
%doc README.md
%license LICENSE.txt NOTICE.txt
%{_datadir}/java/avro/avro-tools-nodeps.jar

%changelog
* Tue Dec 19 2023 wangkai <13474090681@163.com> - 1.10.2-4
- Fix CVE-2021-43045

* Mon Aug 21 2023 xu_ping <707078654@qq.com> - 1.10.2-3
- Fix aarch64 strip failure.

* Sat Mar 04 2023 Ge Wang <wangge20@h-partners.com> - 1.10.2-2
- Fix check strip failure

* Tue Jun 29 2021 Ge Wang <wangge20@huawei.com> - 1.10.2-1
- Init package

