use of com.itemis.maven.plugins.unleash.util.PomPropertyResolver in project unleash-maven-plugin by shillner.
the class CheckPluginDependencyVersions method execute.
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
this.log.info("Checking that none of the reactor project's plugins contain SNAPSHOT dependencies.");
Map<MavenProject, PomPropertyResolver> propertyResolvers = Maps.newHashMapWithExpectedSize(this.reactorProjects.size());
Map<MavenProject, Multimap<ArtifactCoordinates, ArtifactCoordinates>> snapshotsByProjectAndPlugin = Maps.newHashMapWithExpectedSize(this.reactorProjects.size());
boolean hasSnapshots = false;
for (MavenProject project : this.reactorProjects) {
this.log.debug("\tChecking plugin dependencies of reactor project '" + ProjectToString.INSTANCE.apply(project) + "':");
PomPropertyResolver propertyResolver = new PomPropertyResolver(project, this.settings, this.profiles, this.releaseArgs);
propertyResolvers.put(project, propertyResolver);
Multimap<ArtifactCoordinates, ArtifactCoordinates> snapshots = HashMultimap.create();
snapshots.putAll(getSnapshotsFromManagement(project, propertyResolver));
snapshots.putAll(getSnapshots(project, propertyResolver));
snapshots.putAll(getSnapshotsFromAllProfiles(project, propertyResolver));
removePluginForIntegrationTests(snapshots);
snapshotsByProjectAndPlugin.put(project, snapshots);
if (!snapshots.isEmpty()) {
hasSnapshots = true;
}
}
failIfSnapshotsAreReferenced(hasSnapshots, snapshotsByProjectAndPlugin, propertyResolvers);
}
use of com.itemis.maven.plugins.unleash.util.PomPropertyResolver in project unleash-maven-plugin by shillner.
the class ReleaseMetadata method init.
@PostConstruct
public void init() {
// setting the artifact version to a release version temporarily since the dist repository checks for a snapshot
// version of the artifact. Maybe this can be implemented in a different manner but then we would have to setup the
// repository manually
org.apache.maven.artifact.Artifact projectArtifact = this.project.getArtifact();
String oldVersion = projectArtifact.getVersion();
projectArtifact.setVersion("1");
// replace properties in remote repository URL and getting the remote repo
ArtifactRepository artifactRepository = this.project.getDistributionManagementArtifactRepository();
if (artifactRepository != null) {
PomPropertyResolver propertyResolver = new PomPropertyResolver(this.project, this.settings, this.profiles, this.releaseArgs);
artifactRepository.setUrl(propertyResolver.expandPropertyReferences(artifactRepository.getUrl()));
this.deploymentRepository = RepositoryUtils.toRepo(artifactRepository);
}
// resetting the artifact version
projectArtifact.setVersion(oldVersion);
for (MavenProject p : this.reactorProjects) {
// puts the initial module artifact coordinates into the cache
addArtifactCoordinates(ProjectToCoordinates.POM.apply(p), ReleasePhase.PRE_RELEASE);
// caching of SCM settings of every POM in order to go back to it before setting next dev version
this.cachedScmSettings.put(ProjectToCoordinates.EMPTY_VERSION.apply(p), p.getModel().getScm());
Optional<Document> parsedPOM = PomUtil.parsePOM(p);
if (parsedPOM.isPresent()) {
this.originalPOMs.put(ProjectToCoordinates.EMPTY_VERSION.apply(p), parsedPOM.get());
}
}
}
use of com.itemis.maven.plugins.unleash.util.PomPropertyResolver in project unleash-maven-plugin by shillner.
the class CheckDependencyVersions method execute.
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
this.log.info("Checking that none of the reactor projects contain SNAPSHOT dependencies.");
Map<MavenProject, PomPropertyResolver> propertyResolvers = Maps.newHashMapWithExpectedSize(this.reactorProjects.size());
Multimap<MavenProject, ArtifactCoordinates> snapshotsByProject = HashMultimap.create();
for (MavenProject project : this.reactorProjects) {
this.log.debug("\tChecking dependencies of reactor project '" + ProjectToString.INSTANCE.apply(project) + "':");
PomPropertyResolver propertyResolver = new PomPropertyResolver(project, this.settings, this.profiles, this.releaseArgs);
propertyResolvers.put(project, propertyResolver);
snapshotsByProject.putAll(project, getSnapshotsFromManagement(project, propertyResolver));
snapshotsByProject.putAll(project, getSnapshots(project, propertyResolver));
snapshotsByProject.putAll(project, getSnapshotsFromAllProfiles(project, propertyResolver));
}
failIfSnapshotsAreReferenced(snapshotsByProject, propertyResolvers);
}
use of com.itemis.maven.plugins.unleash.util.PomPropertyResolver in project unleash-maven-plugin by shillner.
the class CheckDependencyVersions method failIfSnapshotsAreReferenced.
private void failIfSnapshotsAreReferenced(Multimap<MavenProject, ArtifactCoordinates> snapshotsByProject, Map<MavenProject, PomPropertyResolver> propertyResolvers) throws MojoFailureException {
if (!snapshotsByProject.values().isEmpty()) {
this.log.error("\tThere are SNAPSHOT dependency references! The following list contains all SNAPSHOT dependencies grouped by module:");
for (MavenProject p : snapshotsByProject.keySet()) {
PomPropertyResolver propertyResolver = propertyResolvers.get(p);
Collection<ArtifactCoordinates> snapshots = snapshotsByProject.get(p);
if (!snapshots.isEmpty()) {
this.log.error("\t\t[PROJECT] " + ProjectToString.INSTANCE.apply(p));
for (ArtifactCoordinates dependency : snapshots) {
String resolvedVersion = propertyResolver.expandPropertyReferences(dependency.getVersion());
String coordinates = dependency.toString();
if (!Objects.equal(resolvedVersion, dependency.getVersion())) {
coordinates = coordinates + " (resolves to " + resolvedVersion + ")";
}
this.log.error("\t\t\t[DEPENDENCY] " + coordinates);
}
}
}
throw new MojoFailureException("The project cannot be released due to one or more SNAPSHOT dependencies!");
}
}
use of com.itemis.maven.plugins.unleash.util.PomPropertyResolver in project unleash-maven-plugin by shillner.
the class CheckPluginDependencyVersions method failIfSnapshotsAreReferenced.
private void failIfSnapshotsAreReferenced(boolean hasSnapshots, Map<MavenProject, Multimap<ArtifactCoordinates, ArtifactCoordinates>> snapshotsByProjectAndPlugin, Map<MavenProject, PomPropertyResolver> propertyResolvers) throws MojoFailureException {
if (hasSnapshots) {
this.log.error("\tThere are plugins with SNAPSHOT dependencies! The following list contains all SNAPSHOT dependencies grouped by plugin and module:");
for (MavenProject p : snapshotsByProjectAndPlugin.keySet()) {
PomPropertyResolver propertyResolver = propertyResolvers.get(p);
Multimap<ArtifactCoordinates, ArtifactCoordinates> snapshots = snapshotsByProjectAndPlugin.get(p);
if (!snapshots.isEmpty()) {
this.log.error("\t\t[PROJECT] " + ProjectToString.INSTANCE.apply(p));
for (ArtifactCoordinates plugin : snapshots.keySet()) {
this.log.error("\t\t\t[PLUGIN] " + plugin);
for (ArtifactCoordinates dependency : snapshots.get(plugin)) {
String resolvedVersion = propertyResolver.expandPropertyReferences(dependency.getVersion());
String coordinates = dependency.toString();
if (!Objects.equal(resolvedVersion, dependency.getVersion())) {
coordinates = coordinates + " (resolves to " + resolvedVersion + ")";
}
this.log.error("\t\t\t\t[DEPENDENCY] " + coordinates);
}
}
}
}
throw new MojoFailureException("The project cannot be released due to one or more SNAPSHOT plugin-dependencies!");
}
}
Aggregations