Skip to content

Commit f342e9e

Browse files
committed
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 apache#63 git-svn-id: https://svn.apache.org/repos/asf/aries/trunk@1785640 13f79535-47bb-0310-9956-ffa450edef68
1 parent b59a004 commit f342e9e

File tree

9 files changed

+217
-8
lines changed

9 files changed

+217
-8
lines changed

esa-maven-plugin/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
</scm>
4343

4444
<dependencies>
45+
<dependency>
46+
<groupId>org.apache.aries</groupId>
47+
<artifactId>org.apache.aries.util</artifactId>
48+
<version>1.1.3</version>
49+
</dependency>
4550
<dependency>
4651
<groupId>biz.aQute</groupId>
4752
<artifactId>bndlib</artifactId>

esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java

+37-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* under the License.
2020
*/
2121

22+
import static org.apache.aries.util.manifest.BundleManifest.fromBundle;
23+
2224
import java.io.File;
2325
import java.io.IOException;
2426
import java.util.HashSet;
@@ -28,6 +30,7 @@
2830
import java.util.Map;
2931
import java.util.Set;
3032

33+
import org.apache.aries.util.manifest.BundleManifest;
3134
import org.apache.maven.archiver.PomPropertiesUtil;
3235
import org.apache.maven.artifact.Artifact;
3336
import org.apache.maven.plugin.AbstractMojo;
@@ -239,7 +242,9 @@ private void addDependenciesToArchive() throws MojoExecutionException {
239242
artifacts.add(project.getArtifact());
240243
}
241244

242-
artifacts = selectArtifacts(artifacts);
245+
artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts);
246+
artifacts = selectNonJarArtifactsAndBundles(artifacts);
247+
243248
int cnt = 0;
244249
for (Artifact artifact : artifacts) {
245250
if (!artifact.isOptional() /*&& filter.include(artifact)*/) {
@@ -424,9 +429,8 @@ private void writeSubsystemManifest(String fileName)
424429
}
425430

426431
// Write the SUBSYSTEM-CONTENT
427-
// TODO: check that the dependencies are bundles (currently, the converter
428-
// will throw an exception)
429432
Set<Artifact> artifacts = null;
433+
430434
switch (EsaManifestContent.valueOf(manifestContent)) {
431435
case content:
432436
// only include the direct dependencies in the content
@@ -439,8 +443,10 @@ private void writeSubsystemManifest(String fileName)
439443
default:
440444
throw new MojoExecutionException("Invalid configuration for <manifestContent/>. Valid values are content and all." );
441445
}
442-
443-
artifacts = selectArtifacts(artifacts);
446+
447+
artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts);
448+
artifacts = selectNonJarArtifactsAndBundles(artifacts);
449+
444450
Iterator<Artifact> iter = artifacts.iterator();
445451

446452
FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_CONTENT + ": ");
@@ -551,7 +557,7 @@ private void includeCustomSubsystemManifestFile()
551557
/**
552558
* Return non-pom artifacts in 'compile' or 'runtime' scope only.
553559
*/
554-
private Set<Artifact> selectArtifacts(Set<Artifact> artifacts)
560+
private Set<Artifact> selectArtifactsInCompileOrRuntimeScope(Set<Artifact> artifacts)
555561
{
556562
Set<Artifact> selected = new LinkedHashSet<Artifact>();
557563
for (Artifact artifact : artifacts) {
@@ -567,6 +573,31 @@ private Set<Artifact> selectArtifacts(Set<Artifact> artifacts)
567573
return selected;
568574
}
569575

576+
/**
577+
* Returns bundles and artifacts that aren't JARs
578+
*/
579+
private Set<Artifact> selectNonJarArtifactsAndBundles(Set<Artifact> artifacts)
580+
{
581+
Set<Artifact> selected = new LinkedHashSet<Artifact>();
582+
for (Artifact artifact : artifacts) {
583+
if (isNonJarOrOSGiBundle(artifact)) {
584+
selected.add(artifact);
585+
} else {
586+
getLog().warn("Skipping dependency on non-bundle JAR! groupId: " + artifact.getGroupId() + " artifactId:" + artifact.getArtifactId());
587+
}
588+
}
589+
return selected;
590+
}
591+
592+
private boolean isNonJarOrOSGiBundle(Artifact artifact) {
593+
if(!artifact.getFile().getName().endsWith(".jar")){
594+
return true;
595+
} else {
596+
BundleManifest manifest = fromBundle(artifact.getFile());
597+
return manifest != null && manifest.getSymbolicName() != null;
598+
}
599+
}
600+
570601
private void includeSharedResources() throws MojoExecutionException {
571602
try
572603
{

esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java

+48-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
import java.util.jar.Attributes;
3131
import java.util.jar.Manifest;
3232

33-
import aQute.lib.osgi.Analyzer;
34-
3533
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
3634
import org.codehaus.plexus.archiver.zip.ZipEntry;
3735
import org.codehaus.plexus.archiver.zip.ZipFile;
3836

37+
import aQute.lib.osgi.Analyzer;
38+
3939
/**
4040
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
4141
*/
@@ -414,6 +414,52 @@ public void testArchiveContentConfigurationNoBundles()
414414

415415
}
416416

417+
public void testBasicEsaWithoutNonBundleJars()
418+
throws Exception
419+
{
420+
File testPom = new File( getBasedir(),
421+
"target/test-classes/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml" );
422+
423+
EsaMojo mojo = ( EsaMojo ) lookupMojo( "esa", testPom );
424+
425+
assertNotNull( mojo );
426+
427+
String finalName = ( String ) getVariableValueFromObject( mojo, "finalName" );
428+
429+
String workDir = ( String ) getVariableValueFromObject( mojo, "workDirectory" );
430+
431+
String outputDir = ( String ) getVariableValueFromObject( mojo, "outputDirectory" );
432+
433+
mojo.execute();
434+
435+
//check the generated esa file
436+
File esaFile = new File( outputDir, finalName + ".esa" );
437+
438+
assertTrue( esaFile.exists() );
439+
440+
//expected files/directories inside the esa file
441+
List expectedFiles = new ArrayList();
442+
443+
expectedFiles.add( "maven-artifact01-1.0-SNAPSHOT.jar" );
444+
expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-esa-test/pom.properties" );
445+
expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-esa-test/pom.xml" );
446+
expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-esa-test/" );
447+
expectedFiles.add( "META-INF/maven/org.apache.maven.test/" );
448+
expectedFiles.add( "META-INF/maven/" );
449+
expectedFiles.add( "META-INF/" );
450+
expectedFiles.add( "OSGI-INF/SUBSYSTEM.MF" );
451+
expectedFiles.add( "OSGI-INF/" );
452+
453+
ZipFile esa = new ZipFile( esaFile );
454+
455+
Enumeration entries = esa.getEntries();
456+
457+
assertTrue( entries.hasMoreElements() );
458+
459+
int missing = getSizeOfExpectedFiles(entries, expectedFiles);
460+
assertEquals("Missing files: " + expectedFiles, 0, missing);
461+
}
462+
417463
public void testArchiveContentConfigurationSubsystemContentBundles()
418464
throws Exception
419465
{

esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub10.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
package org.apache.aries.plugin.esa.stubs;
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
220

321
import java.util.LinkedHashSet;
422
import java.util.Set;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.apache.aries.plugin.esa.stubs;
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
import java.io.File;
22+
import java.util.HashSet;
23+
import java.util.Set;
24+
25+
public class EsaMavenProjectStub11 extends EsaMavenProjectStub
26+
{
27+
public File getFile()
28+
{
29+
return new File( getBasedir(), "src/test/resources/unit/basic-esa-exclude-non-bundle-jars/plugin-config.xml" );
30+
}
31+
32+
public Set getArtifacts()
33+
{
34+
Set artifacts = new HashSet();
35+
artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false ) );
36+
artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact05-no-bundle-manifest", "1.1-SNAPSHOT", false ));
37+
return artifacts;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>org.apache.maven.test</groupId>
23+
<artifactId>maven-artifact05-no-bundle-manifest</artifactId>
24+
<version>1.1-SNAPSHOT</version>
25+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
<project>
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<artifactId>esa-maven-plugin</artifactId>
25+
<configuration>
26+
<esaSourceDirectory>${basedir}/src/test/resources/unit/basic-esa-exclude-non-bundle-jars/src/main/esa</esaSourceDirectory>
27+
<generateManifest>true</generateManifest>
28+
<archiveContent>all</archiveContent>
29+
<instructions>
30+
</instructions>
31+
<addMavenDescriptor>true</addMavenDescriptor>
32+
<includeEmptyDirs>true</includeEmptyDirs>
33+
<workDirectory>${basedir}/target/unit/basic-esa-exclude-non-bundle-jars/target/basic-esa-exclude-non-bundle-jars
34+
</workDirectory>
35+
<sharedResources>${basedir}/target/unit/basic-esa-exclude-non-bundle-jars/target/maven-shared-archive-resources
36+
</sharedResources>
37+
<outputDirectory>${basedir}/target/unit/basic-esa-exclude-non-bundle-jars/target
38+
</outputDirectory>
39+
<finalName>test-esa-exclude-non-bundle-jars</finalName>
40+
<project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub11" />
41+
</configuration>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
</project>

0 commit comments

Comments
 (0)