Skip to content

Commit

Permalink
Improved toString
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed Oct 3, 2017
1 parent 32d936c commit bbed844
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ Auto-skip versioning when 'clean' or 'test' tasks are enqueued.
**minor** - User defined value, it must be coherent(=0) if you increase _Major_ version.

## Installation
Configure script dependencies in the project _build.gradle_ file:
Configure script dependencies in the project _build.gradle_ file:
``` groovy
buildscript {
repositories {
jcenter() //not yet
// Please Use jcenter for dependecies: mavenCentral is not enough
jcenter()
// and (for now)
maven { url "http://dl.bintray.com/davideas/maven" }
// or Gradle Plugins Repository
maven { url "https://plugins.gradle.org/m2/" }
Expand Down
16 changes: 10 additions & 6 deletions src/main/groovy/eu/davidea/gradle/VersioningExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class VersioningExtension {
patch = Integer.valueOf(versionProps.getProperty(VersionType.PATCH.toString(), "0"))
build = Integer.valueOf(versionProps.getProperty(VersionType.BUILD.toString(), "0"))
code = Integer.valueOf(versionProps.getProperty(VersionType.CODE.toString(), "0"))
println("INFO - Current versioning: " + toString())
println("INFO - Current versioning: " + toStringCurrent())
}

private isPreRelease() {
Expand Down Expand Up @@ -129,14 +129,18 @@ class VersioningExtension {
return date.format(format)
}

String toString() {
return (major > 0 ? "u" + major + "." + minor + " - " : "") +
(propMajor > 0 ? propMajor : major) +
"." + (propMinor > 0 ? propMinor : minor) +
"." + patch +
String toStringCurrent() {
return propMajor + "." + propMinor + "." + patch +
(propPreRelease != null && !propPreRelease.isEmpty() ? "-" + propPreRelease : "") +
" #" + build +
" code=" + code
}

String toString() {
return major + "." + minor + "." + patch +
(preRelease != null && !preRelease.isEmpty() ? "-" + preRelease : "") +
" #" + build +
" code=" + code
}

}
8 changes: 4 additions & 4 deletions src/test/groovy/eu/davidea/gradle/GrabVerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ class GrabVerTest {
*/
private void printResults(String title) {
println("TEST - " + title)
println("TEST - code=" + project.versioning.code)
println("TEST - name=" + project.versioning.name)
println("TEST - fullVersionName=" + project.versioning.fullVersionName)
println("TEST - " + project.versioning)
println("TEST - code=$project.versioning.code")
println("TEST - name=$project.versioning.name")
println("TEST - fullVersionName: $project.versioning.fullVersionName")
println("TEST - New versioning: $project.versioning")
}

private static void simulateProperties(int major, int minor, int patch, int build, int code) {
Expand Down

0 comments on commit bbed844

Please sign in to comment.