You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/07/24 16:22:09 UTC
svn commit: r679418 - in
/servicemix/smx4/kernel/trunk/testing/features-maven-plugin: ./
src/main/java/org/apache/servicemix/tooling/features/ src/test/
src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/servicemix/ sr...
Author: gertv
Date: Thu Jul 24 07:22:08 2008
New Revision: 679418
URL: http://svn.apache.org/viewvc?rev=679418&view=rev
Log:
SMX4-49: Better handling of versions and super-bundles that wrap multiple JAR files
Added:
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/features/
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojoTest.java
Modified:
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/pom.xml
servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/main/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojo.java
Modified: servicemix/smx4/kernel/trunk/testing/features-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/testing/features-maven-plugin/pom.xml?rev=679418&r1=679417&r2=679418&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/testing/features-maven-plugin/pom.xml (original)
+++ servicemix/smx4/kernel/trunk/testing/features-maven-plugin/pom.xml Thu Jul 24 07:22:08 2008
@@ -1,54 +1,51 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <!--
-
- 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.
- -->
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.servicemix.kernel.testing</groupId>
- <artifactId>testing</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.apache.servicemix.kernel.testing</groupId>
- <artifactId>features-maven-plugin</artifactId>
- <packaging>maven-plugin</packaging>
- <version>1.0.0-SNAPSHOT</version>
- <name>Apache ServiceMix Kernel :: Testing - Features plugin</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>2.0.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>2.0.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.1</version>
- </dependency>
-
- </dependencies>
-
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <!--
+ 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.
+ -->
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.servicemix.kernel.testing</groupId>
+ <artifactId>testing</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.servicemix.kernel.testing</groupId>
+ <artifactId>features-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Apache ServiceMix Kernel :: Testing - Features plugin</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>2.5.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
Modified: servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/main/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojo.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/main/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojo.java?rev=679418&r1=679417&r2=679418&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/main/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojo.java (original)
+++ servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/main/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojo.java Thu Jul 24 07:22:08 2008
@@ -23,6 +23,7 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -37,6 +38,7 @@
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -216,24 +218,60 @@
}
private Artifact findServicemixBundle(Artifact artifact) {
- Artifact wrapper = factory.createArtifact("org.apache.servicemix.bundles",
+ Artifact noVersionWrapper = factory.createArtifact("org.apache.servicemix.bundles",
"org.apache.servicemix.bundles." + artifact.getArtifactId(),
- artifact.getVersion() + project.getProperties().getProperty("servicemix.bundle.suffix"),
+ "",
artifact.getScope(), artifact.getType());
+
try {
+ List versions = artifactMetadataSource.retrieveAvailableVersions(noVersionWrapper, localRepo, remoteRepos);
+ Artifact wrapper = factory.createArtifact("org.apache.servicemix.bundles",
+ "org.apache.servicemix.bundles." + artifact.getArtifactId(),
+ getBestVersionForArtifact(artifact, versions),
+ artifact.getScope(), artifact.getType());
// let's check if the servicemix bundle for this artifact exists
resolver.resolve(wrapper, remoteRepos, localRepo);
+ for (Artifact dependency : getDependencies(wrapper)) {
+ //some of these wrapper bundles provide for multiple JAR files, no need to include any of them after adding the wrapper
+ getLog().debug(String.format("'%s' also provides '%s'", wrapper, dependency));
+ currentFeature.add(dependency);
+ }
+ return wrapper;
} catch (ArtifactResolutionException e) {
- return null;
+ getLog().debug("Couldn't find a ServiceMix bundle for " + artifact, e);
} catch (ArtifactNotFoundException e) {
+ getLog().debug("Couldn't find a ServiceMix bundle for " + artifact, e);
+ } catch (ArtifactMetadataRetrievalException e) {
+ getLog().debug("Couldn't find a ServiceMix bundle for " + artifact, e);
+ }
+ if (artifact.getArtifactId().contains("-")) {
+ //let's try to see if we can't find a bundle wrapping multiple artifacts (e.g. mina -> mina-core, mina-codec, ...)
+ return findServicemixBundle(factory.createArtifact(artifact.getGroupId(), artifact.getArtifactId().split("-")[0],
+ artifact.getVersion(), artifact.getScope(), artifact.getType()));
+ } else {
return null;
}
- for (Artifact dependency : getDependencies(wrapper)) {
- //some of these wrapper bundles provide for multiple JAR files, no need to include any of them after adding the wrapper
- getLog().debug(String.format("'%s' also provides '%s'", wrapper, dependency));
- currentFeature.add(dependency);
+ }
+
+ protected String getBestVersionForArtifact(Artifact artifact, List<ArtifactVersion> versions) throws ArtifactMetadataRetrievalException {
+ if (versions.size() == 0) {
+ throw new ArtifactMetadataRetrievalException("No wrapper bundle available for " + artifact);
+ }
+ Collections.sort(versions, Collections.reverseOrder());
+ //check for same version
+ for (ArtifactVersion version : versions) {
+ if (version.toString().startsWith(artifact.getVersion())) {
+ return version.toString();
+ }
+ }
+ //check for same major/minor version
+ for (ArtifactVersion version : versions) {
+ String[] elements = version.toString().split("\\.");
+ if (elements.length >= 2 && artifact.getVersion().startsWith(elements[0] + "." + elements[1])) {
+ return version.toString();
+ }
}
- return wrapper;
+ throw new ArtifactMetadataRetrievalException("No suitable version found for " + artifact + " wrapper bundle");
}
private boolean isProvided(Artifact bundle) {
Added: servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojoTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojoTest.java?rev=679418&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojoTest.java (added)
+++ servicemix/smx4/kernel/trunk/testing/features-maven-plugin/src/test/java/org/apache/servicemix/tooling/features/GenerateFeaturesFileMojoTest.java Thu Jul 24 07:22:08 2008
@@ -0,0 +1,105 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.servicemix.tooling.features;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+
+/**
+ * Test cases for {@link GenerateFeaturesFileMojo}
+ */
+public class GenerateFeaturesFileMojoTest extends TestCase {
+
+ private Mockery mockery;
+ private GenerateFeaturesFileMojo mojo;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mojo = new GenerateFeaturesFileMojo();
+ mockery = new Mockery();
+ }
+
+ public void testGetBestVersionForArtifactWithOneVersion() throws Exception {
+ final Artifact artifact = mockery.mock(Artifact.class);
+ mockery.checking(new Expectations() {{
+ allowing(artifact).getVersion(); will(returnValue("2.1.6"));
+ }});
+
+ assertEquals("2.1.6_1-SNAPSHOT", mojo.getBestVersionForArtifact(artifact, createVersionList("2.1.6_1-SNAPSHOT")));
+ }
+
+ public void testGetBestVersionForArtifactWithTwoVersions() throws Exception {
+ final Artifact artifact = mockery.mock(Artifact.class);
+ mockery.checking(new Expectations() {{
+ allowing(artifact).getVersion(); will(returnValue("2.1.6"));
+ }});
+
+ assertEquals("2.1.6_2-SNAPSHOT", mojo.getBestVersionForArtifact(artifact, createVersionList("2.1.6_1-SNAPSHOT", "2.1.6_2-SNAPSHOT")));
+ }
+
+ public void testGetBestVersionForArtifactWithSameMajorMinor() throws Exception {
+ final Artifact artifact = mockery.mock(Artifact.class);
+ mockery.checking(new Expectations() {{
+ allowing(artifact).getVersion(); will(returnValue("3.8.2"));
+ }});
+
+ assertEquals("3.8.1_1-SNAPSHOT", mojo.getBestVersionForArtifact(artifact, createVersionList("3.8.1_1-SNAPSHOT")));
+ }
+
+
+ public void testGetBestVersionForArtifactWithOneNonMatchingVersion() throws Exception {
+ final Artifact artifact = mockery.mock(Artifact.class);
+ mockery.checking(new Expectations() {{
+ allowing(artifact).getVersion(); will(returnValue("9.1.0.1"));
+ }});
+
+ try {
+ mojo.getBestVersionForArtifact(artifact, createVersionList("9.0_1-SNAPSHOT"));
+ fail("ArtifactMetadataRetrievalException should have been thrown if no matching version was found");
+ } catch (ArtifactMetadataRetrievalException e) {
+ // this is expected
+ }
+ }
+
+ public void testGetBestVersionForArtifactWithNoVersions() throws Exception {
+ try {
+ mojo.getBestVersionForArtifact(mockery.mock(Artifact.class), createVersionList());
+ fail("ArtifactMetadataRetrievalException should have been thrown if no matching version was found");
+ } catch (ArtifactMetadataRetrievalException e) {
+ // this is expected
+ }
+ }
+
+ private List<ArtifactVersion> createVersionList(String... versions) {
+ List<ArtifactVersion> results = new ArrayList<ArtifactVersion>();
+ for (final String version : versions) {
+ results.add(new DefaultArtifactVersion(version));
+ }
+ return results;
+ }
+}