-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XIVY-10541 Detect different plugin versions and throw error if so
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/ch/ivyteam/ivy/maven/validate/ValidateMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ch.ivyteam.ivy.maven.validate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.project.MavenProject; | ||
|
||
@Mojo(name = ValidateMojo.GOAL, requiresProject = true) | ||
public class ValidateMojo extends AbstractMojo { | ||
|
||
public static final String GOAL = "validate"; | ||
private static final String PLUGIN_GROUPID = "com.axonivy.ivy.ci"; | ||
private static final String PLUGIN_ARTIFACTID = "project-build-plugin"; | ||
|
||
@Parameter(defaultValue = "${session}", readonly = true, required = true) | ||
private MavenSession session; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
validateConsistentPluginVersion(session.getAllProjects()); | ||
} | ||
|
||
protected void validateConsistentPluginVersion(List<MavenProject> projects) throws MojoExecutionException { | ||
Map<String, Set<MavenProject>> versionToProjectsMap = new HashMap<>(); | ||
for (var project : projects) { | ||
for (var plugin : project.getBuild().getPlugins()) { | ||
if (PLUGIN_GROUPID.equals(plugin.getGroupId()) && PLUGIN_ARTIFACTID.equals(plugin.getArtifactId())) { | ||
var version = plugin.getVersion(); | ||
// Skip checking plug ins that do not have a version | ||
if (version == null) { | ||
continue; | ||
} | ||
getLog().debug(PLUGIN_GROUPID + ":" + plugin.getArtifactId() + ":" + version + " configured in " + project); | ||
var projectSet = versionToProjectsMap.get(version); | ||
if (projectSet == null) { | ||
projectSet = new LinkedHashSet<>(); | ||
versionToProjectsMap.put(version, projectSet); | ||
} | ||
projectSet.add(project); | ||
} | ||
} | ||
} | ||
if (versionToProjectsMap.size() > 1) { | ||
var versions = new ArrayList<>(versionToProjectsMap.keySet()); | ||
Collections.sort(versions); | ||
getLog().error("Several versions of project-build-plugins are configured " + versions + ":"); | ||
for (var version : versions) { | ||
getLog().error(version + ":"); | ||
for (var project : versionToProjectsMap.get(version)) { | ||
getLog().error("\t" + project.toString()); | ||
} | ||
} | ||
throw new MojoExecutionException("All project-build-plugins configured in one reactor must use the same version"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters