summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJan Sievers2012-08-08 09:30:50 (EDT)
committer Jan Sievers2012-08-08 09:42:48 (EDT)
commit305eb576d58f1adf8c8f80fee8bdca49da196816 (patch)
tree12e03d32fcb51100cafbaf61b83b4ada256d19b0
parente7289312212ba62e522c1fa40604c25a7c327378 (diff)
downloadorg.eclipse.tycho-305eb576d58f1adf8c8f80fee8bdca49da196816.zip
org.eclipse.tycho-305eb576d58f1adf8c8f80fee8bdca49da196816.tar.gz
org.eclipse.tycho-305eb576d58f1adf8c8f80fee8bdca49da196816.tar.bz2
386490 detect reactor with mixed tycho versions and fail-fastrefs/changes/38/7138/1
The maven build extension tycho-maven-plugin is merged into the maven core classloader at runtime. AFAIK the maven core classloader supports only one version per artifact. Dependencies from tycho plugins to artifacts in tycho-maven-plugin such as tycho-core are all remapped to the one single version provided by the maven core classloader. This can lead to various binary mismatch errors at runtime if several tycho versions are used. This means we cannot support several versions of tycho plugins in the same reactor. Detect this situation as early as possible and fail with a clear error message. Change-Id: Id6f9f38dd5d5a7871443c0008c82fd31d996ce77
-rw-r--r--tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java57
-rw-r--r--tycho-its/projects/multipleVersions/p1/META-INF/MANIFEST.MF4
-rw-r--r--tycho-its/projects/multipleVersions/p1/build.properties4
-rw-r--r--tycho-its/projects/multipleVersions/p1/pom.xml31
-rw-r--r--tycho-its/projects/multipleVersions/pom.xml25
-rw-r--r--tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/MixedTychoVersionsTest.java37
6 files changed, 157 insertions, 1 deletions
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java
index 0dd2fd4..3efb896 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java
@@ -11,8 +11,14 @@
package org.eclipse.tycho.core.maven;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.maven.AbstractMavenLifecycleParticipant;
@@ -21,12 +27,14 @@ import org.apache.maven.execution.AbstractExecutionListener;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.logging.Logger;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.core.osgitools.BundleReader;
@@ -36,6 +44,13 @@ import org.eclipse.tycho.resolver.TychoDependencyResolver;
@Component(role = AbstractMavenLifecycleParticipant.class, hint = "TychoMavenLifecycleListener")
public class TychoMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant {
+
+ private static final String TYCHO_GROUPID = "org.eclipse.tycho";
+ private static final Set<String> TYCHO_PLUGIN_IDS = new HashSet<String>(Arrays.asList("tycho-maven-plugin",
+ "tycho-p2-director-plugin", "tycho-p2-plugin", "tycho-p2-publisher-plugin", "tycho-p2-repository-plugin",
+ "tycho-packaging-plugin", "tycho-pomgenerator-plugin", "tycho-source-plugin", "tycho-surefire-plugin",
+ "tycho-versions-plugin"));
+
@Requirement
private BundleReader bundleReader;
@@ -45,13 +60,16 @@ public class TychoMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
@Requirement
private PlexusContainer plexus;
+ @Requirement
+ private Logger log;
+
@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
if (disableLifecycleParticipation(session)) {
return;
}
List<MavenProject> projects = session.getProjects();
- validateUniqueBaseDirs(projects);
+ validate(projects);
registerExecutionListener(session);
configureComponents(session);
@@ -65,6 +83,43 @@ public class TychoMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
}
}
+ private void validate(List<MavenProject> projects) throws MavenExecutionException {
+ validateConsistentTychoVersion(projects);
+ validateUniqueBaseDirs(projects);
+ }
+
+ private void validateConsistentTychoVersion(List<MavenProject> projects) throws MavenExecutionException {
+ Map<String, Set<MavenProject>> versionToProjectsMap = new HashMap<String, Set<MavenProject>>();
+ for (MavenProject project : projects) {
+ for (Plugin plugin : project.getBuild().getPlugins()) {
+ if (TYCHO_GROUPID.equals(plugin.getGroupId()) && TYCHO_PLUGIN_IDS.contains(plugin.getArtifactId())) {
+ String version = plugin.getVersion();
+ log.debug(TYCHO_GROUPID + ":" + plugin.getArtifactId() + ":" + version + " configured in "
+ + project);
+ Set<MavenProject> projectSet = versionToProjectsMap.get(version);
+ if (projectSet == null) {
+ projectSet = new LinkedHashSet<MavenProject>();
+ versionToProjectsMap.put(version, projectSet);
+ }
+ projectSet.add(project);
+ }
+ }
+ }
+ if (versionToProjectsMap.size() > 1) {
+ List<String> versions = new ArrayList<String>(versionToProjectsMap.keySet());
+ Collections.sort(versions);
+ log.error("Several versions of tycho plugins are configured " + versions + ":");
+ for (String version : versions) {
+ log.error(version + ":");
+ for (MavenProject project : versionToProjectsMap.get(version)) {
+ log.error("\t" + project.toString());
+ }
+ }
+ throw new MavenExecutionException("All tycho plugins configured in one reactor must use the same version",
+ projects.get(0).getFile());
+ }
+ }
+
private void validateUniqueBaseDirs(List<MavenProject> projects) throws MavenExecutionException {
// we store intermediate build results in the target/ folder and use the baseDir as unique key
// so multiple modules in the same baseDir would lead to irreproducible/unexpected results
diff --git a/tycho-its/projects/multipleVersions/p1/META-INF/MANIFEST.MF b/tycho-its/projects/multipleVersions/p1/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..383b50e
--- /dev/null
+++ b/tycho-its/projects/multipleVersions/p1/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: tychoits.multipleversions.p1
+Bundle-Version: 1.0.0.qualifier
diff --git a/tycho-its/projects/multipleVersions/p1/build.properties b/tycho-its/projects/multipleVersions/p1/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/tycho-its/projects/multipleVersions/p1/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/tycho-its/projects/multipleVersions/p1/pom.xml b/tycho-its/projects/multipleVersions/p1/pom.xml
new file mode 100644
index 0000000..dc50871
--- /dev/null
+++ b/tycho-its/projects/multipleVersions/p1/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>tychoits.multipleversions</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tychoits.multipleversions.p1</artifactId>
+ <packaging>eclipse-plugin</packaging>
+
+ <!-- use different tycho versions than in parent -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-maven-plugin</artifactId>
+ <version>0.13.0</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-source-plugin</artifactId>
+ <version>0.14.0</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tycho-its/projects/multipleVersions/pom.xml b/tycho-its/projects/multipleVersions/pom.xml
new file mode 100644
index 0000000..084ee33
--- /dev/null
+++ b/tycho-its/projects/multipleVersions/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>tychoits.multipleversions</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>p1</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-maven-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/MixedTychoVersionsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/MixedTychoVersionsTest.java
new file mode 100644
index 0000000..02efa6f
--- /dev/null
+++ b/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/MixedTychoVersionsTest.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 SAP AG 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tycho.test.buildextension;
+
+import static org.junit.Assert.fail;
+
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.eclipse.tycho.core.utils.TychoVersion;
+import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
+import org.junit.Test;
+
+public class MixedTychoVersionsTest extends AbstractTychoIntegrationTest {
+
+ @Test
+ public void testSeveralTychoVersionsConfigured() throws Exception {
+ Verifier verifier = getVerifier("multipleVersions", false);
+ try {
+ verifier.executeGoal("compile");
+ fail();
+ } catch (VerificationException e) {
+ // expected
+ verifier.verifyTextInLog("[ERROR] Several versions of tycho plugins are configured [0.13.0, 0.14.0, "
+ + TychoVersion.getTychoVersion() + "]:");
+ }
+ }
+
+}