Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for MRELEASE-835: Automatically resolve snapshot dependencies in release:prepare #19

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,21 @@ public interface ReleaseDescriptor
void setScmRelativePathProjectDirectory( String scmRelativePathProjectDirectory );

void setScmSourceUrl( String scmUrl );

/**
* Returns whether unresolved SNAPSHOT dependencies should automatically be resolved.
* If this is set, then this specifies the default answer to be used when unresolved SNAPSHOT
* dependencies should automatically be resolved ( 0:All 1:Project Dependencies 2:Plugins
* 3:Reports 4:Extensions ). Possible values are:
* <ul>
* <li>"all" or "0": resolve all kinds of snapshots, ie. project, plugin, report and extension dependencies </li>
* <li>"dependencies" or "1": resolve project dependencies</li>
* <li>"plugins" or "2": resolve plugin dependencis</li>
* <li>"reports" or "3": resolve report dependencies</li>
* <li>"extensions" or "4": resolve extension dependencies</li>
* </ul>
*
* @return String
*/
String getAutoResolveSnapshots();
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ public void write( BuilderReleaseDescriptor config, File file )
properties.setProperty( "workItem", config.getWorkItem() );
}

if ( config.getAutoResolveSnapshots() != null )
{
properties.setProperty( "autoResolveSnapshots", config.getAutoResolveSnapshots() );
}

// others boolean properties are not written to the properties file because the value from the caller is always
// used

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependen
return this;
}

public ReleaseDescriptorBuilder setAutoResolveSnapshots( String autoResolveSnapshots )
{
releaseDescriptor.setAutoResolveSnapshots( autoResolveSnapshots );
return this;
}

BuilderReleaseDescriptor build()
{
return releaseDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public static void copyPropertiesToReleaseDescriptor( Properties properties, Rel
{
builder.setWorkItem( properties.getProperty( "workItem" ) );
}
if ( properties.containsKey( "autoResolveSnapshots" ) )
{
String resolve = properties.getProperty( "autoResolveSnapshots" );
builder.setAutoResolveSnapshots( resolve );
}

loadResolvedDependencies( properties, builder );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void checkProject( MavenProject project, ReleaseDescriptor releaseDescri
if ( !usedSnapshotDependencies.isEmpty() || !usedSnapshotReports.isEmpty()
|| !usedSnapshotExtensions.isEmpty() || !usedSnapshotPlugins.isEmpty() )
{
if ( releaseDescriptor.isInteractive() )
if ( releaseDescriptor.isInteractive() || null != releaseDescriptor.getAutoResolveSnapshots() )
{
resolveSnapshots( usedSnapshotDependencies, usedSnapshotReports, usedSnapshotExtensions,
usedSnapshotPlugins, releaseDescriptor );
Expand Down Expand Up @@ -365,49 +365,101 @@ private void resolveSnapshots( Set<Artifact> projectDependencies, Set<Artifact>
{
try
{
String autoResolveSnapshots = releaseDescriptor.getAutoResolveSnapshots();
if ( resolveSnapshot == null )
{
prompter.showMessage( RESOLVE_SNAPSHOT_MESSAGE );
resolveSnapshot = prompter.prompt( RESOLVE_SNAPSHOT_PROMPT, Arrays.asList( "yes", "no" ), "no" );
if ( autoResolveSnapshots != null )
{
resolveSnapshot = "yes";
prompter.showMessage( RESOLVE_SNAPSHOT_PROMPT + " " + resolveSnapshot );
}
else
{
resolveSnapshot = prompter.prompt( RESOLVE_SNAPSHOT_PROMPT, Arrays.asList( "yes", "no" ), "no" );
}
}

if ( resolveSnapshot.toLowerCase( Locale.ENGLISH ).startsWith( "y" ) )
{
if ( resolveSnapshotType == null )
{
prompter.showMessage( RESOLVE_SNAPSHOT_TYPE_MESSAGE );
resolveSnapshotType =
prompter.prompt( RESOLVE_SNAPSHOT_TYPE_PROMPT, Arrays.asList( "0", "1", "2", "3" ), "1" );
int defaultAnswer = -1;
if ( autoResolveSnapshots != null )
{
if ( "all".equalsIgnoreCase( autoResolveSnapshots ) )
{
defaultAnswer = 0;
}
else if ( "dependencies".equalsIgnoreCase( autoResolveSnapshots ) )
{
defaultAnswer = 1;
}
else if ( "plugins".equalsIgnoreCase( autoResolveSnapshots ) )
{
defaultAnswer = 2;
}
else if ( "reports".equalsIgnoreCase( autoResolveSnapshots ) )
{
defaultAnswer = 3;
}
else if ( "extensions".equalsIgnoreCase( autoResolveSnapshots ) )
{
defaultAnswer = 4;
}
else
{
try
{
defaultAnswer = Integer.parseInt( autoResolveSnapshots );
}
catch ( NumberFormatException e )
{
throw new ReleaseExecutionException( e.getMessage(), e );
}
}
}
if ( defaultAnswer >= 0 && defaultAnswer <= 4 )
{
prompter.showMessage( RESOLVE_SNAPSHOT_TYPE_PROMPT + " " + autoResolveSnapshots );
resolveSnapshotType = Integer.toString( defaultAnswer );
}
else
{
resolveSnapshotType =
prompter.prompt( RESOLVE_SNAPSHOT_TYPE_PROMPT, Arrays.asList( "0", "1", "2", "3" ), "1" );
}
}

switch ( Integer.parseInt( resolveSnapshotType.toLowerCase( Locale.ENGLISH ) ) )
{
// all
case 0:
processSnapshot( projectDependencies, releaseDescriptor );
processSnapshot( pluginDependencies, releaseDescriptor );
processSnapshot( reportDependencies, releaseDescriptor );
processSnapshot( extensionDependencies, releaseDescriptor );
processSnapshot( projectDependencies, releaseDescriptor, autoResolveSnapshots );
processSnapshot( pluginDependencies, releaseDescriptor, autoResolveSnapshots );
processSnapshot( reportDependencies, releaseDescriptor, autoResolveSnapshots );
processSnapshot( extensionDependencies, releaseDescriptor, autoResolveSnapshots );
break;

// project dependencies
case 1:
processSnapshot( projectDependencies, releaseDescriptor );
processSnapshot( projectDependencies, releaseDescriptor, autoResolveSnapshots );
break;

// plugins
case 2:
processSnapshot( pluginDependencies, releaseDescriptor );
processSnapshot( pluginDependencies, releaseDescriptor, autoResolveSnapshots );
break;

// reports
case 3:
processSnapshot( reportDependencies, releaseDescriptor );
processSnapshot( reportDependencies, releaseDescriptor, autoResolveSnapshots );
break;

// extensions
case 4:
processSnapshot( extensionDependencies, releaseDescriptor );
processSnapshot( extensionDependencies, releaseDescriptor, autoResolveSnapshots );
break;

default:
Expand All @@ -420,7 +472,8 @@ private void resolveSnapshots( Set<Artifact> projectDependencies, Set<Artifact>
}
}

private void processSnapshot( Set<Artifact> snapshotSet, ReleaseDescriptor releaseDescriptor )
private void processSnapshot( Set<Artifact> snapshotSet, ReleaseDescriptor releaseDescriptor,
String autoResolveSnapshots )
throws PrompterException, VersionParseException
{
Iterator<Artifact> iterator = snapshotSet.iterator();
Expand All @@ -435,8 +488,17 @@ private void processSnapshot( Set<Artifact> snapshotSet, ReleaseDescriptor relea

prompter.showMessage(
"Dependency '" + versionlessKey + "' is a snapshot (" + currentArtifact.getVersion() + ")\n" );
String result = prompter.prompt( "Which release version should it be set to?",
versionInfo.getReleaseVersionString() );
String message = "Which release version should it be set to?";
String result;
if ( null != autoResolveSnapshots )
{
result = versionInfo.getReleaseVersionString();
prompter.showMessage( message + " " + result );
}
else
{
result = prompter.prompt( message, versionInfo.getReleaseVersionString() );
}

releaseDescriptor.addDependencyReleaseVersion( versionlessKey, result );

Expand All @@ -456,7 +518,16 @@ private void processSnapshot( Set<Artifact> snapshotSet, ReleaseDescriptor relea
nextVersion = versionInfo.toString();
}

result = prompter.prompt( "What version should the dependency be reset to for development?", nextVersion );
message = "What version should the dependency be reset to for development?";
if ( null != autoResolveSnapshots )
{
result = nextVersion;
prompter.showMessage( message + " " + result );
}
else
{
result = prompter.prompt( message, nextVersion );
}

releaseDescriptor.addDependencyDevelopmentVersion( versionlessKey, result );
}
Expand Down
24 changes: 23 additions & 1 deletion maven-release-manager/src/main/mdo/release-descriptor.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,26 @@
</description>
</field>

<field>
<name>autoResolveSnapshots</name>
<version>3.0.0+</version>
<type>String</type>
<description>
<![CDATA[Specifies whether unresolved SNAPSHOT dependencies are automatically resolved.
If set, it is used as the answer to use when being asked how unresolved SNAPSHOT
dependencies should be resolved:
<ul>
<li>"all" or "0": resolve all kinds of snapshots, ie. project, plugin, report and extension dependencies</li>
<li>"dependencies" or "1": resolve project dependencies</li>
<li>"plugins" or "2": resolve plugin dependencies</li>
<li>"reports" or "3": resolve report dependencies</li>
<li>"extensions" or "4": resolve extension dependencies</li>
</ul>
Additionally this implies that the default values for the dependency's release and next
development version are used.]]>
</description>
</field>

<!-- Announcement Information

Announcement related info, this can be a second part of the process.
Expand Down Expand Up @@ -798,7 +818,8 @@
!java.util.Objects.equals( performGoals, that.getPerformGoals() ) ||
!java.util.Objects.equals( defaultReleaseVersion, that.getDefaultReleaseVersion() ) ||
!java.util.Objects.equals( workItem, that.getWorkItem() ) ||
!java.util.Objects.equals( scmReleasedPomRevision, that.getScmReleasedPomRevision() )
!java.util.Objects.equals( scmReleasedPomRevision, that.getScmReleasedPomRevision() ) ||
!java.util.Objects.equals( autoResolveSnapshots, that.getAutoResolveSnapshots() )
)
{
return false;
Expand Down Expand Up @@ -1054,6 +1075,7 @@
result = 29 * result + java.util.Objects.hashCode( defaultReleaseVersion );
result = 29 * result + java.util.Objects.hashCode( scmReleasedPomRevision );
result = 29 * result + java.util.Objects.hashCode( workItem );
result = 29 * result + java.util.Objects.hashCode( autoResolveSnapshots );

return result;
}
Expand Down
71 changes: 71 additions & 0 deletions maven-release-plugin/src/it/projects/prepare/MRELEASE-835/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.release.its</groupId>
<artifactId>mrelease-835</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<scm>
<connection>scm:dummy|nul</connection>
<developerConnection>scm:dummy|nul</developerConnection>
</scm>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<autoResolveSnapshots>dependencies</autoResolveSnapshots>
<arguments>-Dflag -Dfoo=bar</arguments>
<mavenExecutorId>invoker</mavenExecutorId>
<goals>validate</goals>
<preparationGoals>validate</preparationGoals>
<completionGoals>verify</completionGoals>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.release</groupId>
<artifactId>maven-scm-provider-dummy</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>dependency</artifactId>
<version>1.2.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>dependency.test</artifactId>
<version>2.3.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

assert 1 == buildLog.getText().count("[DEBUG] (f) autoResolveSnapshots = dependencies")

File pomXmlNext = new File( basedir, 'pom.xml.next' )
assert pomXmlNext.exists()
assert 1 == pomXmlNext.getText().count("<version>1.2.3</version>")
assert 1 == pomXmlNext.getText().count("<version>2.3.4</version>")
Loading