diff --git a/.github/workflows/build_main.yml b/.github/workflows/build_main.yml index 42d2277..26d8a98 100644 --- a/.github/workflows/build_main.yml +++ b/.github/workflows/build_main.yml @@ -10,71 +10,6 @@ on: tags: - "[2-9][0-9][0-9][0-9].[0-9]+-rev[0-9]+" -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: Checkout Source - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Verify Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - # If we're building a release, we need to set the variable RELEASE_VERSION - - name: Set Environment Variables for Release Version - if: startsWith(github.ref, 'refs/tags/') - run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV - - - name: Execute Gradle Build - uses: gradle/gradle-build-action@v2 - env: - CI: true - with: - gradle-version: wrapper - arguments: buildDocs - - # release and deploy only if we're building a release - - name: Prepare Deployment - if: startsWith(github.ref, 'refs/tags/') - run: | - rm -rf ./build/tmp - cp ./docs-ext/curriculum-*.pdf ./build 2>/dev/null || : - zip -r release.zip ./build - mkdir release_dir - cp ./build/curriculum-*.pdf ./release_dir 2>/dev/null || : - mv release.zip ./release_dir/release-${{ env.RELEASE_VERSION }}.zip - - name: Create New Release - if: startsWith(github.ref, 'refs/tags/') - id: create-release - uses: ncipollo/release-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag: ${{ env.RELEASE_VERSION }} - name: Release ${{ env.RELEASE_VERSION }} - draft: false - prerelease: false - bodyFile: "CHANGELOG.md" - artifacts: "license-copyright/LICENSE.adoc,release_dir/*.pdf,release_dir/*.zip" - token: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy - if: startsWith(github.ref, 'refs/tags/') - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' - commit_message: Publish Release ${{ env.RELEASE_VERSION }} + call_workflow_build: + uses: isaqb-org/github-workflows/.github/workflows/build_main.yml@main diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml index a1d0aa0..df494bc 100644 --- a/.github/workflows/build_pr.yml +++ b/.github/workflows/build_pr.yml @@ -7,37 +7,7 @@ name: CI – Pull Requests on: pull_request: branches: [ main ] -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: checkout source - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Verify Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - name: Execute Gradle Build - uses: gradle/gradle-build-action@v2 - with: - gradle-version: wrapper - arguments: buildDocs - - name: Upload Build Artifacts - uses: actions/upload-artifact@v3 - with: - name: curriculum files (PDF and HTML) - path: | - build/*.pdf - build/*.html - retention-days: 10 +jobs: + call_workflow_build_pr: + uses: isaqb-org/github-workflows/.github/workflows/build_pr.yml@main diff --git a/.github/workflows/build_releasecandidate.yml b/.github/workflows/build_releasecandidate.yml index 005b42d..e6d6511 100644 --- a/.github/workflows/build_releasecandidate.yml +++ b/.github/workflows/build_releasecandidate.yml @@ -9,77 +9,6 @@ on: tags: - "[2-9][0-9][0-9][0-9].[0-9]+-RC[0-9]+" -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: Checkout Source - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Update index.adoc - run: | - rm docs/index.adoc - mv docs/index_rc.adoc docs/index.adoc - - name: Verify Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - # If we're building a release, we need to set the variable RELEASE_VERSION - - name: Set Environment Variables for Release Version - if: startsWith(github.ref, 'refs/tags/') - run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV - - - name: Execute Gradle Build - uses: gradle/gradle-build-action@v2 - env: - CI: true - with: - gradle-version: wrapper - arguments: buildDocs - - # do the following two things only for a release! - - name: Prepare Deployment - if: startsWith(github.ref, 'refs/tags/') - run: | - rm -rf ./build/tmp - cp ./docs-ext/curriculum-*.pdf ./build 2>/dev/null || : - zip -r release.zip ./build - mkdir release_dir - cp ./build/curriculum-*.pdf ./release_dir 2>/dev/null || : - mv release.zip ./release_dir/release-${{ env.RELEASE_VERSION }}.zip - - name: Create New Release Candidate - if: startsWith(github.ref, 'refs/tags/') - id: create-release-candidate - uses: ncipollo/release-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag: ${{ env.RELEASE_VERSION }} - name: Release Candidate ${{ env.RELEASE_VERSION }} - draft: false - prerelease: true - bodyFile: "CHANGELOG.md" - artifacts: "license-copyright/LICENSE.adoc,release_dir/*.pdf,release_dir/*.zip" - token: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy Release Candidate to GitHub Pages - if: startsWith(github.ref, 'refs/tags/') - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build - destination_dir: release-candidate - keep_files: true - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' - commit_message: Publish Release Candidate ${{ env.RELEASE_VERSION }} + call_workflow_build_pr: + uses: isaqb-org/github-workflows/.github/workflows/build_releasecandidate.yml@main diff --git a/.github/workflows/update_pr_with_comment.yml b/.github/workflows/update_pr_with_comment.yml index 172c879..539e577 100644 --- a/.github/workflows/update_pr_with_comment.yml +++ b/.github/workflows/update_pr_with_comment.yml @@ -6,66 +6,5 @@ on: workflows: [CI – Pull Requests] jobs: - comment: - if: ${{ github.event.workflow_run.conclusion == 'success' }} && ${{github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - steps: - - name: Get Artifact and Pull request info - env: - GITHUB_TOKEN: ${{ github.token }} - WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} - OWNER: ${{ github.repository_owner }} - REPO: ${{ github.event.repository.name }} - run: | - PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") - echo "Previous Job ID: $PREVIOUS_JOB_ID" - echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV" - - SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ") - echo "Previous Suite ID: $SUITE_ID" - echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV" - - ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ - --jq ".artifacts.[] | - select(.workflow_run.id==${PREVIOUS_JOB_ID}) | - select(.expired==false) | - .id") - - echo "Artifact ID: $ARTIFACT_ID" - echo "ARTIFACT_ID=$ARTIFACT_ID" >> "$GITHUB_ENV" - - PR_NUMBER=$(jq -r '.pull_requests[0].number' \ - <<< "$WORKFLOW_RUN_EVENT_OBJ") - - echo "Pull request Number: $PR_NUMBER" - echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" - - HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \ - <<< "$WORKFLOW_RUN_EVENT_OBJ") - - echo "Head SHA: $HEAD_SHA" - echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: find-comment - with: - issue-number: ${{ env.PR_NUMBER }} - comment-author: 'github-actions[bot]' - - name: Update Comment - env: - JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" - ARTIFACT_URL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}" - HEAD_SHA: "${{ env.HEAD_SHA }}" - uses: peter-evans/create-or-update-comment@v3 - with: - issue-number: ${{ env.PR_NUMBER }} - comment-id: ${{ steps.find-comment.outputs.comment-id }} - edit-mode: replace - body: |- - Build Successful! You can find a link to the downloadable artifacts below. - - | Name | Link | - | -------- | ----------------------- | - | Commit | ${{ env.HEAD_SHA }} | - | Logs | ${{ env.JOB_PATH }} | - | Download | ${{ env.ARTIFACT_URL }} | + call_workflow_build: + uses: isaqb-org/github-workflows/.github/workflows/update_pr_with_comment.yml@main diff --git a/.gitignore b/.gitignore index 68e8a0f..d39da11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .DS_Store .gradle +gradlew +gradlew.bat +gradle/ build .idea topic-backlog-expert-level.iml diff --git a/.gitmodules b/.gitmodules index f80c461..15a8ee2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "license-copyright"] path = license-copyright url = https://github.com/isaqb-org/license-copyright +[submodule "gradle-tools"] + path = gradle-tools + url = https://github.com/isaqb-org/gradle-tools diff --git a/README.adoc b/README.adoc index aa652e5..51e1122 100644 --- a/README.adoc +++ b/README.adoc @@ -33,10 +33,7 @@ Create an issue, a merge- or pull-request == How to build the documents Prerequisite: You need a Java Runtime(tm) installed. -You build the output documents with gradle: -[source,console] -$ ./gradlew buildDocs - +You build the output documents with gradle: `./gradle-tools/gradlew buildDocs` That will produce both pdf and html output in German (DE) _and_ English (EN), unless you modify the configuration. In case you want to change that, adjust the following part of `build.gradle`: diff --git a/build.gradle b/build.gradle index 8fdbc7b..a5e9648 100644 --- a/build.gradle +++ b/build.gradle @@ -1,42 +1,6 @@ -import java.text.SimpleDateFormat - -plugins { - id "java" - id "application" -} - -def group = "org.isaqb" -def releaseVersion = System.getenv("RELEASE_VERSION") -def localVersion = "LocalBuild" -project.version = releaseVersion == null ? localVersion : releaseVersion -def curriculumFileName = "topic-backlog-expert-level" -def versionDate = new SimpleDateFormat("yyyyMMdd").format(new Date()) -def languages = ["DE", "EN"] - -repositories { - mavenCentral() -} - -dependencies { - implementation("org.asciidoctor:asciidoctorj:2.5.10") - implementation("org.asciidoctor:asciidoctorj-pdf:2.3.9") -} - -application { - mainClass.set("org.isaqb.asciidoc.Main") - applicationDefaultJvmArgs = [ - """-DprojectVersion=${project.version}""", - """-DcurriculumFileName=${curriculumFileName}""", - """-DversionDate=${versionDate}""", - """-Dlanguages=${languages.join(',')}""", - """--add-opens""", """java.base/sun.nio.ch=ALL-UNNAMED""", - """--add-opens""", """java.base/java.io=ALL-UNNAMED"""] -} - -tasks.register('buildDocs') { - description = 'Grouping task for generating all languages in several formats' - group = 'documentation' - dependsOn "run" +ext { + curriculumFileName = "topic-backlog-expert-level" + languages = ["DE", "EN"] } -defaultTasks "buildDocs" +defaultTasks 'buildDocs' diff --git a/gradle-tools b/gradle-tools new file mode 160000 index 0000000..96b90ba --- /dev/null +++ b/gradle-tools @@ -0,0 +1 @@ +Subproject commit 96b90ba98b8d5eb3d709163305b479d15d146b38 diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index b8c8a87..0000000 --- a/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -org.gradle.jvmargs=-Xmx1024m --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index d64cd49..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 1af9e09..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 1aa94a4..0000000 --- a/gradlew +++ /dev/null @@ -1,249 +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##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && 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=SC2039,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=SC2039,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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. - -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 6689b85..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/settings.gradle b/settings.gradle new file mode 100644 index 0000000..c6c4e15 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include('gradle-tools') \ No newline at end of file diff --git a/src/main/java/org/isaqb/asciidoc/Main.java b/src/main/java/org/isaqb/asciidoc/Main.java deleted file mode 100644 index 456e4db..0000000 --- a/src/main/java/org/isaqb/asciidoc/Main.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.isaqb.asciidoc; - -import org.asciidoctor.Asciidoctor; -import org.asciidoctor.Attributes; -import org.asciidoctor.Options; -import org.asciidoctor.SafeMode; - -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Stream; - -import static org.asciidoctor.Asciidoctor.Factory.create; - -public class Main { - - private static final String PROJECT_VERSION = "projectVersion"; - private static final String CURRICULUM_FILE_NAME = "curriculumFileName"; - private static final String INDEX_FILE_NAME = "index"; - private static final String VERSION_DATE = "versionDate"; - private static final String LANGUAGES = "languages"; - private static final String[] FORMATS = {"html", "pdf"}; - - private static final String LANGUAGE_SEPERATOR = ","; - - private static final String SOURCE_DIR = "./docs/"; - private static final String BASE_DIR = SOURCE_DIR; - private static final String OUTPUT_DIR = "./build/"; - - private static final String ADOC = "adoc"; - private static final String HTML = "html"; - private static final String HTML5 = "html5"; - private static final String PDF = "pdf"; - private static final String ENGLISH = "EN"; - - public static void main(final String[] args) { - Objects.requireNonNull(System.getProperty(PROJECT_VERSION)); - Objects.requireNonNull(System.getProperty(CURRICULUM_FILE_NAME)); - Objects.requireNonNull(System.getProperty(VERSION_DATE)); - Objects.requireNonNull(System.getProperty(LANGUAGES)); - - final String projectVersion = System.getProperty(PROJECT_VERSION); - final String curriculumFileName = System.getProperty(CURRICULUM_FILE_NAME); - final String versionDate = System.getProperty(VERSION_DATE); - final String[] languages = System.getProperty(LANGUAGES).split(LANGUAGE_SEPERATOR); - - Stream.of(languages).forEach(language -> convertInLanguage( - language, - projectVersion, - curriculumFileName, - versionDate, - curriculumFileName - )); - - convertInFormat(HTML, - projectVersion, - INDEX_FILE_NAME, - versionDate, - ENGLISH, - curriculumFileName); - } - - private static void convertInLanguage( - final String language, - final String projectVersion, - final String curriculumFileName, - final String versionDate, - final String curriculumName) { - Stream.of(FORMATS).forEach(format -> convertInFormat( - format, projectVersion, - curriculumFileName, - versionDate, - language, - curriculumName - )); - } - - private static void convertInFormat( - final String format, - final String projectVersion, - final String curriculumFileName, - final String versionDate, - final String language, - final String curriculumName) { - try (final Asciidoctor asciidoctor = create()) { - final Attributes attributes = toAttributes( - projectVersion, - curriculumName, - versionDate, - language); - asciidoctor.convertDirectory( - List.of(new File("%s%s.%s".formatted( - SOURCE_DIR, - curriculumFileName, - ADOC))), - Options.builder() - .baseDir(new File(BASE_DIR)) - .backend(toBackend(format)) - .mkDirs(true) - .attributes(attributes) - .standalone(true) - .toDir(new File(OUTPUT_DIR)) - .safe(SafeMode.UNSAFE) - .build()); - - if (!INDEX_FILE_NAME.equals(curriculumFileName)) { - // rename only if we're not creating the index file. - renameResultAccordingToLanguage(curriculumFileName, format, language); - } - } - } - - private static Attributes toAttributes( - final String projectVersion, - final String curriculumFileName, - final String versionDate, - final String language) { - final String fileVersion = "%s-%s".formatted(projectVersion, language); - final String documentVersion = "%s-%s".formatted(fileVersion, versionDate); - - final Map attributes = new HashMap<>() {{ - put("icons", "font"); - put("version-label", ""); - put("revnumber", fileVersion); - put("revdate", versionDate); - put("document-version", documentVersion); - put("currentDate", versionDate); - put("language", language); - put("curriculumFileName", curriculumFileName); - put("pdf-themesdir", "../pdf-theme/themes"); - put("pdf-fontsdir", "../pdf-theme/fonts"); - put("pdf-theme", "isaqb"); - put("stylesheet", "../html-theme/adoc-github.css"); - put("stylesheet-dir", "../html-theme"); - put("data-uri", true); - put("allow-uri-read", true); - }}; - - return Attributes.builder().attributes(attributes).build(); - } - - private static String toBackend(final String format) { - return switch (format) { - case HTML -> HTML5; - case PDF -> PDF; - default -> throw new IllegalArgumentException("Unknown target format %s".formatted(format)); - }; - } - - private static void renameResultAccordingToLanguage( - final String fileName, - final String format, - final String language) { - final File original = new File("%s%s.%s".formatted(OUTPUT_DIR, fileName, format)); - final File renamed = new File("%s%s-%s.%s".formatted(OUTPUT_DIR, fileName, language.toLowerCase(), format)); - if (!original.exists()) { - System.err.printf("Failed to rename result file %s as it does not exist", original.getAbsolutePath()); - } else if (!original.renameTo(renamed)) { - System.err.printf("Failed to rename result file %s to %s%n", original.getName(), renamed.getName()); - } - original.deleteOnExit(); - } -}