TychoMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant { protected void validateConsistentTychoVersion(List<MavenProject> projects) throws MavenExecutionException { Map<String, Set<MavenProject>> versionToProjectsMap = new HashMap<>(); 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(); if (version == null) { continue; } log.debug(TYCHO_GROUPID + ":" + plugin.getArtifactId() + ":" + version + " configured in " + project); Set<MavenProject> projectSet = versionToProjectsMap.get(version); if (projectSet == null) { projectSet = new LinkedHashSet<>(); versionToProjectsMap.put(version, projectSet); } projectSet.add(project); } } } if (versionToProjectsMap.size() > 1) { List<String> versions = new ArrayList<>(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()); } } TychoMavenLifecycleParticipant(); protected  TychoMavenLifecycleParticipant(Logger log); @Override void afterProjectsRead(MavenSession session);  }
@Test public void validateConsistentTychoVersionWithSameVersion() throws MavenExecutionException { TychoMavenLifecycleParticipant tycho = new TychoMavenLifecycleParticipant(new SilentLog()); MavenProject project = createProject(); addTychoPlugin(project, "tycho-packaging-plugin", "0.22.0"); addTychoPlugin(project, "tycho-versions-plugin", "0.22.0"); tycho.validateConsistentTychoVersion(Arrays.asList(project)); }
@Test public void validateConsistentTychoVersionWithNullAsVersion() throws MavenExecutionException { TychoMavenLifecycleParticipant tycho = new TychoMavenLifecycleParticipant(new SilentLog()); MavenProject project = createProject(); addTychoPlugin(project, "tycho-packaging-plugin", null); addTychoPlugin(project, "tycho-versions-plugin", "0.23.0"); tycho.validateConsistentTychoVersion(Arrays.asList(project)); }
@Test(expected = MavenExecutionException.class) public void validateConsistentTychoVersionWithDifferentVersionsInSameProject() throws MavenExecutionException { TychoMavenLifecycleParticipant tycho = new TychoMavenLifecycleParticipant(new SilentLog()); MavenProject project = createProject(); addTychoPlugin(project, "tycho-packaging-plugin", "0.22.0"); addTychoPlugin(project, "tycho-versions-plugin", "0.23.0"); tycho.validateConsistentTychoVersion(Arrays.asList(project)); }
@Test(expected = MavenExecutionException.class) public void validateConsistentTychoVersionWithDifferentVersionsInDifferentProjects() throws MavenExecutionException { TychoMavenLifecycleParticipant tycho = new TychoMavenLifecycleParticipant(new SilentLog()); MavenProject project1 = createProject(); addTychoPlugin(project1, "tycho-packaging-plugin", "0.22.0"); MavenProject project2 = createProject(); addTychoPlugin(project2, "tycho-versions-plugin", "0.23.0"); tycho.validateConsistentTychoVersion(Arrays.asList(project1, project2)); }