%bcond_with jp_minimal
%global extra_version 1.0.3
Name:                glassfish-hk2
Version:             2.5.0
Release:             1
Summary:             Glassfish Hundred Kilobytes Kernel
License:             EPL-2.0 or GPLv2 with exceptions
URL:                 https://github.com/eclipse-ee4j/glassfish-hk2/
Source0:             https://github.com/eclipse-ee4j/glassfish-hk2/archive/%{version}-RELEASE/%{name}-%{version}.tar.gz
Source1:             https://github.com/eclipse-ee4j/glassfish-hk2-extra/archive/%{extra_version}-RELEASE/%{name}-extra-%{extra_version}.tar.gz
Source2:             hk2-inhabitant-generator-osgi.bundle
Patch0:              0001-OSGi-metadata-fixes.patch
Patch1:              0002-Fixed-tests.patch
BuildRequires:       maven-local mvn(aopalliance:aopalliance)
BuildRequires:       mvn(javax.annotation:javax.annotation-api) mvn(javax.enterprise:cdi-api)
BuildRequires:       mvn(javax.inject:javax.inject) mvn(junit:junit) mvn(org.apache.ant:ant)
BuildRequires:       mvn(org.apache.commons:commons-lang3) mvn(org.apache.felix:maven-bundle-plugin)
BuildRequires:       mvn(org.apache.maven:maven-core) mvn(org.apache.maven:maven-plugin-api)
BuildRequires:       mvn(org.apache.maven.plugins:maven-plugin-plugin)
BuildRequires:       mvn(org.apache.maven.shared:maven-osgi) mvn(org.easymock:easymock)
BuildRequires:       mvn(org.javassist:javassist) mvn(org.osgi:osgi.cmpn) mvn(org.osgi:osgi.core)
BuildRequires:       mvn(org.ow2.asm:asm-all)
%if %{without jp_minimal}
BuildRequires:       mvn(args4j:args4j) mvn(com.google.inject:guice)
BuildRequires:       mvn(com.google.protobuf:protobuf-java) mvn(com.sun:tools)
BuildRequires:       mvn(javax.el:javax.el-api) mvn(javax.json:javax.json-api)
BuildRequires:       mvn(javax.validation:validation-api) mvn(javax.xml.bind:jaxb-api)
BuildRequires:       mvn(org.apache.bcel:bcel)
BuildRequires:       mvn(org.apache.felix:org.apache.felix.bundlerepository)
BuildRequires:       mvn(org.apache.maven.plugins:maven-antrun-plugin)
BuildRequires:       mvn(org.apache.maven.plugins:maven-dependency-plugin)
BuildRequires:       mvn(org.assertj:assertj-core) mvn(org.glassfish:javax.json)
BuildRequires:       mvn(org.hibernate:hibernate-validator) mvn(org.mockito:mockito-core)
BuildRequires:       mvn(org.springframework:spring-context) mvn(org.testng:testng)
%endif
BuildArch:           noarch
%description
HK2 for Hundred Kilobytes Kernel is an abstraction to
a module subsystem coupled with a simple yet powerful
component model to build server side software.

%package hk2
Summary:             HK2 module of HK2 itself
%description hk2
This is so that other modules can depend on HK2 as an HK2 module.

%package api
Summary:             HK2 API module
%description api
Hundred Kilobytes Kernel API module.

%package core
Summary:             HK2 core module
%description core
Hundred Kilobytes Kernel core module.

%package configuration
Summary:             HK2 configuration modules
%description configuration
Hundred Kilobytes Kernel configuration modules.

%package extras
Summary:             HK2 extras module
%description extras
Default implementations for HK2 services.

%package jmx
Summary:             HK2 JMX module
%description jmx
Hundred Kilobytes Kernel JMX module.

%package locator
Summary:             HK2 ServiceLocator Default Implementation
%description locator
Hundred Kilobytes Kernel ServiceLocator Default Implementation.

%package metadata-generator
Summary:             HK2 Metadata Generator
%description metadata-generator
HK2 Metadata Generator Subsystem.

%package runlevel
Summary:             HK2 Run Level Service
%description runlevel
Hundred Kilobytes Kernel Run Level Service.

%package utils
Summary:             HK2 Implementation Utilities
%description utils
Hundred Kilobytes Kernel Implementation Utilities.

%package class-model
Summary:             Class Model for Hk2
%description class-model
Hundred Kilobytes Kernel Class Model.

%package osgi-resource-locator
Summary:             HK2 OSGi resource locator bundle
Obsoletes:           osgi-resource-locator < %{version}-%{release}
Provides:            osgi-resource-locator = %{version}-%{release}
%description osgi-resource-locator
Hundred Kilobytes Kernel - OSGi resource locator bundle. Used by
various API providers that rely on META-INF/services mechanism to
locate providers.
%if %{without jp_minimal}

%package dependency-verifier
Summary:             HK2 Static Analyser for verifying module dependency
%description dependency-verifier
HK2 Static Analyser for verifying module dependency.

%package dependency-visualizer
Summary:             HK2 Tool to visualize the dependencies
%description dependency-visualizer
Tool to visualize the dependencies generated by HK2's dependency-verifier.

%package guice-bridge
Summary:             HK2 Guice Bridge
%description guice-bridge
Hundred Kilobytes Kernel Guice Bridge.

%package spring-bridge
Summary:             HK2 Spring Bridge
%description spring-bridge
Hundred Kilobytes Kernel Spring Bridge.

%package osgi
Summary:             HK2 OSGi Adapter
%description osgi
Hundred Kilobytes Kernel OSGi Adapter.
%endif

%package testing
Summary:             Utilities for testing with HK2
Obsoletes:           %{name}-locator-extras < %{version}-%{release}
Provides:            %{name}-locator-extras = %{version}-%{release}
Obsoletes:           %{name}-locator-no-proxies < %{version}-%{release}
Provides:            %{name}-locator-no-proxies = %{version}-%{release}
Obsoletes:           %{name}-locator-no-proxies2 < %{version}-%{release}
Provides:            %{name}-locator-no-proxies2 = %{version}-%{release}
Obsoletes:           %{name}-runlevel-extras < %{version}-%{release}
Provides:            %{name}-runlevel-extras = %{version}-%{release}
Obsoletes:           %{name}-testng < %{version}-%{release}
Provides:            %{name}-testng = %{version}-%{release}
%description testing
Hundred Kilobytes Kernel utilities for testing.

%package maven-plugins
Summary:             HK2 Maven Plug-ins
Obsoletes:           %{name}-maven < %{version}-%{release}
Provides:            %{name}-maven < %{version}-%{release}
Obsoletes:           %{name}-inhabitant-generator < %{version}-%{release}
Provides:            %{name}-inhabitant-generator < %{version}-%{release}
%description maven-plugins
This package provides various maven plug-ins:
* consolidatedbundle-maven-plugin
* osgiversion-maven-plugin
* hk2-inhabitant-generator

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

%prep
%setup -q -n glassfish-hk2-%{version}-RELEASE
%patch0 -p1
%patch1 -p1
tar xf %{SOURCE1} --strip-components=1 \
  %{name}-extra-%{extra_version}-RELEASE/osgi-resource-locator \
  %{name}-extra-%{extra_version}-RELEASE/dependency-{verifier,visualizer}
%pom_xpath_set "pom:dependency[pom:groupId ='org.glassfish.hk2']/pom:version" %{version} dependency-verifier
for mod in osgi-resource-locator dependency-verifier dependency-visualizer ; do
  %pom_xpath_inject "pom:modules" "<module>$mod</module>"
  %pom_remove_parent $mod
  %pom_add_parent "org.glassfish.hk2:hk2-parent:%{version}" $mod
done
find . -name '*.jar' ! -name "gendir.jar" -type f -print -delete
find . -name '*.class' -print -delete
%pom_remove_parent bom .
%pom_change_dep -r jakarta.servlet:jakarta.servlet-api javax.servlet:javax.servlet-api
%pom_change_dep -r jakarta.annotation:jakarta.annotation-api javax.annotation:javax.annotation-api
%pom_change_dep -r jakarta.el:jakarta.el-api javax.el:javax.el-api
%pom_change_dep -r jakarta.json:jakarta.json-api javax.json:javax.json-api
%pom_change_dep -r org.glassfish:jakarta.json org.glassfish:javax.json
%pom_change_dep -r org.glassfish.hk2.external:jakarta.inject javax.inject:javax.inject
%pom_change_dep -r org.glassfish.hk2.external:asm-repackaged org.ow2.asm:asm-all:'${asm.version}'
%pom_change_dep -r org.glassfish.hk2.external:aopalliance-repackaged aopalliance:aopalliance:'${aopalliance.version}'
find class-model maven-plugins/hk2-inhabitant-generator hk2-testing/hk2-junitrunner \
   -name "*.java" -exec sed -i "s/org.glassfish.hk2.external.org.objectweb.asm/org.objectweb.asm/g" {} +
%pom_change_dep :osgi-resource-locator ::%{extra_version}
%pom_remove_dep org.osgi:org.osgi.enterprise
%pom_change_dep :org.osgi.enterprise org.osgi:osgi.cmpn:6.0.0 class-model
%pom_remove_plugin :maven-download-plugin
%pom_remove_plugin :maven-site-plugin
%pom_remove_plugin :maven-eclipse-plugin
%pom_remove_plugin :maven-enforcer-plugin
%pom_remove_plugin :findbugs-maven-plugin
%pom_remove_plugin :jacoco-maven-plugin
%pom_remove_dep :jacoco-maven-plugin
%pom_remove_plugin :maven-jar-plugin osgi-resource-locator
%pom_remove_plugin :maven-source-plugin osgi-resource-locator
%pom_remove_plugin :maven-javadoc-plugin osgi-resource-locator
%pom_remove_plugin :maven-release-plugin osgi-resource-locator
%pom_remove_plugin :maven-gpg-plugin osgi-resource-locator
%pom_xpath_remove "pom:plugin[pom:artifactId ='maven-jar-plugin']/pom:executions" hk2
%pom_disable_module external
%pom_disable_module examples
%pom_disable_module osgi-adapter-test osgi/adapter-tests
%pom_remove_dep org.ops4j.pax.exam:
%pom_remove_dep org.ops4j.pax.url:
%pom_remove_dep org.ops4j.pax.logging:
%pom_disable_module jersey hk2-testing
%if %{with jp_minimal}
%pom_disable_module dependency-verifier
%pom_disable_module dependency-visualizer
%pom_disable_module osgi
%pom_disable_module guice-bridge
%pom_disable_module spring-bridge
%pom_remove_dep :osgi-adapter bom
%pom_remove_dep :guice-bridge bom
%pom_remove_dep :spring-bridge bom
%pom_disable_module hk2-xml hk2-configuration/persistence
%pom_xpath_set "pom:modules" "<module>hk2-junitrunner</module>" hk2-testing
%pom_remove_dep javax.validation:validation-api hk2-utils
%pom_remove_dep org.hibernate:hibernate-validator hk2-utils
%pom_remove_dep javax.el:javax.el-api hk2-utils
rm hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/ValidatorUtilities.java \
   hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/internal/MessageInterpolatorImpl.java \
   hk2-utils/src/test/java/org/glassfish/hk2/utilities/test/ValidatorTest.java
%endif
%pom_remove_dep org.osgi:osgi_R4_core
%pom_remove_dep :com.springsource.org.junit
%pom_remove_dep -r :jboss-logging
%pom_remove_dep -r :classmate
%pom_xpath_remove "pom:plugin[pom:artifactId ='maven-surefire-plugin']/pom:configuration" hk2-api
%pom_xpath_remove "pom:plugin[pom:artifactId ='maven-surefire-plugin']/pom:configuration" hk2-locator
%pom_xpath_set "pom:dependency[pom:groupId ='com.sun']/pom:artifactId" tools hk2-testing/ant
%pom_xpath_remove "pom:dependency[pom:groupId ='com.sun']/pom:scope" hk2-testing/ant
%pom_xpath_remove "pom:dependency[pom:groupId ='com.sun']/pom:systemPath" hk2-testing/ant
%pom_xpath_remove "pom:profiles/pom:profile[pom:id ='mac']" hk2-testing/ant
%pom_xpath_set "pom:addClasspath" false dependency-verifier
mkdir -p hk2/target/classes
rm maven-plugins/hk2-inhabitant-generator/src/main/resources/META-INF/MANIFEST.MF
%pom_add_plugin org.apache.felix:maven-bundle-plugin maven-plugins/hk2-inhabitant-generator '
<configuration>
  <supportedProjectTypes>
   <supportedProjectType>maven-plugin</supportedProjectType>
  </supportedProjectTypes>
</configuration>
<executions>
  <execution>
    <id>bundle-manifest</id>
    <phase>process-classes</phase>
    <goals>
      <goal>manifest</goal>
    </goals>
  </execution>
</executions>'
cp -p %SOURCE2 maven-plugins/hk2-inhabitant-generator/osgi.bundle
%pom_add_plugin org.glassfish.hk2:osgiversion-maven-plugin:'${project.version}' maven-plugins/hk2-inhabitant-generator
%pom_add_plugin org.apache.maven.plugins:maven-jar-plugin:2.4 maven-plugins/hk2-inhabitant-generator "
<configuration>
  <archive>
    <manifestFile>\${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
    <manifestEntries>
      <service>foo</service>
    </manifestEntries>
  </archive>
</configuration>"
%pom_xpath_remove "pom:plugin[pom:artifactId = 'maven-jar-plugin']/pom:configuration/pom:useDefaultManifestFile" . hk2-utils
%pom_xpath_inject "pom:plugin[pom:artifactId = 'maven-jar-plugin']/pom:configuration/pom:archive" \
  "<manifestFile>\${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>" hk2-utils
for mod in $(grep -l maven-bundle-plugin $(find */ -name pom.xml) ) ; do
  if [ "$(dirname $mod)" = "hk-utils" ] ; then
    continue
  fi
  %pom_add_plugin org.apache.maven.plugins:maven-jar-plugin $mod "
<configuration>
  <archive>
    <manifestFile>\${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
  </archive>
</configuration>"
done
%mvn_package ":::tests:" __noinstall
%mvn_package ":hk2-bom" %{name}
%mvn_package ":hk2-parent" %{name}
%mvn_package ":hk2" hk2
%mvn_package ":hk2-api" api
%mvn_package ":hk2-core" core
%mvn_package ":hk2-configuration" configuration
%mvn_package ":hk2-configuration-hub" configuration
%mvn_package ":hk2-configuration-integration" configuration
%mvn_package ":hk2-configuration-persistence" configuration
%mvn_package ":hk2-property-file" configuration
%mvn_package ":hk2-xml-parent" configuration
%mvn_package ":hk2-xml-schema" configuration
%mvn_package ":hk2-xml-integration-test" __noinstall
%mvn_package ":hk2-xml-test" __noinstall
%mvn_package ":hk2-json" configuration
%mvn_package ":hk2-pbuf" configuration
%mvn_package ":hk2-xml" configuration
%mvn_package ":hk2-extras" extras
%mvn_package ":hk2-jmx" jmx
%mvn_package ":hk2-locator" locator
%mvn_package ":hk2-metadata-generator" metadata-generator
%mvn_package ":hk2-metadata-generator-parent" metadata-generator
%mvn_package ":hk2-metadata-generator-test1" __noinstall
%mvn_package ":hk2-runlevel" runlevel
%mvn_package ":hk2-utils" utils
%mvn_package ":class-model" class-model
%mvn_package ":osgi-resource-locator" osgi-resource-locator
%mvn_package ":hk2-dependency-verifier" dependency-verifier
%mvn_package ":hk2-dependency-visualizer" dependency-visualizer
%mvn_package ":guice-bridge" guice-bridge
%mvn_package ":spring-bridge" spring-bridge
%mvn_package ":osgi" osgi
%mvn_package ":osgi-adapter" osgi
%mvn_package ":osgi-adapter-tests-parent" __noinstall
%mvn_package ":contract-bundle" __noinstall
%mvn_package ":faux-sdp-bundle" __noinstall
%mvn_package ":no-hk2-bundle" __noinstall
%mvn_package ":osgi-adapter-test" __noinstall
%mvn_package ":sdp-management-bundle" __noinstall
%mvn_package ":test-module-startup" __noinstall
%mvn_package ":hk2-testing" testing
%mvn_package ":hk2-ant-test" testing
%mvn_package ":hk2-collections-tests" testing
%mvn_package ":hk2-junitrunner" testing
%mvn_package ":hk2-locator-extras" testing
%mvn_package ":hk2-locator-no-proxies" testing
%mvn_package ":hk2-locator-no-proxies2" testing
%mvn_package ":hk2-mockito" testing
%mvn_package ":hk2-runlevel-extras" testing
%mvn_package ":hk2-testng" testing
%mvn_package ":interceptor-events" testing
%mvn_package ":maven-plugins" maven-plugins
%mvn_package ":consolidatedbundle-maven-plugin" maven-plugins
%mvn_package ":hk2-inhabitant-generator" maven-plugins
%mvn_package ":osgiversion-maven-plugin" maven-plugins

%build
%mvn_build -- -Dhk2.mvn.plugins.version=%{version}

%install
%mvn_install

%files -f .mfiles-%{name}
%doc README.md
%license LICENSE.md NOTICE.md

%files hk2 -f .mfiles-hk2
%license LICENSE.md NOTICE.md

%files api -f .mfiles-api
%license LICENSE.md NOTICE.md

%files core -f .mfiles-core
%license LICENSE.md NOTICE.md

%files configuration -f .mfiles-configuration
%license LICENSE.md NOTICE.md

%files extras -f .mfiles-extras
%license LICENSE.md NOTICE.md

%files jmx -f .mfiles-jmx
%license LICENSE.md NOTICE.md

%files locator -f .mfiles-locator
%license LICENSE.md NOTICE.md

%files metadata-generator -f .mfiles-metadata-generator
%license LICENSE.md NOTICE.md

%files runlevel -f .mfiles-runlevel
%license LICENSE.md NOTICE.md

%files utils -f .mfiles-utils
%license LICENSE.md NOTICE.md

%files class-model -f .mfiles-class-model
%license LICENSE.md NOTICE.md

%files osgi-resource-locator -f .mfiles-osgi-resource-locator
%license LICENSE.md NOTICE.md
%if %{without jp_minimal}

%files dependency-verifier -f .mfiles-dependency-verifier
%license LICENSE.md NOTICE.md

%files dependency-visualizer -f .mfiles-dependency-visualizer
%doc dependency-visualizer/README
%license LICENSE.md NOTICE.md

%files guice-bridge -f .mfiles-guice-bridge
%license LICENSE.md NOTICE.md

%files spring-bridge -f .mfiles-spring-bridge
%license LICENSE.md NOTICE.md

%files osgi -f .mfiles-osgi
%license LICENSE.md NOTICE.md
%endif

%files testing -f .mfiles-testing
%license LICENSE.md NOTICE.md

%files maven-plugins -f .mfiles-maven-plugins
%license LICENSE.md NOTICE.md

%files javadoc -f .mfiles-javadoc
%license LICENSE.md NOTICE.md

%changelog
* Fri Aug 28 2020 chengzihan <chengzihan2@huawei.com> - 2.5.0-1
- Package init
