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<Artifact> 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 <manifestContent/>. Valid values are content and all." ); + } artifacts = selectArtifacts(artifacts); Iterator<Artifact> 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<Artifact> selectArtifacts(Set<Artifact> 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<String, Map<String, String>> header = getHeader(mf, "Subsystem-Content"); + + Map<String, String> 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<String, Map<String, String>> header = getHeader(mf, "Subsystem-Content"); + + System.out.println(header); + + Map<String, String> 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 @@ +<!-- 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. --> + +<project> + <build> + <plugins> + <plugin> + <artifactId>esa-maven-plugin</artifactId> + <configuration> + <esaSourceDirectory>${basedir}/src/test/resources/unit/basic-esa-content-bundles-only/src/main/esa</esaSourceDirectory> + <generateManifest>true</generateManifest> + <archiveContent>all</archiveContent> + <forceCreation>true</forceCreation> + <instructions> + </instructions> + <addMavenDescriptor>true</addMavenDescriptor> + <includeEmptyDirs>true</includeEmptyDirs> + <workDirectory>${basedir}/target/unit/basic-esa-content-bundles-only/target/esa-test-content-bundles-only + </workDirectory> + <sharedResources>${basedir}/target/unit/basic-esa-content-bundles-only/target/maven-shared-archive-resources + </sharedResources> + <outputDirectory>${basedir}/target/unit/basic-esa-content-bundles-only/target + </outputDirectory> + <finalName>test-esa-content-all-transitive</finalName> + <project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub10" /> + </configuration> + </plugin> + </plugins> + </build> +</project> 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 @@ +<!-- 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. --> + +<project> + <build> + <plugins> + <plugin> + <artifactId>esa-maven-plugin</artifactId> + <configuration> + <esaSourceDirectory>${basedir}/src/test/resources/unit/basic-esa-content-bundles-only/src/main/esa</esaSourceDirectory> + <generateManifest>true</generateManifest> + <archiveContent>all</archiveContent> + <manifestContent>all</manifestContent> + <instructions> + </instructions> + <addMavenDescriptor>false</addMavenDescriptor> + <includeEmptyDirs>true</includeEmptyDirs> + <workDirectory>${basedir}/target/unit/basic-esa-content-bundles-only/target/esa-test-content-bundles-only + </workDirectory> + <sharedResources>${basedir}/target/unit/basic-esa-content-bundles-only/target/maven-shared-archive-resources + </sharedResources> + <outputDirectory>${basedir}/target/unit/basic-esa-content-bundles-only/target + </outputDirectory> + <finalName>test-esa-content-type-all-transitive</finalName> + <project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub10" /> + </configuration> + </plugin> + </plugins> + </build> +</project> 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 @@ +<!-- 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. --> + +<project> + <build> + <plugins> + <plugin> + <artifactId>esa-maven-plugin</artifactId> + <configuration> + <esaSourceDirectory>${basedir}/src/test/resources/unit/basic-esa-content-bundles-only/src/main/esa</esaSourceDirectory> + <generateManifest>true</generateManifest> + <archiveContent>all</archiveContent> + <manifestContent>content</manifestContent> + <instructions> + </instructions> + <addMavenDescriptor>false</addMavenDescriptor> + <includeEmptyDirs>true</includeEmptyDirs> + <workDirectory>${basedir}/target/unit/basic-esa-content-bundles-only/target/esa-test-content-bundles-only + </workDirectory> + <sharedResources>${basedir}/target/unit/basic-esa-content-bundles-only/target/maven-shared-archive-resources + </sharedResources> + <outputDirectory>${basedir}/target/unit/basic-esa-content-bundles-only/target + </outputDirectory> + <finalName>test-esa-content-type-bundles-only</finalName> + <project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub10" /> + </configuration> + </plugin> + </plugins> + </build> +</project>
