Skip to content

Commit

Permalink
Merge pull request #67 from thokuest/release-props-from-command-line
Browse files Browse the repository at this point in the history
Issue #44 Release version and new version as build parameters
  • Loading branch information
townsfolk committed Nov 29, 2013
2 parents bfb497f + 9dd158d commit 65cb6b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ This means the gradle-release plugin does not support sub projects that have dif

In a continuous integration environment like Jenkins or Hudson, you don't want to have an interactive release process. To avoid having to enter any information manually during the process, you can tell the plugin to automatically set and update the version number.

You can do this by setting the 'gradle.release.useAutomaticVersion' property on the command line, or in Jenkins when you execute gradle.
You can do this by setting the `gradle.release.useAutomaticVersion` property on the command line, or in Jenkins when you execute gradle. The version to release and the next version can be optionally defined using the properties `releaseVersion` and `nextVersion`.

-Pgradle.release.useAutomaticVersion=true -PreleaseVersion=1.0.0 -PnewVersion=1.1.0-SNAPSHOT

-Pgradle.release.useAutomaticVersion=true

## Getting Help

Expand Down
41 changes: 25 additions & 16 deletions src/main/groovy/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package release

import java.util.regex.Matcher

import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -8,15 +10,12 @@ import org.gradle.api.artifacts.Dependency
import org.gradle.api.tasks.GradleBuild
import org.gradle.api.tasks.TaskState

import java.util.regex.Matcher

/**
* @author elberry
* @author evgenyg
* Created: Tue Aug 09 15:32:00 PDT 2011
*/
class ReleasePlugin extends PluginHelper implements Plugin<Project> {

static final String RELEASE_GROUP = "Release"

@SuppressWarnings('StatelessClass')
Expand Down Expand Up @@ -94,15 +93,12 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
}
}


void initScmPlugin() {
checkPropertiesFile()
scmPlugin.init()
}


void checkSnapshotDependencies() {

def matcher = { Dependency d -> d.version?.contains('SNAPSHOT') }
def collector = { Dependency d -> "${d.group ?: ''}:${d.name}:${d.version ?: ''}" }

Expand Down Expand Up @@ -134,13 +130,19 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
}

void confirmReleaseVersion() {
def version = "$project.version"
if (!useAutomaticVersion()) {
version = readLine("This release version:", version)
}
def version = getReleaseVersion();
updateVersionProperty(version)
}

String getReleaseVersion(String candidateVersion = "${project.version}") {
String releaseVersion = project.properties['releaseVersion'];

if (useAutomaticVersion()) {
return releaseVersion ?: candidateVersion;
}

return readLine("This release version:", releaseVersion ?: candidateVersion);
}

void unSnapshotVersion() {
def version = project.version.toString()
Expand All @@ -155,7 +157,6 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
}
}


void preTagCommit() {
if (project.properties['usesSnapshot'] || project.properties['versionModified']) {
// should only be committed if the project was using a snapshot version.
Expand All @@ -169,7 +170,6 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
}
}


void updateVersion() {
def version = project.version.toString()
Map<String, Closure> patterns = releaseConvention().versionPatterns
Expand All @@ -186,9 +186,9 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
if (project.properties['usesSnapshot']) {
nextVersion += '-SNAPSHOT'
}
if (!useAutomaticVersion()) {
nextVersion = readLine("Enter the next version (current one released as [$version]):", nextVersion)
}

nextVersion = getNextVersion(nextVersion);

project.ext.set("release.oldVersion", project.version)
project.ext.set("release.newVersion", nextVersion)
updateVersionProperty(nextVersion)
Expand All @@ -199,6 +199,15 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
throw new GradleException("Failed to increase version [$version] - unknown pattern")
}

String getNextVersion(String candidateVersion) {
String nextVersion = project.properties['newVersion'];

if (useAutomaticVersion()) {
return nextVersion ?: candidateVersion;
}

return readLine("Enter the next version (current one released as [${project.version}]):", nextVersion ?: candidateVersion);
}

def commitNewVersion() {
def message = releaseConvention().newVersionCommitMessage +
Expand All @@ -211,7 +220,6 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {


def checkPropertiesFile() {

File propertiesFile = findPropertiesFile()

Properties properties = new Properties()
Expand All @@ -225,6 +233,7 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
if ( !isVersionDefined() ) {
project.version = properties.version
}

try {
// test to make sure the version property is in the correct version=[version] format.
project.ant.replace(file: propertiesFile, token: "version=${project.version}", value: "version=${project.version}", failOnNoReplacements: true, preserveLastModified: true)
Expand Down

0 comments on commit 65cb6b5

Please sign in to comment.