├── .github └── workflows │ └── build.yml ├── .gitignore ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── build.gradle ├── buildSrc └── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ ├── gradle-wrapper.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ └── gradlew.bat ├── gradlew ├── gradlew.bat ├── readme.md └── src ├── main └── groovy │ └── com │ └── cinnober │ └── gradle │ └── semver_git │ └── SemverGitPlugin.groovy └── test └── groovy ├── .gitignore └── com └── cinnober └── gradle └── semver_git ├── SemverGitPluginFunctionalTest.groovy └── SemverGitPluginTest.groovy /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [push, pull_request, workflow_dispatch] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout Source Code 8 | uses: actions/checkout@v2 9 | - name: Install Java 10 | uses: actions/setup-java@v1 11 | with: 12 | java-version: 8 13 | - name: Setup Gradle 14 | uses: gradle/gradle-build-action@v2 15 | with: 16 | cache-read-only: ${{ github.event_name == 'pull_request' }} 17 | - name: Build 18 | run: ./gradlew build -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .nb-gradle 3 | .nb-gradle-properties 4 | .gradle 5 | /build 6 | /buildSrc/build 7 | .idea 8 | *.iml 9 | out 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | Thank you for wanting to contribute to Semver-Git! 4 | Here are a few important things you should know about contributing: 5 | 6 | * Large changes, such as API changes, require discussion. Please create 7 | an [issue][] (or comment on an existing one). 8 | * Pull requests are great for small fixes for bugs, documentation, etc. 9 | * Code contributions require signing the [Cinnober CLA][]. 10 | 11 | [issue]: https://github.com/cinnober/semver-git/issues 12 | [Cinnober CLA]: http://www.cinnober.com/cla 13 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Mikael Brännström 2 | Anders Lindgren 3 | Morgan Johansson 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 The Semver-Git Authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("se.patrikerdes.use-latest-versions") version "0.2.13" 3 | id("com.github.ben-manes.versions") version "0.27.0" 4 | id("java-gradle-plugin") 5 | id "com.gradle.plugin-publish" version "0.11.0" 6 | id "org.gradle.test-retry" version "1.3.1" 7 | } 8 | 9 | description = 'Gradle plugin that combines git tags and semantic versioning, and sets the gradle version property accordingly.' 10 | 11 | apply plugin: "com.gradle.plugin-publish" 12 | 13 | apply plugin: 'groovy' 14 | sourceCompatibility = '1.8' 15 | 16 | dependencies { 17 | compile gradleApi() 18 | compile localGroovy() 19 | testImplementation gradleTestKit() 20 | testImplementation platform("org.spockframework:spock-bom:2.0-groovy-2.5") 21 | testImplementation "org.spockframework:spock-core" 22 | } 23 | 24 | apply plugin: 'maven-publish' 25 | apply plugin: 'signing' 26 | apply plugin: 'wrapper' 27 | 28 | wrapper { 29 | gradleVersion = "5.0" 30 | distributionType = Wrapper.DistributionType.ALL 31 | } 32 | 33 | repositories { 34 | mavenCentral() 35 | } 36 | 37 | // the following sets the version property 38 | plugins.apply com.cinnober.gradle.semver_git.SemverGitPlugin 39 | 40 | group = 'com.cinnober.gradle' 41 | 42 | test { 43 | useJUnitPlatform() 44 | retry { 45 | maxRetries = 5 46 | } 47 | } 48 | 49 | // -- Maven Central -- 50 | 51 | task javadocJar(type: Jar) { 52 | classifier = 'javadoc' 53 | from javadoc 54 | } 55 | 56 | task sourcesJar(type: Jar) { 57 | classifier = 'sources' 58 | from sourceSets.main.allSource 59 | } 60 | 61 | artifacts { 62 | archives javadocJar, sourcesJar 63 | } 64 | 65 | // -- Gradle Plugin Portal -- 66 | 67 | gradlePlugin { 68 | plugins { 69 | semver { 70 | id = "com.cinnober.gradle.semver-git" 71 | implementationClass = "com.cinnober.gradle.semver_git.SemverGitPlugin" 72 | displayName = "semver-git" 73 | } 74 | } 75 | } 76 | 77 | pluginBundle { 78 | website = 'https://github.com/cinnober/semver-git' 79 | vcsUrl = 'https://github.com/cinnober/semver-git' 80 | description = project.description 81 | tags = ['git', 'semantic-versioning', 'semver'] 82 | } 83 | 84 | publishing { 85 | repositories { 86 | maven { 87 | def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 88 | def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" 89 | url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl 90 | 91 | credentials { 92 | username ossrhUsername 93 | password ossrhPassword 94 | } 95 | } 96 | } 97 | } 98 | 99 | publishing.publications.whenObjectAdded { 100 | it.pom { 101 | url = 'https://github.com/cinnober/semver-git' 102 | description = project.description 103 | 104 | scm { 105 | connection = 'scm:git:https://github.com/cinnober/semver-git' 106 | developerConnection = 'scm:git:https://github.com/cinnober/semver-git' 107 | url = 'https://github.com/cinnober/semver-git' 108 | } 109 | 110 | licenses { 111 | license { 112 | name = 'MIT License' 113 | url = 'http://www.opensource.org/licenses/mit-license.php' 114 | } 115 | } 116 | 117 | developers { 118 | developer { 119 | id = 'mikael.brannstrom' 120 | name = 'Mikael Brännström' 121 | email = 'mikael.brannstrom@cinnober.com' 122 | } 123 | developer { 124 | id = 'deepy' 125 | name = 'Alex Nordlund' 126 | email = 'alexander.nordlund@cinnober.com' 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "groovy" 2 | 3 | dependencies { 4 | compile gradleApi() 5 | compile localGroovy() 6 | } 7 | 8 | sourceSets { 9 | main { 10 | groovy { 11 | srcDirs = ['../src/main/groovy'] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # The following properties should be defined in your ~/.gradle/gradle.properties file. 2 | 3 | # The following is required for uploadArchives (to maven central) 4 | ossrhUsername=dummy 5 | ossrhPassword=secret1 6 | 7 | # Signing is also required for uploadArchives 8 | #signing.keyId=XXXXXXXX 9 | #signing.password=secret2 10 | #signing.secretKeyRingFile=path_to_file 11 | 12 | # The following is required for publishPlugins (to gradle plugin portal) 13 | # They need to be prefixed with 'systemProp.' if placed in your ~/.gradle/gradle.properties file (why?!). 14 | #gradle.publish.key=the_api_key 15 | #gradle.publish.secret=secret3 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nasdaq/semver-git/960d0ff2fb35d84eebd43731c5211385a191b68e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nasdaq/semver-git/960d0ff2fb35d84eebd43731c5211385a191b68e/gradle/wrapper/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradle/wrapper/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # semver-git # 2 | [![Build Status](https://travis-ci.org/cinnober/semver-git.svg?branch=master)](https://travis-ci.org/cinnober/semver-git) 3 | 4 | The gradle plugin 'semver-git' sets the `project.version` based on _annotated_ git tags. 5 | Version numbers must follow [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html), with the syntax _major.minor.patch_. 6 | 7 | ## Usage ## 8 | 9 | In your `build.gradle` file: 10 | 11 | plugins { 12 | id "com.cinnober.gradle.semver-git" version "2.2.0" apply false 13 | } 14 | // optionally: ext.nextVersion = "major", "minor" (default), "patch" or e.g. "3.0.0-rc2" 15 | // optionally: ext.snapshotSuffix = "SNAPSHOT" (default) or a pattern, e.g. ".g-SNAPSHOT" 16 | // optionally: ext.dirtyMarker = "-dirty" (default) replaces in snapshotSuffix 17 | // optionally: ext.gitDescribeArgs = '--match *[0-9].[0-9]*.[0-9]*' (default) or other arguments for git describe. 18 | // optionally: ext.semverPrefix = 'v' if your tags are named like v3.0.0 19 | apply plugin: 'com.cinnober.gradle.semver-git' 20 | 21 | Note: Use `apply false` combined with a manual apply if you want to change `nextVersion` and `snapshotSuffix`. 22 | 23 | Then everything should just work. To create a release, create an 24 | annotated git tag, e.g.: 25 | 26 | git tag -a 1.0.0 -m "New release" 27 | git push --tags 28 | 29 | When standing on an annotated tag commit, then version is simply the 30 | same as the tag (1.0.0 in this example). After a few commits `git 31 | describe` will show something like `1.0.0-5-g5242341` in which case 32 | the version is the snapshot of the next version. In this example the 33 | next version is minor, and the version will be `1.1.0-SNAPSHOT`. 34 | 35 | The snapshot suffix pattern can contain `` and `` which 36 | will be replaced with the commit count (`5`) and the commit sha 37 | (`5242341`) respectively. 38 | For example the snapshot suffix `.g` will generate the 39 | version `1.1.0-5.g5242341`, i.e. a non-snapshot pre-release. 40 | For example the snapshot suffix pattern is `.g-SNAPSHOT` 41 | which will generate the version `1.1.0-5.g5242341-SNAPSHOT`, which is 42 | a unique snapshot version. 43 | 44 | ### Release ### 45 | 46 | Versions are stored as annotated tags in git. [Semantic versioning](http://semver.org) is used. 47 | 48 | To create a new release, e.g. 1.2.3: 49 | 50 | git tag -a 1.2.3 -m "New release" 51 | git push --tags 52 | 53 | If changes are made after version 1.2.3 then the version number be '1.3.0-SNAPSHOT' (default a minor change). 54 | 55 | To upload the archives to the Maven Central (through the OSSRH), run: 56 | 57 | gradle clean build uploadArchives 58 | 59 | To upload the plugin to the Gradle Plugin Portal, run: 60 | 61 | gradle clean build publishPlugins 62 | 63 | Note that credentials are required for uploads. They should be placed in e.g. your 64 | ~/.gradle/gradle.properties for `uploadArchives`. 65 | See [gradle.properties](gradle.properties) for more information. 66 | -------------------------------------------------------------------------------- /src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 The Semver-Git Authors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.cinnober.gradle.semver_git 26 | 27 | import org.gradle.api.Project 28 | import org.gradle.api.Plugin 29 | 30 | class SemverGitPlugin implements Plugin { 31 | 32 | def static String getGitVersion(String nextVersion, String snapshotSuffix, String dirtyMarker, 33 | String gitArgs, String semverPrefix, File projectDir = null) { 34 | def proc = ("git describe --exact-match " + gitArgs).execute(null, projectDir); 35 | proc.waitFor(); 36 | if (proc.exitValue() == 0) { 37 | return checkVersion(proc.text.trim(), semverPrefix) 38 | } 39 | proc = ("git describe --tags --dirty --abbrev=7 " + gitArgs).execute(null, projectDir); 40 | proc.waitFor(); 41 | if (proc.exitValue() == 0) { 42 | def describe = proc.text.trim() 43 | def dirty = describe.endsWith('-dirty') 44 | if (dirty) { 45 | describe = describe.substring(0, describe.length() - 6) 46 | } 47 | def version = (describe =~ /-[0-9]+-g[0-9a-f]+$/).replaceFirst("") 48 | def suffixMatcher = (describe =~ /-([0-9]+)-g([0-9a-f]+)$/) 49 | def count = suffixMatcher[0][1]; 50 | def sha = suffixMatcher[0][2]; 51 | def suffix = snapshotSuffix; 52 | suffix = suffix.replaceAll("", count); 53 | suffix = suffix.replaceAll("", sha); 54 | suffix = suffix.replaceAll("", dirty ? dirtyMarker : ''); 55 | return getNextVersion(version, nextVersion, semverPrefix, suffix); 56 | } 57 | return getNextVersion("0.0.0", nextVersion, semverPrefix, "SNAPSHOT") 58 | } 59 | 60 | def static String checkVersion(String version, String prefix) { 61 | return formatVersion(parseVersion(version, prefix)) 62 | } 63 | 64 | def static Object[] parseVersion(String version, String prefix) { 65 | def pattern 66 | if (prefix) { 67 | pattern = /^$prefix?([0-9]+)\.([0-9]+)\.([0-9]+)(-([a-zA-Z0-9.-]+))?$/ 68 | } else { 69 | pattern = /^([0-9]+)\.([0-9]+)\.([0-9]+)(-([a-zA-Z0-9.-]+))?$/ 70 | } 71 | def matcher = version =~ pattern 72 | def arr = matcher.collect { it }[0] 73 | if (arr == null) { 74 | throw new IllegalArgumentException("Not a valid version: '" + version + "'") 75 | } 76 | return [arr[1].toInteger(), arr[2].toInteger(), arr[3].toInteger(), arr[5]] 77 | } 78 | 79 | def static String formatVersion(version) { 80 | return "" + version[0] + "." + version[1] + "." + version[2] + (version[3] != null ? "-" + version[3] : ""); 81 | } 82 | 83 | def static String getNextVersion(String version, String nextVersion, String prefix, String snapshotSuffix) { 84 | def v 85 | switch (nextVersion) { 86 | case "major": 87 | v = parseVersion(version, prefix) 88 | if (v[3] == null) { 89 | v[0] += 1 90 | v[1] = 0 91 | v[2] = 0 92 | } 93 | v[3] = snapshotSuffix 94 | return formatVersion(v) 95 | case "minor": 96 | v = parseVersion(version, prefix) 97 | if (v[3] == null) { 98 | v[1] += 1 99 | v[2] = 0 100 | } 101 | v[3] = snapshotSuffix 102 | return formatVersion(v); 103 | case "patch": 104 | v = parseVersion(version, prefix) 105 | if (v[3] == null) { 106 | v[2] += 1 107 | } 108 | v[3] = snapshotSuffix 109 | return formatVersion(v); 110 | default: 111 | return checkVersion(nextVersion, prefix); 112 | } 113 | } 114 | 115 | void apply(Project project) { 116 | def nextVersion = "minor" 117 | def snapshotSuffix = "SNAPSHOT" 118 | def dirtyMarker = "-dirty" 119 | def gitDescribeArgs = '--match *[0-9].[0-9]*.[0-9]*' 120 | String semverPrefix = null 121 | if (project.ext.properties.containsKey("nextVersion")) { 122 | nextVersion = project.ext.nextVersion 123 | } 124 | if (project.ext.properties.containsKey("snapshotSuffix")) { 125 | snapshotSuffix = project.ext.snapshotSuffix 126 | } 127 | if (project.ext.properties.containsKey("gitDescribeArgs")) { 128 | gitDescribeArgs = project.ext.gitDescribeArgs 129 | } 130 | if (project.ext.properties.containsKey("dirtyMarker")) { 131 | dirtyMarker = project.ext.dirtyMarker 132 | } 133 | if (project.ext.properties.containsKey("semverPrefix")) { 134 | semverPrefix = project.ext.semverPrefix 135 | } 136 | project.version = getGitVersion(nextVersion, snapshotSuffix, dirtyMarker, gitDescribeArgs, semverPrefix, project.projectDir) 137 | project.tasks.register('showVersion') { 138 | group = 'Help' 139 | description = 'Show the project version' 140 | doLast { 141 | println "Version: " + project.version 142 | } 143 | } 144 | } 145 | } -------------------------------------------------------------------------------- /src/test/groovy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nasdaq/semver-git/960d0ff2fb35d84eebd43731c5211385a191b68e/src/test/groovy/.gitignore -------------------------------------------------------------------------------- /src/test/groovy/com/cinnober/gradle/semver_git/SemverGitPluginFunctionalTest.groovy: -------------------------------------------------------------------------------- 1 | package com.cinnober.gradle.semver_git 2 | 3 | import org.gradle.testkit.runner.BuildResult 4 | import org.gradle.testkit.runner.GradleRunner 5 | import spock.lang.Ignore 6 | import spock.lang.Shared 7 | import spock.lang.Specification 8 | import spock.lang.TempDir 9 | 10 | import java.nio.file.Files 11 | import java.nio.file.Path 12 | 13 | @Ignore 14 | class SemverGitPluginFunctionalTest extends Specification { 15 | @Shared 16 | Boolean slowIo = false 17 | 18 | @TempDir 19 | Path baseDir 20 | File projectDir 21 | File build 22 | File settings 23 | 24 | def setupSpec() { 25 | try { 26 | if (InetAddress.getLocalHost().getHostName().startsWith("SE40MAC")) { 27 | slowIo = true 28 | } 29 | } catch (Exception ignored) {} 30 | } 31 | 32 | def setup() { 33 | projectDir = Files.createTempDirectory(baseDir, "test").toFile() 34 | build = new File(projectDir, "build.gradle") 35 | settings = new File(projectDir, "settings.gradle") 36 | settings << "rootProject.name = 'semver-test'" 37 | } 38 | 39 | def "Simple build"() { 40 | when: 41 | setupPluginWithClasspath() 42 | init() 43 | BuildResult result = gradleBuild("showVersion") 44 | 45 | then: 46 | result.getOutput().contains("Version: 0.1.0-SNAPSHOT") 47 | } 48 | 49 | def "Simple build with commit"() { 50 | when: 51 | setupPluginWithClasspath() 52 | init() 53 | commit() 54 | tag("1.0.0") 55 | commit() 56 | BuildResult result = gradleBuild("showVersion") 57 | 58 | then: 59 | result.getOutput().contains("Version: 1.1.0-SNAPSHOT") 60 | } 61 | 62 | def "Prefixed tag"() { 63 | when: 64 | setupPluginWithClasspath('v') 65 | init() 66 | commit() 67 | tag("v1.0.0") 68 | BuildResult result = gradleBuild("showVersion") 69 | 70 | then: 71 | result.getOutput().contains("Version: 1.0.0") 72 | } 73 | 74 | def "Prefixed tag with commit"() { 75 | when: 76 | setupPluginWithClasspath('v') 77 | init() 78 | commit() 79 | tag("v1.0.0") 80 | commit() 81 | BuildResult result = gradleBuild("showVersion") 82 | 83 | then: 84 | result.getOutput().contains("Version: 1.1.0-SNAPSHOT") 85 | } 86 | 87 | def git(String argument) { 88 | return ("git " + argument).execute(null, projectDir) 89 | } 90 | 91 | def init() { 92 | return git("init") 93 | } 94 | 95 | def commit() { 96 | return git("commit --allow-empty -m empty") 97 | } 98 | 99 | def tag(String name) { 100 | return git("tag -a $name -m tag") 101 | } 102 | 103 | def setupPluginWithClasspath( 104 | String prefix = null 105 | ) { 106 | build.write """ 107 | plugins { 108 | id "com.cinnober.gradle.semver-git" apply false 109 | } 110 | // optionally: ext.nextVersion = "major", "minor" (default), "patch" or e.g. "3.0.0-rc2" 111 | // optionally: ext.snapshotSuffix = "SNAPSHOT" (default) or a pattern, e.g. ".g-SNAPSHOT" 112 | // optionally: ext.dirtyMarker = "-dirty" (default) replaces in snapshotSuffix 113 | // optionally: ext.gitDescribeArgs = '--match *[0-9].[0-9]*.[0-9]*' (default) or other arguments for git describe. 114 | """ 115 | if (prefix) { 116 | build << "ext.semverPrefix = '$prefix'" 117 | } 118 | build << """ 119 | apply plugin: 'com.cinnober.gradle.semver-git' 120 | """ 121 | } 122 | 123 | BuildResult gradleBuild(String... arguments) { 124 | if (slowIo) { 125 | sleep(1000) 126 | } 127 | return GradleRunner.create() 128 | .withProjectDir(projectDir) 129 | .withArguments(arguments) 130 | .withPluginClasspath() 131 | .build() 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/test/groovy/com/cinnober/gradle/semver_git/SemverGitPluginTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 The Semver-Git Authors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.cinnober.gradle.semver_git 26 | 27 | import spock.lang.Specification 28 | 29 | 30 | class SemverGitPluginTest extends Specification { 31 | def "parseVersion"(String input, expected) { 32 | expect: 33 | def actual = SemverGitPlugin.parseVersion(input, null) 34 | expected == actual 35 | 36 | where: 37 | input || expected 38 | "1.0.0" || [1,0,0,null] 39 | "1.2.3" || [1,2,3,null] 40 | "1.2.3-beta" || [1,2,3,"beta"] 41 | "1.2.3-SNAPSHOT"|| [1,2,3,"SNAPSHOT"] 42 | "12.34.56-rc78" || [12,34,56,"rc78"] 43 | } 44 | 45 | def "parseVersion prefixed"(String input, prefix, expected) { 46 | expect: 47 | def actual = SemverGitPlugin.parseVersion(input, prefix) 48 | expected == actual 49 | 50 | where: 51 | input | prefix || expected 52 | "v1.0.0" | 'v' || [1,0,0,null] 53 | "v1.2.3" | 'v' || [1,2,3,null] 54 | "v1.2.3-beta" | 'v' || [1,2,3,"beta"] 55 | "v1.2.3-SNAPSHOT"| 'v' || [1,2,3,"SNAPSHOT"] 56 | "v12.34.56-rc78" | 'v' || [12,34,56,"rc78"] 57 | } 58 | 59 | def "formatVersion"(input, expected) { 60 | expect: 61 | def actual = SemverGitPlugin.formatVersion(input) 62 | expected == actual 63 | 64 | where: 65 | input || expected 66 | [1,0,0,null] || "1.0.0" 67 | [1,2,3,null] || "1.2.3" 68 | [1,2,3,"beta"] || "1.2.3-beta" 69 | [1,2,3,"SNAPSHOT"] || "1.2.3-SNAPSHOT" 70 | [12,34,56,"rc78"] || "12.34.56-rc78" 71 | } 72 | 73 | def "testFail"(String input) { 74 | when: 75 | SemverGitPlugin.parseVersion(input, null) 76 | 77 | then: 78 | thrown(IllegalArgumentException) 79 | 80 | where: 81 | input << ["a.b.c", "1", "a1.2.3", "1.2.3a"] 82 | } 83 | 84 | def "testNextVersion"(String expected, String version, String nextVersion) { 85 | expect: 86 | def actual = SemverGitPlugin.getNextVersion(version, nextVersion, null, "SNAPSHOT") 87 | expected == actual 88 | 89 | where: 90 | version | nextVersion || expected 91 | "1.2.3" | "patch" || "1.2.4-SNAPSHOT" 92 | "1.2.3-beta" | "patch" || "1.2.3-SNAPSHOT" 93 | "1.2.3" | "minor" || "1.3.0-SNAPSHOT" 94 | "1.2.3-beta" | "minor" || "1.2.3-SNAPSHOT" 95 | "1.2.0-beta" | "minor" || "1.2.0-SNAPSHOT" 96 | "1.2.3" | "major" || "2.0.0-SNAPSHOT" 97 | "1.2.3-beta" | "major" || "1.2.3-SNAPSHOT" 98 | "1.0.0-beta" | "major" || "1.0.0-SNAPSHOT" 99 | } 100 | 101 | } --------------------------------------------------------------------------------