Repository: karaf Updated Branches: refs/heads/master 27f895eb2 -> 6da94cb93
KARAF-4102: add parameter to set the name of the primary feature. Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6da94cb9 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6da94cb9 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6da94cb9 Branch: refs/heads/master Commit: 6da94cb937996ffef8273b5f4c7a4fd622218fae Parents: 27f895e Author: Benson Margulies <[email protected]> Authored: Mon Nov 9 10:29:32 2015 -0500 Committer: Benson Margulies <[email protected]> Committed: Mon Nov 9 10:29:32 2015 -0500 ---------------------------------------------------------------------- .../src/it/test-rename-main-feature/control.xml | 6 ++ .../src/it/test-rename-main-feature/pom.xml | 61 ++++++++++++++++++++ .../src/main/java/test/App.java | 30 ++++++++++ .../src/it/test-rename-main-feature/verify.bsh | 35 +++++++++++ .../features/GenerateDescriptorMojo.java | 20 +++++-- 5 files changed, 146 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/6da94cb9/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/control.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/control.xml b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/control.xml new file mode 100644 index 0000000..816f56d --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/control.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" name="test-rename-project-artifact"> + <feature name="test-feature" description="test-rename-project-artifact" version="1.0.0.SNAPSHOT"> + <bundle>mvn:test/test-rename-project-artifact/1.0-SNAPSHOT</bundle> + </feature> +</features> http://git-wip-us.apache.org/repos/asf/karaf/blob/6da94cb9/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/pom.xml b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/pom.xml new file mode 100644 index 0000000..afd6990 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/pom.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <!-- + + 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. + --> + + <modelVersion>4.0.0</modelVersion> + + <groupId>test</groupId> + <artifactId>test-rename-project-artifact</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>bundle</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-maven-plugin</artifactId> + <version>@pom.version@</version> + <executions> + <execution> + <id>generate-features-file</id> + <phase>package</phase> + <goals> + <goal>features-generate-descriptor</goal> + </goals> + <configuration> + <primaryFeatureName>test-feature</primaryFeatureName> + <includeProjectArtifact>true</includeProjectArtifact> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/karaf/blob/6da94cb9/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/src/main/java/test/App.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/src/main/java/test/App.java b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/src/main/java/test/App.java new file mode 100644 index 0000000..c95d245 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/src/main/java/test/App.java @@ -0,0 +1,30 @@ +/* + * 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 test; + +/** + * Hello world! + */ +public class App { + + public static void main( String[] args ) { + System.out.println( "Hello World!" ); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/6da94cb9/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/verify.bsh ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/verify.bsh new file mode 100644 index 0000000..6af1a7c --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-rename-main-feature/verify.bsh @@ -0,0 +1,35 @@ +/* + * 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. + */ + +import org.custommonkey.xmlunit.*; +import java.io.*; +import java.lang.*; + +Reader r = new FileReader(new File(basedir, "control.xml")); + +// load the features file pushed to the repository +File generated = new File(basedir, "target/feature/feature.xml" ); +if (generated.exists()) { + try { + XMLAssert.assertXMLEqual(r, new FileReader(generated)); + return true; + } catch (Throwable ignored) { } +} + +return false; http://git-wip-us.apache.org/repos/asf/karaf/blob/6da94cb9/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java index 168a639..c786e40 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java @@ -213,6 +213,15 @@ public class GenerateDescriptorMojo extends MojoSupport { @Parameter(defaultValue = "false") private boolean includeProjectArtifact; + /** + * The name of the primary feature. This is the feature that will be created or modified to include the + * main project artifact and/or the bundles. + * @see #addBundlesToPrimaryFeature + * @see #includeProjectArtifact + */ + @Parameter(defaultValue = "${project.artifactId}") + private String primaryFeatureName; + // ************************************************* // READ-ONLY MAVEN PLUGIN PARAMETERS // ************************************************* @@ -289,13 +298,13 @@ public class GenerateDescriptorMojo extends MojoSupport { Feature feature = null; for (Feature test : features.getFeature()) { - if (test.getName().equals(project.getArtifactId())) { + if (test.getName().equals(primaryFeatureName)) { feature = test; } } if (feature == null) { feature = objectFactory.createFeature(); - feature.setName(project.getArtifactId()); + feature.setName(primaryFeatureName); } if (!feature.hasVersion()) { feature.setVersion(project.getArtifact().getBaseVersion()); @@ -397,7 +406,7 @@ public class GenerateDescriptorMojo extends MojoSupport { */ private Manifest getManifest(File file) throws IOException { - InputStream is = null; + InputStream is; try { is = new BufferedInputStream(new FileInputStream(file)); } catch (Exception e) { @@ -415,9 +424,8 @@ public class GenerateDescriptorMojo extends MojoSupport { jar.close(); return m; } finally { - if (is != null) { // just in case when we did not open bundle - is.close(); - } + // just in case when we did not open bundle + is.close(); } }
