diff --git a/.circleci/config.yml b/.circleci/config.yml index 64d62be..65723f0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,54 +1,41 @@ -version: 2 +inversion: 2 defaults: &defaults working_directory: ~/repo environment: JVM_OPTS: -Xmx3200m TERM: dumb - CI: true + CI_NAME: "CircleCI" -defaults_gradle: &defaults_gradle +defaults_gradle: &defaults_bld steps: - checkout - - restore_cache: - keys: - - gradle-dependencies-{{ checksum "build.gradle.kts" }} - # fallback to using the latest cache if no exact match is found - - gradle-dependencies- - run: - name: Gradle Dependencies - command: ./gradlew dependencies - - save_cache: - paths: ~/.m2 - key: gradle-dependencies-{{ checksum "build.gradle.kts" }} + name: Download the dependencies + command: ./bld download - run: - name: Run All Checks - command: ./gradlew check - - store_artifacts: - path: build/reports/ - destination: reports - - store_test_results: - path: build/reports/ + name: Run tests with bld + command: ./bld compile test jobs: - build_gradle_jdk17: + bld_jdk20: + <<: *defaults + + docker: + - image: cimg/openjdk:20.0 + + <<: *defaults_bld + + bld_jdk17: <<: *defaults docker: - image: cimg/openjdk:17.0 - <<: *defaults_gradle - - build_gradle_jdk11: - <<: *defaults - - docker: - - image: cimg/openjdk:11.0 - - <<: *defaults_gradle + <<: *defaults_bld workflows: version: 2 - gradle: + bld: jobs: - - build_gradle_jdk20 - - build_gradle_jdk17 + - bld_jdk17 + - bld_jdk20 diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml new file mode 100644 index 0000000..79093d1 --- /dev/null +++ b/.github/workflows/bld.yml @@ -0,0 +1,53 @@ +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/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index 13384a8..0000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: gradle-ci - -on: [ push, pull_request, workflow_dispatch ] - -jobs: - build: - runs-on: ubuntu-latest - - env: - GRADLE_OPTS: "-Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m" - SONAR_JDK: "17" - - strategy: - matrix: - java-version: [ 17, 20 ] - - steps: - - 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 gradlew - run: chmod +x gradlew - - - name: Cache SonarCloud packages - if: matrix.java-version == env.SONAR_JDK - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Test with Gradle - uses: gradle/gradle-build-action@v2 - with: - arguments: build check --stacktrace - - - name: SonarCloud - if: success() && matrix.java-version == env.SONAR_JDK - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./gradlew sonar --info diff --git a/.gitignore b/.gitignore index 097f727..091e664 100644 --- a/.gitignore +++ b/.gitignore @@ -1,84 +1,57 @@ - -!.vscode/extensions.json -!.vscode/launch.json -!.vscode/settings.json -!.vscode/tasks.json -*.class -*.code-workspace -*.ctxt -*.iws -*.log -*.nar -*.rar -*.sublime-* -*.tar.gz -*.zip -.DS_Store -.classpath .gradle -.history -.kobalt -.mtj.tmp/ -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar -.nb-gradle -.project -.scannerwork -.settings -.vscode/* -/**/.idea/$CACHE_FILE$ -/**/.idea/$PRODUCT_WORKSPACE_FILE$ -/**/.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/sonarlint* -/**/.idea_modules/ -Thumbs.db -__pycache__ +.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 atlassian-ide-plugin.xml -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/ -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 -venv + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Editor-based Rest Client +.idea/httpRequests + +local.properties \ No newline at end of file diff --git a/.idea/app.iml b/.idea/app.iml new file mode 100644 index 0000000..787b59b --- /dev/null +++ b/.idea/app.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/bld.iml b/.idea/bld.iml new file mode 100644 index 0000000..e63e11e --- /dev/null +++ b/.idea/bld.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml deleted file mode 100644 index 17101f8..0000000 --- a/.idea/checkstyle-idea.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/checkstyleidea-libs/readme.txt b/.idea/checkstyleidea-libs/readme.txt deleted file mode 100644 index 71cc7ff..0000000 --- a/.idea/checkstyleidea-libs/readme.txt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index d91f848..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index a857b2a..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/BSD_3_Clause.xml b/.idea/copyright/BSD_3_Clause.xml new file mode 100644 index 0000000..956f692 --- /dev/null +++ b/.idea/copyright/BSD_3_Clause.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/Erik_s_Copyright_Notice.xml b/.idea/copyright/Erik_s_Copyright_Notice.xml deleted file mode 100644 index ef51a2d..0000000 --- a/.idea/copyright/Erik_s_Copyright_Notice.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 1419e40..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7e0a3c7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index dd4c951..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index b23fa44..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 5806fb3..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/libraries-with-intellij-classes.xml b/.idea/libraries-with-intellij-classes.xml deleted file mode 100644 index 9fa3156..0000000 --- a/.idea/libraries-with-intellij-classes.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml new file mode 100644 index 0000000..abca604 --- /dev/null +++ b/.idea/libraries/bld.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/compile.xml b/.idea/libraries/compile.xml new file mode 100644 index 0000000..9bd86aa --- /dev/null +++ b/.idea/libraries/compile.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/runtime.xml b/.idea/libraries/runtime.xml new file mode 100644 index 0000000..2ae5c4b --- /dev/null +++ b/.idea/libraries/runtime.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/test.xml b/.idea/libraries/test.xml new file mode 100644 index 0000000..b80486a --- /dev/null +++ b/.idea/libraries/test.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 90755e7..ea78ec7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,118 +1,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..55adcb9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/examples-kotlin_main.iml b/.idea/modules/examples-kotlin_main.iml deleted file mode 100644 index 4aeac9a..0000000 --- a/.idea/modules/examples-kotlin_main.iml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/examples-kotlin_test.iml b/.idea/modules/examples-kotlin_test.iml deleted file mode 100644 index 4b23562..0000000 --- a/.idea/modules/examples-kotlin_test.iml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Run Tests.xml b/.idea/runConfigurations/Run Tests.xml new file mode 100644 index 0000000..4f6af10 --- /dev/null +++ b/.idea/runConfigurations/Run Tests.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/.idea/scopes/Copyright.xml b/.idea/scopes/Copyright.xml deleted file mode 100644 index 7fb840b..0000000 --- a/.idea/scopes/Copyright.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7a56afd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "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 new file mode 100644 index 0000000..c83239c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "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/README.md b/README.md index 84e3efc..d993dd6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,16 @@ # 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) [![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) +[![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) -[![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) +[![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). diff --git a/appveyor.yml b/appveyor.yml index 0d75649..3eebf3d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,23 +8,20 @@ build: verbosity: detailed build_script: - - gradlew.bat assemble --info --no-daemon + - bld.bat download compile test_script: - - gradlew.bat check --info --no-daemon + - bld.bat test 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\jdk19 + - JAVA_HOME: C:\Program Files\Java\jdk20 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 new file mode 100644 index 0000000..5ae1016 --- /dev/null +++ b/bin/main/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,33 @@ +# +# 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 new file mode 100644 index 0000000..b299307 Binary files /dev/null and b/bin/main/net/thauvin/erik/semver/Constants.class differ diff --git a/bin/main/net/thauvin/erik/semver/Version.class b/bin/main/net/thauvin/erik/semver/Version.class new file mode 100644 index 0000000..239b8a2 Binary files /dev/null and b/bin/main/net/thauvin/erik/semver/Version.class differ diff --git a/bin/main/net/thauvin/erik/semver/VersionInfo.class b/bin/main/net/thauvin/erik/semver/VersionInfo.class new file mode 100644 index 0000000..8351bcf Binary files /dev/null and b/bin/main/net/thauvin/erik/semver/VersionInfo.class differ diff --git a/bin/main/net/thauvin/erik/semver/VersionProcessor.class b/bin/main/net/thauvin/erik/semver/VersionProcessor.class new file mode 100644 index 0000000..38b5676 Binary files /dev/null and b/bin/main/net/thauvin/erik/semver/VersionProcessor.class differ diff --git a/bin/main/net/thauvin/erik/semver/package.html b/bin/main/net/thauvin/erik/semver/package.html new file mode 100644 index 0000000..1b1b126 --- /dev/null +++ b/bin/main/net/thauvin/erik/semver/package.html @@ -0,0 +1,12 @@ + + + + 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 new file mode 100644 index 0000000..0a58f86 --- /dev/null +++ b/bin/main/semver-kt.mustache @@ -0,0 +1,38 @@ +/* +* 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 new file mode 100644 index 0000000..cd7c567 --- /dev/null +++ b/bin/main/semver.mustache @@ -0,0 +1,34 @@ +/* +* 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 new file mode 100644 index 0000000..c8c9fde Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/ConstantsTest.class differ diff --git a/bin/test/net/thauvin/erik/semver/VersionInfoTest.class b/bin/test/net/thauvin/erik/semver/VersionInfoTest.class new file mode 100644 index 0000000..8c5f8b4 Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/VersionInfoTest.class differ diff --git a/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class b/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class new file mode 100644 index 0000000..5166fb7 Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class differ diff --git a/bin/test/net/thauvin/erik/semver/VersionTest.class b/bin/test/net/thauvin/erik/semver/VersionTest.class new file mode 100644 index 0000000..0047ff2 Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/VersionTest.class differ diff --git a/bld b/bld new file mode 100755 index 0000000..824b742 --- /dev/null +++ b/bld @@ -0,0 +1,2 @@ +#!/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 new file mode 100644 index 0000000..ab43bcd --- /dev/null +++ b/bld.bat @@ -0,0 +1,4 @@ +@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 deleted file mode 100644 index 478fc4b..0000000 --- a/build.gradle +++ /dev/null @@ -1,221 +0,0 @@ -// import com.github.spotbugs.snom.SpotBugsTask -import org.apache.tools.ant.taskdefs.condition.Os - -plugins { - id 'java' - id 'jacoco' - id 'maven-publish' - id 'pmd' - id 'signing' - id 'com.github.ben-manes.versions' version '0.47.0' - id 'net.thauvin.erik.gradle.semver' version '1.0.4' - // id 'com.github.spotbugs' version '5.0.14' - id 'org.sonarqube' version '4.2.1.3168' -} - -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' - -def isNonStable = { String version -> - def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) } - def regex = /^[0-9,.v-]+(-r)?$/ - return !stableKeyword && !(version ==~ regex) -} - -ext.versions = [ - pmd: '6.54.0', - // spotbugs: '4.7.3' -] - -repositories { - mavenLocal() - mavenCentral() - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } -} - -dependencies { - implementation 'com.github.spullara.mustache.java:compiler:0.9.10' - - // spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0' - // spotbugsPlugins 'com.mebigfatguy.sb-contrib:sb-contrib:7.6.0' - - // compileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs" - // testCompileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs" - - testImplementation 'org.testng:testng:7.8.0' -} - - -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - withSourcesJar() - withJavadocJar() -} - -tasks.named("dependencyUpdates").configure { - rejectVersionIf { - isNonStable(it.candidate.version) - } -} - -pmd { - toolVersion = versions.pmd - ignoreFailures = true - ruleSets = [] - ruleSetFiles = files("${projectDir}/config/pmd.xml") - consoleOutput = true -} - -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - groupId = project.group - artifactId = rootProject.name - - pom { - name = mavenName - description = mavenDescription - url = mavenUrl - licenses { - license { - name = mavenLicense - url = mavenLicenseUrl - } - } - developers { - developer { - id = 'ethauvin' - name = 'Erik C. Thauvin' - email = 'erik@thauvin.net' - url = 'https://erik.thauvin.net/' - } - } - scm { - connection = 'scm:git:' + mavenScmCon - developerConnection = 'scm:git:' + mavenScmDevCon - url = mavenUrl - } - } - } - } - repositories { - maven { - name = 'ossrh' - project.afterEvaluate { - url = project.version.contains('SNAPSHOT') - ? 'https://oss.sonatype.org/content/repositories/snapshots/' - : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' - } - credentials(PasswordCredentials) - } - } -} - -signing { - useGpgCmd() - sign publishing.publications.mavenJava -} - -javadoc { - doFirst { - title = "$mavenDescription $project.version API" - } - options.with { - source = '17' - tags = ['created'] - author = true - //addBooleanOption('html4', true) - links('https://docs.oracle.com/en/java/javase/17/docs/api/') - //addStringOption('Xdoclint:none', '-quiet') - } -} - -test { - testLogging { - exceptionFormat = 'full' - events('passed', 'skipped', 'failed') - } - - useTestNG() - - finalizedBy jacocoTestReport -} - -// spotbugs { -// toolVersion.set("${versions.spotbugs}") -// excludeFilter.set(file("$projectDir/config/spotbugs/excludeFilter.xml")) -// } - -// tasks.withType(SpotBugsTask).configureEach { -// reports { -// xml.required = false -// html.required = true -// } -// } - -tasks.register('release') { - group = 'Publishing' - description = 'Releases new version to local maven repository.' - dependsOn(wrapper, clean, publishToMavenLocal) - doFirst { - println "Version: $version" - } -} - -tasks.register('pandoc', 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 { - dependsOn test - reports { - xml.required = true - html.required = true - } -} - - -sonarqube { - properties { - property('sonar.organization', 'ethauvin-github') - property('sonar.projectKey', 'ethauvin_semver') - property('sonar.host.url', 'https://sonarcloud.io') - property('sonar.sourceEncoding', 'UTF-8') - } -} - -tasks.sonar { - dependsOn 'jacocoTestReport' -} diff --git a/config/pmd.xml b/config/pmd.xml index e23c3fa..add20da 100644 --- a/config/pmd.xml +++ b/config/pmd.xml @@ -25,7 +25,6 @@ - diff --git a/docs/README.html b/docs/README.html index 2eab8e6..8758e21 100644 --- a/docs/README.html +++ b/docs/README.html @@ -5,83 +5,135 @@ Semantic Version Annotation Processor - - - + + -

Semantic Version Annotation Processor

-

License (3-Clause BSD) release Maven Central
-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.

+

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.

Table of Contents

  • Examples
  • @@ -95,7 +147,8 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
  • Gradle
  • Kotlin
      @@ -107,34 +160,50 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
      • Using annotation elements:
      - +
      import net.thauvin.erik.semver.Version;
      +
      +@Version(major = 1, minor = 0, patch = 0, preRelease = "beta")
      +public class A {
      +// ...
      - - -

      View Examples

      +
      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

      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:

      @@ -152,7 +221,8 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni - + @@ -203,17 +273,19 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
      BUILDDATE The build date.java.util.Datejava.util.Date
      VERSION

      Custom Template

      A very simple custom template might look something like:

      - -

      The mustache variables automatically filled in by the processor are:

      +
      /* 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:

      @@ -284,13 +356,17 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni - +
      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:

      @@ -335,7 +411,8 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni - + @@ -384,7 +461,8 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni - + @@ -395,89 +473,150 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
      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:

      - - +

      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=
      +# ...
      -

      ⚠️ 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:

      - -

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

      - +

      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

      Gradle

      Class Generation

      -

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

      -
      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:

      +
      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.

      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.annotationProcessorGeneratedSourcesDirectory = 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.generatedSourceOutputDirectory.set(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:

      - -

      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:

      +
      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.

      Kotlin & Gradle

      -

      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.

      +

      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.

      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/gradle.properties b/gradle.properties deleted file mode 100644 index e69de29..0000000 diff --git a/gradlew b/gradlew deleted file mode 100755 index fcb6fca..0000000 --- a/gradlew +++ /dev/null @@ -1,248 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original 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 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/. -# -############################################################################## - -# 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 -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -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 ;; -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 - 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. - -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" ) - 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 - done -fi - - -# 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' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 93e3f59..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,92 +0,0 @@ -@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=. -@rem This is normally unused -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% equ 0 goto execute - -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 execute - -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 - -: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 %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 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% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar new file mode 100644 index 0000000..e96bdc7 Binary files /dev/null and b/lib/bld/bld-wrapper.jar differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties new file mode 100644 index 0000000..5daccca3 --- /dev/null +++ b/lib/bld/bld-wrapper.properties @@ -0,0 +1,9 @@ +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 new file mode 100755 index 0000000..2ac666d --- /dev/null +++ b/pandoc.sh @@ -0,0 +1,9 @@ +#!/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 new file mode 100644 index 0000000..8bb99f9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + + 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 deleted file mode 100755 index 76c698d..0000000 --- a/preflightcheck.sh +++ /dev/null @@ -1,201 +0,0 @@ -#!/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="sonar" -# 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.5 -# - -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")" == "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 - if [ -f "$f" ]; then - checkCopyright "$f" - fi - 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 deleted file mode 100644 index 0b39698..0000000 --- a/settings.gradle +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 new file mode 100644 index 0000000..3c63dd8 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,7 @@ +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 new file mode 100644 index 0000000..8c5de48 --- /dev/null +++ b/src/bld/java/net/thauvin/erik/semver/SemverBuild.java @@ -0,0 +1,147 @@ +/* + * 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.testng", "testng", version(7, 8, 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()); + } + + @BuildCommand(summary = "Run tests with TestNG") + public void test() throws Exception { + new TestNgOperation() + .fromProject(this) + .packages("net.thauvin.erik.semver") + .execute(); + } + + @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 27c0733..8dbc3d5 100644 --- a/src/main/java/net/thauvin/erik/semver/Constants.java +++ b/src/main/java/net/thauvin/erik/semver/Constants.java @@ -36,9 +36,10 @@ package net.thauvin.erik.semver; * The Constants class holds the constant variables used throughout this project. * * @author Erik C. Thauvin - * @created 2016-01-13 + * @created.on 2016-01-13 * @since 1.0 */ +@SuppressWarnings("PMD.DataClass") 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 98b18db..9e73b07 100644 --- a/src/main/java/net/thauvin/erik/semver/Version.java +++ b/src/main/java/net/thauvin/erik/semver/Version.java @@ -41,7 +41,7 @@ import java.lang.annotation.Target; * The Version class implements the annotation interface. * * @author Erik C. Thauvin - * @created 2016-01-13 + * @created.on 2016-01-13 * @since 1.0 */ @SuppressWarnings("SameReturnValue") diff --git a/src/main/java/net/thauvin/erik/semver/VersionInfo.java b/src/main/java/net/thauvin/erik/semver/VersionInfo.java index 297dc08..3fb3437 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionInfo.java +++ b/src/main/java/net/thauvin/erik/semver/VersionInfo.java @@ -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 2016-01-16 + * @created.on 2016-01-16 * @since 1.0 */ @SuppressWarnings("PMD.DataClass") @@ -101,15 +101,6 @@ 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. * @@ -119,15 +110,6 @@ 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. * @@ -137,15 +119,6 @@ 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. * @@ -164,15 +137,6 @@ 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. * @@ -182,15 +146,6 @@ 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. * @@ -200,15 +155,6 @@ 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. * @@ -218,15 +164,6 @@ 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. * @@ -236,15 +173,6 @@ 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. * @@ -254,15 +182,6 @@ 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. * @@ -272,15 +191,6 @@ 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()}. * @@ -299,15 +209,6 @@ 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. * @@ -334,7 +235,106 @@ public class VersionInfo { + minor + separator + patch - + (preRelease.length() > 0 ? preReleasePrefix + preRelease : "") - + (buildMeta.length() > 0 ? buildMetaPrefix + buildMeta : ""); + + (!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; } } diff --git a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java index 878f478..1c9f150 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java +++ b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java @@ -56,7 +56,7 @@ import java.util.Set; * The VersionProcessor class implements a semantic version annotation processor. * * @author Erik C. Thauvin - * @created 2016-01-13 + * @created.on 2016-01-13 * @since 1.0 */ @SuppressWarnings({"PMD.GuardLogStatement", "PMD.BeanMembersShouldSerialize"}) @@ -66,10 +66,24 @@ public class VersionProcessor extends AbstractProcessor { 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); } @@ -77,7 +91,7 @@ public class VersionProcessor extends AbstractProcessor { private VersionInfo findValues(final Version version) throws IOException { final VersionInfo versionInfo = new VersionInfo(version); - if (version.properties().length() > 0) { + if (!version.properties().isEmpty()) { final File propsFile = getLocalFile(version.properties()); if (propsFile.isFile() && propsFile.canRead()) { note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')'); @@ -180,15 +194,7 @@ public class VersionProcessor extends AbstractProcessor { versionInfo.setPackageName(packageElement.getQualifiedName().toString()); } note("Found version: " + versionInfo.getVersion()); - 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(); - } + final String template = getTemplate(isLocalTemplate, version); writeTemplate(version.type(), versionInfo, template); } catch (IOException | MustacheNotFoundException e) { diff --git a/src/main/java/net/thauvin/erik/semver/package.html b/src/main/java/net/thauvin/erik/semver/package.html index e37a084..1b1b126 100644 --- a/src/main/java/net/thauvin/erik/semver/package.html +++ b/src/main/java/net/thauvin/erik/semver/package.html @@ -1,35 +1,3 @@ - - 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 44488e0..5ae1016 100644 --- a/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1 +1,33 @@ +# +# 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 0151a5e..0a58f86 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 be65867..cd7c567 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 0847819..ace903e 100644 --- a/src/test/java/net/thauvin/erik/semver/ConstantsTest.java +++ b/src/test/java/net/thauvin/erik/semver/ConstantsTest.java @@ -38,13 +38,13 @@ import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertEquals; // NOPMD /** * The ConstantsTest class. * * @author Erik C. Thauvin - * @created 2019-04-14 + * @created.on 2019-04-14 * @since 1.0 */ public class ConstantsTest { diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java index 47b0436..fe08c3f 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java @@ -37,13 +37,13 @@ import org.testng.annotations.Test; import java.util.Date; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertEquals; // NOPMD /** * The VersionInfoTest class. * * @author Erik C. Thauvin - * @created 2016-02-03 + * @created.on 2016-02-03 * @since 1.0 */ public class VersionInfoTest { diff --git a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java index 5fe3e12..674bb31 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java @@ -38,13 +38,13 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Properties; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertEquals; // NOPMD /** * The VersionProcessorTest class. * * @author Erik C. Thauvin - * @created 2019-04-02 + * @created.on 2019-04-02 * @since 1.2.0 */ public class VersionProcessorTest { diff --git a/src/test/java/net/thauvin/erik/semver/VersionTest.java b/src/test/java/net/thauvin/erik/semver/VersionTest.java index 8c2a76e..0153b1d 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionTest.java @@ -38,7 +38,7 @@ import java.lang.annotation.Annotation; * The VersionTest class. * * @author Erik C. Thauvin - * @created 2019-04-02 + * @created.on 2019-04-02 * @since 1.2.0 */ @SuppressWarnings({"ClassExplicitlyAnnotation", "SameReturnValue", "java:S2187", "PMD.TestClassWithoutTestCases"}) diff --git a/updatewrappers.sh b/updatewrappers.sh deleted file mode 100755 index b841e09..0000000 --- a/updatewrappers.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/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