Search in sources :

Example 1 with PomPropertyResolver

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);
}
Also used : Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) PomPropertyResolver(com.itemis.maven.plugins.unleash.util.PomPropertyResolver) MavenProject(org.apache.maven.project.MavenProject) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates)

Example 2 with PomPropertyResolver

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());
        }
    }
}
Also used : PomPropertyResolver(com.itemis.maven.plugins.unleash.util.PomPropertyResolver) MavenProject(org.apache.maven.project.MavenProject) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Document(org.w3c.dom.Document) PostConstruct(javax.annotation.PostConstruct)

Example 3 with PomPropertyResolver

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);
}
Also used : PomPropertyResolver(com.itemis.maven.plugins.unleash.util.PomPropertyResolver) MavenProject(org.apache.maven.project.MavenProject) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates)

Example 4 with PomPropertyResolver

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!");
    }
}
Also used : PomPropertyResolver(com.itemis.maven.plugins.unleash.util.PomPropertyResolver) MavenProject(org.apache.maven.project.MavenProject) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) ProjectToString(com.itemis.maven.plugins.unleash.util.functions.ProjectToString)

Example 5 with PomPropertyResolver

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!");
    }
}
Also used : PomPropertyResolver(com.itemis.maven.plugins.unleash.util.PomPropertyResolver) MavenProject(org.apache.maven.project.MavenProject) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) ProjectToString(com.itemis.maven.plugins.unleash.util.functions.ProjectToString)

Aggregations

PomPropertyResolver (com.itemis.maven.plugins.unleash.util.PomPropertyResolver)7 MavenProject (org.apache.maven.project.MavenProject)7 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)6 ProjectToString (com.itemis.maven.plugins.unleash.util.functions.ProjectToString)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 PostConstruct (javax.annotation.PostConstruct)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 Document (org.w3c.dom.Document)1