From ac2088aa54c101ed487bedb49ccf75253e7fc1eb Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 3 Feb 2016 13:12:21 -0800 Subject: [PATCH] Added test. --- README.html | 10 +- README.md | 10 +- build.gradle | 264 +++++++++--------- example/build.gradle | 84 +++--- example/example.iml | 6 +- .../erik/semver/example/GeneratedVersion.java | 13 +- example/version.properties | 4 +- semver.ipr | 13 +- .../thauvin/erik/semver/VersionInfoTest.java | 79 ++++++ version.properties | 2 +- 10 files changed, 274 insertions(+), 211 deletions(-) create mode 100644 src/test/java/net/thauvin/erik/semver/VersionInfoTest.java diff --git a/README.html b/README.html index 2ae130b..204e15f 100644 --- a/README.html +++ b/README.html @@ -244,13 +244,13 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
<dependency>
     <groupId>net.thauvin.erik</groupId>
     <artifactId>semver</artifactId>
-    <version>0.9.4-beta</version>
+    <version>0.9.5-beta</version>
 </dependency>

Gradle

Class Generation

To install and run from Gradle, add the following to the build.gradle file:

dependencies {
-    compile 'net.thauvin.erik:semver:0.9.4-beta'
+    compile 'net.thauvin.erik:semver:0.9.5-beta'
 }

The GeneratedVersion class will be automatically created in the build directory upon compiling.

Class & Source Generation

@@ -260,11 +260,11 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf }

Then add the following to the build.gradle file:

dependencies {
-    compile 'net.thauvin.erik:semver:0.9.4-beta'
+    compile 'net.thauvin.erik:semver:0.9.5-beta'
 }
 
 annotationProcessor {
-    library 'net.thauvin.erik:semver:0.9.4-beta'
+    library 'net.thauvin.erik:semver:0.9.5-beta'
     processor 'net.thauvin.erik.semver.VersionProcessor'
     // sourcesDir 'src/generated/java'
 }
@@ -278,7 +278,7 @@ compileJava {
 

Kobalt

To install and run from Kobalt, add the following to the Build.kt file:

dependencies {
-    apt("net.thauvin.erik:semver:0.9.4-beta")
+    apt("net.thauvin.erik:semver:0.9.5-beta")
 }

Auto-Increment

Incrementing the version is best left to your favorite build system.

diff --git a/README.md b/README.md index 08dacf3..905705b 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ To install and run from [Maven](http://maven.apache.org/), configure an artifact net.thauvin.erik semver - 0.9.4-beta + 0.9.5-beta ``` @@ -141,7 +141,7 @@ To install and run from [Gradle](https://gradle.org/), add the following to the ```gradle dependencies { - compile 'net.thauvin.erik:semver:0.9.4-beta' + compile 'net.thauvin.erik:semver:0.9.5-beta' } ``` @@ -161,11 +161,11 @@ Then add the following to the `build.gradle` file: ```gradle dependencies { - compile 'net.thauvin.erik:semver:0.9.4-beta' + compile 'net.thauvin.erik:semver:0.9.5-beta' } annotationProcessor { - library 'net.thauvin.erik:semver:0.9.4-beta' + library 'net.thauvin.erik:semver:0.9.5-beta' processor 'net.thauvin.erik.semver.VersionProcessor' // sourcesDir 'src/generated/java' } @@ -186,7 +186,7 @@ To install and run from [Kobalt](http://beust.com/kobalt/), add the following to ```gradle dependencies { - apt("net.thauvin.erik:semver:0.9.4-beta") + apt("net.thauvin.erik:semver:0.9.5-beta") } ``` diff --git a/build.gradle b/build.gradle index 5ba8e2e..6789b8e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.jfrog.bintray" version "1.5" + id "com.jfrog.bintray" version "1.5" } apply plugin: 'java' apply plugin: 'idea' @@ -11,26 +11,26 @@ import org.apache.tools.ant.taskdefs.condition.Os defaultTasks 'deploy' def getVersion(isIncrement = false) { - def propsFile = 'version.properties' - def majorKey = 'version.major' - def minorKey = 'version.minor' - def patchKey = 'version.patch' - def metaKey = 'version.buildmeta' - def preKey = 'version.prerelease' - if (isIncrement) { - ant.propertyfile(file: propsFile) { - entry(key: patchKey, - type: 'int', - default: '-1', - operation: '+') - } - } - def p = new Properties() - file(propsFile).withInputStream { stream -> p.load(stream) } - def metadata = p.getProperty(metaKey, '') - def prerelease = p.getProperty(preKey, '') - return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + - (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) + def propsFile = 'version.properties' + def majorKey = 'version.major' + def minorKey = 'version.minor' + def patchKey = 'version.patch' + def metaKey = 'version.buildmeta' + def preKey = 'version.prerelease' + if (isIncrement) { + ant.propertyfile(file: propsFile) { + entry(key: patchKey, + type: 'int', + default: '-1', + operation: '+') + } + } + def p = new Properties() + file(propsFile).withInputStream { stream -> p.load(stream) } + def metadata = p.getProperty(metaKey, '') + def prerelease = p.getProperty(preKey, '') + return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + + (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) } version = getVersion() @@ -54,167 +54,163 @@ def pkgLabels = ['java', 'annotation', 'processor', 'semantic', 'version'] [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { - mavenLocal() - mavenCentral() + mavenLocal() + mavenCentral() } dependencies { - compile 'org.apache.velocity:velocity:1.7' - testCompile 'org.testng:testng:6.9.10' + compile 'org.apache.velocity:velocity:1.7' + testCompile 'org.testng:testng:6.9.10' } bintray { - user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') - key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') - publications = ['MyPublication'] - dryRun = true - pkg { - repo = 'maven' - name = mavenName - licenses = pkgLicenses - desc = mavenDescription - websiteUrl = mavenUrl - issueTrackerUrl = pkgIssueTrackerUrl - vcsUrl = mavenScmCon - labels = pkgLabels - publicDownloadNumbers = true - version { - name = project.version - desc = 'Version ' + project.version - vcsTag = project.version - gpg { - sign = true - } - } - } + user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') + key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') + publications = ['MyPublication'] + dryRun = true + pkg { + repo = 'maven' + name = mavenName + licenses = pkgLicenses + desc = mavenDescription + websiteUrl = mavenUrl + issueTrackerUrl = pkgIssueTrackerUrl + vcsUrl = mavenScmCon + labels = pkgLabels + publicDownloadNumbers = true + version { + name = project.version + desc = 'Version ' + project.version + vcsTag = project.version + gpg { + sign = true + } + } + } } def pomConfig = { - licenses { - license { - name mavenLicense - url mavenLicenseUrl - distribution 'repo' - } - } - developers { - developer { - id 'ethauvin' - name 'Erik C. Thauvin' - email 'erik@thauvin.net' - } - } - scm { - connection 'scm:git:' + mavenScmCon - developerConnection 'scm:git:' + mavenScmDevCon - url mavenScmCon - } + licenses { + license { + name mavenLicense + url mavenLicenseUrl + distribution 'repo' + } + } + developers { + developer { + id 'ethauvin' + name 'Erik C. Thauvin' + email 'erik@thauvin.net' + } + } + scm { + connection 'scm:git:' + mavenScmCon + developerConnection 'scm:git:' + mavenScmDevCon + url mavenScmCon + } } publishing { - publications { - MyPublication(MavenPublication) { - from components.java - artifact sourcesJar - artifact javadocJar - groupId mavenGroupId - artifactId rootProject.name - version project.version + publications { + MyPublication(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + groupId mavenGroupId + artifactId rootProject.name + version project.version - pom.withXml { - def root = asNode() - root.appendNode('name', mavenName) - root.appendNode('description', mavenDescription) - root.appendNode('url', mavenUrl) - root.children().last() + pomConfig - } - } - } + pom.withXml { + def root = asNode() + root.appendNode('name', mavenName) + root.appendNode('description', mavenDescription) + root.appendNode('url', mavenUrl) + root.children().last() + pomConfig + } + } + } } task javadocJar(type: Jar, dependsOn: javadoc) { - group = 'Build' - description = 'Builds an archive of the javadoc docs.' - classifier = 'javadoc' - from javadoc.destinationDir + group = 'Build' + description = 'Builds an archive of the javadoc docs.' + classifier = 'javadoc' + from javadoc.destinationDir } task sourcesJar(type: Jar) { - group = 'Build' - description = 'Builds an archive of the source code.' - classifier = 'sources' - from sourceSets.main.allSource + group = 'Build' + description = 'Builds an archive of the source code.' + classifier = 'sources' + from sourceSets.main.allSource } artifacts { - archives javadocJar - archives sourcesJar + archives javadocJar + archives sourcesJar } javadoc { - title = mavenDescription + ' ' + version - options.tags = ['created'] - options.author = true - options.addStringOption('link', 'http://docs.oracle.com/javase/8/docs/api/') - options.addStringOption('sourcepath', project.hasProperty('jdkSrc') ? jdkSrc : "$System.env.JAVA_HOME/src.zip") - if (JavaVersion.current().isJava8Compatible()) - { - options.addStringOption('Xdoclint:none', '-quiet') - } + title = mavenDescription + ' ' + version + options.tags = ['created'] + options.author = true + options.addStringOption('link', 'http://docs.oracle.com/javase/8/docs/api/') + options.addStringOption('sourcepath', project.hasProperty('jdkSrc') ? jdkSrc : "$System.env.JAVA_HOME/src.zip") + if (JavaVersion.current().isJava8Compatible()) { + options.addStringOption('Xdoclint:none', '-quiet') + } } test { - useTestNG() + useTestNG() } compileJava { - doFirst { - project.version = getVersion(isRelease) - } + doFirst { + project.version = getVersion(isRelease) + } } clean { - delete deployDir + delete deployDir } task copyToDeploy(type: Copy) { - from jar - into deployDir + from jar + into deployDir } task deploy(dependsOn: ['build', 'copyToDeploy']) { - description = 'Copies all needed files to the ${deployDir} directory.' - group = 'Publishing' - outputs.dir deployDir - inputs.files copyToDeploy - mustRunAfter clean + description = 'Copies all needed files to the ${deployDir} directory.' + group = 'Publishing' + outputs.dir deployDir + inputs.files copyToDeploy + mustRunAfter clean } task wrapper(type: Wrapper) { - gradleVersion = gradle.gradleVersion + gradleVersion = gradle.gradleVersion } task release(dependsOn: ['deploy', 'wrapper']) << { - group = 'Publishing' - description = 'Releases new version.' - isRelease = true + group = 'Publishing' + description = 'Releases new version.' + isRelease = true } task pandoc(type: Exec) { - group = 'Documentation' - def pandoc_args = ['--from', 'markdown_github', '--to', 'html5', '-s', '-o', 'README.html', 'README.md'] - if (Os.isFamily(Os.FAMILY_WINDOWS)) - { - commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) - } - else - { - executable '/usr/local/bin/pandoc' - args pandoc_args - } - standardOutput = new ByteArrayOutputStream() - ext.output = { - return standardOutput.toString() - } + group = 'Documentation' + def pandoc_args = ['--from', 'markdown_github', '--to', 'html5', '-s', '-o', 'README.html', 'README.md'] + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) + } else { + executable '/usr/local/bin/pandoc' + args pandoc_args + } + standardOutput = new ByteArrayOutputStream() + ext.output = { + return standardOutput.toString() + } } diff --git a/example/build.gradle b/example/build.gradle index 2c39634..ac00908 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.2" + id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.2" } apply plugin: 'java' apply plugin: 'idea' @@ -12,26 +12,26 @@ def deployDir = 'deploy' // Get version from properties file. Increment patch if specified. def getVersion(isIncrement = false) { - def propsFile = 'version.properties' - def majorKey = 'version.major' - def minorKey = 'version.minor' - def patchKey = 'version.patch' - def metaKey = 'version.buildmeta' - def preKey = 'version.prerelease' - if (isIncrement) { - ant.propertyfile(file: propsFile) { - entry(key: patchKey, - type: 'int', - default: '-1', - operation: '+') - } - } - def p = new Properties() - file(propsFile).withInputStream { stream -> p.load(stream) } - def metadata = p.getProperty(metaKey, '') - def prerelease = p.getProperty(preKey, '') - return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + - (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) + def propsFile = 'version.properties' + def majorKey = 'version.major' + def minorKey = 'version.minor' + def patchKey = 'version.patch' + def metaKey = 'version.buildmeta' + def preKey = 'version.prerelease' + if (isIncrement) { + ant.propertyfile(file: propsFile) { + entry(key: patchKey, + type: 'int', + default: '-1', + operation: '+') + } + } + def p = new Properties() + file(propsFile).withInputStream { stream -> p.load(stream) } + def metadata = p.getProperty(metaKey, '') + def prerelease = p.getProperty(preKey, '') + return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + + (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) } version = getVersion() @@ -40,55 +40,55 @@ mainClassName = 'net.thauvin.erik.semver.example.Example' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { - mavenLocal() - mavenCentral() + mavenLocal() + mavenCentral() } dependencies { - compile 'net.thauvin.erik:semver:0.9.4-beta' + compile 'net.thauvin.erik:semver:0.9.5-beta' } annotationProcessor { - // Update version, increment on release. - project.version = getVersion(isRelease) - library 'net.thauvin.erik:semver:0.9.4-beta' - processor 'net.thauvin.erik.semver.VersionProcessor' + // Update version, increment on release. + project.version = getVersion(isRelease) + library 'net.thauvin.erik:semver:0.9.5-beta' + processor 'net.thauvin.erik.semver.VersionProcessor' } compileJava { - options.compilerArgs << '-proc:none' + options.compilerArgs << '-proc:none' } jar { - manifest.attributes('Main-Class': mainClassName) + manifest.attributes('Main-Class': mainClassName) } clean { - delete deployDir + delete deployDir } task copyToDeploy(type: Copy) { - from jar - into deployDir + from jar + into deployDir } task deploy(dependsOn: ['build', 'copyToDeploy']) { - description = 'Copies all needed files to the ${deployDir} directory.' - group = 'Publishing' - outputs.dir deployDir - inputs.files copyToDeploy - mustRunAfter clean + description = 'Copies all needed files to the ${deployDir} directory.' + group = 'Publishing' + outputs.dir deployDir + inputs.files copyToDeploy + mustRunAfter clean } task release(dependsOn: ['deploy', 'wrapper']) << { - group = 'Publishing' - description = 'Releases new version.' - isRelease = true + group = 'Publishing' + description = 'Releases new version.' + isRelease = true } task wrapper(type: Wrapper) { - gradleVersion = gradle.gradleVersion + gradleVersion = gradle.gradleVersion } diff --git a/example/example.iml b/example/example.iml index 3fc19f2..b8c5d74 100644 --- a/example/example.iml +++ b/example/example.iml @@ -1,5 +1,5 @@ - + @@ -16,10 +16,6 @@ - - - - - + @@ -305,7 +305,7 @@ - @@ -357,15 +357,6 @@ - - - - - - - - - diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java new file mode 100644 index 0000000..90639be --- /dev/null +++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java @@ -0,0 +1,79 @@ +/* + * VersionInfoTest.java + * + * Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.thauvin.erik.semver; + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * The VersionInfoTest class. + * + * @author Erik C. Thauvin + * @created 2016-02-03 + * @since 1.0 + */ +public class VersionInfoTest +{ + @Test + public void testGetVersion() + throws Exception + { + + final VersionInfo version = new VersionInfo(); + + Assert.assertEquals(version.getVersion(), "1.0.0"); + + version.setMajor(3); + + Assert.assertEquals(version.getVersion(), "3.0.0"); + + version.setMinor(2); + + Assert.assertEquals(version.getVersion(), "3.2.0"); + + version.setPatch(1); + + Assert.assertEquals(version.getVersion(), "3.2.1"); + + version.setPreRelease("beta"); + + Assert.assertEquals(version.getVersion(), "3.2.1-beta"); + + version.setBuildMetadata("001"); + + Assert.assertEquals(version.getVersion(), "3.2.1-beta+001"); + + version.setPreRelease(""); + + Assert.assertEquals(version.getVersion(), "3.2.1+001"); + } +} \ No newline at end of file diff --git a/version.properties b/version.properties index d88dfda..7b8dc84 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ #Thu, 28 Jan 2016 17:33:17 -0800 version.major=0 version.minor=9 -version.patch=4 +version.patch=5 version.buildmeta= version.prerelease=beta