This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 57a5ada797a1c8855f79726ef3f6bf49858d95ab Author: Guillaume Nodet <[email protected]> AuthorDate: Fri Jan 17 16:01:51 2020 +0100 [CAMEL-14444] Build speed improvements: Include a copy of the bundle plugin and switch to it --- .../META-INF/maven/archetype-metadata.xml | 4 +- .../__artifactId__-component/pom.xml | 7 +- .../META-INF/maven/archetype-metadata.xml | 4 +- .../src/main/resources/archetype-resources/pom.xml | 6 +- .../META-INF/maven/archetype-metadata.xml | 4 +- .../src/main/resources/archetype-resources/pom.xml | 7 +- .../META-INF/maven/archetype-metadata.xml | 4 +- .../src/main/resources/archetype-resources/pom.xml | 7 +- catalog/camel-catalog-lucene/pom.xml | 5 +- catalog/camel-catalog-maven/pom.xml | 5 +- catalog/camel-catalog-provider-karaf/pom.xml | 5 +- components/camel-blueprint/pom.xml | 4 +- .../camel-debezium-maven-plugin/pom.xml | 4 +- components/camel-jasypt/pom.xml | 6 +- .../camel-salesforce-maven-plugin/pom.xml | 4 +- .../camel-servicenow-maven-plugin/pom.xml | 4 +- components/camel-spring/pom.xml | 4 +- components/camel-test-karaf/pom.xml | 4 +- components/pom.xml | 56 ++- core/camel-caffeine-lrucache/pom.xml | 6 +- core/camel-core-engine/pom.xml | 4 +- core/camel-core/pom.xml | 4 +- core/pom.xml | 52 ++ .../camel-example-artemis-amqp-blueprint/pom.xml | 5 +- .../pom.xml | 5 +- examples/camel-example-fhir-osgi/pom.xml | 5 +- .../camel-example-netty-http/myapp-cdi/pom.xml | 4 +- .../core-rest/pom.xml | 4 +- .../tika-detect/pom.xml | 4 +- .../tika-parse/pom.xml | 4 +- examples/camel-example-ssh-security/pom.xml | 5 +- examples/camel-example-ssh/pom.xml | 5 +- examples/camel-example-swagger-osgi/pom.xml | 5 +- .../camel-example-transformer-blueprint/pom.xml | 4 +- examples/pom.xml | 57 ++- parent/pom.xml | 73 +-- platforms/commands/commands-core/pom.xml | 5 +- platforms/karaf/commands/pom.xml | 5 +- tests/test-bundles/pom.xml | 5 +- tooling/apt/pom.xml | 1 + tooling/camel-util-json/pom.xml | 53 ++ tooling/{ => maven}/camel-bundle-plugin/pom.xml | 25 +- .../org/apache/camel/maven/bundle/CamelPlugin.java | 0 .../apache/felix/bundleplugin/ManifestPlugin.java | 548 +++++++++++++++++++++ .../felix/bundleplugin/VersionCleanerPlugin.java | 78 +++ tooling/maven/pom.xml | 19 +- tooling/meta-annotations/pom.xml | 53 ++ tooling/pom.xml | 1 - tooling/spi-annotations/pom.xml | 53 ++ 49 files changed, 1038 insertions(+), 198 deletions(-) diff --git a/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml index 954b9bd..8bded3c 100644 --- a/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml +++ b/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml @@ -36,8 +36,8 @@ <requiredProperty key="maven-resources-plugin-version"> <defaultValue>${maven-resources-plugin-version}</defaultValue> </requiredProperty> - <requiredProperty key="maven-bundle-plugin-version"> - <defaultValue>${maven-bundle-plugin-version}</defaultValue> + <requiredProperty key="camel-bundle-plugin-version"> + <defaultValue>${camel-bundle-plugin-version}</defaultValue> </requiredProperty> <requiredProperty key="maven-javadoc-plugin-version"> <defaultValue>${maven-javadoc-plugin-version}</defaultValue> diff --git a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml index 187e52d..922fe39 100644 --- a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml +++ b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml @@ -123,10 +123,9 @@ <!-- to generate the MANIFEST-FILE of the bundle --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${maven-bundle-plugin-version}</version> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> <configuration> <instructions> <Bundle-Name>Camel Component for ${componentName}</Bundle-Name> diff --git a/archetypes/camel-archetype-blueprint/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/archetypes/camel-archetype-blueprint/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml index c5884a8..e772283 100644 --- a/archetypes/camel-archetype-blueprint/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml +++ b/archetypes/camel-archetype-blueprint/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml @@ -30,8 +30,8 @@ <requiredProperty key="maven-resources-plugin-version"> <defaultValue>${maven-resources-plugin-version}</defaultValue> </requiredProperty> - <requiredProperty key="maven-bundle-plugin-version"> - <defaultValue>${maven-bundle-plugin-version}</defaultValue> + <requiredProperty key="camel-bundle-plugin-version"> + <defaultValue>${camel-bundle-plugin-version}</defaultValue> </requiredProperty> <requiredProperty key="maven-jar-plugin-version"> <defaultValue>${maven-jar-plugin-version}</defaultValue> diff --git a/archetypes/camel-archetype-blueprint/src/main/resources/archetype-resources/pom.xml b/archetypes/camel-archetype-blueprint/src/main/resources/archetype-resources/pom.xml index 25b19f9..15c785e 100644 --- a/archetypes/camel-archetype-blueprint/src/main/resources/archetype-resources/pom.xml +++ b/archetypes/camel-archetype-blueprint/src/main/resources/archetype-resources/pom.xml @@ -107,9 +107,9 @@ <!-- to generate the MANIFEST.MF of the bundle --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${maven-bundle-plugin-version}</version> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> <extensions>false</extensions> <executions> <execution> diff --git a/archetypes/camel-archetype-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/archetypes/camel-archetype-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml index 62128d9..4cdc5b5 100644 --- a/archetypes/camel-archetype-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml +++ b/archetypes/camel-archetype-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml @@ -35,8 +35,8 @@ <requiredProperty key="maven-resources-plugin-version"> <defaultValue>${maven-resources-plugin-version}</defaultValue> </requiredProperty> - <requiredProperty key="maven-bundle-plugin-version"> - <defaultValue>${maven-bundle-plugin-version}</defaultValue> + <requiredProperty key="camel-bundle-plugin-version"> + <defaultValue>${camel-bundle-plugin-version}</defaultValue> </requiredProperty> <requiredProperty key="slf4j-version"> <defaultValue>${slf4j-version}</defaultValue> diff --git a/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml b/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml index 3146ceb..515bb3c 100644 --- a/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml +++ b/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml @@ -134,10 +134,9 @@ <!-- OSGi support (remove if not using OSGi) --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${maven-bundle-plugin-version}</version> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> <configuration> <instructions> <Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName> diff --git a/archetypes/camel-archetype-dataformat/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/archetypes/camel-archetype-dataformat/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml index 83443da..ebc42a0 100644 --- a/archetypes/camel-archetype-dataformat/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml +++ b/archetypes/camel-archetype-dataformat/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml @@ -35,8 +35,8 @@ <requiredProperty key="maven-resources-plugin-version"> <defaultValue>${maven-resources-plugin-version}</defaultValue> </requiredProperty> - <requiredProperty key="maven-bundle-plugin-version"> - <defaultValue>${maven-bundle-plugin-version}</defaultValue> + <requiredProperty key="camel-bundle-plugin-version"> + <defaultValue>${camel-bundle-plugin-version}</defaultValue> </requiredProperty> <requiredProperty key="slf4j-version"> <defaultValue>${slf4j-version}</defaultValue> diff --git a/archetypes/camel-archetype-dataformat/src/main/resources/archetype-resources/pom.xml b/archetypes/camel-archetype-dataformat/src/main/resources/archetype-resources/pom.xml index 11fedc1..4341605 100644 --- a/archetypes/camel-archetype-dataformat/src/main/resources/archetype-resources/pom.xml +++ b/archetypes/camel-archetype-dataformat/src/main/resources/archetype-resources/pom.xml @@ -109,10 +109,9 @@ <!-- to generate the MANIFEST-FILE of the bundle --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${maven-bundle-plugin-version}</version> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> <configuration> <instructions> <Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName> diff --git a/catalog/camel-catalog-lucene/pom.xml b/catalog/camel-catalog-lucene/pom.xml index b2d5597..dac9ab6 100644 --- a/catalog/camel-catalog-lucene/pom.xml +++ b/catalog/camel-catalog-lucene/pom.xml @@ -88,9 +88,8 @@ <build> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> </plugin> </plugins> </build> diff --git a/catalog/camel-catalog-maven/pom.xml b/catalog/camel-catalog-maven/pom.xml index b3980aa..8fd4588 100644 --- a/catalog/camel-catalog-maven/pom.xml +++ b/catalog/camel-catalog-maven/pom.xml @@ -107,9 +107,8 @@ <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> </plugin> </plugins> diff --git a/catalog/camel-catalog-provider-karaf/pom.xml b/catalog/camel-catalog-provider-karaf/pom.xml index 680c3c9..b12bc2f 100644 --- a/catalog/camel-catalog-provider-karaf/pom.xml +++ b/catalog/camel-catalog-provider-karaf/pom.xml @@ -77,9 +77,8 @@ <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> </plugin> <!-- generate and include all components in the catalog --> diff --git a/components/camel-blueprint/pom.xml b/components/camel-blueprint/pom.xml index 55439f2..d037b4b 100644 --- a/components/camel-blueprint/pom.xml +++ b/components/camel-blueprint/pom.xml @@ -238,8 +238,8 @@ <!-- Push the execution order of the maven-bundle-plugin further to the end. That's why we add it here again. --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <executions> <execution> <id>bundle-manifest</id> diff --git a/components/camel-debezium-common/camel-debezium-maven-plugin/pom.xml b/components/camel-debezium-common/camel-debezium-maven-plugin/pom.xml index b4db846..1ded555 100644 --- a/components/camel-debezium-common/camel-debezium-maven-plugin/pom.xml +++ b/components/camel-debezium-common/camel-debezium-maven-plugin/pom.xml @@ -95,8 +95,8 @@ </configuration> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <executions> <execution> <phase>none</phase> diff --git a/components/camel-jasypt/pom.xml b/components/camel-jasypt/pom.xml index a4cabeb..78edd0e 100644 --- a/components/camel-jasypt/pom.xml +++ b/components/camel-jasypt/pom.xml @@ -99,9 +99,9 @@ <pluginExecutions> <pluginExecution> <pluginExecutionFilter> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <versionRange>${maven-bundle-plugin-version}</versionRange> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <versionRange>${camel-bundle-plugin-version}</versionRange> <goals> <goal>manifest</goal> </goals> diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/pom.xml b/components/camel-salesforce/camel-salesforce-maven-plugin/pom.xml index 0222e84..994f0d54 100644 --- a/components/camel-salesforce/camel-salesforce-maven-plugin/pom.xml +++ b/components/camel-salesforce/camel-salesforce-maven-plugin/pom.xml @@ -239,8 +239,8 @@ </configuration> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <executions> <execution> <phase>none</phase> diff --git a/components/camel-servicenow/camel-servicenow-maven-plugin/pom.xml b/components/camel-servicenow/camel-servicenow-maven-plugin/pom.xml index ac8f6f0..861aeef 100644 --- a/components/camel-servicenow/camel-servicenow-maven-plugin/pom.xml +++ b/components/camel-servicenow/camel-servicenow-maven-plugin/pom.xml @@ -187,8 +187,8 @@ </configuration> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <executions> <execution> <phase>none</phase> diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml index a061848..d0a0598 100644 --- a/components/camel-spring/pom.xml +++ b/components/camel-spring/pom.xml @@ -347,8 +347,8 @@ <!-- Push the execution order of the maven-bundle-plugin further to the end. That's why we add it here again. --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <executions> <execution> <id>bundle-manifest</id> diff --git a/components/camel-test-karaf/pom.xml b/components/camel-test-karaf/pom.xml index 7d846d0..3acd18e 100644 --- a/components/camel-test-karaf/pom.xml +++ b/components/camel-test-karaf/pom.xml @@ -165,8 +165,8 @@ </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> diff --git a/components/pom.xml b/components/pom.xml index 9f509c8..75e269c 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -364,6 +364,10 @@ <module>camel-zookeeper</module> </modules> + <properties> + <camel.osgi.manifest>${project.build.outputDirectory}/META-INF/MANIFEST.MF</camel.osgi.manifest> + </properties> + <build> <plugins> <plugin> @@ -431,10 +435,30 @@ </executions> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> + <extensions>false</extensions> <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + <noWarningProjectTypes>pom</noWarningProjectTypes> + <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> <instructions> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> + <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> + <Import-Package>${camel.osgi.import}</Import-Package> + <Export-Package>${camel.osgi.export}</Export-Package> + <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> + <Private-Package>${camel.osgi.private.pkg}</Private-Package> + <Require-Capability>${camel.osgi.require.capability}</Require-Capability> + <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> + <Implementation-Title>Apache Camel</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> + <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> + <_failok>${camel.osgi.failok}</_failok> + <_removeheaders>Bnd-LastModified</_removeheaders> <_plugin> org.apache.felix.bundleplugin.BlueprintPlugin, aQute.lib.spring.SpringXMLType, @@ -443,13 +467,27 @@ </_plugin> </instructions> </configuration> - <dependencies> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-bundle-plugin</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <executions> + <execution> + <id>versions</id> + <phase>validate</phase> + <goals> + <goal>cleanVersions</goal> + </goals> + <configuration> + <versions> + <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> + </versions> + </configuration> + </execution> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> </plugin> </plugins> </build> diff --git a/core/camel-caffeine-lrucache/pom.xml b/core/camel-caffeine-lrucache/pom.xml index 5e7eb7d..e597230 100644 --- a/core/camel-caffeine-lrucache/pom.xml +++ b/core/camel-caffeine-lrucache/pom.xml @@ -76,9 +76,9 @@ <build> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${maven-bundle-plugin-version}</version> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> <extensions>false</extensions> <configuration> <supportIncrementalBuild>true</supportIncrementalBuild> diff --git a/core/camel-core-engine/pom.xml b/core/camel-core-engine/pom.xml index b1dee2f..86cb365 100644 --- a/core/camel-core-engine/pom.xml +++ b/core/camel-core-engine/pom.xml @@ -214,8 +214,8 @@ </executions> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <_plugin> diff --git a/core/camel-core/pom.xml b/core/camel-core/pom.xml index 3f26c10..915c28f 100644 --- a/core/camel-core/pom.xml +++ b/core/camel-core/pom.xml @@ -290,8 +290,8 @@ </configuration> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <_plugin> diff --git a/core/pom.xml b/core/pom.xml index b578f43..5339610 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -53,6 +53,10 @@ <module>camel-main</module> </modules> + <properties> + <camel.osgi.manifest>${project.build.outputDirectory}/META-INF/MANIFEST.MF</camel.osgi.manifest> + </properties> + <build> <plugins> <plugin> @@ -95,6 +99,54 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> + <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + <noWarningProjectTypes>pom</noWarningProjectTypes> + <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> + <instructions> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> + <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> + <Import-Package>${camel.osgi.import}</Import-Package> + <Export-Package>${camel.osgi.export}</Export-Package> + <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> + <Private-Package>${camel.osgi.private.pkg}</Private-Package> + <Require-Capability>${camel.osgi.require.capability}</Require-Capability> + <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> + <Implementation-Title>Apache Camel</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> + <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> + <_failok>${camel.osgi.failok}</_failok> + <_removeheaders>Bnd-LastModified</_removeheaders> + </instructions> + </configuration> + <executions> + <execution> + <id>versions</id> + <phase>validate</phase> + <goals> + <goal>cleanVersions</goal> + </goals> + <configuration> + <versions> + <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> + </versions> + </configuration> + </execution> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> </project> diff --git a/examples/camel-example-artemis-amqp-blueprint/pom.xml b/examples/camel-example-artemis-amqp-blueprint/pom.xml index c03178b..556857d 100644 --- a/examples/camel-example-artemis-amqp-blueprint/pom.xml +++ b/examples/camel-example-artemis-amqp-blueprint/pom.xml @@ -124,9 +124,8 @@ <plugins> <!-- to generate the MANIFEST-FILE of the bundle --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> </plugin> <!-- to run the example using mvn camel:run --> diff --git a/examples/camel-example-cxf-ws-security-signature/pom.xml b/examples/camel-example-cxf-ws-security-signature/pom.xml index 73a2320..0b79e22 100644 --- a/examples/camel-example-cxf-ws-security-signature/pom.xml +++ b/examples/camel-example-cxf-ws-security-signature/pom.xml @@ -81,9 +81,8 @@ <defaultGoal>install</defaultGoal> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>camel-example-cxf-ws-security-signature</Bundle-SymbolicName> diff --git a/examples/camel-example-fhir-osgi/pom.xml b/examples/camel-example-fhir-osgi/pom.xml index fdfc9b2..f75fe9a 100644 --- a/examples/camel-example-fhir-osgi/pom.xml +++ b/examples/camel-example-fhir-osgi/pom.xml @@ -185,9 +185,8 @@ </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> diff --git a/examples/camel-example-netty-http/myapp-cdi/pom.xml b/examples/camel-example-netty-http/myapp-cdi/pom.xml index bde0c9f..01a77a0 100644 --- a/examples/camel-example-netty-http/myapp-cdi/pom.xml +++ b/examples/camel-example-netty-http/myapp-cdi/pom.xml @@ -59,8 +59,8 @@ <build> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> diff --git a/examples/camel-example-rest-karaf-osgi-activator/core-rest/pom.xml b/examples/camel-example-rest-karaf-osgi-activator/core-rest/pom.xml index f69ef5e..8f0467d 100644 --- a/examples/camel-example-rest-karaf-osgi-activator/core-rest/pom.xml +++ b/examples/camel-example-rest-karaf-osgi-activator/core-rest/pom.xml @@ -70,8 +70,8 @@ </executions> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <exportScr>true</exportScr> diff --git a/examples/camel-example-rest-karaf-osgi-activator/tika-detect/pom.xml b/examples/camel-example-rest-karaf-osgi-activator/tika-detect/pom.xml index a01d27d..450ee05 100644 --- a/examples/camel-example-rest-karaf-osgi-activator/tika-detect/pom.xml +++ b/examples/camel-example-rest-karaf-osgi-activator/tika-detect/pom.xml @@ -69,8 +69,8 @@ </executions> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <exportScr>true</exportScr> diff --git a/examples/camel-example-rest-karaf-osgi-activator/tika-parse/pom.xml b/examples/camel-example-rest-karaf-osgi-activator/tika-parse/pom.xml index c7eb182..163db6a 100644 --- a/examples/camel-example-rest-karaf-osgi-activator/tika-parse/pom.xml +++ b/examples/camel-example-rest-karaf-osgi-activator/tika-parse/pom.xml @@ -69,8 +69,8 @@ </executions> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <exportScr>true</exportScr> diff --git a/examples/camel-example-ssh-security/pom.xml b/examples/camel-example-ssh-security/pom.xml index 60cfd55..9026e1f 100644 --- a/examples/camel-example-ssh-security/pom.xml +++ b/examples/camel-example-ssh-security/pom.xml @@ -134,9 +134,8 @@ <plugins> <!-- to generate the MANIFEST-FILE of the bundle --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Import-Package>*</Import-Package> diff --git a/examples/camel-example-ssh/pom.xml b/examples/camel-example-ssh/pom.xml index c25fc36..6edbcf4 100644 --- a/examples/camel-example-ssh/pom.xml +++ b/examples/camel-example-ssh/pom.xml @@ -116,9 +116,8 @@ <plugins> <!-- to generate the MANIFEST-FILE of the bundle --> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Import-Package>*</Import-Package> diff --git a/examples/camel-example-swagger-osgi/pom.xml b/examples/camel-example-swagger-osgi/pom.xml index 3664419..ff8a67d 100644 --- a/examples/camel-example-swagger-osgi/pom.xml +++ b/examples/camel-example-swagger-osgi/pom.xml @@ -70,9 +70,8 @@ <build> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> diff --git a/examples/camel-example-transformer-blueprint/pom.xml b/examples/camel-example-transformer-blueprint/pom.xml index 3f07b9e..bb053a2 100644 --- a/examples/camel-example-transformer-blueprint/pom.xml +++ b/examples/camel-example-transformer-blueprint/pom.xml @@ -106,8 +106,8 @@ </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> diff --git a/examples/pom.xml b/examples/pom.xml index 21aab07..03ec899 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -126,7 +126,8 @@ <camel.osgi.symbolic.name>${project.artifactId}</camel.osgi.symbolic.name> <skip.starting.camel.context>false</skip.starting.camel.context> <javax.servlet.api.version>4.0.1</javax.servlet.api.version> - <camel.osgi.export.pkg /> + <camel.osgi.export.pkg/> + <camel.osgi.manifest>${project.build.outputDirectory}/META-INF/MANIFEST.MF</camel.osgi.manifest> </properties> <dependencyManagement> @@ -197,6 +198,56 @@ </systemPropertyVariables> </configuration> </plugin> + + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> + <extensions>false</extensions> + <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + <noWarningProjectTypes>pom</noWarningProjectTypes> + <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> + <instructions> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> + <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> + <Import-Package>${camel.osgi.import}</Import-Package> + <Export-Package>${camel.osgi.export}</Export-Package> + <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> + <Private-Package>${camel.osgi.private.pkg}</Private-Package> + <Require-Capability>${camel.osgi.require.capability}</Require-Capability> + <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> + <Implementation-Title>Apache Camel</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> + <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> + <_failok>${camel.osgi.failok}</_failok> + <_removeheaders>Bnd-LastModified</_removeheaders> + </instructions> + </configuration> + <executions> + <execution> + <id>versions</id> + <phase>validate</phase> + <goals> + <goal>cleanVersions</goal> + </goals> + <configuration> + <versions> + <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> + </versions> + </configuration> + </execution> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> <pluginManagement> <plugins> @@ -210,8 +261,8 @@ <pluginExecutions> <pluginExecution> <pluginExecutionFilter> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <versionRange>[2.3.7,)</versionRange> <goals> <goal>cleanVersions</goal> diff --git a/parent/pom.xml b/parent/pom.xml index a0abba1..320dc37 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -34,10 +34,11 @@ <properties> <compiler.fork>true</compiler.fork> + <camel-bundle-plugin-version>${project.version}</camel-bundle-plugin-version> <cxf.codegenplugin.forkmode>once</cxf.codegenplugin.forkmode> - <cxf.codegen.jvmArgs /> - <camel.surefire.fork.vmargs /> - <cxf.xjc.jvmArgs /> + <cxf.codegen.jvmArgs/> + <camel.surefire.fork.vmargs/> + <cxf.xjc.jvmArgs/> <!-- dependency versions --> <abdera-version>1.1.3</abdera-version> <!-- Note that activemq dependency is only used for testing! --> @@ -671,7 +672,7 @@ <xpp3-version>1.1.4c</xpp3-version> <xstream-bundle-version>1.4.11.1_1</xstream-bundle-version> <xstream-version>1.4.11.1</xstream-version> - <yetus-audience-annotations-version>0.11.0</yetus-audience-annotations-version> + <yetus-audience-annotations-version>0.11.0</yetus-audience-annotations-version> <zendesk-client-version>0.6.2</zendesk-client-version> <zipkin-reporter-version>2.12.1</zipkin-reporter-version> <zipkin-version>2.19.3</zipkin-version> @@ -4206,21 +4207,6 @@ <pluginExecutions> <pluginExecution> <pluginExecutionFilter> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <versionRange>${maven-bundle-plugin-version}</versionRange> - <goals> - <goal>cleanVersions</goal> - <goal>package</goal> - <goal>manifest</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore /> - </action> - </pluginExecution> - <pluginExecution> - <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> <versionRange>${maven-remote-resources-plugin-version}</versionRange> @@ -4301,55 +4287,6 @@ </excludes> </configuration> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${maven-bundle-plugin-version}</version> - <extensions>false</extensions> - <configuration> - <supportIncrementalBuild>true</supportIncrementalBuild> - <noWarningProjectTypes>pom</noWarningProjectTypes> - <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> - <instructions> - <Bundle-Name>${project.artifactId}</Bundle-Name> - <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> - <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> - <Import-Package>${camel.osgi.import}</Import-Package> - <Export-Package>${camel.osgi.export}</Export-Package> - <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> - <Private-Package>${camel.osgi.private.pkg}</Private-Package> - <Require-Capability>${camel.osgi.require.capability}</Require-Capability> - <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> - <Implementation-Title>Apache Camel</Implementation-Title> - <Implementation-Version>${project.version}</Implementation-Version> - <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> - <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> - <_failok>${camel.osgi.failok}</_failok> - <_removeheaders>Bnd-LastModified</_removeheaders> - </instructions> - </configuration> - <executions> - <execution> - <id>versions</id> - <phase>validate</phase> - <goals> - <goal>cleanVersions</goal> - </goals> - <configuration> - <versions> - <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> - </versions> - </configuration> - </execution> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> - </plugin> </plugins> </build> diff --git a/platforms/commands/commands-core/pom.xml b/platforms/commands/commands-core/pom.xml index f51400c..2a4f983 100644 --- a/platforms/commands/commands-core/pom.xml +++ b/platforms/commands/commands-core/pom.xml @@ -83,9 +83,8 @@ <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Private-Package> diff --git a/platforms/karaf/commands/pom.xml b/platforms/karaf/commands/pom.xml index b82c072..41c1a0d 100644 --- a/platforms/karaf/commands/pom.xml +++ b/platforms/karaf/commands/pom.xml @@ -77,9 +77,8 @@ <build> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Import-Package> diff --git a/tests/test-bundles/pom.xml b/tests/test-bundles/pom.xml index ebd213a..a6c8b85 100644 --- a/tests/test-bundles/pom.xml +++ b/tests/test-bundles/pom.xml @@ -87,9 +87,8 @@ <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> diff --git a/tooling/apt/pom.xml b/tooling/apt/pom.xml index 2a81ce2..2a22b1e 100644 --- a/tooling/apt/pom.xml +++ b/tooling/apt/pom.xml @@ -32,6 +32,7 @@ <description>Processes Camel endpoint source code</description> <properties> + <camel.osgi.manifest></camel.osgi.manifest> <camel.osgi.import.pkg> * </camel.osgi.import.pkg> diff --git a/tooling/camel-util-json/pom.xml b/tooling/camel-util-json/pom.xml index 95261c8..1a55008 100644 --- a/tooling/camel-util-json/pom.xml +++ b/tooling/camel-util-json/pom.xml @@ -48,4 +48,57 @@ <scope>test</scope> </dependency> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> + <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + <noWarningProjectTypes>pom</noWarningProjectTypes> + <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> + <instructions> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> + <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> + <Import-Package>${camel.osgi.import}</Import-Package> + <Export-Package>${camel.osgi.export}</Export-Package> + <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> + <Private-Package>${camel.osgi.private.pkg}</Private-Package> + <Require-Capability>${camel.osgi.require.capability}</Require-Capability> + <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> + <Implementation-Title>Apache Camel</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> + <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> + <_failok>${camel.osgi.failok}</_failok> + <_removeheaders>Bnd-LastModified</_removeheaders> + </instructions> + </configuration> + <executions> + <execution> + <id>versions</id> + <phase>validate</phase> + <goals> + <goal>cleanVersions</goal> + </goals> + <configuration> + <versions> + <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> + </versions> + </configuration> + </execution> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/tooling/camel-bundle-plugin/pom.xml b/tooling/maven/camel-bundle-plugin/pom.xml similarity index 74% rename from tooling/camel-bundle-plugin/pom.xml rename to tooling/maven/camel-bundle-plugin/pom.xml index 64b6d57..d7651bc 100644 --- a/tooling/camel-bundle-plugin/pom.xml +++ b/tooling/maven/camel-bundle-plugin/pom.xml @@ -22,28 +22,33 @@ <parent> <groupId>org.apache.camel</groupId> - <artifactId>tooling</artifactId> + <artifactId>maven-plugins</artifactId> <version>3.1.0-SNAPSHOT</version> </parent> <artifactId>camel-bundle-plugin</artifactId> + <packaging>maven-plugin</packaging> - <name>Camel :: Maven Plugins :: Camel Bundle Plugin</name> - <description>Camel maven-bundle-plugin (OSGi)</description> - - <properties> - <camel.osgi.import.pkg> - * - </camel.osgi.import.pkg> - </properties> + <name>Camel :: Maven Plugins :: Enhanced bundle plugin</name> + <description>Bundle plugin detecting stale input</description> <dependencies> - <dependency> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>${maven-bundle-plugin-version}</version> </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>3.4</version> + <scope>provided</scope> + </dependency> </dependencies> + + <build> + <plugins> + </plugins> + </build> </project> diff --git a/tooling/camel-bundle-plugin/src/main/java/org/apache/camel/maven/bundle/CamelPlugin.java b/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/camel/maven/bundle/CamelPlugin.java similarity index 100% rename from tooling/camel-bundle-plugin/src/main/java/org/apache/camel/maven/bundle/CamelPlugin.java rename to tooling/maven/camel-bundle-plugin/src/main/java/org/apache/camel/maven/bundle/CamelPlugin.java diff --git a/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java b/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java new file mode 100644 index 0000000..8c27fd4 --- /dev/null +++ b/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java @@ -0,0 +1,548 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.bundleplugin; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOError; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; +import java.util.jar.Manifest; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipFile; + +import aQute.bnd.osgi.Analyzer; +import aQute.bnd.osgi.Builder; +import aQute.bnd.osgi.Instructions; +import aQute.bnd.osgi.Jar; +import aQute.bnd.osgi.Resource; +import aQute.lib.collections.ExtList; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.Scanner; +import org.osgi.service.metatype.MetaTypeService; +import org.sonatype.plexus.build.incremental.BuildContext; + + +/** + * Generate an OSGi manifest for this project + */ +@Mojo( name = "manifest", requiresDependencyResolution = ResolutionScope.TEST, + threadSafe = true, + defaultPhase = LifecyclePhase.PROCESS_CLASSES) +public class ManifestPlugin extends BundlePlugin +{ + /** + * When true, generate the manifest by rebuilding the full bundle in memory + */ + @Parameter( property = "rebuildBundle" ) + protected boolean rebuildBundle; + + /** + * When true, manifest generation on incremental builds is supported in IDEs like Eclipse. + * Please note that the underlying BND library does not support incremental build, which means + * always the whole manifest and SCR metadata is generated. + */ + @Parameter( property = "supportIncrementalBuild" ) + private boolean supportIncrementalBuild; + + @Component + private BuildContext buildContext; + + @Override + protected void execute(Map<String, String> instructions, ClassPathItem[] classpath ) + throws MojoExecutionException + { + + if (supportIncrementalBuild && isUpToDate(project)) { + return; + } + // in incremental build execute manifest generation only when explicitly activated + // and when any java file was touched since last build + if (buildContext.isIncremental() && !(supportIncrementalBuild && anyJavaSourceFileTouchedSinceLastBuild())) { + getLog().debug("Skipping manifest generation because no java source file was added, updated or removed since last build."); + return; + } + + Analyzer analyzer; + try + { + analyzer = getAnalyzer(project, instructions, classpath); + + if (supportIncrementalBuild) { + writeIncrementalInfo(project); + } + } + catch ( FileNotFoundException e ) + { + throw new MojoExecutionException( "Cannot find " + e.getMessage() + + " (manifest goal must be run after compile phase)", e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error trying to generate Manifest", e ); + } + catch ( MojoFailureException e ) + { + getLog().error( e.getLocalizedMessage() ); + throw new MojoExecutionException( "Error(s) found in manifest configuration", e ); + } + catch ( Exception e ) + { + getLog().error( "An internal error occurred", e ); + throw new MojoExecutionException( "Internal error in maven-bundle-plugin", e ); + } + + File outputFile = new File( manifestLocation, "MANIFEST.MF" ); + + try + { + writeManifest( analyzer, outputFile, niceManifest, exportScr, scrLocation, buildContext, getLog() ); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Error trying to write Manifest to file " + outputFile, e ); + } + finally + { + try + { + analyzer.close(); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error trying to write Manifest to file " + outputFile, e ); + } + } + } + + /** + * Checks if any *.java file was added, updated or removed since last build in any source directory. + */ + private boolean anyJavaSourceFileTouchedSinceLastBuild() { + @SuppressWarnings("unchecked") + List<String> sourceDirectories = project.getCompileSourceRoots(); + for (String sourceDirectory : sourceDirectories) { + File directory = new File(sourceDirectory); + Scanner scanner = buildContext.newScanner(directory); + Scanner deleteScanner = buildContext.newDeleteScanner(directory); + if (containsJavaFile(scanner) || containsJavaFile(deleteScanner)) { + return true; + } + } + return false; + } + private boolean containsJavaFile(Scanner scanner) { + String[] includes = new String[] { "**/*.java" }; + scanner.setIncludes(includes); + scanner.scan(); + return scanner.getIncludedFiles().length > 0; + } + + public Manifest getManifest(MavenProject project, ClassPathItem[] classpath ) throws IOException, MojoFailureException, + MojoExecutionException, Exception + { + return getManifest( project, new LinkedHashMap<String, String>(), classpath, buildContext ); + } + + + public Manifest getManifest(MavenProject project, Map<String, String> instructions, ClassPathItem[] classpath, + BuildContext buildContext ) throws IOException, MojoFailureException, MojoExecutionException, Exception + { + Analyzer analyzer = getAnalyzer(project, instructions, classpath); + + Jar jar = analyzer.getJar(); + Manifest manifest = jar.getManifest(); + + if (exportScr) + { + exportScr(analyzer, jar, scrLocation, buildContext, getLog() ); + } + + // cleanup... + analyzer.close(); + + return manifest; + } + + private static void exportScr(Analyzer analyzer, Jar jar, File scrLocation, BuildContext buildContext, Log log ) throws Exception { + log.debug("Export SCR metadata to: " + scrLocation.getPath()); + scrLocation.mkdirs(); + + // export SCR metadata files from OSGI-INF/ + Map<String, Resource> scrDir = jar.getDirectories().get("OSGI-INF"); + if (scrDir != null) { + for (Map.Entry<String, Resource> entry : scrDir.entrySet()) { + String path = entry.getKey(); + Resource resource = entry.getValue(); + writeSCR(resource, new File(scrLocation, path), buildContext, + log); + } + } + + // export metatype files from OSGI-INF/metatype + Map<String,Resource> metatypeDir = jar.getDirectories().get(MetaTypeService.METATYPE_DOCUMENTS_LOCATION); + if (metatypeDir != null) { + for (Map.Entry<String, Resource> entry : metatypeDir.entrySet()) + { + String path = entry.getKey(); + Resource resource = entry.getValue(); + writeSCR(resource, new File(scrLocation, path), buildContext, log); + } + } + + } + + private static void writeSCR(Resource resource, File destination, BuildContext buildContext, Log log ) throws Exception + { + log.debug("Write SCR file: " + destination.getPath()); + destination.getParentFile().mkdirs(); + OutputStream os = buildContext.newFileOutputStream(destination); + try + { + resource.write(os); + } + finally + { + os.close(); + } + } + + protected Analyzer getAnalyzer( MavenProject project, ClassPathItem[] classpath ) throws IOException, MojoExecutionException, + Exception + { + return getAnalyzer( project, new LinkedHashMap<>(), classpath ); + } + + + protected Analyzer getAnalyzer(MavenProject project, Map<String, String> instructions, ClassPathItem[] classpath ) + throws IOException, MojoExecutionException, Exception + { + if ( rebuildBundle && supportedProjectTypes.contains( project.getArtifact().getType() ) ) + { + return buildOSGiBundle( project, instructions, classpath ); + } + + File file = getOutputDirectory(); + if ( file == null ) + { + file = project.getArtifact().getFile(); + } + + if ( !file.exists() ) + { + if ( file.equals( getOutputDirectory() ) ) + { + file.mkdirs(); + } + else + { + throw new FileNotFoundException( file.getPath() ); + } + } + + Builder analyzer = getOSGiBuilder( project, instructions, classpath ); + + analyzer.setJar( file ); + + // calculateExportsFromContents when we have no explicit instructions defining + // the contents of the bundle *and* we are not analyzing the output directory, + // otherwise fall-back to addMavenInstructions approach + + boolean isOutputDirectory = file.equals( getOutputDirectory() ); + + if ( analyzer.getProperty( Analyzer.EXPORT_PACKAGE ) == null + && analyzer.getProperty( Analyzer.EXPORT_CONTENTS ) == null + && analyzer.getProperty( Analyzer.PRIVATE_PACKAGE ) == null && !isOutputDirectory ) + { + String export = calculateExportsFromContents( analyzer.getJar() ); + analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export ); + } + + addMavenInstructions( project, analyzer ); + + // if we spot Embed-Dependency and the bundle is "target/classes", assume we need to rebuild + if ( analyzer.getProperty( DependencyEmbedder.EMBED_DEPENDENCY ) != null && isOutputDirectory ) + { + analyzer.build(); + } + else + { + analyzer.mergeManifest( analyzer.getJar().getManifest() ); + analyzer.getJar().setManifest( analyzer.calcManifest() ); + } + + mergeMavenManifest( project, analyzer ); + + boolean hasErrors = reportErrors( "Manifest " + project.getArtifact(), analyzer ); + if ( hasErrors ) + { + String failok = analyzer.getProperty( "-failok" ); + if ( null == failok || "false".equalsIgnoreCase( failok ) ) + { + throw new MojoFailureException( "Error(s) found in manifest configuration" ); + } + } + + Jar jar = analyzer.getJar(); + + if ( unpackBundle ) + { + File outputFile = getOutputDirectory(); + for ( Entry<String, Resource> entry : jar.getResources().entrySet() ) + { + File entryFile = new File( outputFile, entry.getKey() ); + if ( !entryFile.exists() || entry.getValue().lastModified() == 0 ) + { + entryFile.getParentFile().mkdirs(); + OutputStream os = buildContext.newFileOutputStream( entryFile ); + entry.getValue().write( os ); + os.close(); + } + } + } + + return analyzer; + } + + private void writeIncrementalInfo(MavenProject project) throws MojoExecutionException { + try { + Path cacheData = getIncrementalDataPath(project); + String curdata = getIncrementalData(); + Files.createDirectories(cacheData.getParent()); + try (Writer w = Files.newBufferedWriter(cacheData)) { + w.append(curdata); + } + } catch (IOException e) { + throw new MojoExecutionException("Error checking manifest uptodate status", e); + } + } + + private boolean isUpToDate(MavenProject project) throws MojoExecutionException { + try { + Path cacheData = getIncrementalDataPath(project); + String prvdata; + if (Files.isRegularFile(cacheData)) { + prvdata = new String(Files.readAllBytes(cacheData), StandardCharsets.UTF_8); + } else { + prvdata = null; + } + String curdata = getIncrementalData(); + if (curdata.equals(prvdata)) { + long lastmod = Files.getLastModifiedTime(cacheData).toMillis(); + Set<String> stale = Stream.concat(Stream.of(new File(project.getBuild().getOutputDirectory())), + project.getArtifacts().stream().map(Artifact::getFile)) + .flatMap(f -> newer(lastmod, f)) + .collect(Collectors.toSet()); + if (!stale.isEmpty()) { + getLog().info("Stale files detected, re-generating manifest."); + if (getLog().isDebugEnabled()) { + getLog().debug("Stale files: " + stale.stream() + .collect(Collectors.joining(", "))); + } + } else { + // everything is in order, skip + getLog().info("Skipping manifest generation, everything is up to date."); + return true; + } + } else { + if (prvdata == null) { + getLog().info("No previous run data found, generating manifest."); + } else { + getLog().info("Configuration changed, re-generating manifest."); + } + } + } catch (IOException e) { + throw new MojoExecutionException("Error checking manifest uptodate status", e); + } + return false; + } + + private String getIncrementalData() { + return getInstructions().entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()) + .collect(Collectors.joining("\n", "", "\n")); + } + + private Path getIncrementalDataPath(MavenProject project) { + return Paths.get(project.getBuild().getDirectory(), "maven-bundle-plugin", + "org.apache.felix_maven-bundle-plugin_manifest_xx"); + } + + private long lastmod(Path p) { + try { + return Files.getLastModifiedTime(p).toMillis(); + } catch (IOException e) { + return 0; + } + } + + private Stream<String> newer(long lastmod, File file) { + try { + if (file.isDirectory()) { + return Files.walk(file.toPath()) + .filter(Files::isRegularFile) + .filter(p -> lastmod(p) > lastmod) + .map(Path::toString); + } else if (file.isFile()) { + if (lastmod(file.toPath()) > lastmod) { + if (file.getName().endsWith(".jar")) { + try (ZipFile zf = new ZipFile(file)) { + return zf.stream() + .filter(ze -> !ze.isDirectory()) + .filter(ze -> ze.getLastModifiedTime().toMillis() > lastmod) + .map(ze -> file.toString() + "!" + ze.getName()) + .collect(Collectors.toList()) + .stream(); + } + } else { + return Stream.of(file.toString()); + } + } else { + return Stream.empty(); + } + } else { + return Stream.empty(); + } + } catch (IOException e) { + throw new IOError(e); + } + } + + + public static void writeManifest(Analyzer analyzer, File outputFile, boolean niceManifest, + boolean exportScr, File scrLocation, BuildContext buildContext, Log log ) throws Exception + { + Properties properties = analyzer.getProperties(); + Jar jar = analyzer.getJar(); + Manifest manifest = jar.getManifest(); + if ( outputFile.exists() && properties.containsKey( "Merge-Headers" ) ) + { + Manifest analyzerManifest = manifest; + manifest = new Manifest(); + InputStream inputStream = new FileInputStream( outputFile ); + try + { + manifest.read( inputStream ); + } + finally + { + inputStream.close(); + } + Instructions instructions = new Instructions( ExtList.from( analyzer.getProperty("Merge-Headers") ) ); + mergeManifest( instructions, manifest, analyzerManifest ); + } + else + { + File parentFile = outputFile.getParentFile(); + parentFile.mkdirs(); + } + writeManifest( manifest, outputFile, niceManifest, buildContext, log ); + + if (exportScr) + { + exportScr(analyzer, jar, scrLocation, buildContext, log); + } + } + + + public static void writeManifest(Manifest manifest, File outputFile, boolean niceManifest, + BuildContext buildContext, Log log ) throws IOException + { + log.debug("Write manifest to " + outputFile.getPath()); + outputFile.getParentFile().mkdirs(); + + OutputStream os = buildContext.newFileOutputStream( outputFile ); + try + { + ManifestWriter.outputManifest( manifest, os, niceManifest ); + } + finally + { + try + { + os.close(); + } + catch ( IOException e ) + { + // nothing we can do here + } + } + } + + + /* + * Patched version of bnd's Analyzer.calculateExportsFromContents + */ + public static String calculateExportsFromContents(Jar bundle ) + { + String ddel = ""; + StringBuffer sb = new StringBuffer(); + Map<String, Map<String, Resource>> map = bundle.getDirectories(); + for (Iterator<Entry<String, Map<String, Resource>>> i = map.entrySet().iterator(); i.hasNext(); ) + { + //---------------------------------------------------- + // should also ignore directories with no resources + //---------------------------------------------------- + Entry<String, Map<String, Resource>> entry = i.next(); + if ( entry.getValue() == null || entry.getValue().isEmpty() ) + continue; + //---------------------------------------------------- + String directory = entry.getKey(); + if ( directory.equals( "META-INF" ) || directory.startsWith( "META-INF/" ) ) + continue; + if ( directory.equals( "OSGI-OPT" ) || directory.startsWith( "OSGI-OPT/" ) ) + continue; + if ( directory.equals( "/" ) ) + continue; + + if ( directory.endsWith( "/" ) ) + directory = directory.substring( 0, directory.length() - 1 ); + + directory = directory.replace( '/', '.' ); + sb.append( ddel ); + sb.append( directory ); + ddel = ","; + } + return sb.toString(); + } +} diff --git a/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/VersionCleanerPlugin.java b/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/VersionCleanerPlugin.java new file mode 100644 index 0000000..021acef --- /dev/null +++ b/tooling/maven/camel-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/VersionCleanerPlugin.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.bundleplugin; + + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter; +import org.apache.maven.shared.osgi.Maven2OsgiConverter; + + +/** + * Clean OSGi versions, ie convert a group of versions to OSGi format. + */ +@Mojo( name = "cleanVersions", threadSafe = true ) +public class VersionCleanerPlugin extends AbstractMojo +{ + + /** + * The BND instructions for the bundle. + */ + @Parameter + private Map<String, String> versions = new LinkedHashMap<String, String>(); + + /** + * The Maven project. + */ + @Parameter( defaultValue = "${project}", readonly = true, required = true ) + private MavenProject project; + + private Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter(); + + + public Maven2OsgiConverter getMaven2OsgiConverter() + { + return maven2OsgiConverter; + } + + + public void setMaven2OsgiConverter( Maven2OsgiConverter maven2OsgiConverter ) + { + this.maven2OsgiConverter = maven2OsgiConverter; + } + + + public void execute() throws MojoExecutionException, MojoFailureException + { + for ( String name : versions.keySet() ) + { + String version = versions.get( name ); + String osgi = maven2OsgiConverter.getVersion( version ); + project.getProperties().put( name, osgi ); + } + } +} diff --git a/tooling/maven/pom.xml b/tooling/maven/pom.xml index a8b588d..e11d43d 100644 --- a/tooling/maven/pom.xml +++ b/tooling/maven/pom.xml @@ -33,6 +33,7 @@ <description>Camel Maven Plugins</description> <modules> + <module>camel-bundle-plugin</module> <module>camel-main-parser</module> <module>camel-main-package-maven-plugin</module> <module>camel-package-maven-plugin</module> @@ -67,26 +68,12 @@ </archive> </configuration> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>none</phase> - </execution> - <execution> - <id>versions</id> - <phase>none</phase> - </execution> - </executions> - </plugin> </plugins> </pluginManagement> <plugins> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> <executions> <execution> <id>bundle-manifest</id> diff --git a/tooling/meta-annotations/pom.xml b/tooling/meta-annotations/pom.xml index 3b53bf0..18ca082 100644 --- a/tooling/meta-annotations/pom.xml +++ b/tooling/meta-annotations/pom.xml @@ -43,4 +43,57 @@ <dependencies> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> + <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + <noWarningProjectTypes>pom</noWarningProjectTypes> + <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> + <instructions> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> + <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> + <Import-Package>${camel.osgi.import}</Import-Package> + <Export-Package>${camel.osgi.export}</Export-Package> + <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> + <Private-Package>${camel.osgi.private.pkg}</Private-Package> + <Require-Capability>${camel.osgi.require.capability}</Require-Capability> + <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> + <Implementation-Title>Apache Camel</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> + <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> + <_failok>${camel.osgi.failok}</_failok> + <_removeheaders>Bnd-LastModified</_removeheaders> + </instructions> + </configuration> + <executions> + <execution> + <id>versions</id> + <phase>validate</phase> + <goals> + <goal>cleanVersions</goal> + </goals> + <configuration> + <versions> + <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> + </versions> + </configuration> + </execution> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/tooling/pom.xml b/tooling/pom.xml index d1d0f9c..8299e5bc 100644 --- a/tooling/pom.xml +++ b/tooling/pom.xml @@ -40,7 +40,6 @@ <module>apt</module> <module>camel-util-json</module> <module>camel-tooling-util</module> - <module>camel-bundle-plugin</module> <module>swagger-rest-dsl-generator</module> <module>openapi-rest-dsl-generator</module> <module>maven</module> diff --git a/tooling/spi-annotations/pom.xml b/tooling/spi-annotations/pom.xml index bf6c447..eb3a399 100644 --- a/tooling/spi-annotations/pom.xml +++ b/tooling/spi-annotations/pom.xml @@ -44,4 +44,57 @@ <dependencies> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${camel-bundle-plugin-version}</version> + <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + <noWarningProjectTypes>pom</noWarningProjectTypes> + <excludeDependencies>${camel.osgi.exclude.dependencies}</excludeDependencies> + <instructions> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${camel.osgi.symbolic.name}</Bundle-SymbolicName> + <Bundle-Activator>${camel.osgi.activator}</Bundle-Activator> + <Import-Package>${camel.osgi.import}</Import-Package> + <Export-Package>${camel.osgi.export}</Export-Package> + <DynamicImport-Package>${camel.osgi.dynamic}</DynamicImport-Package> + <Private-Package>${camel.osgi.private.pkg}</Private-Package> + <Require-Capability>${camel.osgi.require.capability}</Require-Capability> + <Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability> + <Implementation-Title>Apache Camel</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info> + <_versionpolicy>${camel.osgi.import.default.version}</_versionpolicy> + <_failok>${camel.osgi.failok}</_failok> + <_removeheaders>Bnd-LastModified</_removeheaders> + </instructions> + </configuration> + <executions> + <execution> + <id>versions</id> + <phase>validate</phase> + <goals> + <goal>cleanVersions</goal> + </goals> + <configuration> + <versions> + <camel.osgi.version.clean>${project.version}</camel.osgi.version.clean> + </versions> + </configuration> + </execution> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project>
