Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 84C08200C2B for ; Thu, 2 Mar 2017 17:31:02 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 833CE160B6F; Thu, 2 Mar 2017 16:31:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5544A160B6A for ; Thu, 2 Mar 2017 17:31:01 +0100 (CET) Received: (qmail 92266 invoked by uid 500); 2 Mar 2017 16:31:00 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 92255 invoked by uid 99); 2 Mar 2017 16:31:00 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Mar 2017 16:31:00 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id E00413A0158 for ; Thu, 2 Mar 2017 16:30:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1785159 - in /aries/trunk/esa-maven-plugin/src: main/java/org/apache/aries/plugin/esa/ test/java/org/apache/aries/plugin/esa/ test/java/org/apache/aries/plugin/esa/stubs/ test/resources/unit/basic-esa-content-all-transitive/ test/resources... Date: Thu, 02 Mar 2017 16:30:59 -0000 To: commits@aries.apache.org From: davidb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170302163059.E00413A0158@svn01-us-west.apache.org> archived-at: Thu, 02 Mar 2017 16:31:02 -0000 Author: davidb Date: Thu Mar 2 16:30:59 2017 New Revision: 1785159 URL: http://svn.apache.org/viewvc?rev=1785159&view=rev Log: ARIES-1490 Add feature to configure the 'Subsystem-Content' header This allows to include only direct content or also transitive content. Patch applied on behalf of Tom de Wolf with many thanks. This closes https://github.com/apache/aries/pull/69 Added: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-all-transitive/ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-all-transitive/plugin-config.xml aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-all-transitive/ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-all-transitive/plugin-config.xml aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-bundles-only/ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-bundles-only/plugin-config.xml Modified: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java Modified: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java?rev=1785159&r1=1785158&r2=1785159&view=diff ============================================================================== --- aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java (original) +++ aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java Thu Mar 2 16:30:59 2017 @@ -94,7 +94,7 @@ public class ContentInfo { } } } catch (Exception e) { - log.warn("Error creating content information", e); + log.warn("Error creating content information for artifact '" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":v" + artifact.getVersion() + "'", e); return null; } finally { if (zip != null) { Modified: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java?rev=1785159&r1=1785158&r2=1785159&view=diff ============================================================================== --- aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java (original) +++ aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java Thu Mar 2 16:30:59 2017 @@ -19,6 +19,15 @@ package org.apache.aries.plugin.esa; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + import org.apache.maven.archiver.PomPropertiesUtil; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; @@ -28,14 +37,6 @@ import org.codehaus.plexus.archiver.Arch import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; -import java.io.File; -import java.io.IOException; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; /** * Builds OSGi Enterprise Subsystem Archive (esa) files. @@ -50,6 +51,8 @@ public class EsaMojo { public enum EsaContent {none, all, content}; + + public enum EsaManifestContent {all, content}; public static final String SUBSYSTEM_MF_URI = "OSGI-INF/SUBSYSTEM.MF"; @@ -176,7 +179,7 @@ public class EsaMojo /** * Define which bundles to include in the archive. * none - no bundles are included - * subsystemContent - direct dependencies go into the content + * content - direct dependencies go into the content * all - direct and transitive dependencies go into the content * * @parameter expression="${archiveContent}" default-value="content" @@ -184,6 +187,15 @@ public class EsaMojo private String archiveContent; /** + * Define which bundles to include in the manifest Subsystem-Content header. + * all - direct and transitive dependencies go into the Subsystem-Content header + * content - direct dependencies go into the Subsystem-Content header + * + * @parameter expression="${manifestContent}" default-value="content" + */ + private String manifestContent; + + /** * Define the start order for content bundles. * none - no start orders are added * dependencies - start order based on pom dependency order @@ -378,10 +390,17 @@ public class EsaMojo if (archiveContent == null) { archiveContent = new String("content"); } - - getLog().debug( "archiveContent[" + archiveContent + "]" ); - getLog().info( "archiveContent[" + archiveContent + "]" ); - + + getLog().debug( "archiveContent[" + archiveContent + "]" ); + getLog().info( "archiveContent[" + archiveContent + "]" ); + + if (manifestContent == null) { + manifestContent = new String("content"); + } + + getLog().debug( "manifestContent[" + archiveContent + "]" ); + getLog().info( "manifestContent[" + archiveContent + "]" ); + zipArchiver.setIncludeEmptyDirs( includeEmptyDirs ); zipArchiver.setCompress( true ); zipArchiver.setForced( forceCreation ); @@ -408,14 +427,25 @@ public class EsaMojo // TODO: check that the dependencies are bundles (currently, the converter // will throw an exception) Set artifacts = null; - // only include the direct dependencies in the content - artifacts = project.getDependencyArtifacts(); + switch (EsaManifestContent.valueOf(manifestContent)) { + case content: + // only include the direct dependencies in the content + artifacts = project.getDependencyArtifacts(); + break; + case all: + // include direct and transitive dependencies in content + artifacts = project.getArtifacts(); + break; + default: + throw new MojoExecutionException("Invalid configuration for . Valid values are content and all." ); + } artifacts = selectArtifacts(artifacts); Iterator iter = artifacts.iterator(); FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_CONTENT + ": "); int order = 0; + int nbInSubsystemContent = 0; while (iter.hasNext()) { Artifact artifact = iter.next(); order++; @@ -430,8 +460,10 @@ public class EsaMojo if (iter.hasNext()) { entry += ",\n "; } + nbInSubsystemContent++; FileUtils.fileAppend(fileName, entry); } + getLog().info("Added '" + nbInSubsystemContent + "' artefacts to the Subsystem-Content header"); FileUtils.fileAppend(fileName, "\n"); @@ -517,7 +549,7 @@ public class EsaMojo } /** - * Return artifacts in 'compile' or 'runtime' scope only. + * Return non-pom artifacts in 'compile' or 'runtime' scope only. */ private Set selectArtifacts(Set artifacts) { @@ -527,7 +559,9 @@ public class EsaMojo if (scope == null || Artifact.SCOPE_COMPILE.equals(scope) || Artifact.SCOPE_RUNTIME.equals(scope)) { - selected.add(artifact); + if (artifact.getType() == null || !artifact.getType().equals("pom")) { + selected.add(artifact); + } } } return selected; Modified: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java?rev=1785159&r1=1785158&r2=1785159&view=diff ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java (original) +++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java Thu Mar 2 16:30:59 2017 @@ -463,6 +463,149 @@ public class EsaMojoTest } + public void testArchiveContentConfigurationSubsystemContentAll() + throws Exception + { + File testPom = new File( getBasedir(), + "target/test-classes/unit/basic-esa-content-all-transitive/plugin-config.xml" ); + + EsaMojo mojo = ( EsaMojo ) lookupMojo( "esa", testPom ); + + assertNotNull( mojo ); + + String finalName = ( String ) getVariableValueFromObject( mojo, "finalName" ); + + String workDir = ( String ) getVariableValueFromObject( mojo, "workDirectory" ); + + String outputDir = ( String ) getVariableValueFromObject( mojo, "outputDirectory" ); + + mojo.execute(); + + + //check the generated esa file + File esaFile = new File( outputDir, finalName + ".esa" ); + + assertTrue( esaFile.exists() ); + + //expected files/directories inside the esa file + List expectedFiles = new ArrayList(); + + expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-esa-test/pom.properties" ); + expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-esa-test/pom.xml" ); + expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-esa-test/" ); + expectedFiles.add( "META-INF/maven/org.apache.maven.test/" ); + expectedFiles.add( "META-INF/maven/" ); + expectedFiles.add( "META-INF/" ); + expectedFiles.add( "OSGI-INF/SUBSYSTEM.MF" ); + expectedFiles.add( "OSGI-INF/" ); + expectedFiles.add( "maven-artifact01-1.0-SNAPSHOT.jar" ); + expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" ); + expectedFiles.add( "maven-artifact03-1.1-SNAPSHOT.jar" ); + + ZipFile esa = new ZipFile( esaFile ); + + Enumeration entries = esa.getEntries(); + + assertTrue( entries.hasMoreElements() ); + + int missing = getSizeOfExpectedFiles(entries, expectedFiles); + assertEquals("Missing files: " + expectedFiles, 0, missing); + + } + + public void testManifestSubsystemContentContainsOnlyDirectContent() + throws Exception + { + File testPom = new File(getBasedir(), + "target/test-classes/unit/basic-esa-content-type-bundles-only/plugin-config.xml"); + + EsaMojo mojo = (EsaMojo) lookupMojo("esa", testPom); + + assertNotNull(mojo); + + String finalName = (String) getVariableValueFromObject(mojo, "finalName"); + + String workDir = (String) getVariableValueFromObject(mojo, "workDirectory"); + + String outputDir = (String) getVariableValueFromObject(mojo, "outputDirectory"); + + mojo.execute(); + + // check the generated esa file + File esaFile = new File(outputDir, finalName + ".esa"); + + assertTrue(esaFile.exists()); + + ZipFile esa = new ZipFile(esaFile); + + Manifest mf = getSubsystemManifest(esa); + Map> header = getHeader(mf, "Subsystem-Content"); + + Map attributes = null; + + attributes = header.get("maven-artifact01-1.0-SNAPSHOT"); + assertNotNull(attributes); + assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version")); + assertNull(attributes.get("type")); + + attributes = header.get("maven-artifact02-1.0-SNAPSHOT"); + assertNotNull(attributes); + assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version")); + assertNull(attributes.get("type")); + + assertEquals(2, header.size()); + } + + public void testManifestSubsystemContentContainsAllTransitiveDependencies() + throws Exception + { + File testPom = new File(getBasedir(), + "target/test-classes/unit/basic-esa-content-type-all-transitive/plugin-config.xml"); + + EsaMojo mojo = (EsaMojo) lookupMojo("esa", testPom); + + assertNotNull(mojo); + + String finalName = (String) getVariableValueFromObject(mojo, "finalName"); + + String workDir = (String) getVariableValueFromObject(mojo, "workDirectory"); + + String outputDir = (String) getVariableValueFromObject(mojo, "outputDirectory"); + + mojo.execute(); + + // check the generated esa file + File esaFile = new File(outputDir, finalName + ".esa"); + + assertTrue(esaFile.exists()); + + ZipFile esa = new ZipFile(esaFile); + + Manifest mf = getSubsystemManifest(esa); + Map> header = getHeader(mf, "Subsystem-Content"); + + System.out.println(header); + + Map attributes = null; + + attributes = header.get("maven-artifact01-1.0-SNAPSHOT"); + assertNotNull(attributes); + assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version")); + assertNull(attributes.get("type")); + + attributes = header.get("maven-artifact02-1.0-SNAPSHOT"); + assertNotNull(attributes); + assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version")); + assertNull(attributes.get("type")); + + attributes = header.get("maven-artifact03"); + assertNotNull(attributes); + assertEquals("[1.1.0.SNAPSHOT.NNN,1.1.0.SNAPSHOT.NNN]", attributes.get("version")); + assertEquals("osgi.fragment", attributes.get("type")); + + assertEquals(3, header.size()); + } + public void testCustomInstructions() throws Exception { Added: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java?rev=1785159&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java (added) +++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java Thu Mar 2 16:30:59 2017 @@ -0,0 +1,30 @@ +package org.apache.aries.plugin.esa.stubs; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class EsaMavenProjectStub10 extends EsaMavenProjectStub { + + @Override + public Set getArtifacts() + { + Set artifacts = new LinkedHashSet(); + + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false ) ); + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false ) ); + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact03", "1.1-SNAPSHOT", false ) ); + + + return artifacts; + } + + @Override + public Set getDependencyArtifacts() { + Set artifacts = new LinkedHashSet(); + + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false ) ); + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false ) ); + + return artifacts; + } +} Added: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-all-transitive/plugin-config.xml URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-all-transitive/plugin-config.xml?rev=1785159&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-all-transitive/plugin-config.xml (added) +++ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-all-transitive/plugin-config.xml Thu Mar 2 16:30:59 2017 @@ -0,0 +1,38 @@ + + + + + + + esa-maven-plugin + + ${basedir}/src/test/resources/unit/basic-esa-content-bundles-only/src/main/esa + true + all + true + + + true + true + ${basedir}/target/unit/basic-esa-content-bundles-only/target/esa-test-content-bundles-only + + ${basedir}/target/unit/basic-esa-content-bundles-only/target/maven-shared-archive-resources + + ${basedir}/target/unit/basic-esa-content-bundles-only/target + + test-esa-content-all-transitive + + + + + + Added: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-all-transitive/plugin-config.xml URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-all-transitive/plugin-config.xml?rev=1785159&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-all-transitive/plugin-config.xml (added) +++ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-all-transitive/plugin-config.xml Thu Mar 2 16:30:59 2017 @@ -0,0 +1,38 @@ + + + + + + + esa-maven-plugin + + ${basedir}/src/test/resources/unit/basic-esa-content-bundles-only/src/main/esa + true + all + all + + + false + true + ${basedir}/target/unit/basic-esa-content-bundles-only/target/esa-test-content-bundles-only + + ${basedir}/target/unit/basic-esa-content-bundles-only/target/maven-shared-archive-resources + + ${basedir}/target/unit/basic-esa-content-bundles-only/target + + test-esa-content-type-all-transitive + + + + + + Added: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-bundles-only/plugin-config.xml URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-bundles-only/plugin-config.xml?rev=1785159&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-bundles-only/plugin-config.xml (added) +++ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type-bundles-only/plugin-config.xml Thu Mar 2 16:30:59 2017 @@ -0,0 +1,38 @@ + + + + + + + esa-maven-plugin + + ${basedir}/src/test/resources/unit/basic-esa-content-bundles-only/src/main/esa + true + all + content + + + false + true + ${basedir}/target/unit/basic-esa-content-bundles-only/target/esa-test-content-bundles-only + + ${basedir}/target/unit/basic-esa-content-bundles-only/target/maven-shared-archive-resources + + ${basedir}/target/unit/basic-esa-content-bundles-only/target + + test-esa-content-type-bundles-only + + + + + +