%global namedreltag .Final
%global namedversion %{version}%{?namedreltag}
%global pom_url http://repo1.maven.org/maven2/org/hibernate

Name:          hibernate
Summary:       an easy-to-use and powerful object relational persistence framework for Java applications
Version:       5.0.10
Release:       7
License:       LGPLv2+ and ASL 2.0
URL:           http://www.hibernate.org/

Source0:       https://github.com/hibernate/hibernate-orm/archive/%{version}/%{name}-%{namedversion}.tar.gz
Source1:       %{pom_url}/hibernate-c3p0/%{namedversion}/hibernate-c3p0-%{namedversion}.pom
Source2:       %{pom_url}/hibernate-core/%{namedversion}/hibernate-core-%{namedversion}.pom
Source3:       %{pom_url}/hibernate-ehcache/%{namedversion}/hibernate-ehcache-%{namedversion}.pom
Source4:       %{pom_url}/hibernate-entitymanager/%{namedversion}/hibernate-entitymanager-%{namedversion}.pom
Source5:       %{pom_url}/hibernate-envers/%{namedversion}/hibernate-envers-%{namedversion}.pom
Source6:       %{pom_url}/hibernate-hikaricp/%{namedversion}/hibernate-hikaricp-%{namedversion}.pom
Source7:       %{pom_url}/hibernate-infinispan/%{namedversion}/hibernate-infinispan-%{namedversion}.pom
Source8:       %{pom_url}/hibernate-java8/%{namedversion}/hibernate-java8-%{namedversion}.pom
Source9:       %{pom_url}/hibernate-osgi/%{namedversion}/hibernate-osgi-%{namedversion}.pom
Source10:      %{pom_url}/hibernate-proxool/%{namedversion}/hibernate-proxool-%{namedversion}.pom
Source11:      %{pom_url}/hibernate-spatial/%{namedversion}/hibernate-spatial-%{namedversion}.pom
Source12:      %{pom_url}/hibernate-testing/%{namedversion}/hibernate-testing-%{namedversion}.pom
Source50:      hibernate-parent-%{namedversion}.pom
Source60:      http://www.apache.org/licenses/LICENSE-2.0.txt
Source61:      logging-processor.txt
Source62:      hibernate-configuration.txt
Source63:      grammars.txt
Source64:      target-source.txt
Source65:      Bundle-Description.txt
Source66:      Implementation.txt
Source67:      Bundle-Description-Name.txt
Source68:      manifestFile.txt

Patch0000:     CVE-2020-25638.patch

BuildRequires: maven-local mvn(antlr:antlr) mvn(com.experlog:xapool) mvn(com.fasterxml:classmate)
BuildRequires: mvn(com.mchange:c3p0) mvn(com.zaxxer:HikariCP) mvn(dom4j:dom4j) mvn(java_cup:java_cup)
BuildRequires: mvn(javax.enterprise:cdi-api) mvn(javax.validation:validation-api) mvn(junit:junit)
BuildRequires: mvn(net.sf.ehcache:ehcache-core) mvn(org.apache.ant:ant) mvn(org.apache.felix:maven-bundle-plugin)
BuildRequires: mvn(org.apache.geronimo.specs:geronimo-jta_1.1_spec) mvn(org.codehaus.mojo:antlr-maven-plugin)
BuildRequires: mvn(org.bsc.maven:maven-processor-plugin) mvn(org.apache.geronimo.specs:specs-parent:pom:)
BuildRequires: mvn(org.eclipse.osgi:org.eclipse.osgi) mvn(org.hibernate.common:hibernate-commons-annotations)
BuildRequires: mvn(org.hibernate.javax.persistence:hibernate-jpa-2.1-api) mvn(org.javassist:javassist)
BuildRequires: mvn(org.jboss:jandex) mvn(org.jboss.byteman:byteman-bmunit) mvn(org.jboss.byteman:byteman)
BuildRequires: mvn(org.jboss.byteman:byteman-install) mvn(org.jboss.logging:jboss-logging-annotations)
BuildRequires: mvn(org.jboss.logging:jboss-logging) mvn(org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec)
BuildRequires: mvn(org.jboss.logging:jboss-logging-processor) mvn(org.jboss.narayana.jta:jta)
BuildRequires: mvn(org.jvnet.jaxb2.maven2:maven-jaxb22-plugin) mvn(proxool:proxool)
BuildRequires: mvn(org.rhq.helpers:rhq-pluginAnnotations) mvn(org.jvnet.jaxb2_commons:jaxb2-basics)

BuildRequires: mvn(org.infinispan:infinispan-core) >= 7.2.1

BuildArch:     noarch

%description
Hibernate is a powerful, high-performance, feature-rich and very popular ORM solution for Java.
Hibernate facilitates development of persistent objects based on the common Java object model to
mirror the underlying database structure. This approach progresses the business performance to
some extent, advances development efficiency exceedingly and obtains preferable economical
efficiency and practicability.

Provides: %{name}-core = %{version}-%{release}
Provides: %{name}-c3p0 = %{version}-%{release}
Provides: %{name}-ehcache = %{version}-%{release}
Provides: %{name}-entitymanager = %{version}-%{release}
Provides: %{name}-envers = %{version}-%{release}
Provides: %{name}-hikaricp = %{version}-%{release}
Provides: %{name}-infinispan = %{version}-%{release}
Provides: %{name}-java8 = %{version}-%{release}
Provides: %{name}-osgi = %{version}-%{release}
Provides: %{name}-parent = %{version}-%{release}
Provides: %{name}-proxool = %{version}-%{release}
Provides: %{name}-spatial = %{version}-%{release}
Provides: %{name}-testing = %{version}-%{release}
Provides: %{name}-javadoc = %{version}-%{release}

Obsoletes: %{name}-core < %{version}-%{release}
Obsoletes: %{name}-c3p0 < %{version}-%{release}
Obsoletes: %{name}-ehcache < %{version}-%{release}
Obsoletes: %{name}-entitymanager < %{version}-%{release}
Obsoletes: %{name}-envers < %{version}-%{release}
Obsoletes: %{name}-hikaricp < %{version}-%{release}
Obsoletes: %{name}-infinispan < %{version}-%{release}
Obsoletes: %{name}-java8 < %{version}-%{release}
Obsoletes: %{name}-osgi < %{version}-%{release}
Obsoletes: %{name}-parent < %{version}-%{release}
Obsoletes: %{name}-proxool < %{version}-%{release}
Obsoletes: %{name}-spatial < %{version}-%{release}
Obsoletes: %{name}-testing < %{version}-%{release}
Obsoletes: %{name}-javadoc < %{version}-%{release}

%prep
%autosetup -p1 -n %{name}-orm-%{version}
find .  -name "*.jar" -delete
find .  -name "*.class" -delete
rm -r documentation/*

cp -p %{SOURCE1} hibernate-c3p0/pom.xml
cp -p %{SOURCE2} hibernate-core/pom.xml
cp -p %{SOURCE3} hibernate-ehcache/pom.xml
cp -p %{SOURCE4} hibernate-entitymanager/pom.xml
cp -p %{SOURCE5} hibernate-envers/pom.xml
cp -p %{SOURCE6} hibernate-hikaricp/pom.xml
cp -p %{SOURCE7} hibernate-infinispan/pom.xml
cp -p %{SOURCE8} hibernate-java8/pom.xml
cp -p %{SOURCE9} hibernate-osgi/pom.xml
cp -p %{SOURCE10} hibernate-proxool/pom.xml
cp -p %{SOURCE11} hibernate-spatial/pom.xml
cp -p %{SOURCE12} hibernate-testing/pom.xml
cp -p %{SOURCE50} pom.xml
cp -p %{SOURCE60} .
sed -i 's/\r//' LICENSE-2.0.txt

for m in entitymanager envers core; do
%pom_add_plugin org.bsc.maven:maven-processor-plugin:2.2.4 hibernate-${m} "`cat %{SOURCE61}`"
done

pushd hibernate-core

%pom_add_plugin "org.jvnet.jaxb2.maven2:maven-jaxb22-plugin:0.12.3" . "`cat %{SOURCE62}`"
%pom_add_plugin "org.codehaus.mojo:antlr-maven-plugin:2.2" . "`cat %{SOURCE63}`"
%pom_add_plugin "org.apache.maven.plugins:maven-compiler-plugin:3.3" . "`cat %{SOURCE64}`"
%pom_add_plugin org.apache.felix:maven-bundle-plugin:2.5.4 . "`cat %{SOURCE65}`"
%pom_add_plugin org.apache.maven.plugins:maven-jar-plugin:2.6 . "`cat %{SOURCE66}`"
%pom_add_dep "com.fasterxml:classmate:1.1.0"
%pom_add_dep "javax.validation:validation-api:1.1.0.Final"
%pom_add_dep "org.apache.ant:ant:1.9.4:provided"
%pom_add_dep "org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec:1.0.2.Final"
%pom_add_dep "junit:junit:4.12:test"
%pom_add_dep "org.hibernate:hibernate-testing:%{namedversion}:test"

popd

%pom_add_dep "javax.enterprise:cdi-api:1.2" hibernate-entitymanager
%pom_change_dep "com.zaxxer:HikariCP-java6" "com.zaxxer:HikariCP:2.4.0" hibernate-hikaricp
%pom_change_dep "org.osgi:org.osgi.core" "org.eclipse.osgi:org.eclipse.osgi:3.10.102.v20160416-2200" hibernate-osgi
%pom_remove_dep "org.osgi:org.osgi.compendium" hibernate-osgi
%pom_change_dep "org.jboss.jbossts:jbossjta" "org.jboss.narayana.jta:jta" hibernate-testing

for m in c3p0 ehcache entitymanager envers hikaricp infinispan java8 osgi proxool spatial testing; do
%pom_add_plugin org.apache.felix:maven-bundle-plugin:2.5.4 hibernate-${m} "`cat %{SOURCE67}`"
%pom_add_plugin org.apache.maven.plugins:maven-jar-plugin:2.6 hibernate-${m} "`cat %{SOURCE68}`"
done

for f in $(grep -e 'Pedersen\|Lichtmaier\|Chanfreau\|Benke\|Carlos\|CREATE\ SCHEMA' --include *.java -r -l | sort | uniq); do
  native2ascii -encoding UTF8 ${f} ${f}
done

%pom_disable_module hibernate-spatial

%build
%mvn_build -s -f -- -Dproject.build.sourceEncoding=UTF-8

%install
%mvn_install

%files
%dir %{_datadir}
%{_datadir}/*
%doc changelog.txt README.md migration-guide.adoc
%license lgpl.txt LICENSE-2.0.txt
%doc hibernate-osgi/README.md

%changelog
* Sat Dec 12 2020  zhangtao<zhangtao221@huawei.com> - 5.0.10-7
- CVE-2020-25638

* Fri Dec 13 2019 caomeng<caomeng5@huawei.com> - 5.0.10-6
- Package init

