Skip to content

Commit e7cebae

Browse files
authored
Merge pull request #568 from apache/FELIX-6868-bundleall-it
FELIX-6868 maven-bundle-plugin: add an integration test for bundleall
2 parents e6683b3 + e8d1e8b commit e7cebae

7 files changed

Lines changed: 309 additions & 1 deletion

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<groupId>org.apache.felix.bundleits</groupId>
24+
<artifactId>bundleall</artifactId>
25+
<version>1-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.apache.commons</groupId>
30+
<artifactId>commons-compress</artifactId>
31+
<version>1.26.0</version>
32+
</dependency>
33+
</dependencies>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.felix</groupId>
38+
<artifactId>maven-bundle-plugin</artifactId>
39+
<version>@project.version@</version>
40+
<executions>
41+
<execution>
42+
<id>bundleall</id>
43+
<phase>package</phase>
44+
<goals>
45+
<goal>bundleall</goal>
46+
</goals>
47+
<configuration>
48+
<ignoreMissingArtifacts>true</ignoreMissingArtifacts>
49+
</configuration>
50+
</execution>
51+
</executions>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
import java.util.jar.JarFile
21+
22+
// bundleall wraps the project dependencies, including transitive ones, into target/classes.
23+
// commons-compress 1.26.0 depends on commons-io and commons-lang3; commons-io is the version
24+
// selected by dependency mediation, not the one declared by any POM along the way.
25+
def expected = [
26+
"org.apache.commons.commons-compress_1.26.0.jar",
27+
"org.apache.commons.lang3_3.14.0.jar",
28+
"org.apache.commons.commons-io_2.15.1.jar"
29+
] as Set
30+
31+
def bundles = [:]
32+
new File( basedir, "target/classes" ).eachFileMatch( ~/.*\.jar/ ) { f ->
33+
bundles[f.name] = f
34+
}
35+
assert bundles.keySet() == expected : "Unexpected bundles ${bundles.keySet()}"
36+
37+
bundles.each { name, file ->
38+
def jar = new JarFile( file )
39+
try {
40+
assert jar.manifest.mainAttributes.getValue( "Bundle-SymbolicName" ) : "${name} is not an OSGi bundle"
41+
} finally {
42+
jar.close()
43+
}
44+
}
45+
46+
def log = new File( basedir, "build.log" ).text
47+
assert log.contains( "The bundleall goal is no longer supported" )
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<groupId>org.apache.felix.bundleits</groupId>
24+
<artifactId>dep-reduced-pom-transitive</artifactId>
25+
<version>1-SNAPSHOT</version>
26+
<packaging>bundle</packaging>
27+
<repositories>
28+
<repository>
29+
<id>it-local</id>
30+
<url>file:///${basedir}/repo</url>
31+
</repository>
32+
</repositories>
33+
<dependencies>
34+
<dependency>
35+
<groupId>commons-io</groupId>
36+
<artifactId>commons-io</artifactId>
37+
<version>2.7</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.apache.felix.bundleits</groupId>
41+
<artifactId>direct-pom</artifactId>
42+
<version>1.0</version>
43+
<type>pom</type>
44+
</dependency>
45+
</dependencies>
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.felix</groupId>
50+
<artifactId>maven-bundle-plugin</artifactId>
51+
<version>@project.version@</version>
52+
<extensions>true</extensions>
53+
<configuration>
54+
<createDependencyReducedPom>true</createDependencyReducedPom>
55+
<instructions>
56+
<Embed-Dependency>commons-io</Embed-Dependency>
57+
</instructions>
58+
</configuration>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<groupId>org.apache.felix.bundleits</groupId>
24+
<artifactId>direct-pom</artifactId>
25+
<version>1.0</version>
26+
<packaging>pom</packaging>
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.apache.felix.bundleits</groupId>
30+
<artifactId>transitive-pom</artifactId>
31+
<version>1.0</version>
32+
<type>pom</type>
33+
</dependency>
34+
</dependencies>
35+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<groupId>org.apache.felix.bundleits</groupId>
24+
<artifactId>transitive-pom</artifactId>
25+
<version>1.0</version>
26+
<packaging>pom</packaging>
27+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
File pomFile = new File( basedir, "dependency-reduced-pom.xml" );
21+
assert pomFile.isFile()
22+
23+
def ns = new groovy.xml.Namespace("http://maven.apache.org/POM/4.0.0")
24+
def pom = new XmlParser().parse( pomFile )
25+
26+
// the embedded commons-io is removed, the pom dependency stays
27+
def deps = pom[ns.dependencies][ns.dependency]
28+
assert deps.size() == 1
29+
assert deps[0][ns.artifactId].text() == "direct-pom"
30+
31+
// pom type dependencies are not promoted into the reduced POM, so the pom dependency that
32+
// direct-pom brings in transitively is excluded explicitly
33+
def exclusions = deps[0][ns.exclusions][ns.exclusion]
34+
assert exclusions.size() == 1
35+
assert exclusions[0][ns.groupId].text() == "org.apache.felix.bundleits"
36+
assert exclusions[0][ns.artifactId].text() == "transitive-pom"

‎tools/maven-bundle-plugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,52 @@ public void testPropertySanitizing() throws Exception
444444

445445
File file = new File( getBasedir(), "target" + File.separatorChar + "test.props" );
446446
builder.getProperties().store( new FileOutputStream( file ), "TEST" );
447-
}
447+
}
448+
449+
public void testToArtifactCopiesScopeAndOptionalFromDependency()
450+
{
451+
org.eclipse.aether.artifact.Artifact aetherArtifact =
452+
new org.eclipse.aether.artifact.DefaultArtifact( "g", "a", "tests", "jar", "1.0" );
453+
org.eclipse.aether.graph.DependencyNode node = new org.eclipse.aether.graph.DefaultDependencyNode(
454+
new org.eclipse.aether.graph.Dependency( aetherArtifact, Artifact.SCOPE_RUNTIME, true ) );
455+
456+
Artifact artifact = BundlePlugin.toArtifact( node, new MavenProject() );
457+
458+
assertEquals( "g", artifact.getGroupId() );
459+
assertEquals( "a", artifact.getArtifactId() );
460+
assertEquals( "1.0", artifact.getVersion() );
461+
assertEquals( "jar", artifact.getType() );
462+
assertEquals( "tests", artifact.getClassifier() );
463+
assertEquals( Artifact.SCOPE_RUNTIME, artifact.getScope() );
464+
assertTrue( artifact.isOptional() );
465+
}
466+
467+
468+
public void testToArtifactNotOptional()
469+
{
470+
org.eclipse.aether.graph.DependencyNode node = new org.eclipse.aether.graph.DefaultDependencyNode(
471+
new org.eclipse.aether.graph.Dependency(
472+
new org.eclipse.aether.artifact.DefaultArtifact( "g", "a", "jar", "1.0" ), Artifact.SCOPE_SYSTEM ) );
473+
474+
Artifact artifact = BundlePlugin.toArtifact( node, new MavenProject() );
475+
476+
assertEquals( Artifact.SCOPE_SYSTEM, artifact.getScope() );
477+
assertFalse( artifact.isOptional() );
478+
}
479+
480+
481+
public void testToArtifactOfRootIsProjectArtifact()
482+
{
483+
MavenProject project = new MavenProject();
484+
Artifact projectArtifact = new org.apache.maven.artifact.DefaultArtifact( "g", "root", "2.0", null, "jar", null,
485+
new org.apache.maven.artifact.handler.DefaultArtifactHandler( "jar" ) );
486+
project.setArtifact( projectArtifact );
487+
488+
// the root of a collected graph has no dependency
489+
Artifact artifact =
490+
BundlePlugin.toArtifact( new org.eclipse.aether.graph.DefaultDependencyNode( ( org.eclipse.aether.graph.Dependency ) null ), project );
491+
492+
assertSame( projectArtifact, artifact );
493+
}
448494

449495
}

0 commit comments

Comments
 (0)