Author: davidb Date: Mon Mar 6 12:22:24 2017 New Revision: 1785640 URL: http://svn.apache.org/viewvc?rev=1785640&view=rev Log: ARIES-1650 Maven plugin no longer includes non-bundle artifacts
Patch applied on behalf of Wouter Bancken and Tom de Wolf with many thanks! This closes https://github.com/apache/aries/pull/63 Added: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub11.java aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/ aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/ aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.jar (with props) aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.pom aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml Modified: aries/trunk/esa-maven-plugin/pom.xml 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 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-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar Modified: aries/trunk/esa-maven-plugin/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/pom.xml?rev=1785640&r1=1785639&r2=1785640&view=diff ============================================================================== --- aries/trunk/esa-maven-plugin/pom.xml (original) +++ aries/trunk/esa-maven-plugin/pom.xml Mon Mar 6 12:22:24 2017 @@ -43,6 +43,11 @@ <dependencies> <dependency> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.util</artifactId> + <version>1.1.3</version> + </dependency> + <dependency> <groupId>biz.aQute</groupId> <artifactId>bndlib</artifactId> <version>0.0.357</version> 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=1785640&r1=1785639&r2=1785640&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 Mon Mar 6 12:22:24 2017 @@ -19,6 +19,8 @@ package org.apache.aries.plugin.esa; * under the License. */ +import static org.apache.aries.util.manifest.BundleManifest.fromBundle; + import java.io.File; import java.io.IOException; import java.util.HashSet; @@ -28,6 +30,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import org.apache.aries.util.manifest.BundleManifest; import org.apache.maven.archiver.PomPropertiesUtil; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; @@ -239,7 +242,9 @@ public class EsaMojo artifacts.add(project.getArtifact()); } - artifacts = selectArtifacts(artifacts); + artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts); + artifacts = selectNonJarArtifactsAndBundles(artifacts); + int cnt = 0; for (Artifact artifact : artifacts) { if (!artifact.isOptional() /*&& filter.include(artifact)*/) { @@ -424,9 +429,8 @@ public class EsaMojo } // Write the SUBSYSTEM-CONTENT - // TODO: check that the dependencies are bundles (currently, the converter - // will throw an exception) Set<Artifact> artifacts = null; + switch (EsaManifestContent.valueOf(manifestContent)) { case content: // only include the direct dependencies in the content @@ -439,8 +443,10 @@ public class EsaMojo default: throw new MojoExecutionException("Invalid configuration for <manifestContent/>. Valid values are content and all." ); } - - artifacts = selectArtifacts(artifacts); + + artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts); + artifacts = selectNonJarArtifactsAndBundles(artifacts); + Iterator<Artifact> iter = artifacts.iterator(); FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_CONTENT + ": "); @@ -551,7 +557,7 @@ public class EsaMojo /** * Return non-pom artifacts in 'compile' or 'runtime' scope only. */ - private Set<Artifact> selectArtifacts(Set<Artifact> artifacts) + private Set<Artifact> selectArtifactsInCompileOrRuntimeScope(Set<Artifact> artifacts) { Set<Artifact> selected = new LinkedHashSet<Artifact>(); for (Artifact artifact : artifacts) { @@ -567,6 +573,31 @@ public class EsaMojo return selected; } + /** + * Returns bundles and artifacts that aren't JARs + */ + private Set<Artifact> selectNonJarArtifactsAndBundles(Set<Artifact> artifacts) + { + Set<Artifact> selected = new LinkedHashSet<Artifact>(); + for (Artifact artifact : artifacts) { + if (isNonJarOrOSGiBundle(artifact)) { + selected.add(artifact); + } else { + getLog().warn("Skipping dependency on non-bundle JAR! groupId: " + artifact.getGroupId() + " artifactId:" + artifact.getArtifactId()); + } + } + return selected; + } + + private boolean isNonJarOrOSGiBundle(Artifact artifact) { + if(!artifact.getFile().getName().endsWith(".jar")){ + return true; + } else { + BundleManifest manifest = fromBundle(artifact.getFile()); + return manifest != null && manifest.getSymbolicName() != null; + } + } + private void includeSharedResources() throws MojoExecutionException { try { 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=1785640&r1=1785639&r2=1785640&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 Mon Mar 6 12:22:24 2017 @@ -30,12 +30,12 @@ import java.util.Map; import java.util.jar.Attributes; import java.util.jar.Manifest; -import aQute.lib.osgi.Analyzer; - import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codehaus.plexus.archiver.zip.ZipEntry; import org.codehaus.plexus.archiver.zip.ZipFile; +import aQute.lib.osgi.Analyzer; + /** * @author <a href="mailto:[email protected]">Allan Ramirez</a> */ @@ -414,6 +414,52 @@ public class EsaMojoTest } + public void testBasicEsaWithoutNonBundleJars() + throws Exception + { + File testPom = new File( getBasedir(), + "target/test-classes/unit/basic-esa-exclude-non-bundle-jars/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( "maven-artifact01-1.0-SNAPSHOT.jar" ); + 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/" ); + + 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 testArchiveContentConfigurationSubsystemContentBundles() throws Exception { Modified: 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=1785640&r1=1785639&r2=1785640&view=diff ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java (original) +++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java Mon Mar 6 12:22:24 2017 @@ -1,4 +1,22 @@ 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.util.LinkedHashSet; import java.util.Set; Added: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub11.java URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub11.java?rev=1785640&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub11.java (added) +++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub11.java Mon Mar 6 12:22:24 2017 @@ -0,0 +1,39 @@ +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 java.util.HashSet; +import java.util.Set; + +public class EsaMavenProjectStub11 extends EsaMavenProjectStub + { + public File getFile() + { + return new File( getBasedir(), "src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml" ); + } + + public Set getArtifacts() + { + Set artifacts = new HashSet(); + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false ) ); + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact05-no-bundle-manifest", "1.1-SNAPSHOT", false )); + return artifacts; + } +} Added: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.jar URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.jar?rev=1785640&view=auto ============================================================================== Binary file - no diff available. Propchange: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.pom URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.pom?rev=1785640&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.pom (added) +++ aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact05-no-bundle-manifest/1.1-SNAPSHOT/maven-artifact05-no-bundle-manifest-1.1-SNAPSHOT.pom Mon Mar 6 12:22:24 2017 @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.test</groupId> + <artifactId>maven-artifact05-no-bundle-manifest</artifactId> + <version>1.1-SNAPSHOT</version> +</project> Added: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml?rev=1785640&view=auto ============================================================================== --- aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml (added) +++ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml Mon Mar 6 12:22:24 2017 @@ -0,0 +1,45 @@ +<!-- +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-exclude-non-bundle-jars/src/main/esa</esaSourceDirectory> + <generateManifest>true</generateManifest> + <archiveContent>all</archiveContent> + <instructions> + </instructions> + <addMavenDescriptor>true</addMavenDescriptor> + <includeEmptyDirs>true</includeEmptyDirs> + <workDirectory>${basedir}/target/unit/basic-esa-exclude-non-bundle-jars/target/basic-esa-exclude-non-bundle-jars + </workDirectory> + <sharedResources>${basedir}/target/unit/basic-esa-exclude-non-bundle-jars/target/maven-shared-archive-resources + </sharedResources> + <outputDirectory>${basedir}/target/unit/basic-esa-exclude-non-bundle-jars/target + </outputDirectory> + <finalName>test-esa-exclude-non-bundle-jars</finalName> + <project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub11" /> + </configuration> + </plugin> + </plugins> + </build> +</project> Modified: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar?rev=1785640&r1=1785639&r2=1785640&view=diff ============================================================================== Binary files aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar (original) and aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-test-with-pgk-type/target/maven-esa-test-1.0-SNAPSHOT.jar Mon Mar 6 12:22:24 2017 differ
