diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c0190e..9788a59 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,3 @@ -version: 2 defaults: &defaults working_directory: ~/repo docker: @@ -8,6 +7,8 @@ defaults: &defaults TERM: dumb CI: true +version: 2.0 + jobs: build_gradle: <<: *defaults diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index f1ac387..0000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Java CI with Gradle - -on: [push, pull_request, workflow_dispatch] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Test with Gradle - run: ./gradlew check diff --git a/.gitignore b/.gitignore index f007981..a78c5c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,32 @@ -.vscode/* !.vscode/extensions.json !.vscode/launch.json !.vscode/settings.json !.vscode/tasks.json - -__pycache__ +!gradle-wrapper.jar .classpath .DS_Store .gradle .history +.idea_modules/ +.idea/**/contentModel.xml +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/dataSources/ +.idea/**/dbnavigator.xml +.idea/**/dictionaries +.idea/**/dynamic.xml +.idea/**/gradle.xml +.idea/**/libraries +.idea/**/mongoSettings.xml +.idea/**/shelf +.idea/**/sqlDataSources.xml +.idea/**/tasks.xml +.idea/**/uiDesigner.xml +.idea/**/usage.statistics.xml +.idea/**/workspace.xml +.idea/caches/build_file_checksums.ser +.idea/httpRequests +.idea/replstate.xml .kobalt .mtj.tmp/ .mvn/timing.properties @@ -17,39 +35,20 @@ __pycache__ .project .scannerwork .settings +.vscode/* *.class *.code-workspace *.ctxt +*.ear *.iws +*.jar *.log *.nar *.rar *.sublime-* *.tar.gz +*.war *.zip -/**/.idea_modules/ -/**/.idea/**/caches/build_file_checksums.ser -/**/.idea/**/contentModel.xml -/**/.idea/**/dataSources.ids -/**/.idea/**/dataSources.local.xml -/**/.idea/**/dataSources/ -/**/.idea/**/dbnavigator.xml -/**/.idea/**/dictionaries -/**/.idea/**/dynamic.xml -/**/.idea/**/gradle.xml -/**/.idea/**/httpRequests -/**/.idea/**/libraries -/**/.idea/**/mongoSettings.xml -/**/.idea/**/replstate.xml -/**/.idea/**/shelf -/**/.idea/**/shelf/ -/**/.idea/**/sqlDataSources.xml -/**/.idea/**/tasks.xml -/**/.idea/**/uiDesigner.xml -/**/.idea/**/usage.statistics.xml -/**/.idea/**/workspace.xml -/**/.idea/$CACHE_FILE$ -/**/.idea/$PRODUCT_WORKSPACE_FILE$ atlassian-ide-plugin.xml bin/ build/ @@ -81,4 +80,3 @@ release.properties target/ test-output Thumbs.db -venv diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 26820aa..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,31 +0,0 @@ -image: gradle:alpine - -variables: - GRADLE_OPTS: "-Dorg.gradle.daemon=false" - -before_script: - - export GRADLE_USER_HOME=`pwd`/.gradle - -stages: - - build - - test - -build: - stage: build - script: ./gradlew --build-cache assemble - cache: - key: "$CI_COMMIT_REF_NAME" - policy: push - paths: - - build - - .gradle - -test: - stage: test - script: ./gradlew check - cache: - key: "$CI_COMMIT_REF_NAME" - policy: pull - paths: - - build - - .gradle diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index d91f848..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/Erik_s_Copyright_Notice.xml b/.idea/copyright/Erik_s_Copyright_Notice.xml index 914713f..935baa1 100644 --- a/.idea/copyright/Erik_s_Copyright_Notice.xml +++ b/.idea/copyright/Erik_s_Copyright_Notice.xml @@ -1,6 +1,5 @@ - diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 98b5537..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 692822a..82f5b1f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,15 +1,6 @@ - - - - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 4c5218b..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/Copyright.xml b/.idea/scopes/Copyright.xml index 5acbcdb..edcac0e 100644 --- a/.idea/scopes/Copyright.xml +++ b/.idea/scopes/Copyright.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4a40469..25b785f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: java -dist: trusty + +env: + global: + - CI=true jdk: - oraclejdk8 @@ -25,6 +28,6 @@ cache: after_success: - | - if [ "${TRAVIS_TEST_RESULT}" == 0 ]; then - ./gradlew sonarqube - fi + if [ "${TRAVIS_TEST_RESULT}" == 0 ]; then + ./gradlew sonarqube + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c8942..f8e4f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,29 +1,5 @@ # Change Log -## [1.0.4](https://github.com/ethauvin/semver-gradle/tree/1.0.4) (2019-07-26) -[Full Changelog](https://github.com/ethauvin/semver-gradle/compare/1.0.3-beta...1.0.4) - -**Implemented enhancements:** - -- Access semver version properties in Gradle build file. [\#8](https://github.com/ethauvin/semver-gradle/issues/8) - -## [1.0.3-beta](https://github.com/ethauvin/semver-gradle/tree/1.0.3-beta) (2019-07-25) -[Full Changelog](https://github.com/ethauvin/semver-gradle/compare/1.0.2...1.0.3-beta) - -**Closed issues:** - -- Thanks! [\#7](https://github.com/ethauvin/semver-gradle/issues/7) - -## [1.0.2](https://github.com/ethauvin/semver-gradle/tree/1.0.2) (2019-05-24) -[Full Changelog](https://github.com/ethauvin/semver-gradle/compare/1.0.1...1.0.2) - -**Implemented enhancements:** - -- version.properties write issue when using NetBeans on Windows. [\#6](https://github.com/ethauvin/semver-gradle/issues/6) - -## [1.0.1](https://github.com/ethauvin/semver-gradle/tree/1.0.1) (2019-05-24) -[Full Changelog](https://github.com/ethauvin/semver-gradle/compare/1.0.0...1.0.1) - ## [1.0.0](https://github.com/ethauvin/semver-gradle/tree/1.0.0) (2019-04-23) [Full Changelog](https://github.com/ethauvin/semver-gradle/compare/0.9.9-beta...1.0.0) diff --git a/LICENSE.TXT b/LICENSE.TXT index 7345551..8ad4ca5 100644 --- a/LICENSE.TXT +++ b/LICENSE.TXT @@ -1,4 +1,4 @@ -Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) +Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 681d9b4..805dc0e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_semver-gradle&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_semver-gradle) [![Build Status](https://travis-ci.com/ethauvin/semver-gradle.svg?branch=master)](https://travis-ci.com/ethauvin/semver-gradle) [![CircleCI](https://circleci.com/gh/ethauvin/semver-gradle/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/semver-gradle/tree/master) [![Gradle](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/net/thauvin/erik/gradle/semver/maven-metadata.xml.svg?label=gradle&color=blue)](https://plugins.gradle.org/plugin/net.thauvin.erik.gradle.semver) +[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_semver-gradle&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_semver-gradle) [![Build Status](https://travis-ci.org/ethauvin/semver-gradle.svg?branch=master)](https://travis-ci.org/ethauvin/semver-gradle) [![CircleCI](https://circleci.com/gh/ethauvin/semver-gradle/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/semver-gradle/tree/master) [![Gradle](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/net/thauvin/erik/gradle/semver/maven-metadata.xml.svg?label=gradle&color=blue)](https://plugins.gradle.org/plugin/net.thauvin.erik.gradle.semver) # Semantic Version Plugin for Gradle @@ -244,57 +244,6 @@ test.semver=1.0.0 - __Examples__: [Java](https://github.com/ethauvin/semver-gradle/tree/master/examples/java), [Kotlin](https://github.com/ethauvin/semver-gradle/tree/master/examples/kotlin) -### Semver Extension Properties - -The values stored in the version properties file can individually be accessed using the `semver` extension, for example: - -```gradle - fooTask { - doFirst { - println "Build: $semver.buildMeta" - } - } -``` - -The semver extension properties are: - -Property | Description -:-------------------------|:---------------------------- -`semver.semver` | The full semantic version. -`semver.version` | Same as `semver.semver`. -`semver.major` | The major version. -`semver.minor` | The minor version. -`semver.patch` | The patch version. -`semver.preRelease` | The pre-release version -`semver.preReleasePrefix` | The pre-release prefix -`semver.buildMeta` | The build metatdata version -`semver.buildMetaPrefix` | The build metadata prefix -`semver.separator` | The version separator. - -## Version is "unspecified" - -This is a common problem stemming from the configuration and build phases in Gradle. - -It is always preferable to access to version during the execution stage, in a `doFirst` or `doLast` closure within your tasks: - -```gradle -task foo() { - doFirst { - println project.version - } -} -``` - -or if absolutely necessary, at the end of the configuration stage in a `project.afterEvaluate` block: - -```gradle -foo { - project.afterEvaluate { - println project.version - } -} -``` - ## Source Code Generation If you'd like to incorporate the version number data into your source code, please have a look at the [__Semantic Version Annotation Processor__](https://github.com/ethauvin/semver). diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml deleted file mode 100644 index 7d98402..0000000 --- a/bitbucket-pipelines.yml +++ /dev/null @@ -1,9 +0,0 @@ -image: openjdk:8 - -pipelines: - default: - - step: - caches: - - gradle - script: - - bash ./gradlew check diff --git a/build.gradle.kts b/build.gradle.kts index 5d51035..8839bbd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,26 +2,24 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `java-gradle-plugin` + `kotlin-dsl` `maven-publish` jacoco - kotlin("jvm") version "1.3.72" - id("com.github.ben-manes.versions") version "0.36.0" - id("com.gradle.plugin-publish") version "0.12.0" - id("io.gitlab.arturbosch.detekt") version "1.14.2" - id("org.gradle.kotlin.kotlin-dsl") version "1.3.6" - id("org.sonarqube") version "3.0" + id("com.github.ben-manes.versions") version "0.21.0" + id("com.gradle.build-scan") version "2.3" + id("com.gradle.plugin-publish") version "0.10.1" + id("io.gitlab.arturbosch.detekt") version "1.0.0-RC14" + id("org.jmailen.kotlinter") version "1.25.2" + id("org.sonarqube") version "2.7.1" } -version = "1.0.5-beta" +version = "1.0.1" group = "net.thauvin.erik.gradle" -object VersionInfo { - const val spek = "2.0.13" -} -val versions: VersionInfo by extra { VersionInfo } +var github = "https://github.com/ethauvin/semver-gradle" +var packageName = "net.thauvin.erik.gradle.semver" -val github = "https://github.com/ethauvin/semver-gradle" -val packageName = "net.thauvin.erik.gradle.semver" +var spek_version = "2.0.5" repositories { jcenter() @@ -30,15 +28,12 @@ repositories { dependencies { implementation(gradleApi()) - implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - implementation(kotlin("stdlib")) testImplementation(kotlin("reflect")) testImplementation(kotlin("test")) - testImplementation(gradleTestKit()) - testImplementation("org.spekframework.spek2:spek-dsl-jvm:${versions.spek}") - testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:${versions.spek}") + testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spek_version") + testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spek_version") } tasks { @@ -66,12 +61,28 @@ tasks { } } +buildScan { + link("GitHub", "https://github.com/ethauvin/semver-gradle/tree/master") + if ("true" == System.getenv("CI")) { + publishOnFailure() + tag("CI") + } + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" +} + detekt { - // input = files("src/main/kotlin", "src/test/kotlin") - // filters = ".*/resources/.*,.*/build/.*" + input = files("src/main/kotlin", "src/test/kotlin") + filters = ".*/resources/.*,.*/build/.*" baseline = project.rootDir.resolve("detekt-baseline.xml") } +kotlinter { + ignoreFailures = false + reporters = arrayOf("html") + experimentalRules = false +} + sonarqube { properties { property("sonar.projectName", "semver-gradle") diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 52cc674..ffcc67e 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -1,12 +1,13 @@ - - + + + ComplexMethod:Utils.kt$Utils$fun loadProperties(file: File): Properties MagicNumber:Utils.kt$Utils$3 MagicNumber:Utils.kt$Utils$4 - MagicNumber:Utils.kt$Utils$5 + MaxLineLength:SemverPlugin.kt$net.thauvin.erik.gradle.semver.SemverPlugin.kt NestedBlockDepth:Utils.kt$Utils$fun loadProperties(file: File): Properties - NestedBlockDepth:Utils.kt$Utils$fun parseSemVer(input: String?, version: Version): Boolean - NestedBlockDepth:Utils.kt$Utils$fun saveProperties(projectDir: File, config: SemverConfig, version: Version) - - + NestedBlockDepth:Utils.kt$Utils$fun parseSemVer(input: String, version: Version): String + NestedBlockDepth:Utils.kt$Utils$fun saveProperties(config: SemverConfig, version: Version) + + \ No newline at end of file diff --git a/examples/annotation-processor/java/build.gradle b/examples/annotation-processor/java/build.gradle index b343869..4fae1e3 100644 --- a/examples/annotation-processor/java/build.gradle +++ b/examples/annotation-processor/java/build.gradle @@ -1,8 +1,8 @@ plugins { id 'java' id 'application' - id 'net.thauvin.erik.gradle.semver' version '1.0.4' - id 'com.github.ben-manes.versions' version '0.28.0' + id 'net.thauvin.erik.gradle.semver' version '1.0.1' + id 'com.github.ben-manes.versions' version '0.21.0' } // ./gradlew @@ -14,16 +14,13 @@ mainClassName = 'com.example.Example' defaultTasks 'run' +compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java") + def semverProcessor = "net.thauvin.erik:semver:1.2.0" dependencies { annotationProcessor semverProcessor - implementation semverProcessor -} - -tasks.withType(JavaCompile) { - options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java") - options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ] + compileOnly semverProcessor } repositories { diff --git a/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.jar b/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.jar index f3d88b1..5c2d1cf 100644 Binary files a/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.jar and b/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.properties b/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.properties index a2bf131..f4d7b2b 100644 --- a/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.properties +++ b/examples/annotation-processor/java/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/annotation-processor/java/gradlew b/examples/annotation-processor/java/gradlew index 2fe81a7..b0d6d0a 100755 --- a/examples/annotation-processor/java/gradlew +++ b/examples/annotation-processor/java/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -125,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# 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"` @@ -154,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + 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" ;; + (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 @@ -175,9 +175,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +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/annotation-processor/java/gradlew.bat b/examples/annotation-processor/java/gradlew.bat index 62bd9b9..9991c50 100644 --- a/examples/annotation-processor/java/gradlew.bat +++ b/examples/annotation-processor/java/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - @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="-Xmx64m" "-Xms64m" diff --git a/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java b/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java index 5010897..19aa5c6 100644 --- a/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java +++ b/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java @@ -2,7 +2,6 @@ * This file is automatically generated. * Do not modify! -- ALL CHANGES WILL BE ERASED! */ - package com.example; import java.util.Date; @@ -13,17 +12,17 @@ import java.util.Date; * @author Semantic Version Annotation Processor */ public final class GeneratedVersion { - public static final String PROJECT = "Java Example"; - public static final Date BUILDDATE = new Date(1564027571537L); - public static final int MAJOR = 2; - public static final int MINOR = 10; - public static final int PATCH = 0; - public static final String PRERELEASE = ""; - public static final String PRERELEASE_PREFIX = "-"; - public static final String BUILDMETA = ""; - public static final String BUILDMETA_PREFIX = "+"; - public static final String SEPARATOR = "."; - public static final String VERSION = "2.10.0"; + public final static String PROJECT = "Java Example"; + public final static Date BUILDDATE = new Date(1556062927242L); + public final static int MAJOR = 2; + public final static int MINOR = 9; + public final static int PATCH = 0; + public final static String PRERELEASE = ""; + public final static String PRERELEASE_PREFIX = "-"; + public final static String BUILDMETA = ""; + public final static String BUILDMETA_PREFIX = "+"; + public final static String SEPARATOR = "."; + public final static String VERSION = "2.9.0"; /** * Disables the default constructor. diff --git a/examples/annotation-processor/java/version.properties b/examples/annotation-processor/java/version.properties index fc54733..29ed47a 100644 --- a/examples/annotation-processor/java/version.properties +++ b/examples/annotation-processor/java/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Wed Jul 24 21:06:09 PDT 2019 +#Tue Apr 23 16:42:04 PDT 2019 version.buildmeta= version.major=2 -version.minor=10 +version.minor=9 version.patch=0 version.prerelease= version.project=Java Example -version.semver=2.10.0 +version.semver=2.9.0 diff --git a/examples/annotation-processor/kotlin/build.gradle.kts b/examples/annotation-processor/kotlin/build.gradle.kts index 78cd80b..363fdbf 100644 --- a/examples/annotation-processor/kotlin/build.gradle.kts +++ b/examples/annotation-processor/kotlin/build.gradle.kts @@ -1,9 +1,9 @@ plugins { - kotlin("jvm").version("1.3.61") + kotlin("jvm").version("1.3.30") application - id("org.jetbrains.kotlin.kapt").version("1.3.61") - id("net.thauvin.erik.gradle.semver").version("1.0.4") - id("com.github.ben-manes.versions").version("0.28.0") + id("org.jetbrains.kotlin.kapt").version("1.3.31") + id("net.thauvin.erik.gradle.semver").version("1.0.1") + id("com.github.ben-manes.versions").version("0.21.0") } // ./gradlew @@ -17,7 +17,7 @@ var semverProcessor = "net.thauvin.erik:semver:1.2.0" dependencies { kapt(semverProcessor) - implementation(semverProcessor) + compileOnly(semverProcessor) implementation(kotlin("stdlib")) } diff --git a/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.jar b/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.jar index f3d88b1..5c2d1cf 100644 Binary files a/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.jar and b/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.properties b/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.properties index a2bf131..f4d7b2b 100644 --- a/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/examples/annotation-processor/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/annotation-processor/kotlin/gradlew b/examples/annotation-processor/kotlin/gradlew index 2fe81a7..b0d6d0a 100755 --- a/examples/annotation-processor/kotlin/gradlew +++ b/examples/annotation-processor/kotlin/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -125,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# 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"` @@ -154,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + 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" ;; + (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 @@ -175,9 +175,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +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/annotation-processor/kotlin/gradlew.bat b/examples/annotation-processor/kotlin/gradlew.bat index 62bd9b9..9991c50 100644 --- a/examples/annotation-processor/kotlin/gradlew.bat +++ b/examples/annotation-processor/kotlin/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - @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="-Xmx64m" "-Xms64m" diff --git a/examples/annotation-processor/kotlin/version.properties b/examples/annotation-processor/kotlin/version.properties index 8da5e3a..0c32b5e 100644 --- a/examples/annotation-processor/kotlin/version.properties +++ b/examples/annotation-processor/kotlin/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Wed Jul 24 21:06:46 PDT 2019 +#Tue Apr 23 16:42:52 PDT 2019 version.buildmeta= version.major=14 -version.minor=3 +version.minor=2 version.patch=0 version.prerelease= version.project=Kotlin Example -version.semver=14.3.0 +version.semver=14.2.0 diff --git a/examples/java/build.gradle b/examples/java/build.gradle index e841b08..b6b7234 100644 --- a/examples/java/build.gradle +++ b/examples/java/build.gradle @@ -1,8 +1,8 @@ plugins { id 'java' id 'application' - id 'net.thauvin.erik.gradle.semver' version '1.0.4' - id 'com.github.ben-manes.versions' version '0.36.0' + id 'net.thauvin.erik.gradle.semver' version '1.0.1' + id 'com.github.ben-manes.versions' version '0.21.0' } // ./gradlew @@ -10,14 +10,14 @@ plugins { // ./gradlew incrementMinor run // ./gradlew incrementMajor run // ./gradlew incrementBuildMeta run -// ./gradlew echoVersion +mainClassName = 'App' defaultTasks 'run' dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0-M1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.0-M1' } repositories { @@ -28,13 +28,6 @@ test { useJUnitPlatform() } -application { - mainClassName = 'App' -// project.afterEvaluate { -// println "Version: $version" -// } -} - semver { // properties = "example.properties" // keysPrefix = "example." @@ -51,14 +44,9 @@ incrementBuildMeta { run { doFirst { -// println "Version: ${-> version}" println "Version: $version" } // args = ['example.properties'] args = ['version.properties'] } - -task echoVersion(type:Exec) { - commandLine 'echo', "${-> project.version}" -} diff --git a/examples/java/gradle/wrapper/gradle-wrapper.jar b/examples/java/gradle/wrapper/gradle-wrapper.jar index e708b1c..5c2d1cf 100644 Binary files a/examples/java/gradle/wrapper/gradle-wrapper.jar and b/examples/java/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/java/gradle/wrapper/gradle-wrapper.properties b/examples/java/gradle/wrapper/gradle-wrapper.properties index be52383..f4d7b2b 100644 --- a/examples/java/gradle/wrapper/gradle-wrapper.properties +++ b/examples/java/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/java/gradlew b/examples/java/gradlew index 4f906e0..b0d6d0a 100755 --- a/examples/java/gradlew +++ b/examples/java/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -82,7 +82,6 @@ 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 @@ -126,11 +125,10 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# 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 @@ -156,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + 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" ;; + (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 @@ -177,9 +175,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +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/java/gradlew.bat b/examples/java/gradlew.bat index 107acd3..9991c50 100644 --- a/examples/java/gradlew.bat +++ b/examples/java/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - @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="-Xmx64m" "-Xms64m" @@ -40,7 +37,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +51,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto execute +if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,14 +61,28 @@ 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 %* +"%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 diff --git a/examples/java/src/main/java/App.java b/examples/java/src/main/java/App.java index 32b2431..f1550d6 100644 --- a/examples/java/src/main/java/App.java +++ b/examples/java/src/main/java/App.java @@ -17,4 +17,4 @@ public class App { } } } -} +} \ No newline at end of file diff --git a/examples/java/src/test/java/AppTest.java b/examples/java/src/test/java/AppTest.java index b214b69..e5e3dd6 100644 --- a/examples/java/src/test/java/AppTest.java +++ b/examples/java/src/test/java/AppTest.java @@ -9,4 +9,4 @@ class AppTest { assertAll("app should have a main method.", () -> classUnderTest.getClass().getMethod("main", String[].class)); } -} +} \ No newline at end of file diff --git a/examples/java/version.properties b/examples/java/version.properties index f5bf6aa..4a0739e 100644 --- a/examples/java/version.properties +++ b/examples/java/version.properties @@ -1,8 +1,8 @@ #Generated by the Semver Plugin for Gradle -#Fri Sep 25 17:38:33 PDT 2020 -version.buildmeta=20200925173833 +#Fri May 24 01:11:52 PDT 2019 +version.buildmeta=20190524011152 version.major=1 -version.minor=0 -version.patch=0 -version.prerelease= -version.semver=1.0.0+20200925173833 +version.minor=1 +version.patch=8 +version.prerelease=alpha +version.semver=1.1.8-alpha+20190524011152 diff --git a/examples/kotlin/build.gradle.kts b/examples/kotlin/build.gradle.kts index d54e882..d7ece1c 100644 --- a/examples/kotlin/build.gradle.kts +++ b/examples/kotlin/build.gradle.kts @@ -4,10 +4,10 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter plugins { - kotlin("jvm").version("1.4.10") + kotlin("jvm").version("1.3.31") application - id("net.thauvin.erik.gradle.semver").version("1.0.4") - id("com.github.ben-manes.versions").version("0.36.0") + id("net.thauvin.erik.gradle.semver").version("1.0.1") + id("com.github.ben-manes.versions").version("0.21.0") } // ./gradlew @@ -20,7 +20,7 @@ defaultTasks(ApplicationPlugin.TASK_RUN_NAME) dependencies { implementation(kotlin("stdlib")) - testImplementation("org.testng:testng:7.3.0") + testImplementation("org.testng:testng:6.14.3") } repositories { @@ -29,9 +29,6 @@ repositories { application { mainClassName = "com.example.MainKt" -// project.afterEvaluate { -// println("Version: $version") -// } } semver { diff --git a/examples/kotlin/gradle/wrapper/gradle-wrapper.jar b/examples/kotlin/gradle/wrapper/gradle-wrapper.jar index e708b1c..5c2d1cf 100644 Binary files a/examples/kotlin/gradle/wrapper/gradle-wrapper.jar and b/examples/kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/kotlin/gradle/wrapper/gradle-wrapper.properties b/examples/kotlin/gradle/wrapper/gradle-wrapper.properties index be52383..f4d7b2b 100644 --- a/examples/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/examples/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/kotlin/gradlew b/examples/kotlin/gradlew index 4f906e0..b0d6d0a 100755 --- a/examples/kotlin/gradlew +++ b/examples/kotlin/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -82,7 +82,6 @@ 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 @@ -126,11 +125,10 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# 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 @@ -156,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + 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" ;; + (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 @@ -177,9 +175,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +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/kotlin/gradlew.bat b/examples/kotlin/gradlew.bat index 107acd3..9991c50 100644 --- a/examples/kotlin/gradlew.bat +++ b/examples/kotlin/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - @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="-Xmx64m" "-Xms64m" @@ -40,7 +37,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +51,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto execute +if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,14 +61,28 @@ 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 %* +"%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 diff --git a/examples/kotlin/src/main/kotlin/com/example/Main.kt b/examples/kotlin/src/main/kotlin/com/example/Main.kt index caaa0c1..4ef488b 100644 --- a/examples/kotlin/src/main/kotlin/com/example/Main.kt +++ b/examples/kotlin/src/main/kotlin/com/example/Main.kt @@ -13,4 +13,4 @@ fun main(args: Array) { } } } -} +} \ No newline at end of file diff --git a/examples/kotlin/src/test/kotlin/com/example/MainTest.kt b/examples/kotlin/src/test/kotlin/com/example/MainTest.kt index e49aac0..96458e9 100644 --- a/examples/kotlin/src/test/kotlin/com/example/MainTest.kt +++ b/examples/kotlin/src/test/kotlin/com/example/MainTest.kt @@ -5,4 +5,4 @@ import org.testng.annotations.Test class ExampleTest { @Test fun f() = println("Running test") -} +} \ No newline at end of file diff --git a/examples/kotlin/version.properties b/examples/kotlin/version.properties index 98e937a..42b96ca 100644 --- a/examples/kotlin/version.properties +++ b/examples/kotlin/version.properties @@ -1,8 +1,8 @@ #Generated by the Semver Plugin for Gradle -#Mon Nov 09 21:24:16 PST 2020 -version.buildmeta=20201109212416 +#Fri May 24 01:12:52 PDT 2019 +version.buildmeta=20190524011252 version.major=1 version.minor=2 version.patch=4 version.prerelease=beta -version.semver=1.2.4-beta+20201109212416 +version.semver=1.2.4-beta+20190524011252 diff --git a/examples/test/build.gradle b/examples/test/build.gradle index 9813e76..ba95d75 100644 --- a/examples/test/build.gradle +++ b/examples/test/build.gradle @@ -1,10 +1,9 @@ buildscript { repositories { mavenLocal() - mavenCentral() } dependencies { - classpath "net.thauvin.erik.gradle:semver:1.0.5-beta" + classpath "net.thauvin.erik.gradle:semver:1.0.1" } } @@ -14,7 +13,7 @@ apply plugin: 'net.thauvin.erik.gradle.semver' mainClassName = 'App' -//version = 1.0 +version = 1.0 def f = new File("version.properties") @@ -30,13 +29,6 @@ repositories { jcenter() } -application { - println(project.version) - project.afterEvaluate { - println(project.version) - } -} - incrementBuildMeta { doFirst { @@ -47,15 +39,11 @@ incrementBuildMeta { run { doFirst { - println("Version: $semver.major$semver.separator$semver.minor$semver.separator$semver.patch$semver.preReleasePrefix$semver.preRelease$semver.buildMetaPrefix$semver.buildMeta") + println("Version: $version") args = [f.name] } } -task echoVersion(type:Exec) { - commandLine "echo", "${-> version}" -} - semver { properties = "${f.name}" keysPrefix = f.name.substring(0, f.name.indexOf(".") + 1) diff --git a/examples/test/gradle/wrapper/gradle-wrapper.properties b/examples/test/gradle/wrapper/gradle-wrapper.properties index 4b7e1f3..ea13fdf 100644 --- a/examples/test/gradle/wrapper/gradle-wrapper.properties +++ b/examples/test/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/test/gradlew b/examples/test/gradlew index 8e25e6c..b0d6d0a 100755 --- a/examples/test/gradlew +++ b/examples/test/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/test/gradlew.bat b/examples/test/gradlew.bat index 9618d8d..9991c50 100644 --- a/examples/test/gradlew.bat +++ b/examples/test/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/test/src/test/java/AppTest.java b/examples/test/src/test/java/AppTest.java new file mode 100644 index 0000000..7bd2702 --- /dev/null +++ b/examples/test/src/test/java/AppTest.java @@ -0,0 +1,15 @@ +/* + * 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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..5c2d1cf 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be52383..f4d7b2b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..b0d6d0a 100755 --- a/gradlew +++ b/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -82,7 +82,6 @@ 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 @@ -126,11 +125,10 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# 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 @@ -156,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + 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" ;; + (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 @@ -177,9 +175,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +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 index 107acd3..9991c50 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem http://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - @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="-Xmx64m" "-Xms64m" @@ -40,7 +37,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +51,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto execute +if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,14 +61,28 @@ 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 %* +"%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 diff --git a/settings.gradle.kts b/settings.gradle.kts index e9b895f..f9f14c5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,17 +1 @@ -plugins { - id("com.gradle.enterprise").version("3.3.4") -} - -gradleEnterprise { - buildScan { - link("GitHub", "https://github.com/ethauvin/semver-gradle/tree/master") - if ("true" == System.getenv("CI")) { - publishOnFailure() - tag("CI") - } - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" - } -} - rootProject.name = "semver" diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt index 06a8f7b..7327356 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt @@ -1,7 +1,7 @@ /* * SemverConfig.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,11 +32,7 @@ package net.thauvin.erik.gradle.semver -import javax.inject.Inject - -open class SemverConfig @Inject constructor( - private val semVersion: Version -) { +open class SemverConfig { companion object { const val DEFAULT_KEYS_PREFIX = "version." const val DEFAULT_PROPERTIES = "${DEFAULT_KEYS_PREFIX}properties" @@ -52,8 +48,6 @@ open class SemverConfig @Inject constructor( } var properties = DEFAULT_PROPERTIES - - // Keys var semverKey = DEFAULT_SEMVER_KEY get() = "$keysPrefix$field" var majorKey = DEFAULT_MAJOR_KEY @@ -74,32 +68,10 @@ open class SemverConfig @Inject constructor( get() = "$keysPrefix$field" var keysPrefix = DEFAULT_KEYS_PREFIX - // Extension Properties - val semver: String - get() = semVersion.semver - val version: String - get() = semVersion.semver - val major: Int - get() = semVersion.major - val minor: Int - get() = semVersion.minor - val patch: Int - get() = semVersion.patch - val preRelease: String - get() = semVersion.preRelease - val buildMeta: String - get() = semVersion.buildMeta - val preReleasePrefix: String - get() = semVersion.preReleasePrefix - val buildMetaPrefix: String - get() = semVersion.buildMetaPrefix - val separator: String - get() = semVersion.separator - override fun toString(): String { return "SemverConfig(" + "properties='$properties', " + - "semverKey='$semverKey', " + + "semver='$semverKey', " + "majorKey='$majorKey', " + "minorKey='$minorKey', " + "patchKey='$patchKey', " + @@ -108,16 +80,7 @@ open class SemverConfig @Inject constructor( "buildMetaKey='$buildMetaKey', " + "buildMetaPrefixKey='$buildMetaPrefixKey', " + "separator='$separatorKey', " + - "keysPrefix='$keysPrefix', " + - "semver='$semver', " + - "major='$major', " + - "minor='$minor', " + - "patch='$patch', " + - "preRelease='$preRelease', " + - "buildMeta='$buildMeta', " + - "preReleasePrefix='$preReleasePrefix', " + - "buildMetaPrefix='$buildMetaPrefix', " + - "separator='$separator'" + + "keysPrefix='$keysPrefix')" + ')' } } diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementBuildMetaTask.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementBuildMetaTask.kt index 7463ba0..a48e5d7 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementBuildMetaTask.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementBuildMetaTask.kt @@ -1,7 +1,7 @@ /* * SemverIncrementBuildMetaTask.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -59,7 +59,7 @@ open class SemverIncrementBuildMetaTask @Inject constructor( version.buildMeta = buildMeta project.version = version.semver logger.lifecycle("Version: ${project.version}") - Utils.saveProperties(project.projectDir, config, version) + Utils.saveProperties(config, version) } } } diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt index 9e5af44..090580f 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverIncrementTask.kt @@ -1,7 +1,7 @@ /* * SemverIncrementTask.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,10 +54,9 @@ open class SemverIncrementTask @Inject constructor( version.increment( isMajor = type == SemverConfig.DEFAULT_MAJOR_KEY, isMinor = type == SemverConfig.DEFAULT_MINOR_KEY, - isPatch = type == SemverConfig.DEFAULT_PATCH_KEY - ) + isPatch = type == SemverConfig.DEFAULT_PATCH_KEY) project.version = version.semver logger.lifecycle("Version: ${project.version}") - Utils.saveProperties(project.projectDir, config, version) + Utils.saveProperties(config, version) } } diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt index 1e137e7..a6dca00 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt @@ -1,7 +1,7 @@ /* * SemverPlugin.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +36,7 @@ import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.util.GradleVersion +import java.io.File class SemverPlugin : Plugin { private val simpleName = SemverPlugin::class.simpleName @@ -46,7 +47,7 @@ class SemverPlugin : Plugin { if (GradleVersion.current() < GradleVersion.version("4.8.1")) { throw GradleException("The $simpleName plugin requires Gradle version 4.8.1 or greater.") } - config = project.extensions.create("semver", SemverConfig::class.java, version) + config = project.extensions.create("semver", SemverConfig::class.java) project.afterEvaluate(this::afterEvaluate) project.tasks.apply { @@ -58,27 +59,26 @@ class SemverPlugin : Plugin { } private fun afterEvaluate(project: Project) { - val propsFile = Utils.getPropertiesFile(project.projectDir, config.properties) + val propsFile = if (File(config.properties).isAbsolute) { + File(config.properties) + } else { + File("${project.projectDir}${File.separator}${config.properties}") + } if (project.version != "unspecified") { project.logger.warn( - "Please specify the version in ${propsFile.name} and remove it from ${project.buildFile.name}" - ) + "Please specify the version in ${propsFile.name} and remove it from ${project.buildFile.name}") } propsFile.apply { val isNew = !exists() project.logger.info( - "[$simpleName] Attempting to read properties from: `$absoluteFile`. " + - "[exists: $isNew, isFile: $isFile, canRead: ${canRead()}]" - ) + "[$simpleName] Attempting to read properties from: `$absoluteFile`. [exists: $isNew, isFile: $isFile, canRead: ${propsFile.canRead()}]") val props = Utils.loadProperties(this) - val requiredProps = setOf( - config.semverKey, config.majorKey, config.minorKey, config.patchKey, - config.preReleaseKey, config.buildMetaKey - ) + val requiredProps = setOf(config.semverKey, config.majorKey, config.minorKey, config.patchKey, + config.preReleaseKey, config.buildMetaKey) val hasReqProps = !isNew && props.stringPropertyNames().containsAll(requiredProps) && Utils.isNotSystemProperty(requiredProps) @@ -93,7 +93,7 @@ class SemverPlugin : Plugin { if (!hasReqProps || !isFile) { project.logger.info("[$simpleName] Saving version properties to `$absoluteFile`.") - Utils.saveProperties(project.projectDir, config, version) + Utils.saveProperties(config, version) } } } diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SortedProperties.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SortedProperties.kt index 1a99d15..388c91d 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SortedProperties.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SortedProperties.kt @@ -1,7 +1,7 @@ /* * SortedProperties.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/Utils.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/Utils.kt index e7cd681..c4da2b1 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/Utils.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/Utils.kt @@ -1,7 +1,7 @@ /* * Utils.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,6 @@ import org.gradle.api.GradleException import java.io.File import java.io.FileInputStream import java.io.FileOutputStream -import java.io.IOException import java.util.Properties /** @@ -51,6 +50,11 @@ object Utils { return canRead() && isFile } + private fun Int.length() = when (this) { + 0 -> 1 + else -> Math.log10(Math.abs(toDouble())).toInt() + 1 + } + private fun Properties.put(key: String, value: String, isValidCondition: Boolean) { if (isValidCondition) put(key, value) } @@ -62,14 +66,6 @@ object Utils { return true } - fun getPropertiesFile(projectDir: File, propsFile: String): File { - return if (File(propsFile).isAbsolute) { - File(propsFile) - } else { - File(projectDir, propsFile) - } - } - fun loadProperties(file: File): Properties { var isNew = false val props = Properties() @@ -78,7 +74,7 @@ object Utils { if (!exists() && createNewFile()) { isNew = true } - } catch (e: IOException) { + } catch (e: Exception) { throw GradleException("Unable to create: `$absoluteFile`", e) } if (canReadFile()) { @@ -131,92 +127,111 @@ object Utils { fun parseSemVer(input: String?, version: Version): Boolean { if (input.isNullOrBlank()) return false + var semver = StringBuilder(input) + var start = semver.indexOf(version.separator) + var minor = -1 + var major = -1 + var patch = -1 + var preRelease = "" + var buildMeta = "" + try { - val max = 5 - val min = 3 - - val parts = input.split( - Regex("[\\Q${version.separator}${version.preReleasePrefix}${version.buildMetaPrefix}\\E]"), - max - ) - - if (parts.size >= min) { - version.major = parts[0].toInt() - version.minor = parts[1].toInt() - version.patch = parts[2].toInt() - version.preRelease = "" - version.buildMeta = "" - - if (parts.size > min) { - when { - parts.size == max -> { - version.preRelease = parts[3] - version.buildMeta = parts[4] - } - parts.size == 4 -> { - if (input.endsWith(version.buildMetaPrefix + parts[3])) { - version.buildMeta = parts[3] - } else { - version.preRelease = parts[3] + // major + if (start != -1) { + major = Math.abs(semver.substring(0, start).toInt()) + semver.delete(0, start + major.length()) + start = semver.indexOf(version.separator) + // minor + if (start != -1) { + minor = Math.abs(semver.substring(0, start).toInt()) + semver = semver.delete(0, start + minor.length()) + start = semver.indexOf(version.preReleasePrefix) + // patch + if (start != -1) { + patch = Math.abs(semver.substring(0, start).toInt()) + semver.delete(0, start + minor.length()) + start = semver.lastIndexOf(version.buildMetaPrefix) + // pre-release + if (start != -1) { + preRelease = semver.substring(0, start) + semver.delete(0, preRelease.length) + start = semver.indexOf(version.buildMetaPrefix) + // build meta + if (start != -1) { + buildMeta = semver.substring(version.preReleasePrefix.length) + semver.clear() } + } else { + // no build meta + preRelease = semver.toString() + semver.clear() } + } else if (semver.isNotEmpty()) { + // no pre-release + start = semver.lastIndexOf(version.buildMetaPrefix) + // patch & build meta + if (start != -1) { + patch = semver.substring(0, start).toInt() + semver.delete(0, start + minor.length()) + buildMeta = semver.toString() + } else { + // patch + patch = semver.toString().toInt() + } + semver.clear() } } - } else { - throw NumberFormatException("Not enough parts.") } } catch (e: NumberFormatException) { throw GradleException("Unable to parse version: \"$input\" (${e.message})", e) } + if (semver.isNotEmpty()) throw GradleException("Unable to parse version: \"$input\".") + + version.major = major + version.minor = minor + version.patch = patch + version.preRelease = preRelease + version.buildMeta = buildMeta + return true } - fun saveProperties(projectDir: File, config: SemverConfig, version: Version) { - val propsFile = getPropertiesFile(projectDir, config.properties) + fun saveProperties(config: SemverConfig, version: Version) { + val propsFile = File(config.properties) SortedProperties().apply { - try { - propsFile.apply { - if (canReadFile()) { - FileInputStream(this).reader().use { load(it) } - } else { - createNewFile() - } - - put(config.semverKey, version.semver) - put(config.majorKey, version.major.toString()) - put(config.minorKey, version.minor.toString()) - put(config.patchKey, version.patch.toString()) - put(config.preReleaseKey, version.preRelease) - put(config.buildMetaKey, version.buildMeta) - put(config.semverKey, version.semver) - - put( - config.buildMetaPrefixKey, version.buildMetaPrefix, - version.buildMetaPrefix != Version.DEFAULT_BUILDMETA_PREFIX || - containsKey(config.buildMetaPrefixKey) - ) - put( - config.preReleasePrefixKey, version.preReleasePrefix, - version.preReleasePrefix != Version.DEFAULT_PRERELEASE_PREFIX || - containsKey(config.preReleasePrefixKey) - ) - put( - config.separatorKey, version.separator, - version.separator != Version.DEFAULT_SEPARATOR || - containsKey(config.separatorKey) - ) - - if (canWrite()) { - FileOutputStream(this).writer().use { - store(it, "Generated by the Semver Plugin for Gradle") - } - } else { - throw IOException("Can't write.") - } + propsFile.apply { + if (canReadFile()) { + FileInputStream(this).reader().use { load(it) } + } else { + createNewFile() + } + + put(config.semverKey, version.semver) + put(config.majorKey, version.major.toString()) + put(config.minorKey, version.minor.toString()) + put(config.patchKey, version.patch.toString()) + put(config.preReleaseKey, version.preRelease) + put(config.buildMetaKey, version.buildMeta) + put(config.semverKey, version.semver) + + put(config.buildMetaPrefixKey, version.buildMetaPrefix, + version.buildMetaPrefix != Version.DEFAULT_BUILDMETA_PREFIX || + containsKey(config.buildMetaPrefixKey)) + put(config.preReleasePrefixKey, version.preReleasePrefix, + version.preReleasePrefix != Version.DEFAULT_PRERELEASE_PREFIX || + containsKey(config.preReleasePrefixKey)) + put(config.separatorKey, version.separator, + version.separator != Version.DEFAULT_SEPARATOR || + containsKey(config.separatorKey)) + + if (canWrite()) { + FileOutputStream(this).writer().use { + store(it, "Generated by the Semver Plugin for Gradle") + } + } else { + throw GradleException("Unable to write version to: `$absoluteFile`") } - } catch (e: IOException) { - throw GradleException("Unable to write version to: `${propsFile.absoluteFile}`", e) } } } diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt index eedbf38..7982615 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt @@ -1,7 +1,7 @@ /* * Version.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt index 45105a0..99221e8 100644 --- a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt @@ -1,7 +1,7 @@ /* * SemverConfigSpec.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,8 +40,8 @@ import kotlin.test.assertTrue @Suppress("unused") object SemverConfigSpec : Spek({ Feature("SemverConfig") { - val config = SemverConfig(Version()) Scenario("Testing configs") { + val config by memoized { SemverConfig() } val vars = listOf( config.semverKey, config.majorKey, @@ -90,8 +90,7 @@ object SemverConfigSpec : Spek({ config.preReleasePrefixKey, config.buildMetaKey, config.buildMetaPrefixKey, - config.separatorKey - ) + config.separatorKey) } Then("all config keys should start with test.xxxx") { @@ -99,26 +98,6 @@ object SemverConfigSpec : Spek({ assertTrue(k.startsWith("test."), k) } } - - When("checking extension properties") {} - - Then("semver should be defaults") { - val defaultSemver = - "${Version.DEFAULT_MAJOR}${Version.DEFAULT_SEPARATOR}${Version.DEFAULT_MINOR}${Version.DEFAULT_SEPARATOR}${Version.DEFAULT_PATCH}" - assertEquals(config.semver, defaultSemver) - assertEquals( - "${config.major}${config.separator}${config.minor}${config.separator}${config.patch}", - defaultSemver - ) - assertEquals(config.preRelease, Version.DEFAULT_EMPTY) - assertEquals(config.buildMeta, Version.DEFAULT_EMPTY) - assertEquals(config.preReleasePrefix, Version.DEFAULT_PRERELEASE_PREFIX) - assertEquals(config.buildMetaPrefix, Version.DEFAULT_BUILDMETA_PREFIX) - } - - Then("semver = version") { - assertEquals(config.semver, config.version) - } } } }) diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt index 3dc5f1e..f7becf6 100644 --- a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt @@ -1,7 +1,7 @@ /* * SemverVersionSpec.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt index 3ad050f..2c787e7 100644 --- a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt @@ -1,7 +1,7 @@ /* * UtilsSpec.kt * - * Copyright (c) 2018-2020, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2018-2019, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,234 +36,170 @@ import org.gradle.api.GradleException import org.spekframework.spek2.Spek import org.spekframework.spek2.style.gherkin.Feature import java.io.File -import java.util.* +import java.util.Properties import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertNull import kotlin.test.assertTrue @Suppress("unused") -object UtilsSpec : Spek( - { - Feature("Utils") { - val version = Version() - val config = SemverConfig(version) - val propsFile = File("test.properties") - val projectDir = File("./") - lateinit var props: Properties +object UtilsSpec : Spek({ + Feature("Utils") { + val version = Version() + val config = SemverConfig() + val propsFile = File("test.properties") + lateinit var props: Properties - Scenario("Save/Load Properties") { - When("saving the property") { - config.properties = propsFile.name - Utils.saveProperties(projectDir, config, version) - } + Scenario("Save/Load Properties") { + When("saving the property") { + config.properties = propsFile.name + Utils.saveProperties(config, version) + } - Then("properties file should exists and be readable") { - assertEquals(propsFile.canReadFile(), propsFile.canRead() && propsFile.isFile) - } + Then("properties file should exists and be readable") { + assertEquals(propsFile.canReadFile(), propsFile.canRead() && propsFile.isFile) + } - When("loading the properties file") { - props = Utils.loadProperties(propsFile) - propsFile.delete() - } + When("loading the properties file") { + props = Utils.loadProperties(propsFile) + propsFile.delete() + } - Then("version and properties should be the same.") { - assertEquals(props.getProperty(config.majorKey), version.major.toString(), "Major") - assertEquals(props.getProperty(config.minorKey), version.minor.toString(), "Minor") - assertEquals(props.getProperty(config.patchKey), version.patch.toString(), "Patch") - assertEquals(props.getProperty(config.preReleaseKey), version.preRelease, "PreRelease") - assertNull(props.getProperty(config.preReleasePrefixKey), "PreRelease Prefix") - assertEquals(props.getProperty(config.buildMetaKey), version.buildMeta, "Build Meta") - assertNull(props.getProperty(config.buildMetaPrefixKey), "Build Meta Prefix") - assertNull(props.getProperty(config.separatorKey), "Separator") - assertEquals(props.getProperty(config.semverKey), version.semver, "semver") + Then("version and properties should be the same.") { + assertEquals(props.getProperty(config.majorKey), version.major.toString(), "Major") + assertEquals(props.getProperty(config.minorKey), version.minor.toString(), "Minor") + assertEquals(props.getProperty(config.patchKey), version.patch.toString(), "Patch") + assertEquals(props.getProperty(config.preReleaseKey), version.preRelease, "PreRelease") + assertNull(props.getProperty(config.preReleasePrefixKey), "PreRelease Prefix") + assertEquals(props.getProperty(config.buildMetaKey), version.buildMeta, "Build Meta") + assertNull(props.getProperty(config.buildMetaPrefixKey), "Build Meta Prefix") + assertNull(props.getProperty(config.separatorKey), "Separator") + assertEquals(props.getProperty(config.semverKey), version.semver, "semver") + } + } + + Scenario("System Properties") { + lateinit var sysProps: Array> + + Given("new system properties") { + sysProps = arrayOf( + Pair(config.majorKey, "2"), + Pair(config.minorKey, "1"), + Pair(config.patchKey, "1"), + Pair(config.preReleaseKey, "beta"), + Pair(config.buildMetaKey, "007")) + } + + Then("none should already exists") { + assertTrue(Utils.isNotSystemProperty(setOf(config.majorKey, config.minorKey, config.patchKey, config.preReleaseKey, + config.buildMetaKey))) + } + + Then("version should match system properties") { + sysProps.forEach { + System.getProperties().setProperty(it.first, it.second) + if (it.first == config.majorKey || it.first == config.minorKey || it.first == config.patchKey) { + assertEquals(Utils.loadIntProperty(props, it.first, -1), it.second.toInt()) + } else { + assertEquals(Utils.loadProperty(props, it.first, ""), it.second) + } } } - Scenario("System Properties") { - lateinit var sysProps: Array> + When("loading version") { + Utils.loadVersion(config, version, props) + } - Given("new system properties") { - sysProps = arrayOf( - Pair(config.majorKey, "2"), - Pair(config.minorKey, "1"), - Pair(config.patchKey, "1"), - Pair(config.preReleaseKey, "beta"), - Pair(config.buildMetaKey, "007") - ) + Then("version should be identical") { + assertEquals(version.semver, "2.1.1-beta+007") + } + + When("saving properties") { + Utils.saveProperties(config, version) + } + + lateinit var newProps: Properties + + And("loading properties file") { + newProps = Utils.loadProperties(propsFile) + } + + Then("new properties should validate") { + sysProps.forEach { + assertEquals(newProps.getProperty(it.first), it.second, it.second) } + propsFile.delete() + } - Then("none should already exists") { - assertTrue( - Utils.isNotSystemProperty( - setOf( - config.majorKey, - config.minorKey, - config.patchKey, - config.preReleaseKey, - config.buildMetaKey - ) - ) - ) - } + When("setting the version as system property") { + System.getProperties().setProperty(config.semverKey, "3.2.2") + } - Then("version should match system properties") { - sysProps.forEach { - System.getProperties().setProperty(it.first, it.second) - if (it.first == config.majorKey || it.first == config.minorKey || it.first == config.patchKey) { - assertEquals(Utils.loadIntProperty(props, it.first, -1), it.second.toInt()) - } else { - assertEquals(Utils.loadProperty(props, it.first, ""), it.second) - } - } - } + And("loading the properties") { + Utils.loadVersion(config, version, props) + } - When("loading version") { - Utils.loadVersion(config, version, props) - } + Then("versions should match") { + assertEquals(version.semver, System.getProperty(config.semverKey)) + } + } - Then("version should be identical") { - assertEquals(version.semver, "2.1.1-beta+007") - } - - When("saving properties") { - Utils.saveProperties(projectDir, config, version) - } - - lateinit var newProps: Properties - - And("loading properties file") { - newProps = Utils.loadProperties(propsFile) - } - - Then("new properties should validate") { - sysProps.forEach { - assertEquals(newProps.getProperty(it.first), it.second, it.second) - } - propsFile.delete() - } - - When("setting the version as system property") { - System.getProperties().setProperty(config.semverKey, "3.2.2") - } - - And("loading the properties") { - Utils.loadVersion(config, version, props) - } - - Then("versions should match") { - assertEquals(version.semver, System.getProperty(config.semverKey)) + Scenario("Testing Version Parsing") { + When("validating version parsing") { + listOf("1.0.0", "2.1.0-beta", "3.2.1-beta+007", "4.3.2+007").forEach { + assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it") + assertEquals(it, version.semver, it) } } - Scenario("Version Parsing") { - When("validating version parsing") {} + Given("new prefixes") { + version.preReleasePrefix = "." + version.buildMetaPrefix = "." + } - Then("versions should parse") { - listOf( - "1.0.0", - "2.1.0-beta", - "3.2.1-beta+007", - "4.3.2+007", - "11.11.1", - "111.11.11-beta", - "1111.111.11-beta+001.12" - ).forEach { - assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it") - assertEquals(it, version.semver, it) - } - } - - Then("should throw exceptions") { - assertFailsWith("2.1.1a") { - Utils.parseSemVer("2.1.1a", version) - } - assertFailsWith("2a.1.1") { - Utils.parseSemVer("2a.1.1", version) - } - assertFailsWith("2.1a.1") { - Utils.parseSemVer("2.1a.1", version) - } - assertFailsWith("2.1") { - Utils.parseSemVer("2.1", version) - } - } - - Given("new prefixes") { - version.preReleasePrefix = "." - version.buildMetaPrefix = "." - } - - Then("prefixes should parse") { - listOf("2.1.0.beta.1", "2.1.1.1", "3.2.1.beta.1.007").forEach { - assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it") - assertEquals(it, version.semver, it) - } - } - - Then("last pre-release and meta should match") { - assertEquals(version.preRelease, "beta") - assertEquals(version.buildMeta, "1.007") + Then("validating prefixes parsing") { + listOf("2.1.0.beta.1", "2.1.1.1", "3.2.1.beta.1.007").forEach { + assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it") + assertEquals(it, version.semver, it) } } - Scenario("Load locked properties") { - lateinit var locked: File + Then("verifying pre-release and meta") { + assertEquals(version.preRelease, "beta.1") + assertEquals(version.buildMeta, "007") + } + } - Given("the locked location") { - locked = File("locked") - } + Scenario("Load locked properties") { + lateinit var locked: File - Then("loading locked properties") { - assertFailsWith { - Utils.loadProperties(File(locked, propsFile.name)) - } - locked.delete() - } + Given("the locked location") { + locked = File("locked") } - Scenario("Save to locked properties") { - lateinit var propsLocked: File - Given("the locked properties") { - propsLocked = File(System.getProperty("user.home") + File.separator + "locked.properties") - propsLocked.createNewFile() - propsLocked.setReadOnly() - config.properties = propsLocked.name + Then("loading locked properties") { + assertFailsWith { + Utils.loadProperties(File(locked, propsFile.name)) } + locked.delete() + } + } - Then("saving the locked properties file") { - assertFailsWith { - Utils.saveProperties(propsLocked.parentFile, config, version) - } - propsLocked.delete() - } + Scenario("Save to locked properties") { + lateinit var propsLocked: File + Given("the locked properties") { + propsLocked = File("locked.properties") + propsLocked.createNewFile() + propsLocked.setReadOnly() + config.properties = propsLocked.name } - Scenario("Save/Load Properties in foo") { - lateinit var fooDir: File - lateinit var fooProps: File - When("saving the foo property") { - fooDir = File("foo") - fooDir.mkdir() - fooProps = File(fooDir, propsFile.name) - config.properties = fooProps.absolutePath - Utils.saveProperties(projectDir, config, version) - } - - Then("foo properties file should exists and be readable") { - assertEquals(fooProps.canReadFile(), fooProps.canRead() && fooProps.isFile) - } - - When("loading the foo properties file") { - props = Utils.loadProperties(fooProps) - fooProps.delete() - fooDir.delete() - } - - Then("version in foo properties should be the same") { - assertEquals(props.getProperty(config.semverKey), version.semver) + Then("saving the locked properties file") { + assertFailsWith { + Utils.saveProperties(config, version) } + propsLocked.delete() } } } -) +})