diff --git a/.circleci/config.yml b/.circleci/config.yml index 65723f0..4690865 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,41 +1,44 @@ -inversion: 2 +version: 2 defaults: &defaults working_directory: ~/repo + docker: + - image: circleci/openjdk:8-jdk environment: JVM_OPTS: -Xmx3200m TERM: dumb - CI_NAME: "CircleCI" - -defaults_gradle: &defaults_bld - steps: - - checkout - - run: - name: Download the dependencies - command: ./bld download - - run: - name: Run tests with bld - command: ./bld compile test jobs: - bld_jdk20: + build_gradle: <<: *defaults - docker: - - image: cimg/openjdk:20.0 + steps: + - checkout + - restore_cache: + keys: + - gradle-dependencies-{{ checksum "build.gradle" }} + # fallback to using the latest cache if no exact match is found + - gradle-dependencies- - <<: *defaults_bld + - run: + name: Gradle Dependencies + command: ./gradlew dependencies - bld_jdk17: - <<: *defaults + - save_cache: + paths: ~/.m2 + key: gradle-dependencies-{{ checksum "build.gradle" }} - docker: - - image: cimg/openjdk:17.0 + - run: + name: Run All Checks + command: ./gradlew check - <<: *defaults_bld + - store_artifacts: + path: build/reports/ + destination: reports + - store_test_results: + path: build/reports/ workflows: version: 2 - bld: + build_gradle_jdk8: jobs: - - bld_jdk17 - - bld_jdk20 + - build_gradle diff --git a/.editorconfig b/.editorconfig index 1f808de..a6971e1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,2 +1,2 @@ [*] -insert_final_newline = true +insert_final_newline=true diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml deleted file mode 100644 index 79093d1..0000000 --- a/.github/workflows/bld.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: bld-ci - -on: [ push, pull_request, workflow_dispatch ] - -jobs: - build-bld-project: - runs-on: ubuntu-latest - - env: - COVERAGE_SDK: "17" - - strategy: - matrix: - java-version: [ 17, 20 ] - - steps: - - name: Checkout source repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up JDK ${{ matrix.java-version }} - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: ${{ matrix.java-version }} - - - name: Grant execute permission for bld - run: chmod +x bld - - - name: Download the dependencies - run: ./bld download - - - name: Run tests with bld - run: ./bld compile jacoco - - - name: Remove pom.xml - if: success() && matrix.java-version == env.COVERAGE_SDK - run: rm -rf pom.xml - - - name: SonarCloud Scan - uses: sonarsource/sonarcloud-github-action@master - if: success() && matrix.java-version == env.COVERAGE_SDK - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - if: success() && matrix.java-version == env.COVERAGE_SDK - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - diff --git a/.gitignore b/.gitignore index 091e664..f007981 100644 --- a/.gitignore +++ b/.gitignore @@ -1,57 +1,84 @@ -.gradle +.vscode/* +!.vscode/extensions.json +!.vscode/launch.json +!.vscode/settings.json +!.vscode/tasks.json + +__pycache__ +.classpath .DS_Store -build -lib/bld/** -!lib/bld/bld-wrapper.properties -!lib/bld/bld-wrapper.jar -lib/compile/ -lib/runtime/ -lib/standalone/ -lib/test/ - -# IDEA ignores - -# User-specific -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin +.gradle +.history +.kobalt +.mtj.tmp/ +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.nb-gradle +.project +.scannerwork +.settings +*.class +*.code-workspace +*.ctxt +*.iws +*.log +*.nar +*.rar +*.sublime-* +*.tar.gz +*.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 - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Editor-based Rest Client -.idea/httpRequests - -local.properties \ No newline at end of file +bin/ +build/ +cmake-build-*/ +com_crashlytics_export_strings.xml +crashlytics-build.properties +crashlytics.properties +dependency-reduced-pom.xml +deploy/ +dist/ +ehthumbs.db +fabric.properties +gen/ +gradle.properties +hs_err_pid* +kobaltBuild +kobaltw*-test +lib/kotlin* +libs/ +local.properties +out/ +pom.xml.next +pom.xml.releaseBackup +pom.xml.tag +pom.xml.versionsBackup +proguard-project.txt +project.properties +release.properties +target/ +test-output +Thumbs.db +venv diff --git a/.idea/app.iml b/.idea/app.iml deleted file mode 100644 index 787b59b..0000000 --- a/.idea/app.iml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/bld.iml b/.idea/bld.iml deleted file mode 100644 index e63e11e..0000000 --- a/.idea/bld.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..17101f8 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/checkstyleidea-libs/readme.txt b/.idea/checkstyleidea-libs/readme.txt new file mode 100644 index 0000000..71cc7ff --- /dev/null +++ b/.idea/checkstyleidea-libs/readme.txt @@ -0,0 +1,6 @@ +This folder contains libraries copied from the "semver" project. +It is managed by the CheckStyle-IDEA IDE plugin. +Do not modify this folder while the IDE is running. +When the IDE is stopped, you may delete this folder at any time. It will be recreated as needed. +In order to prevent the CheckStyle-IDEA IDE plugin from creating this folder, +uncheck the "Copy libraries from project directory" option in the CheckStyle-IDEA settings dialog. diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..d91f848 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6d140d3 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/BSD_3_Clause.xml b/.idea/copyright/BSD_3_Clause.xml deleted file mode 100644 index 956f692..0000000 --- a/.idea/copyright/BSD_3_Clause.xml +++ /dev/null @@ -1,6 +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 new file mode 100644 index 0000000..ef51a2d --- /dev/null +++ b/.idea/copyright/Erik_s_Copyright_Notice.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..69bc70d --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 7e0a3c7..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..dc2dcae --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..d32dd97 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..5806fb3 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml deleted file mode 100644 index abca604..0000000 --- a/.idea/libraries/bld.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/compile.xml b/.idea/libraries/compile.xml deleted file mode 100644 index 9bd86aa..0000000 --- a/.idea/libraries/compile.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/runtime.xml b/.idea/libraries/runtime.xml deleted file mode 100644 index 2ae5c4b..0000000 --- a/.idea/libraries/runtime.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/test.xml b/.idea/libraries/test.xml deleted file mode 100644 index b80486a..0000000 --- a/.idea/libraries/test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ea78ec7..5ae2566 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,13 +1,26 @@ - - - + + + + + + - + - - + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 55adcb9..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/examples-kotlin_main.iml b/.idea/modules/examples-kotlin_main.iml new file mode 100644 index 0000000..4aeac9a --- /dev/null +++ b/.idea/modules/examples-kotlin_main.iml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/examples-kotlin_test.iml b/.idea/modules/examples-kotlin_test.iml new file mode 100644 index 0000000..4b23562 --- /dev/null +++ b/.idea/modules/examples-kotlin_test.iml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Run Tests.xml b/.idea/runConfigurations/Run Tests.xml deleted file mode 100644 index 4f6af10..0000000 --- a/.idea/runConfigurations/Run Tests.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/scopes/Copyright.xml b/.idea/scopes/Copyright.xml new file mode 100644 index 0000000..7fb840b --- /dev/null +++ b/.idea/scopes/Copyright.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/semver.iml b/.idea/semver.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/.idea/semver.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0161fc0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: java +dist: trusty + +jdk: + - oraclejdk8 + +addons: + sonarcloud: + organization: "ethauvin-github" + +before_install: + - chmod +x gradlew + +after_success: + - | + if [ "${TRAVIS_TEST_RESULT}" == 0 ]; then + ./gradlew sonarqube + fi diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 7a56afd..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Run Tests", - "request": "launch", - "mainClass": "net.thauvin.erik.semver.SemverTest" - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index c83239c..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "java.project.sourcePaths": [ - "src/main/java", - "src/main/resources", - "src/test/java", - "src/bld/java" - ], - "java.configuration.updateBuildConfiguration": "automatic", - "java.project.referencedLibraries": [ - "${HOME}/.bld/dist/bld-1.7.1.jar", - "lib/compile/*.jar", - "lib/runtime/*.jar", - "lib/test/*.jar" - ] -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 41eb07d..43dec57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,6 @@ -# Changelog - -## [1.2.1](https://github.com/ethauvin/semver/tree/1.2.1) (2021-04-29) - -[Full Changelog](https://github.com/ethauvin/semver/compare/1.2.0...1.2.1) - -**Fixed bugs:** - -- NPE with Java 12 and Kotlin 1.3.30 [\#1](https://github.com/ethauvin/semver/issues/1) - -**Closed issues:** - -- Under Java 12 and Gradle 5.4.1 the properties file is not found. [\#6](https://github.com/ethauvin/semver/issues/6) +# Change Log ## [1.2.0](https://github.com/ethauvin/semver/tree/1.2.0) (2019-05-25) - [Full Changelog](https://github.com/ethauvin/semver/compare/1.1.1...1.2.0) **Implemented enhancements:** @@ -25,51 +12,40 @@ **Fixed bugs:** - Default template is not found in 1.1.1 [\#5](https://github.com/ethauvin/semver/issues/5) +- Attempt to compile non-existent Java source in Gradle project using Kapt [\#3](https://github.com/ethauvin/semver/issues/3) +- kapt and Kotlin 1.3.30 require kapt.use.worker.api=true [\#2](https://github.com/ethauvin/semver/issues/2) ## [1.1.1](https://github.com/ethauvin/semver/tree/1.1.1) (2019-03-31) - [Full Changelog](https://github.com/ethauvin/semver/compare/1.1.0-beta...1.1.1) ## [1.1.0-beta](https://github.com/ethauvin/semver/tree/1.1.0-beta) (2018-11-04) - [Full Changelog](https://github.com/ethauvin/semver/compare/1.0.1...1.1.0-beta) ## [1.0.1](https://github.com/ethauvin/semver/tree/1.0.1) (2017-05-30) - [Full Changelog](https://github.com/ethauvin/semver/compare/1.0.0...1.0.1) ## [1.0.0](https://github.com/ethauvin/semver/tree/1.0.0) (2017-05-10) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.6-beta...1.0.0) ## [0.9.6-beta](https://github.com/ethauvin/semver/tree/0.9.6-beta) (2016-07-15) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.5-beta...0.9.6-beta) ## [0.9.5-beta](https://github.com/ethauvin/semver/tree/0.9.5-beta) (2016-02-03) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.4-beta...0.9.5-beta) ## [0.9.4-beta](https://github.com/ethauvin/semver/tree/0.9.4-beta) (2016-01-29) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.3-beta...0.9.4-beta) ## [0.9.3-beta](https://github.com/ethauvin/semver/tree/0.9.3-beta) (2016-01-28) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.2-beta...0.9.3-beta) ## [0.9.2-beta](https://github.com/ethauvin/semver/tree/0.9.2-beta) (2016-01-25) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.1-beta...0.9.2-beta) ## [0.9.1-beta](https://github.com/ethauvin/semver/tree/0.9.1-beta) (2016-01-25) - [Full Changelog](https://github.com/ethauvin/semver/compare/0.9.0-beta...0.9.1-beta) ## [0.9.0-beta](https://github.com/ethauvin/semver/tree/0.9.0-beta) (2016-01-24) -[Full Changelog](https://github.com/ethauvin/semver/compare/aeee81544c6d2881ccf02458fcef1f6ba1c9c169...0.9.0-beta) - - -\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt index 3214597..0b83122 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) +Copyright (c) 2016-2020, 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 d993dd6..50c335a 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,9 @@ # Semantic Version Annotation Processor -[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](https://opensource.org/licenses/BSD-3-Clause) -[![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) -[![bld](https://img.shields.io/badge/1.7.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) -[![release](https://img.shields.io/github/release/ethauvin/semver.svg)](https://github.com/ethauvin/semver/releases/latest) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver) -![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.thauvin.erik.httpstatus/httpstatus?server=https%3A%2F%2Foss.sonatype.org) +[![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) [![release](https://img.shields.io/github/release/ethauvin/semver.svg)](https://github.com/ethauvin/semver/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver) [ ![Download](https://api.bintray.com/packages/ethauvin/maven/SemVer/images/download.svg) ](https://bintray.com/ethauvin/maven/SemVer/_latestVersion)\ +[![Known Vulnerabilities](https://snyk.io/test/github/ethauvin/semver/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/ethauvin/semver?targetFile=build.gradle) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_semver&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_semver) [![Build Status](https://travis-ci.com/ethauvin/semver.svg?branch=master)](https://travis-ci.com/ethauvin/semver) [![Build status](https://ci.appveyor.com/api/projects/status/nbv4mxd1gpxtx69o?svg=true)](https://ci.appveyor.com/project/ethauvin/semver) [![CircleCI](https://circleci.com/gh/ethauvin/semver/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/semver/tree/master) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_semver&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_semver) -[![GitHub CI](https://github.com/ethauvin/semver/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/semver/actions/workflows/gradle.yml) -[![Build status](https://ci.appveyor.com/api/projects/status/nbv4mxd1gpxtx69o?svg=true)](https://ci.appveyor.com/project/ethauvin/semver) -[![CircleCI](https://circleci.com/gh/ethauvin/semver/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/semver/tree/master) - -An [annotation processor](https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html) that automatically generates a `GeneratedVersion` class based on a [Mustache](https://mustache.github.io/) template and containing the [semantic version](https://semver.org/) (major, minor, patch, etc.) that is read from a [Properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) file or defined in the [annotation](https://docs.oracle.com/javase/tutorial/java/annotations/basics.html). +An [annotation processor](https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html) that automatically generates a `GeneratedVersion` class based on a [Mustache](https://mustache.github.io/) template and containing the [semantic version](http://semver.org/) (major, minor, patch, etc.) that is read from a [Properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) file or defined in the [annotation](https://docs.oracle.com/javase/tutorial/java/annotations/basics.html). This processor was inspired by Cédric Beust's [version-processor](https://github.com/cbeust/version-processor) and works well in conjunction with the [__Semantic Version Plugin for Gradle__](https://github.com/ethauvin/semver-gradle). @@ -209,10 +200,6 @@ mvn verify To install and run from [Gradle](https://gradle.org/), add the following to [build.gradle](https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle): ```gradle -repositories { - mavenCentral() -} - dependencies { annotationProcessor 'net.thauvin.erik:semver:1.2.0' compileOnly 'net.thauvin.erik:semver:1.2.0' @@ -235,7 +222,7 @@ In order to also incorporate the generated source code into the `source tree`, a ```gradle tasks.withType(JavaCompile) { - options.generatedSourceOutputDirectory.set(file("${projectDir}/src/generated/java")) + options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java") } ``` diff --git a/appveyor.yml b/appveyor.yml index 3eebf3d..0ee7361 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,3 @@ -image: - - Visual Studio 2022 - version: "{branch} {build}" skip_tags: true @@ -8,20 +5,22 @@ build: verbosity: detailed build_script: - - bld.bat download compile + - gradlew.bat assemble --info --no-daemon test_script: - - bld.bat test + - gradlew.bat check --info --no-daemon branches: only: - master - - 1.2.1-dev + +cache: + - C:\Users\appveyor\.gradle environment: matrix: - - JAVA_HOME: C:\Program Files\Java\jdk17 - - JAVA_HOME: C:\Program Files\Java\jdk20 + - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 + - JAVA_HOME: C:\Program Files (x86)\Java\jdk1.8.0 matrix: fast_finish: true diff --git a/bin/main/META-INF/services/javax.annotation.processing.Processor b/bin/main/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index 5ae1016..0000000 --- a/bin/main/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1,33 +0,0 @@ -# -# javax.annotation.processing.Processor -# -# Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# Neither the name of this project nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -net.thauvin.erik.semver.VersionProcessor diff --git a/bin/main/net/thauvin/erik/semver/Constants.class b/bin/main/net/thauvin/erik/semver/Constants.class deleted file mode 100644 index b299307..0000000 Binary files a/bin/main/net/thauvin/erik/semver/Constants.class and /dev/null differ diff --git a/bin/main/net/thauvin/erik/semver/Version.class b/bin/main/net/thauvin/erik/semver/Version.class deleted file mode 100644 index 239b8a2..0000000 Binary files a/bin/main/net/thauvin/erik/semver/Version.class and /dev/null differ diff --git a/bin/main/net/thauvin/erik/semver/VersionInfo.class b/bin/main/net/thauvin/erik/semver/VersionInfo.class deleted file mode 100644 index 8351bcf..0000000 Binary files a/bin/main/net/thauvin/erik/semver/VersionInfo.class and /dev/null differ diff --git a/bin/main/net/thauvin/erik/semver/VersionProcessor.class b/bin/main/net/thauvin/erik/semver/VersionProcessor.class deleted file mode 100644 index 38b5676..0000000 Binary files a/bin/main/net/thauvin/erik/semver/VersionProcessor.class and /dev/null differ diff --git a/bin/main/net/thauvin/erik/semver/package.html b/bin/main/net/thauvin/erik/semver/package.html deleted file mode 100644 index 1b1b126..0000000 --- a/bin/main/net/thauvin/erik/semver/package.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Semantic Version Annotation Processor - - -An annotation processor that automatically generates a GeneratedVersion class containing the semantic -version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation. - -@since 1.0 - - diff --git a/bin/main/semver-kt.mustache b/bin/main/semver-kt.mustache deleted file mode 100644 index 0a58f86..0000000 --- a/bin/main/semver-kt.mustache +++ /dev/null @@ -1,38 +0,0 @@ -/* -* This file is automatically generated. -* Do not modify! -- ALL CHANGES WILL BE ERASED! -*/ - -package {{packageName}} - -import java.util.Date - -/** -* Provides semantic version information. -* -* @author Semantic Version Annotation Processor -*/ -object {{className}} { -@JvmField -val PROJECT = "{{project}}" -@JvmField -val BUILDDATE = Date({{epoch}}L) -@JvmField -val MAJOR = {{major}} -@JvmField -val MINOR = {{minor}} -@JvmField -val PATCH = {{patch}} -@JvmField -val PRERELEASE = "{{preRelease}}" -@JvmField -val PRERELEASE_PREFIX = "{{preReleasePrefix}}" -@JvmField -val BUILDMETA = "{{buildMeta}}" -@JvmField -val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}" -@JvmField -val SEPARATOR = "{{separator}}" -@JvmField -val VERSION = "{{version}}" -} diff --git a/bin/main/semver.mustache b/bin/main/semver.mustache deleted file mode 100644 index cd7c567..0000000 --- a/bin/main/semver.mustache +++ /dev/null @@ -1,34 +0,0 @@ -/* -* This file is automatically generated. -* Do not modify! -- ALL CHANGES WILL BE ERASED! -*/ - -package {{packageName}}; - -import java.util.Date; - -/** -* Provides semantic version information. -* -* @author Semantic Version Annotation Processor -*/ -public final class {{className}} { -public static final String PROJECT = "{{project}}"; -public static final Date BUILDDATE = new Date({{epoch}}L); -public static final int MAJOR = {{major}}; -public static final int MINOR = {{minor}}; -public static final int PATCH = {{patch}}; -public static final String PRERELEASE = "{{preRelease}}"; -public static final String PRERELEASE_PREFIX = "{{preReleasePrefix}}"; -public static final String BUILDMETA = "{{buildMeta}}"; -public static final String BUILDMETA_PREFIX = "{{buildMetaPrefix}}"; -public static final String SEPARATOR = "{{separator}}"; -public static final String VERSION = "{{version}}"; - -/** -* Disables the default constructor. -*/ -private {{className}}() { -throw new UnsupportedOperationException("Illegal constructor call."); -} -} diff --git a/bin/test/net/thauvin/erik/semver/ConstantsTest.class b/bin/test/net/thauvin/erik/semver/ConstantsTest.class deleted file mode 100644 index c8c9fde..0000000 Binary files a/bin/test/net/thauvin/erik/semver/ConstantsTest.class and /dev/null differ diff --git a/bin/test/net/thauvin/erik/semver/VersionInfoTest.class b/bin/test/net/thauvin/erik/semver/VersionInfoTest.class deleted file mode 100644 index 8c5f8b4..0000000 Binary files a/bin/test/net/thauvin/erik/semver/VersionInfoTest.class and /dev/null differ diff --git a/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class b/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class deleted file mode 100644 index 5166fb7..0000000 Binary files a/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class and /dev/null differ diff --git a/bin/test/net/thauvin/erik/semver/VersionTest.class b/bin/test/net/thauvin/erik/semver/VersionTest.class deleted file mode 100644 index 0047ff2..0000000 Binary files a/bin/test/net/thauvin/erik/semver/VersionTest.class and /dev/null differ diff --git a/bld b/bld deleted file mode 100755 index 824b742..0000000 --- a/bld +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build net.thauvin.erik.semver.SemverBuild "$@" \ No newline at end of file diff --git a/bld.bat b/bld.bat deleted file mode 100644 index ab43bcd..0000000 --- a/bld.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build net.thauvin.erik.semver.SemverBuild %* \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..0910c36 --- /dev/null +++ b/build.gradle @@ -0,0 +1,239 @@ +plugins { + id 'checkstyle' + id 'java' + id 'jacoco' + id 'maven-publish' + id 'pmd' + id 'com.jfrog.bintray' version '1.8.5' + id 'com.github.ben-manes.versions' version '0.28.0' + id 'net.thauvin.erik.gradle.semver' version '1.0.4' + id 'com.github.spotbugs' version '4.4.4' + id 'org.sonarqube' version '3.0' +} + +import com.github.spotbugs.snom.SpotBugsTask +import org.apache.tools.ant.taskdefs.condition.Os + +defaultTasks 'check' + +group = 'net.thauvin.erik' + +final def mavenName = 'SemVer' +final def mavenDescription = 'Semantic Version Annotation Processor' +final def mavenUrl = 'https://github.com/ethauvin/semver' +final def mavenLicense = 'The BSD 3-Clause License' +final def mavenLicenseUrl = 'http://opensource.org/licenses/BSD-3-Clause' +final def mavenScmCon = 'https://github.com/ethauvin/semver.git' +final def mavenScmDevCon = 'git@github.com:ethauvin/semver.git' + +final def pkgLicenses = ['BSD 3-Clause'] +final def pkgIssueTrackerUrl = mavenUrl + '/issues' +final def pkgLabels = ['java', 'kotlin', 'annotation', 'processor', 'semantic', 'version'] + +ext.versions = [ + spotbugs: '4.0.6' +] + +repositories { + mavenLocal() + jcenter() + mavenCentral() +} + +dependencies { + implementation 'com.github.spullara.mustache.java:compiler:0.9.6' + + spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1' + spotbugsPlugins 'com.mebigfatguy.sb-contrib:sb-contrib:7.4.7' + + compileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs" + testCompileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs" + + testImplementation 'org.testng:testng:7.2.0' +} + + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +pmd { + ignoreFailures = true + ruleSets = [] + ruleSetFiles = files("${projectDir}/config/pmd.xml") + consoleOutput = true +} + +bintray { + user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') + key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') + publications = ['MyPublication'] + dryRun = false + pkg { + repo = 'maven' + name = mavenName + licenses = pkgLicenses + desc = mavenDescription + //released = new Date() + websiteUrl = mavenUrl + issueTrackerUrl = pkgIssueTrackerUrl + vcsUrl = mavenScmCon + labels = pkgLabels + publicDownloadNumbers = true + version { + gpg { sign = true } + } + } +} + +bintrayUpload { + versionName = "$project.version" + versionDesc = "$mavenName $project.version" + versionVcsTag = "$project.version" + versionReleased = new Date() +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + group = 'Build' + description = 'Builds an archive of the javadoc docs.' + archiveClassifier.set('javadoc') + from javadoc.destinationDir +} + +task sourceJar(type: Jar) { + group = 'Build' + description = 'Builds an archive of the source code.' + archiveClassifier.set('sources') + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar + archives sourceJar +} + +publishing { + publications { + MyPublication(MavenPublication) { + from components.java + artifact sourceJar + artifact javadocJar + groupId project.group + artifactId rootProject.name + + pom { + name = mavenName + description = mavenDescription + url = mavenUrl + licenses { + license { + name = mavenLicense + url = mavenLicenseUrl + distribution = 'repo' + } + } + developers { + developer { + id = 'ethauvin' + name = 'Erik C. Thauvin' + email = 'erik@thauvin.net' + } + } + scm { + connection = "scm:git:" + mavenScmCon + developerConnection = "scm:git:" + mavenScmDevCon + url = mavenScmCon + } + } + } + } +} + +javadoc { + doFirst { + title = "$mavenDescription $project.version API" + } + options.with { + tags = ['created'] + author = true + //addBooleanOption('html4', true) + links('https://docs.oracle.com/javase/8/docs/api/') + //addStringOption('Xdoclint:none', '-quiet') + } +} + +test { + useTestNG() +} + +spotbugs { + toolVersion = versions.spotbugs + excludeFilter = file("$projectDir/config/spotbugs/excludeFilter.xml") +} + +tasks.withType(SpotBugsTask) { + reports { + xml.enabled = false + html.enabled = true + } +} + +tasks.withType(Checkstyle) { + reports { + xml.enabled = false + html.enabled = true + } +} + +task release(dependsOn: ['wrapper', 'clean', 'publishToMavenLocal']) { + group = 'Publishing' + description = 'Releases new version to local maven repository.' + doFirst { + println("Version: $version") + } +} + +task pandoc(type: Exec) { + group = 'Documentation' + def pandoc_args = ['--from', 'gfm', + '--to', 'html5', + '--metadata', "pagetitle=$mavenDescription", + '-s', + '-c', 'github-pandoc.css', + '-o', 'docs/README.html', + 'README.md'] + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) + } else { + executable 'pandoc' + args pandoc_args + } + standardOutput = new ByteArrayOutputStream() + ext.output = { + return standardOutput.toString() + } +} + +jacocoTestReport { + reports { + html.enabled = true + xml.enabled = true + } + +} + +sonarqube { + properties { + property("sonar.projectKey", "ethauvin_semver") + property("sonar.sourceEncoding", "UTF-8") + } +} + +tasks.sonarqube { + dependsOn("jacocoTestReport") +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..c5f6465 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/pmd.xml b/config/pmd.xml index add20da..65fe3ec 100644 --- a/config/pmd.xml +++ b/config/pmd.xml @@ -5,76 +5,111 @@ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> Erik's Ruleset - - - - - - + + + + + + + + + + value="./MethodDeclarator[@Image='hashCode' or @Image='equals' or @Image='toString']"/> + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - - - - - - - - - - - @@ -82,11 +117,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -94,16 +204,61 @@ + + + + + + + + + + + - - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/docs/README.html b/docs/README.html index 8758e21..1235a99 100644 --- a/docs/README.html +++ b/docs/README.html @@ -6,134 +6,85 @@ Semantic Version Annotation Processor - + + -

Semantic Version -Annotation Processor

-

Java

-

-

An annotation -processor that automatically generates a -GeneratedVersion class based on a Mustache template and containing -the semantic version (major, minor, -patch, etc.) that is read from a Properties -file or defined in the annotation.

-

This processor was inspired by Cédric Beust's version-processor -and works well in conjunction with the Semantic -Version Plugin for Gradle.

+

Semantic Version Annotation Processor

+

License (3-Clause BSD) release Maven Central Download
+Known Vulnerabilities Quality Gate Status Build Status Build status CircleCI

+

An annotation processor that automatically generates a GeneratedVersion class based on a Mustache template and containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.

+

This processor was inspired by Cédric Beust's version-processor and works well in conjunction with the Semantic Version Plugin for Gradle.

Table of Contents

Examples

  • Using annotation elements:
-
import net.thauvin.erik.semver.Version;
-
-@Version(major = 1, minor = 0, patch = 0, preRelease = "beta")
-public class A {
-// ...
+ -
import net.thauvin.erik.semver.Version;
-
-@Version(properties = "version.properties")
-public class A {
-// ...
-
# version.properties
-version.major=1
-version.minor=0
-version.patch=0
-version.prerelease=beta
-

View -Examples

+ + +

View Examples

Template

-

Upon running the annotation processor, a source file GeneratedVersion.java -is automatically generated with static methods to access the semantic -version data. The source is based on a fully customizable Mustache template.

-

To use your own template, simply create a -version.mustache file in the project's root directory. The -processor will automatically look for it.

+

Upon running the annotation processor, a source file GeneratedVersion.java is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Mustache template.

+

To use your own template, simply create a version.mustache file in the project's root directory. The processor will automatically look for it.

To specify your own template name, use:

-
@Version(template = "version.mustache")
-public class A {
-// ...
+

Default Template

-

The default -template implements the following static variables:

+

The default template implements the following static variables:

@@ -221,8 +156,7 @@ template implements the following static variables:

- + @@ -273,19 +207,17 @@ href="https://docs.oracle.com/javase/8/docs/api/java/util/Date.html">java.
BUILDDATE The build date.java.util.Datejava.util.Date
VERSION

Custom Template

A very simple custom template might look something like:

-
/* version.mustache */
-package {{packageName}};
-
-import java.util.Date;
-
-public final class {{className}} {
-    public final static String PROJECT = "{{project}}";
-    public final static Date DATE = new Date({{epoch}}L);
-    public final static String VERSION = "{{semver}}";
-}
-

The mustache variables automatically filled in by the processor -are:

+ +

The mustache variables automatically filled in by the processor are:

@@ -356,17 +288,13 @@ are:

- +
String
{{semver}} or -{{version}}{{semver}} or {{version}} The full semantic version. String
-

Please also look at this example -using java.time

+

Please also look at this example using java.time

Elements & Properties

The following annotation elements and properties are available:

@@ -411,8 +339,7 @@ href="https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html"> - + @@ -461,8 +388,7 @@ style="text-align: left;">version.prerelease.prefix - + @@ -473,150 +399,97 @@ style="text-align: left;">version.prerelease.prefix
preReleasePrefixversion.prerelease.prefixversion.prerelease.prefix The pre-release prefix. -
type Either java or -kt for Kotlin.Either java or kt for Kotlin. java
-

In order to easily incorporate with existing projects, the property -keys may be assigned custom values:

-
@Version(
-  properties = "example.properties",
-  keysPrefix = "example."
-  majorKey = "maj",
-  minorKey = "min",
-  patchKey = "build",
-  preReleaseKey = "rel",
-  buildMetaKey = "meta",
-  projectKey = "project"
-)
-public class Example {
-// ...
-
# example.properties
-example.project=Example
-example.maj=1
-example.min=0
-example.build=0
-example.rel=beta
-example.meta=
-# ...
+

In order to easily incorporate with existing projects, the property keys may be assigned custom values:

+ +
-

⚠️ -keysPrefix is a new element staring in 1.1.0 -and may break older versions when using custom property keys.
- A quick fix is to include -keysPrefix="" in the annotation to remove the default -version. prefix.

+

⚠️ keysPrefix is a new element staring in 1.1.0 and may break older versions when using custom property keys.
+ A quick fix is to include keysPrefix="" in the annotation to remove the default version. prefix.

Maven

-

To install and run from Maven, configure an artifact as -follows:

-
<dependency>
-    <groupId>net.thauvin.erik</groupId>
-    <artifactId>semver</artifactId>
-    <version>1.2.0</version>
-</dependency>
-

Please look at pom.xml -in the examples/java -directory for a sample:

-
mvn verify
+

To install and run from Maven, configure an artifact as follows:

+ +

Please look at pom.xml in the examples/java directory for a sample:

+

Gradle

Class Generation

-

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

-
repositories {
-    mavenCentral()
-}
-
-dependencies {
-    annotationProcessor 'net.thauvin.erik:semver:1.2.0'
-    compileOnly 'net.thauvin.erik:semver:1.2.0'
-}
-
-tasks.withType(JavaCompile) {
-    options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ]
-}
-

The directory containing the configuration files -(version.properties, version.mustache) must be -specified using the semver.project.dir processor -argument.

-

The GeneratedVersion.java -class will be automatically created in the build/generated -directory upon compiling.

-

Please look at build.gradle -in the examples/java -directory for a sample.

+

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

+
dependencies {
+    annotationProcessor 'net.thauvin.erik:semver:1.2.0'
+    implementation 'net.thauvin.erik:semver:1.2.0'
+}
+
+tasks.withType(JavaCompile) {
+    options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ]
+}
+
+

The directory containing the configuration files (version.properties, version.mustache) must be specified using the semver.project.dir processor argument.

+

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

+

Please look at build.gradle in the examples/java directory for a sample.

Class & Source Generation

-

In order to also incorporate the generated source code into the -source tree, add the following to build.gradle:

-
tasks.withType(JavaCompile) {
-    options.generatedSourceOutputDirectory.set(file("${projectDir}/src/generated/java"))
-}
-

The GeneratedVersion.java -file will now be located in src/generated.

+

In order to also incorporate the generated source code into the source tree, add the following to build.gradle:

+
tasks.withType(JavaCompile) {
+    options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java")
+}
+
+

The GeneratedVersion.java file will now be located in src/generated.

Kotlin

-

The annotation processor also supports Kotlin.

-

To generate a Kotlin version file, simply specify the -type as follows:

-
import net.thauvin.erik.semver.Version
-
-@Version(properties = "version.properties", type="kt")
-open class Main {
-// ...
-

The Kotlin -default template implements the same static fields and functions as -the Java template.

-

Please look at the examples/kotlin -project for a build.gradle.kts -sample.

+

The annotation processor also supports Kotlin.

+

To generate a Kotlin version file, simply specify the type as follows:

+ +

The Kotlin default template implements the same static fields and functions as the Java template.

+

Please look at the examples/kotlin project for a build.gradle.kts sample.

Kotlin & Gradle

-

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

-
var semverProcessor = "net.thauvin.erik:semver:1.2.0"
-
-dependencies {
-    kapt(semverProcessor)
-    compileOnly(semverProcessor)
-}
-
-kapt {
-    arguments {
-        arg("semver.project.dir", projectDir)
-    }
-}
-

The directory containing the configuration files -(version.properties, version.mustache) must be -specified using the semver.project.dir processor -argument.

+

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

+ +

The directory containing the configuration files (version.properties, version.mustache) must be specified using the semver.project.dir processor argument.

+

Kobalt

+

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

+
dependencies {
+    apt("net.thauvin.erik:semver:1.2.0")
+    compileOnly("net.thauvin.erik:semver:1.2.0")
+}
+
+

Please look at Build.kt in the examples/java directory for a sample.

Auto-Increment

-

Incrementing the version is best left to your favorite build system. -For a solution using Gradle, please have a look at the Semver Version -Plugin for Gradle.

-

There are also full examples -in both Java -and Kotlin -showing how to use both the plugin and annotation processor -concurrently.

+

Incrementing the version is best left to your favorite build system. For a solution using Gradle, please have a look at the Semver Version Plugin for Gradle.

+

There are also full examples in both Java and Kotlin showing how to use both the plugin and annotation processor concurrently.

diff --git a/examples/examples.sh b/examples/examples.sh index 23ed5a9..99926d3 100755 --- a/examples/examples.sh +++ b/examples/examples.sh @@ -3,14 +3,14 @@ # Version 1.0 if [ $# -eq 0 ]; then - echo "Usage: $0 " - exit 1 + echo "Usage: $0 " + exit 1 fi # set the examples directories declare -a examples=( - "java" - "kotlin") + "java" + "kotlin") dir=$(dirname "$(readlink -f "$0")") cyan=$(tput setaf 6) @@ -18,12 +18,13 @@ normal=$(tput sgr0) i=0 for ex in "${examples[@]}"; do - if [ $i -ne 0 ]; then - read -p "Press [Enter] key to continue..." - clear - fi - cd "$dir/$ex" || exit 1 - echo "> Project: ${cyan}${ex}${normal}" - ./gradlew --console=plain --no-build-cache clean "$@" || exit 1 - ((i++)) + if [ $i -ne 0 ] + then + read -p "Press [Enter] key to continue..." + clear + fi + cd "$dir/$ex" || exit 1 + echo "> Project: ${cyan}${ex}${normal}" + ./gradlew --console=plain --no-build-cache clean "$@" || exit 1 + (( i++ )) done diff --git a/examples/java/.editorconfig b/examples/java/.editorconfig index 1f808de..a6971e1 100644 --- a/examples/java/.editorconfig +++ b/examples/java/.editorconfig @@ -1,2 +1,2 @@ [*] -insert_final_newline = true +insert_final_newline=true diff --git a/examples/java/build.gradle b/examples/java/build.gradle index 9c3c528..07de9b6 100644 --- a/examples/java/build.gradle +++ b/examples/java/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'application' - id 'com.github.ben-manes.versions' version '0.46.0' + id 'com.github.ben-manes.versions' version '0.28.0' } // ./gradlew run @@ -9,7 +9,7 @@ plugins { defaultTasks 'run' -final def semverProcessor = 'net.thauvin.erik:semver:1.2.1-SNAPSHOT' +final def semverProcessor = 'net.thauvin.erik:semver:1.2.0' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -19,7 +19,6 @@ mainClassName = 'com.example.App' repositories { mavenLocal() mavenCentral() - maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } } dependencies { @@ -28,12 +27,13 @@ dependencies { } tasks.withType(JavaCompile) { - options.generatedSourceOutputDirectory.set(file("${projectDir}/src/generated/java")) - options.compilerArgs += ["-Asemver.project.dir=$projectDir"] + options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java") + options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ] } task runExample(type: JavaExec) { group = 'application' classpath = sourceSets.main.runtimeClasspath - mainClass.set('com.example.Example') + + main = 'com.example.Example' } diff --git a/examples/java/gradle/wrapper/gradle-wrapper.jar b/examples/java/gradle/wrapper/gradle-wrapper.jar index 033e24c..62d4c05 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 9f4197d..bb8b2fc 100644 --- a/examples/java/gradle/wrapper/gradle-wrapper.properties +++ b/examples/java/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/java/gradlew b/examples/java/gradlew index fcb6fca..fbd7c51 100755 --- a/examples/java/gradlew +++ b/examples/java/gradlew @@ -1,7 +1,7 @@ -#!/bin/sh +#!/usr/bin/env sh # -# Copyright © 2015-2021 the original authors. +# Copyright 2015 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,98 +17,67 @@ # ############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# +## +## Gradle start up script for UN*X +## ############################################################################## # Attempt to set APP_HOME - # Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum +MAX_FD="maximum" warn () { echo "$*" -} >&2 +} die () { echo echo "$*" echo exit 1 -} >&2 +} # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -118,9 +87,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java + JAVACMD="$JAVA_HOME/jre/sh/java" else - JAVACMD=$JAVA_HOME/bin/java + JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -129,120 +98,88 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi fi -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' +# 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" exec "$JAVACMD" "$@" diff --git a/examples/java/gradlew.bat b/examples/java/gradlew.bat index 93e3f59..5093609 100644 --- a/examples/java/gradlew.bat +++ b/examples/java/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%"=="" @echo off +@if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,8 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused +if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -41,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 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. @@ -55,7 +54,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% @@ -65,6 +64,21 @@ 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 @@ -72,19 +86,17 @@ 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 -if %ERRORLEVEL% equ 0 goto mainEnd +if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/examples/java/pom.xml b/examples/java/pom.xml index 3823de9..9a95781 100644 --- a/examples/java/pom.xml +++ b/examples/java/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 @@ -45,7 +45,7 @@ org.codehaus.mojo exec-maven-plugin - 3.0.0 + 1.6.0 run diff --git a/examples/java/src/generated/java/com/example/ExampleVersion.java b/examples/java/src/generated/java/com/example/ExampleVersion.java index a72d3a9..fe50374 100644 --- a/examples/java/src/generated/java/com/example/ExampleVersion.java +++ b/examples/java/src/generated/java/com/example/ExampleVersion.java @@ -2,14 +2,14 @@ * This file is automatically generated. * Do not modify! -- ALL CHANGES WILL BE ERASED! */ - + package com.example; import java.util.Date; public final class ExampleVersion { public static final String PROJECT = "Java Example"; - public static final Date BUILDDATE = new Date(1624066674216L); + public static final Date BUILDDATE = new Date(1558820521980L); public static final String VERSION = "8.4.97-alpha+T800"; /** diff --git a/examples/java/src/generated/java/com/example/GeneratedVersion.java b/examples/java/src/generated/java/com/example/GeneratedVersion.java index 1f0b0a9..adf8b76 100644 --- a/examples/java/src/generated/java/com/example/GeneratedVersion.java +++ b/examples/java/src/generated/java/com/example/GeneratedVersion.java @@ -2,7 +2,7 @@ * This file is automatically generated. * Do not modify! -- ALL CHANGES WILL BE ERASED! */ - + package com.example; import java.util.Date; @@ -14,7 +14,7 @@ import java.util.Date; */ public final class GeneratedVersion { public static final String PROJECT = "Java App"; - public static final Date BUILDDATE = new Date(1624066674199L); + public static final Date BUILDDATE = new Date(1558820521932L); public static final int MAJOR = 11; public static final int MINOR = 11; public static final int PATCH = 20; diff --git a/examples/java/src/main/java/com/example/Example.java b/examples/java/src/main/java/com/example/Example.java index c8c8c0b..324030f 100644 --- a/examples/java/src/main/java/com/example/Example.java +++ b/examples/java/src/main/java/com/example/Example.java @@ -6,7 +6,7 @@ import java.text.SimpleDateFormat; import java.util.Locale; @Version(properties = "example.properties", template = "example.mustache", className = "ExampleVersion", - keysPrefix = "example.") + keysPrefix = "example.") public final class Example { /** * Command line interface. @@ -19,7 +19,7 @@ public final class Example { System.out.println("-- From Example -------------------------------------"); System.out.println(" " + ExampleVersion.PROJECT + ' ' + ExampleVersion.VERSION - + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')'); + + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')'); System.out.println("-----------------------------------------------------"); } diff --git a/examples/kotlin/.editorconfig b/examples/kotlin/.editorconfig index 1f808de..a6971e1 100644 --- a/examples/kotlin/.editorconfig +++ b/examples/kotlin/.editorconfig @@ -1,2 +1,2 @@ [*] -insert_final_newline = true +insert_final_newline=true diff --git a/examples/kotlin/build.gradle.kts b/examples/kotlin/build.gradle.kts index 9529c16..959ab64 100644 --- a/examples/kotlin/build.gradle.kts +++ b/examples/kotlin/build.gradle.kts @@ -1,8 +1,8 @@ plugins { - id("application") - id("com.github.ben-manes.versions") version "0.46.0" - kotlin("jvm") version "1.7.22" - kotlin("kapt") version "1.7.22" + kotlin("jvm").version("1.3.72") + application + id("org.jetbrains.kotlin.kapt").version("1.3.72") + id("com.github.ben-manes.versions").version("0.28.0") } // ./gradlew @@ -13,7 +13,7 @@ plugins { defaultTasks(ApplicationPlugin.TASK_RUN_NAME) -val semverProcessor = "net.thauvin.erik:semver:1.2.1-SNAPSHOT" +val semverProcessor = "net.thauvin.erik:semver:1.2.0" dependencies { kapt(semverProcessor) @@ -30,31 +30,30 @@ kapt { repositories { mavenLocal() - mavenCentral() - maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } + jcenter() } application { - mainClass.set("com.example.App") + mainClassName = "com.example.App" } tasks { register("runJava", JavaExec::class) { group = "application" - mainClass.set("com.example.JavaApp") - classpath = sourceSets.main.get().runtimeClasspath + main = "com.example.JavaApp" + classpath = sourceSets["main"].runtimeClasspath } register("runJavaExample", JavaExec::class) { group = "application" - mainClass.set("com.example.JavaExample") - classpath = sourceSets.main.get().runtimeClasspath + main = "com.example.JavaExample" + classpath = sourceSets["main"].runtimeClasspath } register("runExample", JavaExec::class) { group = "application" - mainClass.set("com.example.Example") - classpath = sourceSets.main.get().runtimeClasspath + main = "com.example.Example" + classpath = sourceSets["main"].runtimeClasspath } } diff --git a/examples/kotlin/gradle/wrapper/gradle-wrapper.jar b/examples/kotlin/gradle/wrapper/gradle-wrapper.jar index 033e24c..62d4c05 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 9f4197d..bb8b2fc 100644 --- a/examples/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/examples/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/kotlin/gradlew b/examples/kotlin/gradlew index fcb6fca..fbd7c51 100755 --- a/examples/kotlin/gradlew +++ b/examples/kotlin/gradlew @@ -1,7 +1,7 @@ -#!/bin/sh +#!/usr/bin/env sh # -# Copyright © 2015-2021 the original authors. +# Copyright 2015 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,98 +17,67 @@ # ############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# +## +## Gradle start up script for UN*X +## ############################################################################## # Attempt to set APP_HOME - # Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum +MAX_FD="maximum" warn () { echo "$*" -} >&2 +} die () { echo echo "$*" echo exit 1 -} >&2 +} # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -118,9 +87,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java + JAVACMD="$JAVA_HOME/jre/sh/java" else - JAVACMD=$JAVA_HOME/bin/java + JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -129,120 +98,88 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi fi -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' +# 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" exec "$JAVACMD" "$@" diff --git a/examples/kotlin/gradlew.bat b/examples/kotlin/gradlew.bat index 93e3f59..5093609 100644 --- a/examples/kotlin/gradlew.bat +++ b/examples/kotlin/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%"=="" @echo off +@if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,8 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused +if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -41,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 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. @@ -55,7 +54,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% @@ -65,6 +64,21 @@ 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 @@ -72,19 +86,17 @@ 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 -if %ERRORLEVEL% equ 0 goto mainEnd +if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/examples/kotlin/src/main/java/com/example/JavaExample.java b/examples/kotlin/src/main/java/com/example/JavaExample.java index b9aa8a9..cf6918c 100644 --- a/examples/kotlin/src/main/java/com/example/JavaExample.java +++ b/examples/kotlin/src/main/java/com/example/JavaExample.java @@ -15,7 +15,7 @@ public final class JavaExample { System.out.println("-- From JavaExample -----------------------------------"); System.out.println(" " + ExampleVersion.PROJECT + ' ' + ExampleVersion.VERSION - + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')'); + + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')'); System.out.println("-------------------------------------------------------"); } diff --git a/examples/kotlin/src/main/kotlin/com/example/Example.kt b/examples/kotlin/src/main/kotlin/com/example/Example.kt index 5db8c0d..81bf914 100644 --- a/examples/kotlin/src/main/kotlin/com/example/Example.kt +++ b/examples/kotlin/src/main/kotlin/com/example/Example.kt @@ -5,7 +5,7 @@ import java.text.SimpleDateFormat import java.util.Locale @Version(properties = "example.properties", type = "kt", template = "example.mustache", className = "ExampleVersion", - keysPrefix = "example.") + keysPrefix = "example.") class Example { companion object { @JvmStatic @@ -15,7 +15,7 @@ class Example { println("-------------------------------------------------------") println(" ${ExampleVersion.PROJECT} ${ExampleVersion.VERSION} (" - + sdf.format(ExampleVersion.BUILDDATE) + ')') + + sdf.format(ExampleVersion.BUILDDATE) + ')') println("-------------------------------------------------------") } diff --git a/examples/test/.editorconfig b/examples/test/.editorconfig index 1f808de..a6971e1 100644 --- a/examples/test/.editorconfig +++ b/examples/test/.editorconfig @@ -1,2 +1,2 @@ [*] -insert_final_newline = true +insert_final_newline=true diff --git a/examples/test/build.gradle b/examples/test/build.gradle index 9444d47..6a3587b 100644 --- a/examples/test/build.gradle +++ b/examples/test/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'application' - id 'com.github.ben-manes.versions' version '0.46.0' + id 'com.github.ben-manes.versions' version '0.21.0' } // ./gradlew run @@ -14,6 +14,8 @@ final def semverProcessor = 'net.thauvin.erik:semver:1.2.0' sourceCompatibility = 1.8 targetCompatibility = 1.8 +compileJava. + mainClassName = 'com.example.Example' repositories { @@ -27,6 +29,6 @@ dependencies { } tasks.withType(JavaCompile) { - options.generatedSourceOutputDirectory.set(file("${projectDir}/src/generated/java")) - options.compilerArgs += ["-Asemver.project.dir=${projectDir}/example"] + options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java") + options.compilerArgs += [ "-Asemver.project.dir=${projectDir}/example" ] } diff --git a/examples/test/gradle/wrapper/gradle-wrapper.properties b/examples/test/gradle/wrapper/gradle-wrapper.properties index 9f4197d..f4d7b2b 100644 --- a/examples/test/gradle/wrapper/gradle-wrapper.properties +++ b/examples/test/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/test/gradlew b/examples/test/gradlew old mode 100755 new mode 100644 index fcb6fca..b0d6d0a --- a/examples/test/gradlew +++ b/examples/test/gradlew @@ -1,13 +1,13 @@ -#!/bin/sh +#!/usr/bin/env sh # -# Copyright © 2015-2021 the original authors. +# Copyright 2015 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # 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, @@ -17,110 +17,78 @@ # ############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# +## +## Gradle start up script for UN*X +## ############################################################################## # Attempt to set APP_HOME - # Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum +MAX_FD="maximum" warn () { echo "$*" -} >&2 +} die () { echo echo "$*" echo exit 1 -} >&2 +} # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java + JAVACMD="$JAVA_HOME/jre/sh/java" else - JAVACMD=$JAVA_HOME/bin/java + JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -129,120 +97,92 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# 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" -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" +# 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 -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - exec "$JAVACMD" "$@" diff --git a/examples/test/gradlew.bat b/examples/test/gradlew.bat index 93e3f59..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, @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%"=="" @echo off +@if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,14 +25,10 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused +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" @@ -41,7 +37,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 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. @@ -55,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% @@ -65,26 +61,38 @@ 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 -if %ERRORLEVEL% equ 0 goto mainEnd +if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/examples/test/src/generated/java/com/example/ExampleVersion.java b/examples/test/src/generated/java/com/example/ExampleVersion.java index ef81de4..ddf4200 100644 --- a/examples/test/src/generated/java/com/example/ExampleVersion.java +++ b/examples/test/src/generated/java/com/example/ExampleVersion.java @@ -2,14 +2,14 @@ * This file is automatically generated. * Do not modify! -- ALL CHANGES WILL BE ERASED! */ - + package com.example; import java.util.Date; public final class ExampleVersion { public static final String PROJECT = "Java Example"; - public static final Date BUILDDATE = new Date(1619673811155L); + public static final Date BUILDDATE = new Date(1558820496856L); public static final String VERSION = "8.4.97-alpha+T800"; /** diff --git a/examples/test/src/main/java/com/example/Example.java b/examples/test/src/main/java/com/example/Example.java index c8c8c0b..324030f 100644 --- a/examples/test/src/main/java/com/example/Example.java +++ b/examples/test/src/main/java/com/example/Example.java @@ -6,7 +6,7 @@ import java.text.SimpleDateFormat; import java.util.Locale; @Version(properties = "example.properties", template = "example.mustache", className = "ExampleVersion", - keysPrefix = "example.") + keysPrefix = "example.") public final class Example { /** * Command line interface. @@ -19,7 +19,7 @@ public final class Example { System.out.println("-- From Example -------------------------------------"); System.out.println(" " + ExampleVersion.PROJECT + ' ' + ExampleVersion.VERSION - + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')'); + + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')'); System.out.println("-----------------------------------------------------"); } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 033e24c..62d4c05 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 9f4197d..bb8b2fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..fbd7c51 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..5093609 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,104 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@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 +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem 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" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar deleted file mode 100644 index e96bdc7..0000000 Binary files a/lib/bld/bld-wrapper.jar and /dev/null differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties deleted file mode 100644 index 5daccca3..0000000 --- a/lib/bld/bld-wrapper.properties +++ /dev/null @@ -1,9 +0,0 @@ -bld.downloadExtensionJavadoc=false -bld.downloadExtensionSources=true -bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.2 -bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.0 -bld.extensions-testng=com.uwyn.rife2:bld-testng:0.9.1-SNAPSHOT -bld.repositories=MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES -bld.downloadLocation= -bld.sourceDirectories= -bld.version=1.7.1 diff --git a/pandoc.sh b/pandoc.sh deleted file mode 100755 index 2ac666d..0000000 --- a/pandoc.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -pandoc --from gfm \ ---to html5 \ ---metadata "pagetitle=Semantic Version Annotation Processor" \ --s \ --c docs/github-pandoc.css \ --o docs/README.html \ -README.md diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 8bb99f9..0000000 --- a/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - net.thauvin.erik.semver - semver - 1.2.1-SNAPSHOT - SemVer - Semantic Version Annotation Processor - https://github.com/ethauvin/semver - - - The BSD 3-Clause License - http://opensource.org/licenses/BSD-3-Clause - - - - - com.github.spullara.mustache.java - compiler - 0.9.10 - compile - - - - - ethauvin - Erik C. Thauvin - erik@thauvin.net - https://erik.thauvin.net/ - - - - scm:git:https://github.com/ethauvin/semver.git - scm:git:git@github.com:ethauvin/semver.git - https://github.com/ethauvin/semver - - diff --git a/preflightcheck.sh b/preflightcheck.sh new file mode 100644 index 0000000..67359b9 --- /dev/null +++ b/preflightcheck.sh @@ -0,0 +1,210 @@ +#!/bin/bash + +# set source and test locations +src="src/main/java/net/thauvin/erik/semver" +test="src/test/java/net/thauvin/erik/semver" +# e.g: .java, .kt, etc. +ext=".java" +java8=true +# e.g: +declare -a examples=( + "examples/java run runExample" + "examples/kotlin run runJava runExample runJavaExample") +# e.g: empty or javadoc, etc. +gradle_doc="javadoc pandoc" +# e.g. empty or sonarqube +gradle_sonar="sonarqube" +# gradle options for examples +gradle_opts="--console=plain --no-build-cache --no-daemon" +# maven arguments for examples +maven_args="compile exec:java" + +# +# Version: 1.1.3 +# + +if [ "$java8" = true ] +then + export JAVA_HOME="$JAVA8_HOME" + export PATH="$(cygpath "$JAVA_HOME")/bin:$PATH" +fi + +pwd=$PWD +red=$(tput setaf 1) +cyan=$(tput setaf 6) +std=$(tput sgr0) +date=$(date +%Y) + +pause() { + read -p "Press [Enter] key to continue..." +} + +checkCopyright() { + if [ "$(grep -c "$date" "$1")" -eq 0 ] + then + echo -e " Invalid: ${red}$f${std}" + else + echo -e " Checked: $1" + fi +} + +runGradle() { + cd "$1" || exit 1 + clear + reset + echo -e "> Project: ${cyan}${1}${std} [Gradle]" + shift + ./gradlew $@ || exit 1 + pause + cd "$pwd" +} + +runKobalt() { + cd "$1" || exit 1 + if [ -f kobalt/src/Build.kt ] + then + clear + reset + echo -e "> Project: ${cyan}${1}${std} [Kobalt]" + shift + ./kobaltw $@ || exit 1 + pause + fi + cd "$pwd" +} + +runMaven() { + cd "$1" || exit 1 + if [ -f pom.xml ] + then + clear + reset + echo -e "> Project: ${cyan}${1}${std} [Maven]" + shift + mvn $@ || exit 1 + pause + fi + cd "$pwd" +} + +updateWrappers() { + clear + ./updatewrappers.sh + pause +} + +checkDeps() { + clear + echo -e "${cyan}Checking depencencies...${std}" + gradle --console=plain dU || exit 1 + read -p "Check Examples depencencies? [y/n] " cont + clear + case $cont in + [Nn] ) return ;; + * ) for ex in "${!examples[@]}" + do + runGradle $(echo "${examples[ex]}" | cut -d " " -f 1) dU + runKobalt $(echo "${examples[ex]}" | cut -d " " -f 1) checkVersions + runMaven $(echo "${examples[ex]}" | cut -d " " -f 1) versions:display-dependency-updates + if [ "$ex" -eq "${#examples}" ] + then + read -p "Continue? [y/n]: " cont + clear + case $cont in + * ) continue ;; + [Nn] ) return ;; + esac + fi + done ;; + esac +} + +gradleCheck() { + clear + echo -e "${cyan}Checking Gradle build....${std}" + gradle $gradle_opts clean check $gradle_doc $gradle_sonar || exit 1 + pause +} + +runExamples() { + for ex in "${!examples[@]}" + do + runGradle ${examples[ex]} clean $gradle_opts + runKobalt ${examples[ex]} clean + runMaven $(echo "${examples[ex]}" | cut -d " " -f 1) clean $maven_args + done +} + +examplesMenu() { + clear + echo -e "${cyan}Examples${std}" + for ex in "${!examples[@]}" + do + printf ' %d. %s\n' $(($ex + 1)) $(echo "${examples[ex]}" | cut -d " " -f 1) + done + echo " $((${#examples[@]} + 1)). Run All Examples" + read -p "Enter choice [1-${#examples[@]}]: " choice + clear + case $choice in + [0-9] ) if [ "$choice" -gt "${#examples[@]}" ] + then + runExamples + examplesMenu + else + runGradle ${examples[$(($choice - 1))]} + runKobalt ${examples[$(($choice - 1))]} + runMaven $(echo "${examples[$(($choice - 1))]}" | cut -d " " -f 1) $maven_args + examplesMenu + fi ;; + * ) return ;; + esac +} + +validateCopyrights() { + clear + echo -e "${cyan}Validating copyrights...${std}" + for f in LICENSE.TXT ${src}/*${ext} ${test}/*${ext} + do + checkCopyright "$f" + done + pause +} + +everything() { + updateWrappers + checkDeps + gradleCheck + runExamples + validateCopyrights +} + +showMenu() { + clear + echo "${cyan}Preflight Check${std}" + echo " 1. Update Wrappers" + echo " 2. Check Dependencies" + echo " 3. Check Gradle Build" + echo " 4. Run Examples" + echo " 5. Validate Copyrights" + echo " 6. Check Everything" +} + +readOptions(){ + local choice + read -p "Enter choice [1-6]: " choice + case $choice in + 1) updateWrappers ;; + 2) checkDeps ;; + 3) gradleCheck ;; + 4) examplesMenu ;; + 5) validateCopyrights ;; + 6) everything ;; + *) exit 0 ;; + esac +} + +while true +do + showMenu + readOptions +done diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..0b39698 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,19 @@ +/* + * This settings file was auto generated by the Gradle buildInit task + * by 'erik' at '1/13/16 1:03 PM' with Gradle 2.10 + * + * The settings file is used to specify which projects to include in your build. + * In a single project build this file can be empty or even removed. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/2.10/userguide/multi_project_builds.html + */ + +/* +// To declare projects as part of a multi-project build use the 'include' method +include 'shared' +include 'api' +include 'services:webservice' +*/ +rootProject.name = 'semver' + diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 3c63dd8..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,7 +0,0 @@ -sonar.organization=ethauvin-github -sonar.projectKey=ethauvin_semver -sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml -sonar.sources=src/main/java/ -sonar.tests=src/test/java/ -sonar.java.binaries=build/main,build/test -sonar.java.libraries=lib/compile/*.jar diff --git a/src/bld/java/net/thauvin/erik/semver/SemverBuild.java b/src/bld/java/net/thauvin/erik/semver/SemverBuild.java deleted file mode 100644 index 1e94f53..0000000 --- a/src/bld/java/net/thauvin/erik/semver/SemverBuild.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * SemverBuild.java - * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of this project nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package net.thauvin.erik.semver; - -import rife.bld.BuildCommand; -import rife.bld.Project; -import rife.bld.extension.JacocoReportOperation; -import rife.bld.extension.PmdOperation; -import rife.bld.extension.TestNgOperation; -import rife.bld.publish.*; -import rife.tools.exceptions.FileUtilsErrorException; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; - -import static rife.bld.dependencies.Repository.*; -import static rife.bld.dependencies.Scope.compile; -import static rife.bld.dependencies.Scope.test; -import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING; - -public class SemverBuild extends Project { - public SemverBuild() { - pkg = "net.thauvin.erik.semver"; - name = "SemVer"; - version = version(1, 2, 1, "SNAPSHOT"); - - var description = "Semantic Version Annotation Processor"; - var url = "https://github.com/ethauvin/semver"; - - javaRelease = 17; - - downloadSources = true; - repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS); - - scope(compile) - .include(dependency("com.github.spullara.mustache.java", "compiler", - version(0, 9, 10))); - scope(test) - .include(dependency("org.assertj", "assertj-joda-time", version(2, 2, 0))) - .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0))) - .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0))); - - - javadocOperation().javadocOptions() - .tag("created.on", "a", "Created on:") - .windowTitle(name + ' ' + version.toString() + " API") - .docLint(NO_MISSING); - - publishOperation() - .repository(version.isSnapshot() ? repository(SONATYPE_SNAPSHOTS_LEGACY.location()) - .withCredentials(property("sonatype.user"), property("sonatype.password")) - : repository(SONATYPE_RELEASES.location()) - .withCredentials(property("sonatype.user"), property("sonatype.password"))) - .repository(MAVEN_LOCAL) - .info(new PublishInfo() - .groupId(pkg) - .artifactId(name.toLowerCase()) - .name(name).version(version) - .description(description) - .url(url) - .developer(new PublishDeveloper() - .id("ethauvin") - .name("Erik C. Thauvin") - .email("erik@thauvin.net") - .url("https://erik.thauvin.net/")) - .license(new PublishLicense() - .name("The BSD 3-Clause License") - .url("http://opensource.org/licenses/BSD-3-Clause")) - .scm(new PublishScm() - .connection("scm:git:" + url + ".git") - .developerConnection("scm:git:git@github.com:ethauvin/" + name.toLowerCase() + ".git") - .url(url)) - .signKey(property("sign.key")) - .signPassphrase(property("sign.passphrase"))); - } - - public static void main(String[] args) { - new SemverBuild().start(args); - } - - @BuildCommand(summary = "Generates JaCoCo Reports") - public void jacoco() throws IOException { - new JacocoReportOperation().fromProject(this).execute(); - } - - @BuildCommand(summary = "Runs PMD analysis") - public void pmd() { - new PmdOperation() - .fromProject(this) - .failOnViolation(true) - .ruleSets("config/pmd.xml") - .execute(); - } - - private void rootPom() throws FileUtilsErrorException { - PomBuilder.generateInto(publishOperation().info(), publishOperation().dependencies(), - Path.of(workDirectory.getPath(), "pom.xml").toFile()); - } - - @Override - public void publish() throws Exception { - super.publish(); - rootPom(); - } - - @Override - public void publishLocal() throws Exception { - super.publishLocal(); - rootPom(); - } -} diff --git a/src/main/java/net/thauvin/erik/semver/Constants.java b/src/main/java/net/thauvin/erik/semver/Constants.java index 8dbc3d5..22cf4d5 100644 --- a/src/main/java/net/thauvin/erik/semver/Constants.java +++ b/src/main/java/net/thauvin/erik/semver/Constants.java @@ -1,7 +1,7 @@ /* * Constants.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,10 +36,10 @@ package net.thauvin.erik.semver; * The Constants class holds the constant variables used throughout this project. * * @author Erik C. Thauvin - * @created.on 2016-01-13 + * @created 2016-01-13 * @since 1.0 */ -@SuppressWarnings("PMD.DataClass") +@SuppressWarnings("WeakerAccess") public final class Constants { /** * The default metadata prefix. diff --git a/src/main/java/net/thauvin/erik/semver/Version.java b/src/main/java/net/thauvin/erik/semver/Version.java index 9e73b07..f687f00 100644 --- a/src/main/java/net/thauvin/erik/semver/Version.java +++ b/src/main/java/net/thauvin/erik/semver/Version.java @@ -1,7 +1,7 @@ /* * Version.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,10 +41,9 @@ import java.lang.annotation.Target; * The Version class implements the annotation interface. * * @author Erik C. Thauvin - * @created.on 2016-01-13 + * @created 2016-01-13 * @since 1.0 */ -@SuppressWarnings("SameReturnValue") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) public @interface Version { diff --git a/src/main/java/net/thauvin/erik/semver/VersionInfo.java b/src/main/java/net/thauvin/erik/semver/VersionInfo.java index 3fb3437..19e4807 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionInfo.java +++ b/src/main/java/net/thauvin/erik/semver/VersionInfo.java @@ -1,7 +1,7 @@ /* * VersionInfo.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ package net.thauvin.erik.semver; * The VersionInfo class is used to hold and retrieve the semantic version values. * * @author Erik C. Thauvin - * @created.on 2016-01-16 + * @created 2016-01-16 * @since 1.0 */ @SuppressWarnings("PMD.DataClass") @@ -101,6 +101,15 @@ public class VersionInfo { return buildMeta; } + /** + * Sets the build meta-data. + * + * @param buildMeta The new build meta-data. + */ + public void setBuildMeta(final String buildMeta) { + this.buildMeta = buildMeta; + } + /** * Returns the meta-data prefix. * @@ -110,6 +119,15 @@ public class VersionInfo { return buildMetaPrefix; } + /** + * Sets the meta-data prefix. + * + * @param buildMetaPrefix The meta-data prefix. + */ + public void setBuildMetaPrefix(final String buildMetaPrefix) { + this.buildMetaPrefix = buildMetaPrefix; + } + /** * Returns the class name. * @@ -119,6 +137,15 @@ public class VersionInfo { return className; } + /** + * Sets the class name. + * + * @param className The new class name. + */ + public void setClassName(final String className) { + this.className = className; + } + /** * Returns the build epoch/Unix timestamp. * @@ -137,6 +164,15 @@ public class VersionInfo { return major; } + /** + * Sets the major version. + * + * @param major The new major version. + */ + public void setMajor(final int major) { + this.major = major; + } + /** * Returns the major version. * @@ -146,6 +182,15 @@ public class VersionInfo { return minor; } + /** + * Sets the minor version. + * + * @param minor The new minor version. + */ + public void setMinor(final int minor) { + this.minor = minor; + } + /** * Returns the package name. * @@ -155,6 +200,15 @@ public class VersionInfo { return packageName; } + /** + * Sets the package name. + * + * @param packageName The new package name. + */ + public void setPackageName(final String packageName) { + this.packageName = packageName; + } + /** * Returns the patch version. * @@ -164,6 +218,15 @@ public class VersionInfo { return patch; } + /** + * Sets the patch version. + * + * @param patch The new patch version. + */ + public void setPatch(final int patch) { + this.patch = patch; + } + /** * Returns the pre-release version. * @@ -173,6 +236,15 @@ public class VersionInfo { return preRelease; } + /** + * Sets the pre-release version. + * + * @param preRelease The new pre-release version. + */ + public void setPreRelease(final String preRelease) { + this.preRelease = preRelease; + } + /** * Returns the pre-release prefix. * @@ -182,6 +254,15 @@ public class VersionInfo { return preReleasePrefix; } + /** + * Sets the pre-release prefix. + * + * @param preReleasePrefix The new pre-release prefix. + */ + public void setPreReleasePrefix(final String preReleasePrefix) { + this.preReleasePrefix = preReleasePrefix; + } + /** * Returns the project name. * @@ -191,6 +272,15 @@ public class VersionInfo { return project; } + /** + * Sets the project name. + * + * @param project The new project name. + */ + public void setProject(final String project) { + this.project = project; + } + /** * Sames as {@link #getVersion()}. * @@ -209,6 +299,15 @@ public class VersionInfo { return separator; } + /** + * Sets the version separator. + * + * @param separator The new version separator. + */ + public void setSeparator(final String separator) { + this.separator = separator; + } + /** * Returns the full version string. * @@ -231,110 +330,11 @@ public class VersionInfo { */ public String getVersion() { return major - + separator - + minor - + separator - + patch - + (!preRelease.isEmpty() ? preReleasePrefix + preRelease : "") - + (!buildMeta.isEmpty() ? buildMetaPrefix + buildMeta : ""); - } - - /** - * Sets the build meta-data. - * - * @param buildMeta The new build meta-data. - */ - public void setBuildMeta(final String buildMeta) { - this.buildMeta = buildMeta; - } - - /** - * Sets the meta-data prefix. - * - * @param buildMetaPrefix The meta-data prefix. - */ - public void setBuildMetaPrefix(final String buildMetaPrefix) { - this.buildMetaPrefix = buildMetaPrefix; - } - - /** - * Sets the class name. - * - * @param className The new class name. - */ - public void setClassName(final String className) { - this.className = className; - } - - /** - * Sets the major version. - * - * @param major The new major version. - */ - public void setMajor(final int major) { - this.major = major; - } - - /** - * Sets the minor version. - * - * @param minor The new minor version. - */ - public void setMinor(final int minor) { - this.minor = minor; - } - - /** - * Sets the package name. - * - * @param packageName The new package name. - */ - public void setPackageName(final String packageName) { - this.packageName = packageName; - } - - /** - * Sets the patch version. - * - * @param patch The new patch version. - */ - public void setPatch(final int patch) { - this.patch = patch; - } - - /** - * Sets the pre-release version. - * - * @param preRelease The new pre-release version. - */ - public void setPreRelease(final String preRelease) { - this.preRelease = preRelease; - } - - /** - * Sets the pre-release prefix. - * - * @param preReleasePrefix The new pre-release prefix. - */ - public void setPreReleasePrefix(final String preReleasePrefix) { - this.preReleasePrefix = preReleasePrefix; - } - - /** - * Sets the project name. - * - * @param project The new project name. - */ - public void setProject(final String project) { - this.project = project; - } - - /** - * Sets the version separator. - * - * @param separator The new version separator. - */ - public void setSeparator(final String separator) { - this.separator = separator; + + separator + + minor + + separator + + patch + + (preRelease.length() > 0 ? preReleasePrefix + preRelease : "") + + (buildMeta.length() > 0 ? buildMetaPrefix + buildMeta : ""); } } diff --git a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java index 1c9f150..02cde7b 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java +++ b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java @@ -1,7 +1,7 @@ /* * VersionProcessor.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,8 +36,14 @@ import com.github.mustachejava.DefaultMustacheFactory; import com.github.mustachejava.Mustache; import com.github.mustachejava.MustacheFactory; import com.github.mustachejava.MustacheNotFoundException; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import javax.annotation.processing.*; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedOptions; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -45,7 +51,12 @@ import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; import javax.tools.FileObject; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.HashSet; @@ -56,70 +67,57 @@ import java.util.Set; * The VersionProcessor class implements a semantic version annotation processor. * * @author Erik C. Thauvin - * @created.on 2016-01-13 + * @created 2016-01-13 * @since 1.0 */ -@SuppressWarnings({"PMD.GuardLogStatement", "PMD.BeanMembersShouldSerialize"}) +@SuppressWarnings("PMD.GuardLogStatement") @SupportedOptions({Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME, Constants.SEMVER_PROJECT_DIR_ARG}) public class VersionProcessor extends AbstractProcessor { private Filer filer; private Messager messager; - private static String getTemplate(final boolean isLocalTemplate, final Version version) { - final String template; - if (isLocalTemplate && Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template())) { - template = Constants.DEFAULT_TEMPLATE_NAME; - } else if (Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template()) && Constants.KOTLIN_TYPE - .equals(version.type())) { - template = Constants.DEFAULT_KOTLIN_TEMPLATE; - } else { - template = version.template(); - } - return template; - } - private void error(final String s) { log(Diagnostic.Kind.ERROR, s); } - @SuppressWarnings("PMD.UnusedPrivateMethod") private void error(final String s, final Throwable t) { - log(Diagnostic.Kind.ERROR, t != null ? t.toString() : s); + log(Diagnostic.Kind.ERROR, (t != null ? t.toString() : s)); } + @SuppressFBWarnings({"PATH_TRAVERSAL_IN", "UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH"}) private VersionInfo findValues(final Version version) throws IOException { final VersionInfo versionInfo = new VersionInfo(version); - if (!version.properties().isEmpty()) { + if (version.properties().length() > 0) { final File propsFile = getLocalFile(version.properties()); if (propsFile.isFile() && propsFile.canRead()) { note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')'); final Properties p = new Properties(); - try (InputStreamReader reader = new InputStreamReader( - Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) { + try (final InputStreamReader reader = new InputStreamReader( + Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) { p.load(reader); versionInfo.setProject( - p.getProperty(version.keysPrefix() + version.projectKey(), version.project())); + p.getProperty(version.keysPrefix() + version.projectKey(), version.project())); versionInfo.setMajor( - parseIntProperty(p, version.keysPrefix() + version.majorKey(), version.major())); + parseIntProperty(p, version.keysPrefix() + version.majorKey(), version.major())); versionInfo.setMinor( - parseIntProperty(p, version.keysPrefix() + version.minorKey(), version.minor())); + parseIntProperty(p, version.keysPrefix() + version.minorKey(), version.minor())); versionInfo.setPatch( - parseIntProperty(p, version.keysPrefix() + version.patchKey(), version.patch())); + parseIntProperty(p, version.keysPrefix() + version.patchKey(), version.patch())); versionInfo.setBuildMeta( - p.getProperty(version.keysPrefix() + version.buildMetaKey(), version.buildMeta())); + p.getProperty(version.keysPrefix() + version.buildMetaKey(), version.buildMeta())); versionInfo.setBuildMetaPrefix( - p.getProperty(version.keysPrefix() + version.buildMetaPrefixKey(), version.buildMetaPrefix())); + p.getProperty(version.keysPrefix() + version.buildMetaPrefixKey(), version.buildMetaPrefix())); versionInfo.setPreRelease( - p.getProperty(version.keysPrefix() + version.preReleaseKey(), version.preRelease())); + p.getProperty(version.keysPrefix() + version.preReleaseKey(), version.preRelease())); versionInfo.setPreReleasePrefix(p.getProperty(version.keysPrefix() + version.preReleasePrefixKey(), - version.preReleasePrefix())); + version.preReleasePrefix())); versionInfo.setSeparator( - p.getProperty(version.keysPrefix() + version.separatorKey(), version.separator())); + p.getProperty(version.keysPrefix() + version.separatorKey(), version.separator())); } } else { final String findOrRead; @@ -130,13 +128,14 @@ public class VersionProcessor extends AbstractProcessor { } error("Could not " + findOrRead + ": " + propsFile); throw new FileNotFoundException( - "Could not " + findOrRead + " the specified file: `" + propsFile.getAbsolutePath() + '`'); + "Could not " + findOrRead + " the specified file: `" + propsFile.getAbsolutePath() + '`'); } } return versionInfo; } + @SuppressFBWarnings("PATH_TRAVERSAL_IN") private File getLocalFile(final String fileName) { if (processingEnv != null) { // null when testing. final String prop = processingEnv.getOptions().get(Constants.SEMVER_PROJECT_DIR_ARG); @@ -194,7 +193,15 @@ public class VersionProcessor extends AbstractProcessor { versionInfo.setPackageName(packageElement.getQualifiedName().toString()); } note("Found version: " + versionInfo.getVersion()); - final String template = getTemplate(isLocalTemplate, version); + final String template; + if (isLocalTemplate && Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template())) { + template = Constants.DEFAULT_TEMPLATE_NAME; + } else if (Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template()) && Constants.KOTLIN_TYPE + .equals(version.type())) { + template = Constants.DEFAULT_KOTLIN_TEMPLATE; + } else { + template = version.template(); + } writeTemplate(version.type(), versionInfo, template); } catch (IOException | MustacheNotFoundException e) { @@ -209,7 +216,7 @@ public class VersionProcessor extends AbstractProcessor { private void log(final Diagnostic.Kind kind, final String s) { if (messager != null) { messager.printMessage(kind, - '[' + VersionProcessor.class.getSimpleName() + "] " + s + System.lineSeparator()); + '[' + VersionProcessor.class.getSimpleName() + "] " + s + System.lineSeparator()); } } @@ -230,17 +237,25 @@ public class VersionProcessor extends AbstractProcessor { log(Diagnostic.Kind.WARNING, s); } + @SuppressFBWarnings({"PATH_TRAVERSAL_IN", "UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH"}) private void writeTemplate(final String type, final VersionInfo versionInfo, final String template) - throws IOException { + throws IOException { final File dir = getLocalFile(""); final MustacheFactory mf = new DefaultMustacheFactory(dir); final Mustache mustache = mf.compile(template); - final String templateName = switch (mustache.getName()) { - case Constants.DEFAULT_JAVA_TEMPLATE -> "default (Java)"; - case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)"; - default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')'; - }; + final String templateName; + switch (mustache.getName()) { + case Constants.DEFAULT_JAVA_TEMPLATE: + templateName = "default (Java)"; + break; + case Constants.DEFAULT_KOTLIN_TEMPLATE: + templateName = "default (Kotlin)"; + break; + default: + templateName = mustache.getName() + " (" + dir.getAbsolutePath() + ')'; + break; + } note("Loaded template: " + templateName); final String fileName = versionInfo.getClassName() + '.' + type; @@ -253,15 +268,15 @@ public class VersionProcessor extends AbstractProcessor { if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) { note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath()); } - try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()), - StandardCharsets.UTF_8)) { + try (final OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()), + StandardCharsets.UTF_8)) { mustache.execute(osw, versionInfo).flush(); } note("Generated source: " + fileName + " (" + ktFile.getParentFile().getAbsolutePath() + ')'); } else { final FileObject jfo = filer.createSourceFile( - versionInfo.getPackageName() + '.' + versionInfo.getClassName()); - try (Writer writer = jfo.openWriter()) { + versionInfo.getPackageName() + '.' + versionInfo.getClassName()); + try (final Writer writer = jfo.openWriter()) { mustache.execute(writer, versionInfo).flush(); } note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')'); diff --git a/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/main/resources/META-INF/services/javax.annotation.processing.Processor index 5ae1016..44488e0 100644 --- a/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1,33 +1 @@ -# -# javax.annotation.processing.Processor -# -# Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# Neither the name of this project nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - net.thauvin.erik.semver.VersionProcessor diff --git a/src/main/resources/semver-kt.mustache b/src/main/resources/semver-kt.mustache index 0a58f86..0151a5e 100644 --- a/src/main/resources/semver-kt.mustache +++ b/src/main/resources/semver-kt.mustache @@ -1,38 +1,38 @@ /* -* This file is automatically generated. -* Do not modify! -- ALL CHANGES WILL BE ERASED! -*/ - + * This file is automatically generated. + * Do not modify! -- ALL CHANGES WILL BE ERASED! + */ + package {{packageName}} import java.util.Date /** -* Provides semantic version information. -* -* @author Semantic Version Annotation Processor -*/ + * Provides semantic version information. + * + * @author Semantic Version Annotation Processor + */ object {{className}} { -@JvmField -val PROJECT = "{{project}}" -@JvmField -val BUILDDATE = Date({{epoch}}L) -@JvmField -val MAJOR = {{major}} -@JvmField -val MINOR = {{minor}} -@JvmField -val PATCH = {{patch}} -@JvmField -val PRERELEASE = "{{preRelease}}" -@JvmField -val PRERELEASE_PREFIX = "{{preReleasePrefix}}" -@JvmField -val BUILDMETA = "{{buildMeta}}" -@JvmField -val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}" -@JvmField -val SEPARATOR = "{{separator}}" -@JvmField -val VERSION = "{{version}}" + @JvmField + val PROJECT = "{{project}}" + @JvmField + val BUILDDATE = Date({{epoch}}L) + @JvmField + val MAJOR = {{major}} + @JvmField + val MINOR = {{minor}} + @JvmField + val PATCH = {{patch}} + @JvmField + val PRERELEASE = "{{preRelease}}" + @JvmField + val PRERELEASE_PREFIX = "{{preReleasePrefix}}" + @JvmField + val BUILDMETA = "{{buildMeta}}" + @JvmField + val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}" + @JvmField + val SEPARATOR = "{{separator}}" + @JvmField + val VERSION = "{{version}}" } diff --git a/src/main/resources/semver.mustache b/src/main/resources/semver.mustache index cd7c567..be65867 100644 --- a/src/main/resources/semver.mustache +++ b/src/main/resources/semver.mustache @@ -1,34 +1,34 @@ /* -* This file is automatically generated. -* Do not modify! -- ALL CHANGES WILL BE ERASED! -*/ - + * This file is automatically generated. + * Do not modify! -- ALL CHANGES WILL BE ERASED! + */ + package {{packageName}}; import java.util.Date; /** -* Provides semantic version information. -* -* @author Semantic Version Annotation Processor -*/ + * Provides semantic version information. + * + * @author Semantic Version Annotation Processor + */ public final class {{className}} { -public static final String PROJECT = "{{project}}"; -public static final Date BUILDDATE = new Date({{epoch}}L); -public static final int MAJOR = {{major}}; -public static final int MINOR = {{minor}}; -public static final int PATCH = {{patch}}; -public static final String PRERELEASE = "{{preRelease}}"; -public static final String PRERELEASE_PREFIX = "{{preReleasePrefix}}"; -public static final String BUILDMETA = "{{buildMeta}}"; -public static final String BUILDMETA_PREFIX = "{{buildMetaPrefix}}"; -public static final String SEPARATOR = "{{separator}}"; -public static final String VERSION = "{{version}}"; + public static final String PROJECT = "{{project}}"; + public static final Date BUILDDATE = new Date({{epoch}}L); + public static final int MAJOR = {{major}}; + public static final int MINOR = {{minor}}; + public static final int PATCH = {{patch}}; + public static final String PRERELEASE = "{{preRelease}}"; + public static final String PRERELEASE_PREFIX = "{{preReleasePrefix}}"; + public static final String BUILDMETA = "{{buildMeta}}"; + public static final String BUILDMETA_PREFIX = "{{buildMetaPrefix}}"; + public static final String SEPARATOR = "{{separator}}"; + public static final String VERSION = "{{version}}"; -/** -* Disables the default constructor. -*/ -private {{className}}() { -throw new UnsupportedOperationException("Illegal constructor call."); -} + /** + * Disables the default constructor. + */ + private {{className}}() { + throw new UnsupportedOperationException("Illegal constructor call."); + } } diff --git a/src/test/java/net/thauvin/erik/semver/ConstantsTest.java b/src/test/java/net/thauvin/erik/semver/ConstantsTest.java index f1feef2..b1424dd 100644 --- a/src/test/java/net/thauvin/erik/semver/ConstantsTest.java +++ b/src/test/java/net/thauvin/erik/semver/ConstantsTest.java @@ -1,7 +1,7 @@ /* * ConstantsTest.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,31 +32,30 @@ package net.thauvin.erik.semver; - -import org.junit.jupiter.api.Test; +import org.testng.Assert; +import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.testng.Assert.assertEquals; /** * The ConstantsTest class. * * @author Erik C. Thauvin - * @created.on 2019-04-14 + * @created 2019-04-14 * @since 1.0 */ public class ConstantsTest { @Test public void testDefaults() { - assertEquals(1, Constants.DEFAULT_MAJOR, "major"); - assertEquals(0, Constants.DEFAULT_MINOR, "minor"); - assertEquals(0, Constants.DEFAULT_PATCH, "patch"); - assertEquals("-", Constants.DEFAULT_PRERELEASE_PREFIX, "preRelease"); - assertEquals("+", Constants.DEFAULT_BUILDMETA_PREFIX, "buildMeta"); - assertEquals(".", Constants.DEFAULT_SEPARATOR, "separator"); + assertEquals(Constants.DEFAULT_MAJOR, 1, "major"); + assertEquals(Constants.DEFAULT_MINOR, 0, "minor"); + assertEquals(Constants.DEFAULT_PATCH, 0, "patch"); + assertEquals(Constants.DEFAULT_PRERELEASE_PREFIX, "-", "preRelease"); + assertEquals(Constants.DEFAULT_BUILDMETA_PREFIX, "+", "buildMeta"); + assertEquals(Constants.DEFAULT_SEPARATOR, ".", "separator"); } @Test @@ -67,7 +66,7 @@ public class ConstantsTest { templates.add(Constants.DEFAULT_TEMPLATE_NAME); for (final String tp : templates) { - assertTrue(tp.endsWith(".mustache"), tp); + Assert.assertTrue(tp.endsWith(".mustache"), tp); } } } diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java index 071b2e4..cb42be2 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java @@ -1,7 +1,7 @@ /* * VersionInfoTest.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,70 +32,73 @@ package net.thauvin.erik.semver; -import org.junit.jupiter.api.Test; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.testng.Assert; +import org.testng.annotations.Test; -import java.util.Date; +import java.util.Calendar; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.testng.Assert.assertEquals; /** * The VersionInfoTest class. * * @author Erik C. Thauvin - * @created.on 2016-02-03 + * @created 2016-02-03 * @since 1.0 */ +@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") public class VersionInfoTest { + private final Calendar now = Calendar.getInstance(); private VersionInfo versionInfo = new VersionInfo(); @SuppressWarnings("PMD.AvoidUsingHardCodedIP") @Test public void testGetVersion() { - assertEquals("1.0.0", versionInfo.getVersion(), "getVersion(1.0.0)"); + assertEquals(versionInfo.getVersion(), "1.0.0", "getVersion(1.0.0)"); versionInfo.setMajor(3); - assertEquals("3.0.0", versionInfo.getVersion(), "getVersion(3.0.0)"); + assertEquals(versionInfo.getVersion(), "3.0.0", "getVersion(3.0.0)"); versionInfo.setMinor(2); - assertEquals("3.2.0", versionInfo.getVersion(), "getVersion(3.2.0)"); + assertEquals(versionInfo.getVersion(), "3.2.0", "getVersion(3.2.0)"); versionInfo.setPatch(1); - assertEquals("3.2.1", versionInfo.getVersion(), "getVersion(3.2.1)"); + assertEquals(versionInfo.getVersion(), "3.2.1", "getVersion(3.2.1)"); versionInfo.setPreRelease("beta"); - assertEquals("3.2.1-beta", versionInfo.getVersion(), "getVersion(3.2.1-beta)"); + assertEquals(versionInfo.getVersion(), "3.2.1-beta", "getVersion(3.2.1-beta)"); versionInfo.setBuildMeta("001"); - assertEquals("3.2.1-beta+001", versionInfo.getVersion(), "getVersion(3.2.1-beta+001)"); + assertEquals(versionInfo.getVersion(), "3.2.1-beta+001", "getVersion(3.2.1-beta+001)"); versionInfo.setPreReleasePrefix("+"); - assertEquals("3.2.1+beta+001", versionInfo.getVersion(), "getVersion(3.2.1+beta+001)"); + assertEquals(versionInfo.getVersion(), "3.2.1+beta+001", "getVersion(3.2.1+beta+001)"); versionInfo.setPreReleasePrefix("-"); versionInfo.setPreRelease(""); - assertEquals("3.2.1+001", versionInfo.getVersion(), "getVersion(3.2.1+001)"); + assertEquals(versionInfo.getVersion(), "3.2.1+001", "getVersion(3.2.1+001)"); versionInfo.setBuildMetaPrefix("."); - assertEquals("3.2.1.001", versionInfo.getVersion(), "getVersion(3.2.1.001)"); + assertEquals(versionInfo.getVersion(), "3.2.1.001", "getVersion(3.2.1.001)"); versionInfo.setBuildMetaPrefix("+"); versionInfo.setSeparator("-"); - assertEquals("3-2-1+001", versionInfo.getVersion(), "getVersion(3-2-1+001)"); + assertEquals(versionInfo.getVersion(), "3-2-1+001", "getVersion(3-2-1+001)"); - assertEquals(versionInfo.getSemver(), versionInfo.getVersion(), - "getVersion(3-2-1+001) = getSemver(3-2-1+001) "); + assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), + "getVersion(3-2-1+001) = getSemver(3-2-1+001) "); } @Test @@ -104,59 +107,59 @@ public class VersionInfoTest { versionInfo.setMajor(1); - assertEquals(1, versionInfo.getMajor(), "getMajor(1)"); + assertEquals(versionInfo.getMajor(), 1, "getMajor(1)"); versionInfo.setMinor(2); - assertEquals(2, versionInfo.getMinor(), "getMinor(2)"); + assertEquals(versionInfo.getMinor(), 2, "getMinor(2)"); versionInfo.setPatch(3); - assertEquals(3, versionInfo.getPatch(), "getPatch(3)"); + assertEquals(versionInfo.getPatch(), 3, "getPatch(3)"); versionInfo.setPreRelease("alpha"); - assertEquals("alpha", versionInfo.getPreRelease(), "getPreRelease(alpha)"); + assertEquals(versionInfo.getPreRelease(), "alpha", "getPreRelease(alpha)"); versionInfo.setBuildMeta("001"); - assertEquals("001", versionInfo.getBuildMeta(), "getBuildMeta(001)"); + assertEquals(versionInfo.getBuildMeta(), "001", "getBuildMeta(001)"); versionInfo.setPackageName("com.example"); - assertEquals("com.example", versionInfo.getPackageName(), "getPackageName(com.example)"); + assertEquals(versionInfo.getPackageName(), "com.example", "getPackageName(com.example)"); - assertEquals("1.2.3-alpha+001", versionInfo.getVersion(), "getVersion(1.2.3-alpha+001)"); + assertEquals(versionInfo.getVersion(), "1.2.3-alpha+001", "getVersion(1.2.3-alpha+001)"); - assertEquals(versionInfo.getSemver(), versionInfo.getVersion(), "getVersion() = getSemver()"); + assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), "getVersion() = getSemver()"); versionInfo.setBuildMetaPrefix(""); - assertEquals("", versionInfo.getBuildMetaPrefix(), "getBuildMetaPrefix( )"); + assertEquals(versionInfo.getBuildMetaPrefix(), "", "getBuildMetaPrefix( )"); - assertEquals("1.2.3-alpha001", versionInfo.getVersion(), "getVersion(1.2.3+alpha001)"); + assertEquals(versionInfo.getVersion(), "1.2.3-alpha001", "getVersion(1.2.3+alpha001)"); versionInfo.setPreReleasePrefix("."); - assertEquals(".", versionInfo.getPreReleasePrefix(), "getPreReleasePrefix(.)"); + assertEquals(versionInfo.getPreReleasePrefix(), ".", "getPreReleasePrefix(.)"); - assertEquals("1.2.3.alpha001", versionInfo.getVersion(), "getVersion(1.2.3.alpha001"); + assertEquals(versionInfo.getVersion(), "1.2.3.alpha001", "getVersion(1.2.3.alpha001"); versionInfo.setSeparator("-"); - assertEquals("-", versionInfo.getSeparator(), "getSeparator(-)"); + assertEquals(versionInfo.getSeparator(), "-", "getSeparator(-)"); - assertEquals("1-2-3.alpha001", versionInfo.getVersion(), "getVersion(1-2-3.alpha001)"); + assertEquals(versionInfo.getVersion(), "1-2-3.alpha001", "getVersion(1-2-3.alpha001)"); versionInfo.setProject("My Example"); - assertEquals("My Example", versionInfo.getProject(), "getProject(My Example)"); + assertEquals(versionInfo.getProject(), "My Example", "getProject(My Example)"); versionInfo.setClassName("Example"); - assertEquals("Example", versionInfo.getClassName(), "getClassName(Example"); + assertEquals(versionInfo.getClassName(), "Example", "getClassName(Example"); - assertTrue((versionInfo.getEpoch() - new Date().getTime()) < 1000, "buildDate - now < 1s"); + Assert.assertTrue((versionInfo.getEpoch() - now.getTimeInMillis()) < 1000, "buildDate - now < 1s"); } @Test @@ -164,32 +167,32 @@ public class VersionInfoTest { final Version version = new VersionTest(); versionInfo = new VersionInfo(version); - assertEquals(version.major(), versionInfo.getMajor(), "getMajor(major)"); + assertEquals(versionInfo.getMajor(), version.major(), "getMajor(major)"); - assertEquals(version.minor(), versionInfo.getMinor(), "getMinor(minor)"); + assertEquals(versionInfo.getMinor(), version.minor(), "getMinor(minor)"); - assertEquals(version.patch(), versionInfo.getPatch(), "getPatch(patch)"); + assertEquals(versionInfo.getPatch(), version.patch(), "getPatch(patch)"); - assertEquals(version.preRelease(), versionInfo.getPreRelease(), "getPreRelease(preRelease)"); + assertEquals(versionInfo.getPreRelease(), version.preRelease(), "getPreRelease(preRelease)"); - assertEquals(version.preReleasePrefix(), versionInfo.getPreReleasePrefix(), - "getPreReleasePrefix(preReleasePrefix)"); + assertEquals(versionInfo.getPreReleasePrefix(), version.preReleasePrefix(), + "getPreReleasePrefix(preReleasePrefix)"); - assertEquals(version.buildMeta(), versionInfo.getBuildMeta(), "getBuildMeta(buildMeta)"); + assertEquals(versionInfo.getBuildMeta(), version.buildMeta(), "getBuildMeta(buildMeta)"); - assertEquals(version.buildMetaPrefix(), versionInfo.getBuildMetaPrefix(), - "getBuildMetaPrefix(buildMetaPrefix)"); + assertEquals(versionInfo.getBuildMetaPrefix(), version.buildMetaPrefix(), + "getBuildMetaPrefix(buildMetaPrefix)"); - assertEquals(version.packageName(), versionInfo.getPackageName(), "getPackageName(packageName)"); + assertEquals(versionInfo.getPackageName(), version.packageName(), "getPackageName(packageName)"); assertEquals(versionInfo.getVersion(), - version.major() + "." + version.minor() + '.' + version.patch() + '-' + version.preRelease() + '+' - + version.buildMeta(), "getVersion(version)"); + version.major() + "." + version.minor() + '.' + version.patch() + '-' + version.preRelease() + '+' + + version.buildMeta(), "getVersion(version)"); - assertEquals(versionInfo.getSemver(), versionInfo.getVersion(), "getVersion(version) = getSemver(version)"); + assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), "getVersion(version) = getSemver(version)"); - assertEquals(version.project(), versionInfo.getProject(), "getProject(project)"); + assertEquals(versionInfo.getProject(), version.project(), "getProject(project)"); - assertEquals(version.className(), versionInfo.getClassName(), "getClassName(className)"); + assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)"); } } diff --git a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java index efda7e7..328fc08 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java @@ -1,7 +1,7 @@ /* * VersionProcessorTest.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,37 +32,38 @@ package net.thauvin.erik.semver; -import org.junit.jupiter.api.Test; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.testng.annotations.Test; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Properties; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.testng.Assert.assertEquals; /** * The VersionProcessorTest class. * * @author Erik C. Thauvin - * @created.on 2019-04-02 + * @created 2019-04-02 * @since 1.2.0 */ public class VersionProcessorTest { private final VersionProcessor processor = new VersionProcessor(); private final Version version = new VersionTest(); - @SuppressWarnings("PMD.AvoidAccessibilityAlteration") + @SuppressFBWarnings("RFI_SET_ACCESSIBLE") @Test public void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { final Method method = processor.getClass().getDeclaredMethod("findValues", Version.class); method.setAccessible(true); final VersionInfo versionInfo = (VersionInfo) method.invoke(processor, version); - assertEquals("0-0-7:vodka++martini", versionInfo.getVersion(), "getVersion(0-0-7:vodka++martin)"); - assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)"); + assertEquals(versionInfo.getVersion(), "0-0-7:vodka++martini", "getVersion(0-0-7:vodka++martin)"); + assertEquals(versionInfo.getProject(), "James Bond", "getProject(James Bond)"); } - @SuppressWarnings("PMD.AvoidAccessibilityAlteration") + @SuppressFBWarnings("RFI_SET_ACCESSIBLE") @Test public void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { final Properties p = new Properties(); @@ -72,12 +73,12 @@ public class VersionProcessorTest { p.setProperty("4", " 4 "); final Method method = processor.getClass().getDeclaredMethod("parseIntProperty", Properties.class, String.class, - int.class); + int.class); method.setAccessible(true); - assertEquals(1, method.invoke(processor, p, "1", -1), "parseIntProperty(1)"); - assertEquals(-1, method.invoke(processor, p, "2", -1), "parseIntProperty(2.1)"); - assertEquals(-1, method.invoke(processor, p, "3", -1), "parseIntProperty(zero)"); - assertEquals(4, method.invoke(processor, p, "4", -1), "parseIntProperty( 4 )"); + assertEquals(method.invoke(processor, p, "1", -1), 1, "parseIntProperty(1)"); + assertEquals(method.invoke(processor, p, "2", -1), -1, "parseIntProperty(2.1)"); + assertEquals(method.invoke(processor, p, "3", -1), -1, "parseIntProperty(zero)"); + assertEquals(method.invoke(processor, p, "4", -1), 4, "parseIntProperty( 4 )"); } } diff --git a/src/test/java/net/thauvin/erik/semver/VersionTest.java b/src/test/java/net/thauvin/erik/semver/VersionTest.java index 0153b1d..d8c2db8 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionTest.java @@ -1,7 +1,7 @@ /* * VersionTest.java * - * Copyright (c) 2016-2023, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016-2020, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,10 +38,10 @@ import java.lang.annotation.Annotation; * The VersionTest class. * * @author Erik C. Thauvin - * @created.on 2019-04-02 + * @created 2019-04-02 * @since 1.2.0 */ -@SuppressWarnings({"ClassExplicitlyAnnotation", "SameReturnValue", "java:S2187", "PMD.TestClassWithoutTestCases"}) +@SuppressWarnings({"ClassExplicitlyAnnotation"}) class VersionTest implements Version { @Override public Class annotationType() { diff --git a/updatewrappers.sh b/updatewrappers.sh new file mode 100644 index 0000000..000f0b6 --- /dev/null +++ b/updatewrappers.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# +# Version: 1.0.2 +# + +# set the examples directories +declare -a dirs=( + "${PWD##*/}" + "examples/java" + "examples/kotlin") +java8=true + +### + +pwd=$PWD +cyan=$(tput setaf 6) +green=$(tput setaf 2) +red=$(tput setaf 1) +std=$(tput sgr0) + +#if [ "$java8" = true ] +#then +# export JAVA_HOME="$JAVA8_HOME" +# export PATH="$(cygpath "$JAVA_HOME")/bin:$PATH" +#fi + +#kVer=$(kobaltw --version | awk '{print substr($2, 1, length($2)-1)}') +updateWrappers() { + curVer="$(gradle --version | awk '/Gradle/ {print $2}')" + if [ -d gradle ]; then + if [ "$curVer" != "$(./gradlew --version | awk '/Gradle/ {print $2}')" ]; then + gradle -q --console=plain wrapper + echo -e " $(./gradlew --version | awk '/Gradle/') ${green}UPDATED${std}" + else + echo -e " Gradle $curVer UP-TO-DATE" + fi + fi +# if [ -d kobalt ]; then +# kw=$(cut -d "=" -f 2 kobalt/wrapper/kobalt-wrapper.properties) +# if [ "$kw" = "$kVer" ] +# then +# echo -e " Kobalt $kw UP-TO-DATE" +# else +# echo -e "kobalt.version=$kVer" > kobalt/wrapper/kobalt-wrapper.properties +# echo -e " Kobalt $kVer ${green}UPDATED${std}" +# fi +# fi +} + +echo -e "Updating wrappers..." + +for d in "${!dirs[@]}"; do + if [ "$d" -ne 0 ]; then + cd "${dirs[d]}" || exit 1 + fi + echo -e " ${cyan}${dirs[d]}${std}" + updateWrappers + cd "$pwd" +done diff --git a/version.properties b/version.properties index 3966686..448ca88 100644 --- a/version.properties +++ b/version.properties @@ -1,8 +1,8 @@ #Generated by the Semver Plugin for Gradle -#Sun May 02 21:54:48 PDT 2021 +#Fri Apr 26 18:43:34 PDT 2019 version.buildmeta= version.major=1 version.minor=2 -version.patch=1 -version.prerelease=SNAPSHOT -version.semver=1.2.1-SNAPSHOT +version.patch=0 +version.prerelease= +version.semver=1.2.0