diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5eb6cd6..a06db3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Check run: ./gradlew check - name: Upload analysis to sonarcloud diff --git a/CHANGELOG.md b/CHANGELOG.md index 418e0d3..3ceece7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +## Version 1.2.0 - 2024-08-07 + +* [#100](https://github.com/xenit-eu/alfresco-gradle-sdk/pull/100) Support for Gradle 8 + +> [!warning] +> This release drops support for Gradle versions <7.1 and Java <11 + ## Version 1.1.0 - 2021-08-20 ### New features diff --git a/README.md b/README.md index 621f21d..028bfec 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ > [products](https://xenit.eu/alfresco-products), please visit our [website](https://xenit.eu). Gradle plugins and tasks to support Alfresco development. -Gradle 5.1 and above are supported. +Gradle 7.1 and above are supported. ## Usage diff --git a/build.gradle b/build.gradle index 77b01ae..bf76508 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id "java-gradle-plugin" id "com.gradle.plugin-publish" version "0.21.0" - id 'org.ajoberstar.reckon' version "0.13.2" id 'org.sonarqube' version '4.3.1.3277' id 'be.vbgn.ci-detect' version '0.5.0' id 'be.vbgn.dev-conventions' version '0.5.3' @@ -12,7 +11,11 @@ plugins { group 'eu.xenit.gradle' -sourceCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(11) + } +} repositories { mavenCentral() @@ -29,14 +32,14 @@ sourceSets { } configurations { - integrationTestCompile.extendsFrom testCompile - integrationTestRuntime.extendsFrom testRuntime + integrationTestCompileClasspath.extendsFrom testCompileClasspath + integrationTestRuntimeClasspath.extendsFrom testRuntimeClasspath } dependencies { - compile gradleApi() - testCompile group: 'junit', name: 'junit', version: '4.13.2' - testCompile group: 'commons-io', name: 'commons-io', version: '2.13.0' + implementation gradleApi() + testImplementation group: 'junit', name: 'junit', version: '4.13.2' + testImplementation group: 'commons-io', name: 'commons-io', version: '2.13.0' } import org.gradle.util.GradleVersion @@ -103,9 +106,3 @@ pluginBundle { } } -reckon { - scopeFromProp() - snapshotFromProp() -} - -reckonTagCreate.dependsOn(check) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf..943f0cb 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dbe85ee..f398c33 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 83f2acf..65dcd68 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# 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. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# 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 -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +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 -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +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" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -105,84 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +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 -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# 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" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +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 - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + 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 - i=$((i+1)) + # 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 - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") +# Collect all arguments for the java command; +# * $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 -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# 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. +# -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +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 index 24467a1..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,14 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +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" @@ -37,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%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%"=="0" goto mainEnd +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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +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 diff --git a/settings.gradle b/settings.gradle index 3ed2837..f4ee638 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,12 @@ +plugins { + id 'org.ajoberstar.reckon.settings' version "0.18.3" +} rootProject.name = 'alfresco-sdk' -enableFeaturePreview('STABLE_PUBLISHING') \ No newline at end of file +reckon { + defaultInferredScope = 'patch' + snapshots() + scopeCalc = calcScopeFromProp() + stageCalc = calcStageFromProp() +} + diff --git a/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/AbstractIntegrationTest.java b/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/AbstractIntegrationTest.java index 03b8c7e..975b07f 100644 --- a/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/AbstractIntegrationTest.java +++ b/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/AbstractIntegrationTest.java @@ -35,21 +35,10 @@ public static Collection testData() { }); } return Arrays.asList(new Object[][]{ - {"7.0"}, - {"6.7.1"}, - {"6.6.1"}, - {"6.5.1"}, - {"6.4.1"}, - {"6.3"}, - {"6.2.2"}, - {"6.1.1"}, - {"6.0.1"}, - {"5.6.4"}, - {"5.5.1"}, - {"5.4.1"}, - {"5.3.1"}, - {"5.2.1"}, - {"5.1.1"} + {"8.9"}, + {"8.0"}, + {"7.6.4"}, + {"7.1"} }); } diff --git a/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/Examples.java b/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/Examples.java index e96df57..204a5b4 100644 --- a/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/Examples.java +++ b/src/integrationTest/java/eu/xenit/gradle/alfrescosdk/Examples.java @@ -11,6 +11,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Map; import java.util.Properties; import java.util.function.Predicate; import org.gradle.util.GUtil; @@ -58,6 +59,9 @@ public void testLegacyDeProject() throws IOException { // Gradle 5.1 has problems with memory usage with the bnd plugin Assume.assumeTrue("Gradle version >= 5.2", GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("5.2")) >= 0); + // Gradle 8 is not supported by the DE plugin + Assume.assumeTrue("Gradle version < 8", + GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("8.0")) < 0); testProjectFolder(EXAMPLES.resolve("legacy-de-project")); Path buildFolder = projectFolder.toPath().resolve("build"); @@ -87,6 +91,9 @@ public void testSimpleDeProject() throws IOException { // Gradle 5.1 has problems with memory usage with the bnd plugin Assume.assumeTrue("Gradle version >= 5.2", GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("5.2")) >= 0); + // Gradle 8 is not supported by the DE plugin + Assume.assumeTrue("Gradle version < 8", + GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("8.0")) < 0); testProjectFolder(EXAMPLES.resolve("simple-de-project")); Path buildFolder = projectFolder.toPath().resolve("build"); diff --git a/src/integrationTest/resources/examples/multi-source-alfresco-project/build.gradle b/src/integrationTest/resources/examples/multi-source-alfresco-project/build.gradle index d650c9d..9cb0701 100644 --- a/src/integrationTest/resources/examples/multi-source-alfresco-project/build.gradle +++ b/src/integrationTest/resources/examples/multi-source-alfresco-project/build.gradle @@ -5,6 +5,7 @@ plugins { version = "0.0.1" +def pr = project sourceSets { main { amp { @@ -17,8 +18,10 @@ sourceSets { share { amp { module { - it.setProperty("module.id", "${project.name}-share") - it.setProperty("module.version", project.version) + // WARNING: when using the closure, using variables from an outside, implicit scope is not possible. + // they must be explicitly assigned to a variable before using them + it.setProperty("module.id", pr.name+"-share") + it.setProperty("module.version", pr.version) } } } diff --git a/src/integrationTest/resources/tasks/amp/empty-amp-task/build.gradle b/src/integrationTest/resources/tasks/amp/empty-amp-task/build.gradle index cd03bcd..05bf8b3 100644 --- a/src/integrationTest/resources/tasks/amp/empty-amp-task/build.gradle +++ b/src/integrationTest/resources/tasks/amp/empty-amp-task/build.gradle @@ -6,6 +6,6 @@ group = 'eu.xenit.gradle.alfrescosdk.test' task amp(type: eu.xenit.gradle.alfrescosdk.tasks.Amp){ moduleProperties = file('module.properties'); - destinationDir = file("$buildDir/amp") - baseName = 'amp' + destinationDirectory = file("$buildDir/amp") + archiveBaseName = 'amp' } \ No newline at end of file diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/AlfrescoPlugin.java b/src/main/java/eu/xenit/gradle/alfrescosdk/AlfrescoPlugin.java index 3f3bb7f..a843b62 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/AlfrescoPlugin.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/AlfrescoPlugin.java @@ -8,7 +8,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.plugins.JavaBasePlugin; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; @@ -29,9 +29,9 @@ public void apply(Project project) { configureRepository(); project.getPlugins().withType(JavaBasePlugin.class, javaBasePlugin -> { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); + SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); - /** + /* * Adds the sourceSets to the default main SourceSet. */ sourceSets.all(sourceSet -> { @@ -51,13 +51,12 @@ public void apply(Project project) { // Configure other amp sourcesets with an alfrescoProvided configuration project.getPlugins().withType(AmpBasePlugin.class, ampBasePlugin -> { - ampBasePlugin.allAmpSourceSets(ampSourceSet -> { - if(ampSourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME)) { + ampBasePlugin.allAmpSourceSetConfigurations(ampSourceSetConfig -> { + if(ampSourceSetConfig.getSourceSet().getName().equals(SourceSet.MAIN_SOURCE_SET_NAME)) { // Main sourceset is already configured above, do not configure it again return; } - SourceSet sourceSet = sourceSets.getByName(ampSourceSet.getName()); - registerAlfrescoProvided(sourceSet); + registerAlfrescoProvided(ampSourceSetConfig.getSourceSet().getSourceSet()); }); }); }); @@ -67,9 +66,9 @@ public void apply(Project project) { private NamedDomainObjectProvider registerAlfrescoProvided(SourceSet sourceSet) { String alfrescoProvidedName = sourceSet.getTaskName(null, ALFRESCO_PROVIDED); NamedDomainObjectProvider alfrescoProvided = project.getConfigurations().register(alfrescoProvidedName); - project.getConfigurations().named(sourceSet.getCompileOnlyConfigurationName()) - .configure(compileOnly -> { - compileOnly.extendsFrom(alfrescoProvided.get()); + project.getConfigurations().named(sourceSet.getCompileClasspathConfigurationName()) + .configure(compileClasspath -> { + compileClasspath.extendsFrom(alfrescoProvided.get()); }); return alfrescoProvided; } diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpBasePlugin.java b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpBasePlugin.java index fa3fde7..0f9bd00 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpBasePlugin.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpBasePlugin.java @@ -1,16 +1,12 @@ package eu.xenit.gradle.alfrescosdk; -import eu.xenit.gradle.alfrescosdk.internal.ConfigurationDispatcher; import eu.xenit.gradle.alfrescosdk.internal.GradleVersionCheck; import eu.xenit.gradle.alfrescosdk.internal.tasks.DefaultAmpSourceSet; +import eu.xenit.gradle.alfrescosdk.internal.tasks.DefaultAmpSourceSetConfiguration; import eu.xenit.gradle.alfrescosdk.tasks.Amp; -import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSet; import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import java.io.File; import java.util.Map; -import java.util.Properties; -import java.util.stream.Collectors; -import javax.inject.Inject; import org.gradle.api.Action; import org.gradle.api.NamedDomainObjectProvider; import org.gradle.api.Plugin; @@ -20,7 +16,7 @@ import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.logging.Logging; import org.gradle.api.plugins.JavaBasePlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; @@ -34,53 +30,39 @@ public class AmpBasePlugin implements Plugin { public static final Logger LOGGER = Logging.getLogger(AmpBasePlugin.class); public static final String PLUGIN_ID = "eu.xenit.amp-base"; - private final ConfigurationDispatcher sourceSetConfigurationDispatcher; private Project project; - @Inject - public AmpBasePlugin() { - sourceSetConfigurationDispatcher = new ConfigurationDispatcher<>(); - } - @Override public void apply(Project target) { GradleVersionCheck.assertSupportedVersion(PLUGIN_ID); project = target; project.getPluginManager().apply(JavaBasePlugin.class); configureSourceSetDefaults(); - } - private static Map propertiesToMap(Properties properties) { - return properties.keySet() - .stream() - .collect(Collectors.toMap(Object::toString, k -> properties.get(k).toString())); - } - - private void configureSourceSetDefaults() { - project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { - DefaultAmpSourceSet ampSourceSet = new DefaultAmpSourceSet(sourceSet, project, - sourceSetConfigurationDispatcher); - new DslObject(sourceSet).getConvention().getPlugins().put("amp", ampSourceSet); - String rootDir = "src/" + ampSourceSet.getName() + "/amp"; + project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(sourceSet -> { + var ampSourceSetConfig = (DefaultAmpSourceSetConfiguration)new DslObject(sourceSet).getExtensions() + .create(AmpSourceSetConfiguration.class, "amp", DefaultAmpSourceSetConfiguration.class, project, sourceSet); + var ampSourceSet = new DefaultAmpSourceSet(sourceSet); + String rootDir = "src/" + sourceSet.getName() + "/amp"; //add default config sourceDir - ampSourceSet.getAmp().getConfig().srcDir(rootDir + "/config"); + ampSourceSetConfig.getConfig().srcDir(rootDir + "/config"); //add default web sourceDir - ampSourceSet.getAmp().getWeb().srcDir(rootDir + "/web"); + ampSourceSetConfig.getWeb().srcDir(rootDir + "/web"); //add module.properties File moduleProperties = project.file(rootDir + "/module.properties"); if (moduleProperties.exists()) { - ampSourceSet.getAmp().module(moduleProperties); + ampSourceSetConfig.module(moduleProperties); } else { - ampSourceSet.getAmp().module(properties -> { + ampSourceSetConfig.module(properties -> { LOGGER.info( "{} does not exist for configured amp sourceset {}. A module.properties file is configured automatically from the project", - moduleProperties, ampSourceSet.getName()); + moduleProperties, sourceSet.getName()); String moduleId = project.getGroup().toString(); if (!moduleId.isEmpty()) { moduleId += "."; @@ -100,18 +82,17 @@ private void configureSourceSetDefaults() { } File fileMappingProperties = project.file(rootDir + "/file-mapping.properties"); if (fileMappingProperties.exists()) { - ampSourceSet.getAmp().fileMapping(fileMappingProperties); + ampSourceSetConfig.fileMapping(fileMappingProperties); } - }); - - sourceSetConfigurationDispatcher.add(ampSourceSet -> { createWritePropertiesTask(ampSourceSet.getModulePropertiesTaskName(), ampSourceSet.getName(), - "module.properties", ampSourceSet.getAmp().getModuleProperties()); + "module.properties", ampSourceSetConfig.getModuleProperties()); createWritePropertiesTask(ampSourceSet.getFileMappingPropertiesTaskName(), ampSourceSet.getName(), - "file-mapping.properties", ampSourceSet.getAmp().getFileMappingProperties()); - createAmpTask(project, ampSourceSet); + "file-mapping.properties", ampSourceSetConfig.getFileMappingProperties()); + createAmpTask(project, ampSourceSet, ampSourceSetConfig); + }); + } private Provider createWritePropertiesTask(String taskName, String sourceSetName, String fileName, @@ -123,7 +104,7 @@ private Provider createWritePropertiesTask(String taskName, Str }); } - private TaskProvider createAmpTask(Project project, DefaultAmpSourceSet ampSourceSet) { + private TaskProvider createAmpTask(Project project, DefaultAmpSourceSet ampSourceSet, DefaultAmpSourceSetConfiguration ampSourceSetConfig) { return project.getTasks().register(ampSourceSet.getAmpTaskName(), Amp.class, amp -> { amp.setModuleProperties( () -> project.getTasks().getByName(ampSourceSet.getModulePropertiesTaskName()).getOutputs() @@ -137,13 +118,13 @@ private TaskProvider createAmpTask(Project project, DefaultAmpSourceSet amp return fileMappingTask.getOutputs().getFiles().getSingleFile(); }); amp.web(copySpec -> { - copySpec.from(ampSourceSet.getAmp().getWeb()); + copySpec.from(ampSourceSetConfig.getWeb()); }); amp.config(copySpec -> { - copySpec.from(ampSourceSet.getAmp().getConfig()); + copySpec.from(ampSourceSetConfig.getConfig()); }); - Provider dynamicExtension = ampSourceSet.getAmp().getDynamicExtension(); + Provider dynamicExtension = ampSourceSetConfig.getDynamicExtension(); Provider ampLibrariesConfiguration = project.getConfigurations() .named(ampSourceSet.getAmpLibrariesConfigurationName()); Provider jarOutputs = project.getTasks().named(ampSourceSet.getJarTaskName()) @@ -161,30 +142,35 @@ private TaskProvider createAmpTask(Project project, DefaultAmpSourceSet amp ); amp.setGroup(LifecycleBasePlugin.BUILD_GROUP); if (!ampSourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME)) { - amp.setClassifier(ampSourceSet.getName()); + amp.getArchiveClassifier().set(ampSourceSet.getName()); } }); } - public void allAmpSourceSets(Action configure) { - sourceSetConfigurationDispatcher.add(configure); + public void allAmpSourceSetConfigurations(Action configure) { + project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(sourceSet -> { + var config = new DslObject(sourceSet).getExtensions().getByType(AmpSourceSetConfiguration.class); + if (config != null) { + configure.execute(config); + } + }); } - void configureAmpSourceSet(String sourceSetName, Action configure) { + void configureAmpSourceSetConfiguration(String sourceSetName, Action configure) { getSourceSet(sourceSetName) .configure(sourceSet -> { - AmpSourceSet ampSourceSet = new DslObject(sourceSet).getConvention().getPlugin(AmpSourceSet.class); - ampSourceSet.amp(configure); + AmpSourceSetConfiguration ampSourceSet = new DslObject(sourceSet).getExtensions().getByType(AmpSourceSetConfiguration.class); + configure.execute(ampSourceSet); }); } - Provider getAmpSourceSet(String sourceSetName) { + Provider getAmpSourceSetConfiguration(String sourceSetName) { return getSourceSet(sourceSetName) - .map(sourceSet -> new DslObject(sourceSet).getConvention().getPlugin(AmpSourceSet.class)); + .map(sourceSet -> new DslObject(sourceSet).getExtensions().getByType(AmpSourceSetConfiguration.class)); } private NamedDomainObjectProvider getSourceSet(String sourceSetName) { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); + SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); if (!sourceSets.getNames().contains(sourceSetName)) { return sourceSets.register(sourceSetName); } else { diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpLegacyPlugin.java b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpLegacyPlugin.java index 062904a..2e8823c 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpLegacyPlugin.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpLegacyPlugin.java @@ -4,7 +4,6 @@ import eu.xenit.gradle.alfrescosdk.config.AmpConfig; import eu.xenit.gradle.alfrescosdk.tasks.Amp; -import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import java.io.File; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -19,13 +18,13 @@ public void apply(Project project) { project.getPlugins().apply(JavaPlugin.class); // Applying the java plugin ensures that the main source set is created project.getPlugins().withType(AmpBasePlugin.class, ampBasePlugin -> { - ampBasePlugin.configureAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, ampSourceSetConfiguration -> { + ampBasePlugin.configureAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME, ampSourceSetConfiguration -> { project.getExtensions().create(AMP_EXTENSION, AmpConfig.class, project, ampSourceSetConfiguration); }); - ampBasePlugin.allAmpSourceSets(ampSourceSet -> { + ampBasePlugin.allAmpSourceSetConfigurations(ampSourceSetConfiguration -> { + var ampSourceSet = ampSourceSetConfiguration.getSourceSet(); if(ampSourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME)) { TaskProvider ampProvider = project.getTasks().named(ampSourceSet.getAmpTaskName()); - AmpSourceSetConfiguration ampSourceSetConfiguration = ampSourceSet.getAmp(); if(ampSourceSetConfiguration.getWeb().getSrcDirs().size() == 1) { ampProvider.configure(amp -> { ((Amp)amp)._setWeb(() -> ampSourceSetConfiguration.getWeb().getSrcDirs().iterator().next()); diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java index 88d1370..dc958d1 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java @@ -2,12 +2,10 @@ import eu.xenit.gradle.alfrescosdk.internal.GradleVersionCheck; import eu.xenit.gradle.alfrescosdk.tasks.Amp; -import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSet; +import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; -import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.TaskProvider; import org.gradle.jvm.tasks.Jar; import org.gradle.language.base.plugins.LifecycleBasePlugin; @@ -33,9 +31,10 @@ public void apply(Project project) { project.getPlugins().withType(AmpBasePlugin.class, ampBasePlugin -> { // Automatically configure main sourceset for amps - ampBasePlugin.configureAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, s -> {}); - ampBasePlugin.allAmpSourceSets(ampSourceSet -> { - configureJarTask(project, ampSourceSet); + ampBasePlugin.configureAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME, s -> {}); + ampBasePlugin.allAmpSourceSetConfigurations(ampSourceSetConfig -> { + var ampSourceSet = ampSourceSetConfig.getSourceSet(); + configureJarTask(project, ampSourceSetConfig); TaskProvider ampTask = project.getTasks().withType(Amp.class).named(ampSourceSet.getAmpTaskName()); // Configure amp artifact @@ -47,23 +46,21 @@ public void apply(Project project) { }); project.getPlugins().withType(IdeaPlugin.class, ideaPlugin -> { - ideaPlugin.getModel().getModule().getResourceDirs().addAll(ampSourceSet.getAmp().getConfig().getSrcDirs()); + ideaPlugin.getModel().getModule().getResourceDirs().addAll(ampSourceSetConfig.getConfig().getSrcDirs()); }); }); }); } - @SuppressWarnings("unchecked") - private TaskProvider configureJarTask(Project project, AmpSourceSet ampSourceSet) { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); - SourceSet sourceSet = sourceSets.getByName(ampSourceSet.getName()); + private TaskProvider configureJarTask(Project project, AmpSourceSetConfiguration ampSourceSetConfig) { + SourceSet sourceSet = ampSourceSetConfig.getSourceSet().getSourceSet(); if(project.getTasks().getNames().contains(sourceSet.getJarTaskName())) { - return (TaskProvider) project.getTasks().named(sourceSet.getJarTaskName()); + return project.getTasks().named(sourceSet.getJarTaskName(), Jar.class); } return project.getTasks().register(sourceSet.getJarTaskName(), Jar.class, jar -> { jar.setGroup(LifecycleBasePlugin.BUILD_GROUP); jar.from(sourceSet.getOutput()); - jar.setClassifier(sourceSet.getName()); + jar.getArchiveClassifier().convention(sourceSet.getName()); jar.dependsOn(sourceSet.getClassesTaskName()); }); } diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/ConfigurationDispatcher.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/ConfigurationDispatcher.java deleted file mode 100644 index ebe1690..0000000 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/ConfigurationDispatcher.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.xenit.gradle.alfrescosdk.internal; - -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import org.gradle.api.Action; - -public class ConfigurationDispatcher { - private final List> actions = new LinkedList<>(); - - private final Set configurations = new LinkedHashSet<>(); - - public void add(T configuration) { - if(!configurations.add(configuration)) { - // Configuration was already added earlier - return; - } - for (Action action : actions) { - action.execute(configuration); - } - } - - public void add(Action action) { - actions.add(action); - for (T configuration : configurations) { - action.execute(configuration); - } - } - -} diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/GradleVersionCheck.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/GradleVersionCheck.java index c5d9071..89905c5 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/GradleVersionCheck.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/GradleVersionCheck.java @@ -7,7 +7,7 @@ public final class GradleVersionCheck { private GradleVersionCheck() { } - private static final GradleVersion MINIMUM_VERSION = GradleVersion.version("5.1"); + private static final GradleVersion MINIMUM_VERSION = GradleVersion.version("7.1"); public static void assertSupportedVersion(String pluginId) { GradleVersion currentVersion = GradleVersion.current(); diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/PropertiesUtil.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/PropertiesUtil.java new file mode 100644 index 0000000..b434609 --- /dev/null +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/PropertiesUtil.java @@ -0,0 +1,46 @@ +package eu.xenit.gradle.alfrescosdk.internal; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import org.gradle.api.UncheckedIOException; + +public final class PropertiesUtil { + private PropertiesUtil() { + throw new UnsupportedOperationException("This utility class can not be instantiated"); + } + + public static Properties loadProperties(File propertyFile) { + try { + try(FileInputStream inputStream = new FileInputStream(propertyFile)) { + return loadProperties(inputStream); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static Properties loadProperties(InputStream inputStream) { + Properties properties = new Properties(); + try { + properties.load(inputStream); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + return properties; + } + + public static void saveProperties(Properties properties, File propertyFile) { + try { + try (FileOutputStream propertiesFileOutputStream = new FileOutputStream(propertyFile)) { + properties.store(propertiesFileOutputStream, null); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + +} diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSet.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSet.java index f4a4ee9..d97262a 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSet.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSet.java @@ -1,36 +1,20 @@ package eu.xenit.gradle.alfrescosdk.internal.tasks; -import eu.xenit.gradle.alfrescosdk.internal.ConfigurationDispatcher; import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSet; -import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; -import org.gradle.api.Action; import org.gradle.api.NonNullApi; -import org.gradle.api.Project; import org.gradle.api.tasks.SourceSet; @NonNullApi public class DefaultAmpSourceSet implements AmpSourceSet { private final SourceSet parentSourceSet; - private final DefaultAmpSourceSetConfiguration amp; - private final ConfigurationDispatcher configurationDispatcher; - public DefaultAmpSourceSet(SourceSet parentSourceSet, Project project, - ConfigurationDispatcher configurationDispatcher) { + public DefaultAmpSourceSet(SourceSet parentSourceSet) { this.parentSourceSet = parentSourceSet; - this.configurationDispatcher = configurationDispatcher; - amp = new DefaultAmpSourceSetConfiguration(project); } @Override - public DefaultAmpSourceSetConfiguration getAmp() { - return amp; - } - - @Override - public AmpSourceSet amp(Action configureAction) { - configureAction.execute(getAmp()); - configurationDispatcher.add(this); - return this; + public SourceSet getSourceSet() { + return parentSourceSet; } @Override diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java index 3781035..f17d70f 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java @@ -1,5 +1,7 @@ package eu.xenit.gradle.alfrescosdk.internal.tasks; +import eu.xenit.gradle.alfrescosdk.internal.PropertiesUtil; +import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSet; import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import java.io.File; import java.util.Collections; @@ -11,10 +13,11 @@ import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; -import org.gradle.util.GUtil; +import org.gradle.api.tasks.SourceSet; public class DefaultAmpSourceSetConfiguration implements AmpSourceSetConfiguration { + private final SourceSet sourceSet; private final SourceDirectorySet config; private final SourceDirectorySet web; private final Project project; @@ -22,8 +25,9 @@ public class DefaultAmpSourceSetConfiguration implements AmpSourceSetConfigurati private final MapProperty fileMappingProperties; private final Property dynamicExtension; - public DefaultAmpSourceSetConfiguration(Project project) { + public DefaultAmpSourceSetConfiguration(Project project, SourceSet sourceSet) { this.project = project; + this.sourceSet = sourceSet; // Creates config sourceDir set. config = project.getObjects().sourceDirectorySet("config", "Alfresco AMP configuration"); @@ -42,6 +46,11 @@ public DefaultAmpSourceSetConfiguration(Project project) { dynamicExtension.set(false); } + @Override + public AmpSourceSet getSourceSet() { + return new DefaultAmpSourceSet(sourceSet); + } + @Override public AmpSourceSetConfiguration module(String moduleProperties) { module(project.file(moduleProperties)); @@ -51,7 +60,7 @@ public AmpSourceSetConfiguration module(String moduleProperties) { @Override public AmpSourceSetConfiguration module(File moduleProperties) { return module(properties -> { - properties.putAll(GUtil.loadProperties(moduleProperties)); + properties.putAll(PropertiesUtil.loadProperties(moduleProperties)); }); } @@ -78,7 +87,7 @@ public AmpSourceSetConfiguration fileMapping(String fileMappingProperties) { @Override public AmpSourceSetConfiguration fileMapping(File fileMappingProperties) { return fileMapping(properties -> { - properties.putAll(GUtil.loadProperties(fileMappingProperties)); + properties.putAll(PropertiesUtil.loadProperties(fileMappingProperties)); }); } @@ -116,4 +125,5 @@ public SourceDirectorySet getConfig() { public SourceDirectorySet getWeb() { return web; } + } diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/Amp.java b/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/Amp.java index ac65125..60fdb84 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/Amp.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/Amp.java @@ -2,7 +2,6 @@ import static eu.xenit.gradle.alfrescosdk.internal.DeprecationHelper.warnDeprecationOnce; -import groovy.lang.Closure; import java.io.File; import java.util.concurrent.Callable; import java.util.function.Supplier; @@ -20,7 +19,6 @@ import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.bundling.Zip; -import org.gradle.util.ConfigureUtil; /** * Assembles an AMP archive. @@ -313,51 +311,6 @@ public void setConfig(Supplier config) { } // - // - /** - * @param web supplier of the directory that will be copied to the {@code /web} directory - * @deprecated since 0.2.0, use {@link #web(Action)} instead. - */ - @Deprecated - public void setWeb(Closure web) { - setWeb(web::call); - } - - /** - * @param config supplier of the directory that will be copied to the {@code /config} directory - * @deprecated since 0.2.0, use {@link #config(Action)} instead - */ - @Deprecated - public void setConfig(Closure config) { - setConfig(config::call); - } - - /** - * @param moduleProperties supplier of the file that will be copied to {@code /module.properties} - * @see #setModuleProperties(Supplier) - */ - public void setModuleProperties(Closure moduleProperties) { - setModuleProperties(moduleProperties::call); - } - - /** - * @param fileMappingProperties supplier of the file that will be copied to {@code /file-mapping.properties} - * @see #setFileMappingProperties(Supplier) - */ - public void setFileMappingProperties(Closure fileMappingProperties) { - setFileMappingProperties(fileMappingProperties::call); - } - - /** - * @see #de(Action) - * @param configureClosure action that configures the {@link CopySpec} for {@code /config/dynamic-extensions/bundles} - * @deprecated since 0.2.0. Use {@link #getDeBundles()} or {@link #setDeBundles(FileCollection)} instead. - */ - @Deprecated - public void de(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, getDe()); - } - // // private Supplier> _web = () -> web; diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSet.java b/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSet.java index b67dd67..c14dde0 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSet.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSet.java @@ -1,24 +1,12 @@ package eu.xenit.gradle.alfrescosdk.tasks; -import groovy.lang.Closure; -import org.gradle.api.Action; import org.gradle.api.Named; import org.gradle.api.NonNullApi; -import org.gradle.util.ConfigureUtil; +import org.gradle.api.tasks.SourceSet; @NonNullApi public interface AmpSourceSet extends Named { - AmpSourceSetConfiguration getAmp(); - - default AmpSourceSet amp(Action configureAction) { - configureAction.execute(getAmp()); - return this; - } - - default AmpSourceSet amp(Closure configureClosure) { - return amp(ConfigureUtil.configureUsing(configureClosure)); - } - + SourceSet getSourceSet(); String getModulePropertiesTaskName(); String getFileMappingPropertiesTaskName(); String getAmpTaskName(); diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSetConfiguration.java b/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSetConfiguration.java index 28aa718..ee94621 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSetConfiguration.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/tasks/AmpSourceSetConfiguration.java @@ -1,16 +1,15 @@ package eu.xenit.gradle.alfrescosdk.tasks; -import groovy.lang.Closure; import java.io.File; import java.util.Map; import java.util.Properties; import org.gradle.api.Action; import org.gradle.api.NonNullApi; import org.gradle.api.file.SourceDirectorySet; -import org.gradle.util.ConfigureUtil; @NonNullApi public interface AmpSourceSetConfiguration { + AmpSourceSet getSourceSet(); AmpSourceSetConfiguration module(String moduleProperties); @@ -34,11 +33,6 @@ default AmpSourceSetConfiguration fileMapping(Map fileMappingPro SourceDirectorySet getConfig(); - default AmpSourceSetConfiguration config(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, getConfig()); - return this; - } - default AmpSourceSetConfiguration config(Action configure) { configure.execute(getConfig()); return this; @@ -47,12 +41,6 @@ default AmpSourceSetConfiguration config(Action conf SourceDirectorySet getWeb(); - default AmpSourceSetConfiguration web(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, getWeb()); - return this; - } - - default AmpSourceSetConfiguration web(Action configure) { configure.execute(getWeb()); return this; diff --git a/src/test/java/eu/xenit/gradle/alfrescosdk/AlfrescoPluginTest.java b/src/test/java/eu/xenit/gradle/alfrescosdk/AlfrescoPluginTest.java index 3863a62..bacece4 100644 --- a/src/test/java/eu/xenit/gradle/alfrescosdk/AlfrescoPluginTest.java +++ b/src/test/java/eu/xenit/gradle/alfrescosdk/AlfrescoPluginTest.java @@ -49,7 +49,7 @@ public void alfrescoProvidedDependency(){ public void alfrescoProvidedSourceSetWithoutMain() { DefaultProject project = getDefaultProject(); AmpBasePlugin ampBasePlugin = project.getPlugins().apply(AmpBasePlugin.class); - ampBasePlugin.configureAmpSourceSet("share", s -> {}); + ampBasePlugin.configureAmpSourceSetConfiguration("share", s -> {}); ConfigurableFileCollection test123JarCollection = project.files(this.getClass().getClassLoader().getResource("test123.jar").getFile()); File test123Jar = test123JarCollection.getSingleFile(); @@ -71,8 +71,8 @@ public void alfrescoProvidedSourceSetWithoutMain() { public void alfrescoProvidedSourceSetWithMain() { DefaultProject project = getDefaultProject(); AmpBasePlugin ampBasePlugin = project.getPlugins().apply(AmpBasePlugin.class); - ampBasePlugin.configureAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, s -> {}); - ampBasePlugin.configureAmpSourceSet("share", s -> {}); + ampBasePlugin.configureAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME, s -> {}); + ampBasePlugin.configureAmpSourceSetConfiguration("share", s -> {}); assertTrue(project.getConfigurations().getNames().contains(ALFRESCO_PROVIDED)); assertTrue(project.getConfigurations().getNames().contains("shareAlfrescoProvided")); diff --git a/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java b/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java index 82b7eaf..ab2f5ef 100644 --- a/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java +++ b/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java @@ -5,8 +5,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import eu.xenit.gradle.alfrescosdk.internal.PropertiesUtil; import eu.xenit.gradle.alfrescosdk.tasks.Amp; -import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSet; +import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -16,12 +17,9 @@ import java.util.Properties; import org.gradle.api.internal.project.DefaultProject; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; -import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.WriteProperties; import org.gradle.testfixtures.ProjectBuilder; -import org.gradle.util.GUtil; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -42,7 +40,7 @@ private DefaultProject getDefaultProject() { public void mainSourceSetOnly() { DefaultProject project = getDefaultProject(); - project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, ampSourceSetConfiguration -> { + project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME, ampSourceSetConfiguration -> { ampSourceSetConfiguration.module(properties -> { properties.setProperty("module.id", "test-module-repo"); properties.setProperty("module.version", "1.0.0"); @@ -63,10 +61,10 @@ public void mainSourceSetOnly() { WriteProperties fileMappingPropertiesTask = project.getTasks().withType(WriteProperties.class).findByName("processFileMappingProperties"); assertNotNull(fileMappingPropertiesTask); - AmpSourceSet ampSourceSet = project.getPlugins().getPlugin(AmpBasePlugin.class).getAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME).get(); + AmpSourceSetConfiguration ampSourceSet = project.getPlugins().getPlugin(AmpBasePlugin.class).getAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME).get(); - assertEquals(Collections.singleton(project.file("src/main/amp/config")), ampSourceSet.getAmp().getConfig().getSrcDirs()); - assertEquals(Collections.singleton(project.file("src/main/amp/web")), ampSourceSet.getAmp().getWeb().getSrcDirs()); + assertEquals(Collections.singleton(project.file("src/main/amp/config")), ampSourceSet.getConfig().getSrcDirs()); + assertEquals(Collections.singleton(project.file("src/main/amp/web")), ampSourceSet.getWeb().getSrcDirs()); } @Test @@ -74,19 +72,19 @@ public void additionalSourceSet() { DefaultProject project = getDefaultProject(); // Create and configure a share amp sourceset - project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSet("share", s -> {}); + project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSetConfiguration("share", s -> {}); assertNotNull(project.getTasks().findByName("processShareModuleProperties")); assertNotNull(project.getTasks().findByName("processShareFileMappingProperties")); assertTrue(project.getTasks().getNames().contains("shareAmp")); - AmpSourceSet shareAmpSourceSet = project.getPlugins() + AmpSourceSetConfiguration shareAmpSourceSet = project.getPlugins() .getPlugin(AmpBasePlugin.class) - .getAmpSourceSet("share") + .getAmpSourceSetConfiguration("share") .get(); - assertEquals(Collections.singleton(project.file("src/share/amp/config")), shareAmpSourceSet.getAmp().getConfig().getSrcDirs()); - assertEquals(Collections.singleton(project.file("src/share/amp/web")), shareAmpSourceSet.getAmp().getWeb().getSrcDirs()); + assertEquals(Collections.singleton(project.file("src/share/amp/config")), shareAmpSourceSet.getConfig().getSrcDirs()); + assertEquals(Collections.singleton(project.file("src/share/amp/web")), shareAmpSourceSet.getWeb().getSrcDirs()); } @Test @@ -97,19 +95,19 @@ public void autoConfigureSourceSet() throws IOException { Properties moduleProperties = new Properties(); moduleProperties.setProperty("module.id", "test-amp"); moduleProperties.setProperty("module.version", "1.0.0"); - GUtil.saveProperties(moduleProperties, modulePropertiesFile); + PropertiesUtil.saveProperties(moduleProperties, modulePropertiesFile); File fileMappingPropertiesFile = ampFolder.resolve("file-mapping.properties").toFile(); Properties fileMappingProperties = new Properties(); fileMappingProperties.setProperty("/override", "/"); - GUtil.saveProperties(fileMappingProperties, fileMappingPropertiesFile); + PropertiesUtil.saveProperties(fileMappingProperties, fileMappingPropertiesFile); DefaultProject project = getDefaultProject(); // Java plugin is required for the jar task project.getPlugins().apply(JavaPlugin.class); // write an amp {} block inside a sourceset - project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, s -> {}); + project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME, s -> {}); WriteProperties modulePropertiesTask = project.getTasks().withType(WriteProperties.class).findByName("processModuleProperties"); assertNotNull(modulePropertiesTask); @@ -133,7 +131,7 @@ public void autoConfigureSourceSet() throws IOException { public void manualConfigureSourceSet() { DefaultProject project = getDefaultProject(); - project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, ampConfig -> { + project.getPlugins().getPlugin(AmpBasePlugin.class).configureAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME, ampConfig -> { ampConfig.module(moduleProperties -> { moduleProperties.setProperty("module.id", "test-amp"); moduleProperties.setProperty("module.version", "1.0.0"); @@ -153,10 +151,10 @@ public void manualConfigureSourceSet() { assertEquals("test-amp", modulePropertiesTask.getProperties().get("module.id")); assertEquals("1.0.0", modulePropertiesTask.getProperties().get("module.version")); - AmpSourceSet ampSourceSet = project.getPlugins().getPlugin(AmpBasePlugin.class).getAmpSourceSet(SourceSet.MAIN_SOURCE_SET_NAME).get(); + AmpSourceSetConfiguration ampSourceSet = project.getPlugins().getPlugin(AmpBasePlugin.class).getAmpSourceSetConfiguration(SourceSet.MAIN_SOURCE_SET_NAME).get(); - assertEquals(Collections.singleton(project.file("src/xyz/amp/config")), ampSourceSet.getAmp().getConfig().getSrcDirs()); - assertEquals(new HashSet<>(Arrays.asList(project.file("src/main/amp/web"), project.file("src/xyz/amp/web"))), ampSourceSet.getAmp().getWeb().getSrcDirs()); + assertEquals(Collections.singleton(project.file("src/xyz/amp/config")), ampSourceSet.getConfig().getSrcDirs()); + assertEquals(new HashSet<>(Arrays.asList(project.file("src/main/amp/web"), project.file("src/xyz/amp/web"))), ampSourceSet.getWeb().getSrcDirs()); } diff --git a/src/test/java/eu/xenit/gradle/alfrescosdk/internal/ConfigurationDispatcherTest.java b/src/test/java/eu/xenit/gradle/alfrescosdk/internal/ConfigurationDispatcherTest.java deleted file mode 100644 index ea5a458..0000000 --- a/src/test/java/eu/xenit/gradle/alfrescosdk/internal/ConfigurationDispatcherTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package eu.xenit.gradle.alfrescosdk.internal; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.gradle.api.Action; -import org.junit.Test; - -public class ConfigurationDispatcherTest { - - private static class CallsCollector implements Action { - private List configurations = new ArrayList<>(); - - @Override - public void execute(String configuration) { - configurations.add(configuration); - } - - public List getConfigurations() { - return configurations; - } - } - - @Test - public void configurationFirst() { - ConfigurationDispatcher dispatcher = new ConfigurationDispatcher<>(); - - dispatcher.add("abc"); - dispatcher.add("xyz"); - - CallsCollector callsCollector = new CallsCollector(); - dispatcher.add(callsCollector); - - assertEquals(Arrays.asList("abc", "xyz"), callsCollector.getConfigurations()); - } - - - @Test - public void actionFirst() { - ConfigurationDispatcher dispatcher = new ConfigurationDispatcher<>(); - - CallsCollector callsCollector = new CallsCollector(); - dispatcher.add(callsCollector); - - assertEquals(Collections.emptyList(), callsCollector.getConfigurations()); - - dispatcher.add("abc"); - dispatcher.add("xyz"); - - assertEquals(Arrays.asList("abc", "xyz"), callsCollector.getConfigurations()); - } - - @Test - public void interleaved() { - ConfigurationDispatcher dispatcher = new ConfigurationDispatcher<>(); - - dispatcher.add("abc"); - - CallsCollector callsCollector = new CallsCollector(); - dispatcher.add(callsCollector); - - assertEquals(Collections.singletonList("abc"), callsCollector.getConfigurations()); - - dispatcher.add("xyz"); - - assertEquals(Arrays.asList("abc", "xyz"), callsCollector.getConfigurations()); - - } - - @Test - public void configurationMultipleIdentical() { - ConfigurationDispatcher dispatcher = new ConfigurationDispatcher<>(); - - dispatcher.add("abc"); - - CallsCollector callsCollector = new CallsCollector(); - dispatcher.add(callsCollector); - - assertEquals(Collections.singletonList("abc"), callsCollector.getConfigurations()); - - dispatcher.add("abc"); - - assertEquals(Collections.singletonList("abc"), callsCollector.getConfigurations()); - - } - -}