From 6d2f528c83b00c4b244b674824f1916991ec7b3f Mon Sep 17 00:00:00 2001 From: Markus Alexander Kuppe Date: Wed, 26 Mar 2014 10:05:45 +0100 Subject: [PATCH] [ARIES-1165] esa-maven-bundle without packaging type "esa" https://issues.apache.org/jira/browse/ARIES-1165 --- .../org/apache/aries/plugin/esa/EsaMojo.java | 16 ++++++- .../apache/aries/plugin/esa/EsaMojoTest.java | 18 +++++++- .../esa/stubs/EsaMavenProjectStub7.java | 43 +++++++++++++++++++ .../plugin-config.xml | 40 +++++++++++++++++ .../target/maven-esa-test-1.0-SNAPSHOT.jar | 1 + 5 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub7.java create mode 100644 esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/plugin-config.xml create mode 100644 esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar diff --git a/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java b/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java index 4ed8232a38..435fddc1c3 100644 --- a/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java +++ b/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java @@ -21,7 +21,6 @@ import org.apache.maven.archiver.PomPropertiesUtil; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; @@ -212,7 +211,7 @@ private void addDependenciesToArchive() throws MojoExecutionException { Set artifacts = null; switch (EsaContent.valueOf(archiveContent)) { case none: - getLog().info("archiveContent=none: subsystem arvhive will not contain any bundles."); + getLog().info("archiveContent=none: subsystem archive will not contain any bundles."); break; case content: // only include the direct dependencies in the archive @@ -227,15 +226,28 @@ private void addDependenciesToArchive() throws MojoExecutionException { } if (artifacts != null) { + // Explicitly add self to bundle set (used when pom packaging + // type != "esa" AND a file is present (no point to add to + // zip archive without file) + final Artifact selfArtifact = project.getArtifact(); + if (!"esa".equals(selfArtifact.getType()) && selfArtifact.getFile() != null) { + getLog().info("Explicitly adding artifact[" + selfArtifact.getGroupId() + ", " + selfArtifact.getId() + ", " + + selfArtifact.getScope() + "]"); + artifacts.add(project.getArtifact()); + } + artifacts = selectArtifacts(artifacts); + int cnt = 0; for (Artifact artifact : artifacts) { if (!artifact.isOptional() /*&& filter.include(artifact)*/) { getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]"); zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType())); + cnt++; } } + getLog().info(String.format("Added %s artifacts to subsystem subsystem archive.", cnt)); } } catch ( ArchiverException e ) diff --git a/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java b/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java index fb3a92e456..6ca9b1dfef 100644 --- a/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java +++ b/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java @@ -50,10 +50,22 @@ public void testEsaTestEnvironment() } public void testBasicEsa() + throws Exception + { + testBasicEsa( "target/test-classes/unit/basic-esa-test/plugin-config.xml", null ); + } + + public void testBasicEsaPgkType() + throws Exception + { + testBasicEsa( "target/test-classes/unit/basic-esa-test-with-pgk-type/plugin-config.xml", "maven-esa-test-1.0-SNAPSHOT.jar" ); + } + + private void testBasicEsa(String path, String extraExpectedFiles) throws Exception { File testPom = new File( getBasedir(), - "target/test-classes/unit/basic-esa-test/plugin-config.xml" ); + path ); EsaMojo mojo = ( EsaMojo ) lookupMojo( "esa", testPom ); @@ -83,6 +95,10 @@ public void testBasicEsa() expectedFiles.add( "META-INF/" ); expectedFiles.add( "maven-artifact01-1.0-SNAPSHOT.jar" ); expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" ); + if (extraExpectedFiles != null) + { + expectedFiles.add( extraExpectedFiles ); + } ZipFile esa = new ZipFile( esaFile ); diff --git a/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub7.java b/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub7.java new file mode 100644 index 0000000000..ff9f45867f --- /dev/null +++ b/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub7.java @@ -0,0 +1,43 @@ +package org.apache.aries.plugin.esa.stubs; + +/* + * 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 java.io.File; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +public class EsaMavenProjectStub7 + extends EsaMavenProjectStub +{ + public File getFile() + { + return new File( getBasedir(), "src/test/resources/unit/basic-esa-test-with-pgk-type/plugin-config.xml" ); + } + + @Override + public Artifact getArtifact() + { + ArtifactStub artfct = (ArtifactStub) super.getArtifact(); + artfct.setFile( new File( getBasedir(), "src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar" ) ); + artfct.setType( "jar" ); + return artfct; + } +} diff --git a/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/plugin-config.xml b/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/plugin-config.xml new file mode 100644 index 0000000000..21316bf532 --- /dev/null +++ b/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/plugin-config.xml @@ -0,0 +1,40 @@ + + + + + + + esa-maven-plugin + + ${basedir}/src/test/resources/unit/basic-esa-test-with-pgk-type/src/main/esa + ${basedir}/src/test/resources/unit/basic-esa-test-with-pgk-type/src/main/esa/OSGI-INF/SUBSYSTEM.MF + true + true + ${basedir}/src/main/esa/META-INF/MANIFEST.MF + ${basedir}/target/unit/basic-esa-test-with-pgk-type/target/esa-test + ${basedir}/target/unit/basic-esa-test-with-pgk-type/target/maven-shared-archive-resources + ${basedir}/target/unit/basic-esa-test-with-pgk-type/target + test-esa + + + + + + diff --git a/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar b/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000..6f5f2f8125 --- /dev/null +++ b/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar @@ -0,0 +1 @@ +This is not an actual jar \ No newline at end of file