commit 17c072b192f77280356269cde0f9def06de6fe06 Author: Erik C. Thauvin Date: Fri Jun 29 20:21:27 2018 -0700 First commit. diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6ec2ae2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# batch files are specific to windows and always crlf +*.bat eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6322c7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +**/.idea/dictionaries +**/.idea/gradle.xml +**/.idea/libraries +**/.idea/tasks.xml +**/.idea/workspace.xml +*.sublime-* +*.iws +.classpath +.DS_Store +.gradle +.kobalt +.nb-gradle +.project +.settings +/bin +/build +/deploy +/dist +/gen +/gradle.properties +/local.properties +/out +/proguard-project.txt +/project.properties +/target +/test-output +ehthumbs.db +kobaltBuild +Thumbs.db \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..13ea6d3 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +semver \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..0a77bef --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/Erik_s_Copyright_Notice.xml b/.idea/copyright/Erik_s_Copyright_Notice.xml new file mode 100644 index 0000000..08660a1 --- /dev/null +++ b/.idea/copyright/Erik_s_Copyright_Notice.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..3423376 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8ff795e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,53 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..12081b6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7d89215 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/semver.iml b/.idea/modules/semver.iml new file mode 100644 index 0000000..4b9aff1 --- /dev/null +++ b/.idea/modules/semver.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/semver_main.iml b/.idea/modules/semver_main.iml new file mode 100644 index 0000000..63d2ae9 --- /dev/null +++ b/.idea/modules/semver_main.iml @@ -0,0 +1,216 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/semver_test.iml b/.idea/modules/semver_test.iml new file mode 100644 index 0000000..bae2277 --- /dev/null +++ b/.idea/modules/semver_test.iml @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/Sources.xml b/.idea/scopes/Sources.xml new file mode 100644 index 0000000..73614ea --- /dev/null +++ b/.idea/scopes/Sources.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/LICENSE.TXT b/LICENSE.TXT new file mode 100644 index 0000000..b7ddd7f --- /dev/null +++ b/LICENSE.TXT @@ -0,0 +1,27 @@ +Copyright (c) 2018, 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. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..d7147d4 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,84 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + `kotlin-dsl` + `java-gradle-plugin` + `maven-publish` + id("com.gradle.plugin-publish") version "0.9.10" + id("com.github.ben-manes.versions") version "0.20.0" +} + +var shortName = "server" +var github = "https://github.com/ethauvin/gradle-semver-plugin" +var packageName = "net.thauvin.erik.gradle.semver" + +version = "0.9.1" +group = "net.thauvin.erik.gradle" + + +var spekVersion = "1.1.5" + +repositories { + jcenter() +} + +dependencies { + compile(gradleApi()) + + testImplementation(kotlin("reflect")) + testImplementation(kotlin("test")) + + testImplementation("org.jetbrains.spek:spek-api:$spekVersion") { + exclude(group = "org.jetbrains.kotlin") + } + + testRuntimeOnly("org.jetbrains.spek:spek-junit-platform-engine:$spekVersion") { + exclude(group = "org.jetbrains.kotlin") + exclude(group = "org.junit.platform") + } + + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.2.0") { + because("Needed to run tests IDEs that bundle an older version") + } + testImplementation(gradleTestKit()) +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" + // Gradle 4.6 + kotlinOptions.apiVersion = "1.2" +} + +tasks.withType { + useJUnitPlatform { + includeEngines("spek") + } +} + +gradlePlugin { + (plugins) { + project.name { + id = packageName + implementationClass = "$packageName.SemverPlugin" + } + } +} + +pluginBundle { + website = github + vcsUrl = github + description = "Gradle plugin to automatically manage Semantic Version numbering." + tags = listOf("semver", "version", "versioning") + + (plugins) { + project.name { + id = packageName + displayName = "Gradle Semamtic Version Plugin" + } + } + + mavenCoordinates { + groupId = project.group.toString() + artifactId = project.name + } +} diff --git a/examples/test/.gitignore b/examples/test/.gitignore new file mode 100644 index 0000000..6322c7f --- /dev/null +++ b/examples/test/.gitignore @@ -0,0 +1,29 @@ +**/.idea/dictionaries +**/.idea/gradle.xml +**/.idea/libraries +**/.idea/tasks.xml +**/.idea/workspace.xml +*.sublime-* +*.iws +.classpath +.DS_Store +.gradle +.kobalt +.nb-gradle +.project +.settings +/bin +/build +/deploy +/dist +/gen +/gradle.properties +/local.properties +/out +/proguard-project.txt +/project.properties +/target +/test-output +ehthumbs.db +kobaltBuild +Thumbs.db \ No newline at end of file diff --git a/examples/test/build.gradle b/examples/test/build.gradle new file mode 100644 index 0000000..1f838e8 --- /dev/null +++ b/examples/test/build.gradle @@ -0,0 +1,37 @@ +buildscript { + repositories { + mavenLocal() + } + dependencies { + classpath "net.thauvin.erik.gradle:semver:0.9.1" + } +} + +apply plugin: 'java' +apply plugin: 'application' +apply plugin: 'net.thauvin.erik.gradle.semver' + +mainClassName = 'App' + +version = 1.0 + +dependencies { + +} + +repositories { + jcenter() +} + +run { + //dependsOn("incrementPatch") + doFirst { + println("Version: $version") + } +} + +semver { + properties = "test.properties" + setKeysPrefix("test.") + buildMetaKey = "another" +} \ No newline at end of file diff --git a/examples/test/gradle/wrapper/gradle-wrapper.jar b/examples/test/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..758de96 Binary files /dev/null and b/examples/test/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/test/gradle/wrapper/gradle-wrapper.properties b/examples/test/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2d80b69 --- /dev/null +++ b/examples/test/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/examples/test/gradlew b/examples/test/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/examples/test/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/examples/test/gradlew.bat b/examples/test/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/examples/test/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/examples/test/settings.gradle b/examples/test/settings.gradle new file mode 100644 index 0000000..3b11439 --- /dev/null +++ b/examples/test/settings.gradle @@ -0,0 +1,10 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/4.8.1/userguide/multi_project_builds.html + */ + +rootProject.name = 'java' diff --git a/examples/test/src/main/java/App.class b/examples/test/src/main/java/App.class new file mode 100644 index 0000000..08ab694 Binary files /dev/null and b/examples/test/src/main/java/App.class differ diff --git a/examples/test/src/main/java/App.java b/examples/test/src/main/java/App.java new file mode 100644 index 0000000..bd9132e --- /dev/null +++ b/examples/test/src/main/java/App.java @@ -0,0 +1,12 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +public class App { + public String getGreeting() { + return "Hello world."; + } + + public static void main(String[] args) { + System.out.println(new App().getGreeting()); + } +} diff --git a/examples/test/src/test/java/AppTest.java b/examples/test/src/test/java/AppTest.java new file mode 100644 index 0000000..e611fc7 --- /dev/null +++ b/examples/test/src/test/java/AppTest.java @@ -0,0 +1,12 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +import org.junit.Test; +import static org.junit.Assert.*; + +public class AppTest { + @Test public void testAppHasAGreeting() { + App classUnderTest = new App(); + assertNotNull("app should have a greeting", classUnderTest.getGreeting()); + } +} diff --git a/examples/test/test.properties b/examples/test/test.properties new file mode 100644 index 0000000..a5f0a74 --- /dev/null +++ b/examples/test/test.properties @@ -0,0 +1,7 @@ +#Generated by the Semver Plugin for Gradle +#Fri Jun 29 19:57:45 PDT 2018 +test.major=1 +test.prerelease= +test.patch=2 +another= +test.minor=0 diff --git a/examples/test/version.properties b/examples/test/version.properties new file mode 100644 index 0000000..4327bfe --- /dev/null +++ b/examples/test/version.properties @@ -0,0 +1,7 @@ +#Generated by the Semver Plugin for Gradle +#Fri Jun 29 19:55:11 PDT 2018 +version.prerelease= +version.buildmeta= +version.patch=0 +version.major=1 +version.minor=0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..758de96 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2d80b69 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..849893a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "semver" +enableFeaturePreview("STABLE_PUBLISHING") \ No newline at end of file diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt new file mode 100644 index 0000000..6c4f959 --- /dev/null +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt @@ -0,0 +1,72 @@ +/* + * SemverConfig.kt + * + * Copyright (c) 2018, 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.gradle.semver + +open class SemverConfig { + + companion object { + const val DEFAULT_KEY_PREFIX = "version." + const val DEFAULT_PROPERTIES = "${DEFAULT_KEY_PREFIX}properties" + const val DEFAULT_MAJOR_KEY = "${DEFAULT_KEY_PREFIX}major" + const val DEFAULT_MINOR_KEY = "${DEFAULT_KEY_PREFIX}minor" + const val DEFAULT_PATCH_KEY = "${DEFAULT_KEY_PREFIX}patch" + const val DEFAULT_PRERELEASE_KEY = "${DEFAULT_KEY_PREFIX}prerelease" + const val DEFAULT_PRERELEASE_PREFIX_KEY = "${DEFAULT_KEY_PREFIX}prerelease.prefix" + const val DEFAULT_BUILDMETA_KEY = "${DEFAULT_KEY_PREFIX}buildmeta" + const val DEFAULT_BUILDMETA_PREFIX_KEY = "${DEFAULT_KEY_PREFIX}buildmeta.prefix" + const val DEFAULT_SEPARATOR = "${DEFAULT_KEY_PREFIX}separator" + } + + var properties = DEFAULT_PROPERTIES + var majorKey = DEFAULT_MAJOR_KEY + var minorKey = DEFAULT_MINOR_KEY + var patchKey = DEFAULT_PATCH_KEY + var preReleaseKey = DEFAULT_PRERELEASE_KEY + var preReleasePrefixKey = DEFAULT_PRERELEASE_PREFIX_KEY + var buildMetaKey = DEFAULT_BUILDMETA_KEY + var buildMetaPrefixKey = DEFAULT_BUILDMETA_PREFIX_KEY + var separatorKey = DEFAULT_SEPARATOR + + @Suppress("unused") + fun setKeysPrefix(keyPrefix: String) { + if (keyPrefix.isNotBlank()) { + majorKey = keyPrefix + majorKey.removePrefix(DEFAULT_KEY_PREFIX) + minorKey = keyPrefix + minorKey.removePrefix(DEFAULT_KEY_PREFIX) + patchKey = keyPrefix + patchKey.removePrefix(DEFAULT_KEY_PREFIX) + preReleaseKey = keyPrefix + preReleaseKey.removePrefix(DEFAULT_KEY_PREFIX) + preReleasePrefixKey = keyPrefix + preReleasePrefixKey.removePrefix(DEFAULT_KEY_PREFIX) + buildMetaKey = keyPrefix + buildMetaKey.removePrefix(DEFAULT_KEY_PREFIX) + buildMetaPrefixKey = keyPrefix + buildMetaPrefixKey.removePrefix(DEFAULT_KEY_PREFIX) + separatorKey = keyPrefix + separatorKey.removePrefix(DEFAULT_KEY_PREFIX) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt new file mode 100644 index 0000000..3a579b0 --- /dev/null +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt @@ -0,0 +1,62 @@ +/* + * SemverIncrementTask.kt + * + * Copyright (c) 2018, 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.gradle.semver + +import net.thauvin.erik.gradle.semver.SemverPlugin.Types +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.TaskAction + +open class SemverIncrementTask : DefaultTask() { + init { + group = "version" + } + + @Input + lateinit var config: SemverConfig + + @Input + lateinit var version: Version + + @Input + lateinit var type: Types + + @Suppress("unused") + @TaskAction + fun increment() { + version.increment(isMajor = type == Types.MAJOR, isMinor = type == Types.MINOR, isPatch = type == Types.PATCH) + project.version = version.semver + logger.warn("Version: ${project.version}") + SemverPlugin.saveProperties(config, version) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt new file mode 100644 index 0000000..31dbffb --- /dev/null +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt @@ -0,0 +1,124 @@ +/* + * SemverPlugin.kt + * + * Copyright (c) 2018, 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.gradle.semver + +import org.gradle.api.GradleException +import org.gradle.api.Plugin +import org.gradle.api.Project +import java.io.File +import java.io.FileInputStream +import java.io.FileOutputStream +import java.util.* + +class SemverPlugin : Plugin { + private var version = Version() + private lateinit var config: SemverConfig + + enum class Types { + MAJOR, MINOR, PATCH + } + + companion object { + fun saveProperties(config: SemverConfig, version: Version) { + Properties().apply { + put(config.majorKey, version.major) + put(config.minorKey, version.minor) + put(config.patchKey, version.patch) + put(config.preReleaseKey, version.preRelease) + put(config.buildMetaKey, version.buildMeta) + if (version.buildMetaPrefix != Version.DEFAULT_BUILDMETA_PREFIX) + put(config.buildMetaPrefixKey, version.buildMetaPrefix) + if (version.preReleasePrefix != Version.DEFAULT_PRERELEASE_PREFIX) + put(config.preReleasePrefixKey, version.preReleasePrefix) + if (version.separator != Version.DEFAULT_SEPARATOR) + put(config.separatorKey, version.separator) + FileOutputStream(config.properties).use { output -> + store(output, "Generated by the Semver Plugin for Gradle") + } + } + } + } + + override fun apply(project: Project?) { + project!!.afterEvaluate(this::afterEvaluate) + config = project.extensions.create("semver", SemverConfig::class.java) + + project.tasks.create("incrementMajor", SemverIncrementTask::class.java) { + description = "Increments Major version number." + config = this@SemverPlugin.config + version = this@SemverPlugin.version + type = Types.MAJOR + } + + project.tasks.create("incrementMinor", SemverIncrementTask::class.java) { + description = "Increments Minor version number." + config = this@SemverPlugin.config + version = this@SemverPlugin.version + type = Types.MINOR + } + + project.tasks.create("incrementPatch", SemverIncrementTask::class.java) { + description = "Increments Patch version number." + config = this@SemverPlugin.config + version = this@SemverPlugin.version + type = Types.PATCH + } + } + + private fun afterEvaluate(project: Project) { + if (project.version != "unspecified") { + project.logger.warn("Please specify the version in ${config.properties} and remove it from ${project.buildFile.name}") + } + File(config.properties).apply { + + if (canRead()) { + FileInputStream(this).use { fis -> + Properties().apply { + load(fis) + version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR) + version.minor = getProperty(config.minorKey, Version.DEFAULT_MINOR) + version.patch = getProperty(config.patchKey, Version.DEFAULT_PATCH) + version.preRelease = getProperty(config.preReleaseKey, Version.DEFAULT_EMPTY) + version.preReleasePrefix = getProperty(config.preReleasePrefixKey, Version.DEFAULT_PRERELEASE_PREFIX) + version.buildMeta = getProperty(config.buildMetaKey, Version.DEFAULT_EMPTY) + version.buildMetaPrefix = getProperty(config.buildMetaPrefixKey, Version.DEFAULT_BUILDMETA_PREFIX) + version.separator = getProperty(config.separatorKey, Version.DEFAULT_SEPARATOR) + project.version = version.semver + } + } + } else if (exists()) { + throw GradleException("Unable to read version from ${config.properties}") + } + saveProperties(config, version) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt new file mode 100644 index 0000000..3b0aded --- /dev/null +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt @@ -0,0 +1,64 @@ +/* + * Version.kt + * + * Copyright (c) 2018, 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.gradle.semver + +class Version { + companion object { + const val DEFAULT_MAJOR: String = "1" + const val DEFAULT_MINOR: String = "0" + const val DEFAULT_PATCH: String = "0" + const val DEFAULT_EMPTY: String = "" + const val DEFAULT_PRERELEASE_PREFIX = "-" + const val DEFAULT_BUILDMETA_PREFIX = "+" + const val DEFAULT_SEPARATOR = "." + } + + var major = DEFAULT_MAJOR + var minor = DEFAULT_MINOR + var patch = DEFAULT_PATCH + var preRelease = DEFAULT_EMPTY + var preReleasePrefix = DEFAULT_PRERELEASE_PREFIX + var buildMeta = DEFAULT_EMPTY + var buildMetaPrefix = DEFAULT_BUILDMETA_PREFIX + var separator = DEFAULT_SEPARATOR + + val semver: String + get()= "$major$separator$minor$separator$patch" + + (if (preRelease.isNotEmpty()) "$preReleasePrefix$preRelease" else "") + + (if (buildMeta.isNotEmpty()) "$buildMetaPrefix$buildMeta" else "") + + fun increment(isMajor: Boolean = false, isMinor: Boolean = false, isPatch: Boolean = false) { + if (isMajor) major = (major.toInt() + 1).toString() + if (isMinor) minor = (minor.toInt() + 1).toString() + if (isPatch) patch = (patch.toInt() + 1).toString() + } +} diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt new file mode 100644 index 0000000..7fa5cee --- /dev/null +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt @@ -0,0 +1,95 @@ +/* + * SemverConfigSpec.kt + * + * Copyright (c) 2018, 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.gradle.semver + +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.given +import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.api.dsl.on +import kotlin.test.assertTrue + +@Suppress("unused") +object SemverConfigSpec : Spek({ + describe("config test") { + given("a config") { + val config = SemverConfig() + val vars = listOf( + config.properties, + config.majorKey, + config.minorKey, + config.patchKey, + config.preReleaseKey, + config.preReleasePrefixKey, + config.buildMetaKey, + config.buildMetaPrefixKey, + config.separatorKey + ) + val defaults = listOf( + SemverConfig.DEFAULT_PROPERTIES, + SemverConfig.DEFAULT_MAJOR_KEY, + SemverConfig.DEFAULT_MINOR_KEY, + SemverConfig.DEFAULT_PATCH_KEY, + SemverConfig.DEFAULT_PRERELEASE_KEY, + SemverConfig.DEFAULT_PRERELEASE_PREFIX_KEY, + SemverConfig.DEFAULT_BUILDMETA_KEY, + SemverConfig.DEFAULT_BUILDMETA_PREFIX_KEY, + SemverConfig.DEFAULT_SEPARATOR + ) + on("defaults") { + defaults.forEachIndexed { i, d -> + it("should be the same: ${vars[i]}, $d") { + assertTrue(vars[i] == d) + } + } + } + on("set keys to test.xxx") { + config.setKeysPrefix("test.") + val keys = listOf( + config.majorKey, + config.minorKey, + config.patchKey, + config.preReleaseKey, + config.preReleasePrefixKey, + config.buildMetaKey, + config.buildMetaPrefixKey, + config.separatorKey) + + keys.forEach { k -> + it("should all start with test.xxx: $k") { + assertTrue(k.startsWith("test.")) + } + } + } + } + } +}) \ No newline at end of file diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt new file mode 100644 index 0000000..8cd7b79 --- /dev/null +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt @@ -0,0 +1,110 @@ +/* + * SemverVersionSpec.kt + * + * Copyright (c) 2018, 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.gradle.semver + +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.given +import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.api.dsl.on +import kotlin.test.assertEquals + +@Suppress("unused") +object SemverVersionSpec : Spek({ + describe("version test") { + given("a version") { + val version = Version() + on("increment major") { + version.increment(isMajor = true) + it("should return 2.0.0") { + assertEquals("2.0.0", version.semver) + } + } + on("increment minor") { + version.increment(isMinor = true) + it("should return 2.1.0") { + assertEquals("2.1.0", version.semver) + } + } + on("increment patch") { + version.increment(isPatch = true) + it("should return 2.1.1") { + assertEquals("2.1.1", version.semver) + } + } + on("increment all") { + version.increment(true, true, true) + it("should rerturn 3.2.2") { + assertEquals("3.2.2", version.semver) + } + } + on("reset version") { + version.major = "1" + version.minor = "0" + version.patch = "0" + it("should return 1.0.0") { + assertEquals("1.0.0", version.semver) + } + } + on("add prerelease") { + version.preRelease = "beta" + it("should return 1.0.0-beta") { + assertEquals("1.0.0-beta", version.semver) + } + } + on("add metadata") { + version.buildMeta = "007" + it("should return 1.0.0-beta+007") { + assertEquals("1.0.0-beta+007", version.semver) + } + } + on("change prerelease prefix") { + version.preReleasePrefix = "--" + it("should return 1.0.0--beta+007") { + assertEquals("1.0.0--beta+007", version.semver) + } + } + on("change prerelease prefix") { + version.buildMetaPrefix = "++" + it("should return 1.0.0--beta+=007") { + assertEquals("1.0.0--beta++007", version.semver) + } + } + on("change sperator") { + version.separator = "-" + it("should return 1-0-0--beta+007") { + assertEquals("1-0-0--beta+007", version.semver) + } + } + } + } +}) \ No newline at end of file