Search in sources :

Example 16 with ArtifactCoordinates

use of com.itemis.maven.aether.ArtifactCoordinates in project unleash-maven-plugin by shillner.

the class TagScm method init.

private void init() {
    this.scmProvider = this.scmProviderRegistry.getProvider();
    Map<ReleasePhase, ArtifactCoordinates> coordinates = this.metadata.getArtifactCoordinatesByPhase(this.project.getGroupId(), this.project.getArtifactId());
    ArtifactCoordinates postReleaseCoordinates = coordinates.get(ReleasePhase.RELEASE);
    this.globalReleaseVersion = postReleaseCoordinates.getVersion();
    this.cachedPOMs = Maps.newHashMap();
}
Also used : ReleasePhase(com.itemis.maven.plugins.unleash.ReleasePhase) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates)

Example 17 with ArtifactCoordinates

use of com.itemis.maven.aether.ArtifactCoordinates in project unleash-maven-plugin by shillner.

the class AbstractTychoVersionsStep method rollback.

@RollbackOnError
public void rollback() throws MojoExecutionException, MojoFailureException {
    VersionsEngine versionsEngine = initializeVersionsEngine();
    try {
        // first add all module version changes to the versions engine of tycho and execute the change command
        for (MavenProject module : this.reactorProjects) {
            String version = this.cachedModuleVersions.get(ProjectToCoordinates.EMPTY_VERSION.apply(module));
            versionsEngine.addVersionChange(module.getArtifactId(), version);
        }
        versionsEngine.apply();
        // second step is to revert all pom changes by simply replacing the poms
        for (MavenProject module : this.reactorProjects) {
            this.log.debug("\tRolling back modifications on POM of module '" + ProjectToString.INSTANCE.apply(this.project) + "'");
            ArtifactCoordinates coordinates = ProjectToCoordinates.EMPTY_VERSION.apply(module);
            Document document = this.cachedPOMs.get(coordinates);
            if (document != null) {
                try {
                    PomUtil.writePOM(document, this.project);
                } catch (Throwable t) {
                    throw new MojoExecutionException("Could not revert the version update after a failed release build.", t);
                }
            }
            String version = this.cachedModuleVersions.get(coordinates);
            if (module.getModel().getVersion() != null) {
                module.getModel().setVersion(version);
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Could not revert the version update after a failed release build.", e);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) ProjectToString(com.itemis.maven.plugins.unleash.util.functions.ProjectToString) IOException(java.io.IOException) VersionsEngine(org.eclipse.tycho.versions.engine.VersionsEngine) Document(org.w3c.dom.Document) RollbackOnError(com.itemis.maven.plugins.cdi.annotations.RollbackOnError)

Example 18 with ArtifactCoordinates

use of com.itemis.maven.aether.ArtifactCoordinates in project unleash-maven-plugin by shillner.

the class CheckAether method execute.

@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
    this.log.info("Checking aether for already released artifacts of modules that are scheduled for release.");
    this.log.debug("\t=> If any of the modules had already been released with the corresponding release version, the release build will fail fast at this point.");
    Collection<MavenProject> snapshotProjects = Collections2.filter(this.reactorProjects, IsSnapshotProject.INSTANCE);
    Map<ArtifactCoordinates, String> remotelyReleasedProjects = Maps.newHashMap();
    List<ArtifactCoordinates> locallyReleasedProjects = Lists.newArrayList();
    for (MavenProject p : snapshotProjects) {
        this.log.debug("\tChecking module '" + ProjectToString.INSTANCE.apply(p) + "'");
        ArtifactCoordinates calculatedCoordinates = this.metadata.getArtifactCoordinatesByPhase(p.getGroupId(), p.getArtifactId()).get(ReleasePhase.RELEASE);
        Optional<ResolutionResult> remoteResolvedArtifact = resolve(calculatedCoordinates.getGroupId(), calculatedCoordinates.getArtifactId(), calculatedCoordinates.getVersion(), true);
        if (remoteResolvedArtifact.isPresent()) {
            remotelyReleasedProjects.put(calculatedCoordinates, remoteResolvedArtifact.get().getRepositoryId());
        } else if (resolve(calculatedCoordinates.getGroupId(), calculatedCoordinates.getArtifactId(), calculatedCoordinates.getVersion(), false).isPresent()) {
            locallyReleasedProjects.add(calculatedCoordinates);
        }
    }
    handleRemoteReleases(remotelyReleasedProjects);
    handleLocalReleases(locallyReleasedProjects);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ResolutionResult(com.itemis.maven.aether.ArtifactResolver.ResolutionResult) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) ProjectToString(com.itemis.maven.plugins.unleash.util.functions.ProjectToString)

Example 19 with ArtifactCoordinates

use of com.itemis.maven.aether.ArtifactCoordinates 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 20 with ArtifactCoordinates

use of com.itemis.maven.aether.ArtifactCoordinates 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)

Aggregations

ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)29 ProjectToString (com.itemis.maven.plugins.unleash.util.functions.ProjectToString)12 MavenProject (org.apache.maven.project.MavenProject)11 ReleasePhase (com.itemis.maven.plugins.unleash.ReleasePhase)9 PomPropertyResolver (com.itemis.maven.plugins.unleash.util.PomPropertyResolver)6 IsSnapshotDependency (com.itemis.maven.plugins.unleash.util.predicates.IsSnapshotDependency)6 Dependency (org.apache.maven.model.Dependency)6 Plugin (org.apache.maven.model.Plugin)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 Profile (org.apache.maven.model.Profile)3 ResolutionResult (com.itemis.maven.aether.ArtifactResolver.ResolutionResult)2 IOException (java.io.IOException)2 Build (org.apache.maven.model.Build)2 BuildBase (org.apache.maven.model.BuildBase)2 Parent (org.apache.maven.model.Parent)2 PluginManagement (org.apache.maven.model.PluginManagement)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 VersionsEngine (org.eclipse.tycho.versions.engine.VersionsEngine)2 Document (org.w3c.dom.Document)2 HashMultimap (com.google.common.collect.HashMultimap)1