aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Gradl2011-08-17 10:48:30 (EDT)
committerjsievers2011-09-23 05:20:50 (EDT)
commit64e98e551473961e420fd4de4f5f95bca9d0c513 (patch)
treeb26c436b43d00404e793d74fa237cb5521e70b6a
parent25a11ba5099d30c1eb0d62fbd13284ba046ef329 (diff)
downloadorg.eclipse.tycho-64e98e551473961e420fd4de4f5f95bca9d0c513.zip
org.eclipse.tycho-64e98e551473961e420fd4de4f5f95bca9d0c513.tar.gz
org.eclipse.tycho-64e98e551473961e420fd4de4f5f95bca9d0c513.tar.bz2
353384 Enforce artifactId = bundle/feature ID
A validate-id goal has been added to the default lifecycle of eclipse-plugin, eclipse-test-plugin and eclipse-feature. The corresponding Mojo checks that the artifactId matches the ids given in MANIFEST.MF or feature.xml
-rw-r--r--tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml3
-rw-r--r--tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/AbstractVersionMojo.java14
-rw-r--r--tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/ValidateIdMojo.java34
-rw-r--r--tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/ValidateIdTest.java81
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/META-INF/MANIFEST.MF5
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/pom.xml24
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/feature.xml7
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/pom.xml24
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/META-INF/MANIFEST.MF5
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/pom.xml24
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/META-INF/MANIFEST.MF5
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/pom.xml24
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/feature.xml7
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/pom.xml24
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/META-INF/MANIFEST.MF5
-rw-r--r--tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/pom.xml24
16 files changed, 308 insertions, 2 deletions
diff --git a/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml b/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml
index 5bed85a..c7d20c4 100644
--- a/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml
+++ b/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml
@@ -14,6 +14,7 @@
<phases>
<validate>
org.eclipse.tycho:tycho-packaging-plugin:${project.version}:build-qualifier,
+ org.eclipse.tycho:tycho-packaging-plugin:${project.version}:validate-id,
org.eclipse.tycho:tycho-packaging-plugin:${project.version}:validate-version
</validate>
<process-resources>
@@ -75,6 +76,7 @@
<phases>
<validate>
org.eclipse.tycho:tycho-packaging-plugin:${project.version}:build-qualifier,
+ org.eclipse.tycho:tycho-packaging-plugin:${project.version}:validate-id,
org.eclipse.tycho:tycho-packaging-plugin:${project.version}:validate-version
</validate>
<process-resources>
@@ -139,6 +141,7 @@
<phases>
<validate>
org.eclipse.tycho:tycho-packaging-plugin:${project.version}:build-qualifier,
+ org.eclipse.tycho:tycho-packaging-plugin:${project.version}:validate-id,
org.eclipse.tycho:tycho-packaging-plugin:${project.version}:validate-version
</validate>
<generate-resources>
diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/AbstractVersionMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/AbstractVersionMojo.java
index fee4915..19f2f2a 100644
--- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/AbstractVersionMojo.java
+++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/AbstractVersionMojo.java
@@ -14,6 +14,7 @@ import java.util.Map;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.project.MavenProject;
+import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.core.TychoProject;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
@@ -39,12 +40,21 @@ public abstract class AbstractVersionMojo extends AbstractMojo {
protected Map<String, TychoProject> projectTypes;
protected String getOSGiVersion() {
+ ArtifactKey osgiArtifact = getOSGiArtifact();
+ return osgiArtifact != null ? osgiArtifact.getVersion() : null;
+ }
+
+ protected String getOSGiId() {
+ ArtifactKey osgiArtifact = getOSGiArtifact();
+ return osgiArtifact != null ? osgiArtifact.getId() : null;
+ }
+
+ private ArtifactKey getOSGiArtifact() {
TychoProject projectType = projectTypes.get(packaging);
if (projectType == null) {
return null;
}
-
- return projectType.getArtifactKey(DefaultReactorProject.adapt(project)).getVersion();
+ return projectType.getArtifactKey(DefaultReactorProject.adapt(project));
}
}
diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/ValidateIdMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/ValidateIdMojo.java
new file mode 100644
index 0000000..734e831
--- /dev/null
+++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/ValidateIdMojo.java
@@ -0,0 +1,34 @@
+package org.eclipse.tycho.buildversion;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.eclipse.tycho.ArtifactKey;
+
+/**
+ * Validates that project Maven and OSGi ids match.
+ *
+ * @goal validate-id
+ * @phase validate
+ */
+
+public class ValidateIdMojo extends AbstractVersionMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (!project.getArtifactId().equals(getOSGiId())) {
+ failBuildDueToIdMismatch();
+ }
+ }
+
+ private void failBuildDueToIdMismatch() throws MojoExecutionException {
+ if (ArtifactKey.TYPE_ECLIPSE_FEATURE.equals(project.getPackaging())) {
+ throw new MojoExecutionException(mismatchMessageFor("feature ID"));
+ } else {
+ throw new MojoExecutionException(mismatchMessageFor("bundle symbolic name"));
+ }
+ }
+
+ private String mismatchMessageFor(String eclipseIdKey) {
+ return String.format("The Maven artifactId (currently: \"%1s\") must be the same as the " + eclipseIdKey
+ + " (currently: \"%2s\")", project.getArtifactId(), getOSGiId());
+ }
+}
diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/ValidateIdTest.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/ValidateIdTest.java
new file mode 100644
index 0000000..cb94f9e
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/ValidateIdTest.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 Sonatype Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tycho.buildversion;
+
+import java.io.File;
+
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.tycho.testing.AbstractTychoMojoTestCase;
+
+public class ValidateIdTest extends AbstractTychoMojoTestCase {
+
+ public void testValidateMatchingIdBundle() throws MojoExecutionException, Exception {
+ File basedir = getBasedir("projects/matchingIds/bundle");
+ ValidateIdMojo mojo = getMojo(basedir);
+ mojo.execute();
+ }
+
+ public void testValidateMatchingIdTestPlugin() throws MojoExecutionException, Exception {
+ File basedir = getBasedir("projects/matchingIds/test-plugin");
+ ValidateIdMojo mojo = getMojo(basedir);
+ mojo.execute();
+ }
+
+ public void testValidateMatchingIdFeature() throws MojoExecutionException, Exception {
+ File basedir = getBasedir("projects/matchingIds/feature");
+ ValidateIdMojo mojo = getMojo(basedir);
+ mojo.execute();
+ }
+
+ public void testFailIfNonMatchingIdBundle() throws MojoExecutionException, Exception {
+ File basedir = getBasedir("projects/nonMatchingIds/bundle");
+ ValidateIdMojo mojo = getMojo(basedir);
+ assertMojoExecutionExceptionThrown(mojo);
+ }
+
+ public void testFailIfNonMatchingIdTestPlugin() throws MojoExecutionException, Exception {
+ File basedir = getBasedir("projects/nonMatchingIds/test-plugin");
+ ValidateIdMojo mojo = getMojo(basedir);
+ assertMojoExecutionExceptionThrown(mojo);
+ }
+
+ public void testFailIfNonMatchingIdFeature() throws MojoExecutionException, Exception {
+ File basedir = getBasedir("projects/nonMatchingIds/feature");
+ ValidateIdMojo mojo = getMojo(basedir);
+ assertMojoExecutionExceptionThrown(mojo);
+ }
+
+ private void assertMojoExecutionExceptionThrown(ValidateIdMojo mojo) throws MojoFailureException {
+ try {
+ mojo.execute();
+ fail();
+ } catch (MojoExecutionException e) {
+ // expected
+ }
+ }
+
+ private ValidateIdMojo getMojo(File basedir) throws Exception {
+ File pom = new File(basedir, "pom.xml");
+ MavenExecutionRequest request = newMavenExecutionRequest(pom);
+ request.getProjectBuildingRequest().setProcessPlugins(false);
+ MavenExecutionResult result = maven.execute(request);
+ MavenProject project = result.getProject();
+ ValidateIdMojo mojo = (ValidateIdMojo) lookupMojo("validate-id", project.getFile());
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "packaging", project.getPackaging());
+ return mojo;
+ }
+
+}
diff --git a/tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/META-INF/MANIFEST.MF b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..2389db2
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: bundle;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-ClassPath: .
+Bundle-Name: bundle
diff --git a/tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/pom.xml b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/pom.xml
new file mode 100644
index 0000000..b677af0
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/bundle/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>matchingIds</groupId>
+ <artifactId>bundle</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-packaging-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/feature.xml b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/feature.xml
new file mode 100644
index 0000000..d91bb9d
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/feature.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="feature"
+ label="Feature"
+ version="1.0.0.qualifier">
+
+</feature>
diff --git a/tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/pom.xml b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/pom.xml
new file mode 100644
index 0000000..4bd1856
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/feature/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>matchingIds</groupId>
+ <artifactId>feature</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>eclipse-feature</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-packaging-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/META-INF/MANIFEST.MF b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..8677c6d
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: testbundle;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-ClassPath: .
+Bundle-Name: testbundle
diff --git a/tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/pom.xml b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/pom.xml
new file mode 100644
index 0000000..fa267f9
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/matchingIds/test-plugin/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>matchingIds</groupId>
+ <artifactId>testbundle</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>eclipse-test-plugin</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-packaging-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/META-INF/MANIFEST.MF b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..7add1f1
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: differentSymbolicName;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-ClassPath: .
+Bundle-Name: differentName
diff --git a/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/pom.xml b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/pom.xml
new file mode 100644
index 0000000..b677af0
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/bundle/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>matchingIds</groupId>
+ <artifactId>bundle</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-packaging-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/feature.xml b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/feature.xml
new file mode 100644
index 0000000..3d7d451
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/feature.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="differentId"
+ label="Feature"
+ version="1.0.0.qualifier">
+
+</feature>
diff --git a/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/pom.xml b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/pom.xml
new file mode 100644
index 0000000..4bd1856
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/feature/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>matchingIds</groupId>
+ <artifactId>feature</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>eclipse-feature</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-packaging-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/META-INF/MANIFEST.MF b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..aaa67b1
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: otherName;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-ClassPath: .
+Bundle-Name: testbundle
diff --git a/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/pom.xml b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/pom.xml
new file mode 100644
index 0000000..fa267f9
--- /dev/null
+++ b/tycho-packaging-plugin/src/test/resources/projects/nonMatchingIds/test-plugin/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>matchingIds</groupId>
+ <artifactId>testbundle</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>eclipse-test-plugin</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-packaging-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file