Skip to content

Commit

Permalink
Added grabverSkip, so calculation can be skipped
Browse files Browse the repository at this point in the history
Fixed #6 - Patch is not being increased in assembleRelease when Build Signed APK is chosen from the menu
Resolved #7 - Ignoring preRelease "" empty string
  • Loading branch information
davideas committed Oct 4, 2017
1 parent bbed844 commit 4f97b37
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'eu.davidea:grabver:0.5.0'
classpath 'eu.davidea:grabver:0.6.0'
// or with Gradle Plugins Repository
classpath "gradle.plugin.eu.davidea:grabver:0.5.0"
classpath "gradle.plugin.eu.davidea:grabver:0.6.0"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion build-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
}
//noinspection GroovyAssignabilityCheck
dependencies {
classpath 'eu.davidea:grabver:0.5.0'
classpath 'eu.davidea:grabver:0.6.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ext {

// Library Repository
libraryName = 'GrabVer'
libraryVersion = '0.5.0'
libraryVersion = '0.6.0'
displayName = 'Gradle Automatic Build Versioning Plugin'
libraryDescription = 'An easy Gradle plugin that follows semver.org rules to automatically generate the Patch version, Build number and Code version, while Major, Minor and Pre-Release suffix remain under our control.'
libraryLabels = ['semver', 'version', 'versioning', 'build-versioning', 'automatic-versioning', 'intellij-idea', 'android-studio', 'auto-reset']
Expand Down
2 changes: 1 addition & 1 deletion module_a/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenLocal()
}
dependencies {
classpath 'eu.davidea:grabver:0.5.0'
classpath 'eu.davidea:grabver:0.6.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion module_b/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenLocal()
}
dependencies {
classpath 'eu.davidea:grabver:0.5.0'
classpath 'eu.davidea:grabver:0.6.0'
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/main/groovy/eu/davidea/gradle/GrabVer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ import org.gradle.api.Project
class GrabVer implements Plugin<Project> {

void apply(Project project) {
println("====== STARTED GrabVer v0.5.0")
println("====== STARTED GrabVer v0.6.0")
println("INFO - ProjectName=" + project.name)

project.task('grabverRelease') {
// Dummy task to trigger release versioning (also used in unit test)
}
project.task('grabverSkip') {
// Dummy task to skip versioning (also used in unit test)
}

// Create new empty versioning instance
VersioningExtension versioning = project.extensions.create("versioning", VersioningExtension)

def runTasks = project.gradle.startParameter.taskNames
println("INFO - runTasks=" + runTasks)

// Module versioning
String module = project.name
String filename = 'version.properties'
Expand All @@ -66,12 +66,16 @@ class GrabVer implements Plugin<Project> {
File versionFile = getFile(filename)
OrderedProperties versionProps = loadProperties(project, versionFile)

if ('clean' in runTasks || 'test' in runTasks) {
println("INFO - Skipping on Task clean & test")
// Check runTasks
def runTasks = project.gradle.startParameter.taskNames
println("INFO - runTasks=" + runTasks)

if (runTasks.contains("clean") || runTasks.contains("test") || runTasks.contains("grabverSkip")) {
println("INFO - Skipping on Task: clean, test & grabverSkip")
versioning.evaluated = true
} else {
// Increment depends on release
if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'grabverRelease' in runTasks) {
if (runTasks.contains("grabverRelease") || runTasks.contains(":" + module + ":assembleRelease")) {
println("INFO - Running with 'release' task: 'Code' version will auto increment")
versioning.increment = 1
} else {
Expand All @@ -82,7 +86,7 @@ class GrabVer implements Plugin<Project> {
project.afterEvaluate {
if (!('clean' in runTasks)) {
// Save new values
println("INFO - Saving Versioning: " + versioning)
println("INFO - Saving versioning: " + versioning)
versionProps.setProperty(VersionType.MAJOR.toString(), String.valueOf(versioning.major))
versionProps.setProperty(VersionType.MINOR.toString(), String.valueOf(versioning.minor))
versionProps.setProperty(VersionType.PATCH.toString(), String.valueOf(versioning.patch))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class VersioningExtension {

String toString() {
return major + "." + minor + "." + patch +
(preRelease != null && !preRelease.isEmpty() ? "-" + preRelease : "") +
(isPreRelease() ? "-" + preRelease : "") +
" #" + build +
" code=" + code
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/groovy/eu/davidea/gradle/GrabVerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ class GrabVerTest {
Assert.assertEquals("code check", 4, project.versioning.code)
}

@Test
void testAutoIncrement_Skip_Versioning() throws Exception {
List tasks = new ArrayList<>()
tasks.add("grabverSkip")
tasks.add("grabverRelease")
project.gradle.startParameter.setTaskNames(tasks)
project.pluginManager.apply PLUGIN_ID
project.versioning {
major = 1
minor = 1
}
printResults("[Skip]")
Assert.assertEquals("major check",1, project.versioning.major)
Assert.assertEquals("minor check",1, project.versioning.minor)
Assert.assertEquals("patch check",1, project.versioning.patch)
Assert.assertEquals("build check",20, project.versioning.build)
Assert.assertEquals("code check", 3, project.versioning.code)
}

@Test
void testAutoIncrement_Release_VersionChange() throws Exception {
List tasks = new ArrayList<>()
Expand Down

0 comments on commit 4f97b37

Please sign in to comment.