From 0f85db15e12b76021b186baa949df7b19609e566 Mon Sep 17 00:00:00 2001 From: James Fredley Date: Tue, 13 Aug 2024 17:24:03 -0400 Subject: [PATCH] Add grails wrapper optional forge feature (#360) * Add Grails Wrapper as an optional forge feature --- config/checkstyle/checkstyle.xml | 2 +- .../forge/build/dependencies/Dependency.java | 6 +- .../forge/build/dependencies/Phase.java | 5 +- .../forge/build/dependencies/Scope.java | 3 +- .../build/gradle/GradleConfiguration.java | 6 +- .../grails/forge/feature/FeatureContext.java | 6 +- .../feature/grailsWrapper/GrailsWrapper.java | 71 ++++++++ .../grailsWrapper/GrailsWrapperFeature.java | 38 +++++ .../grails-wrapper/grails-wrapper.jar | Bin 0 -> 5536 bytes .../src/main/resources/grails-wrapper/grailsw | 152 ++++++++++++++++++ .../main/resources/grails-wrapper/grailsw.bat | 89 ++++++++++ .../grailsWrapper/GrailsWrapperSpec.groovy | 40 +++++ 12 files changed, 410 insertions(+), 8 deletions(-) create mode 100644 grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapper.java create mode 100644 grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapperFeature.java create mode 100644 grails-forge-core/src/main/resources/grails-wrapper/grails-wrapper.jar create mode 100644 grails-forge-core/src/main/resources/grails-wrapper/grailsw create mode 100644 grails-forge-core/src/main/resources/grails-wrapper/grailsw.bat create mode 100644 grails-forge-core/src/test/groovy/org/grails/forge/feature/grailsWrapper/GrailsWrapperSpec.groovy diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 9c3da204..18836e39 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -48,7 +48,7 @@ - + diff --git a/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Dependency.java b/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Dependency.java index 449470e6..ff05905e 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Dependency.java +++ b/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Dependency.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 original authors + * Copyright 2017-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -203,6 +203,10 @@ public Builder annotationProcessor() { return scope(Scope.ANNOTATION_PROCESSOR); } + public Builder profile() { + return scope(Scope.PROFILE); + } + public Builder annotationProcessor(boolean requiresPriority) { this.annotationProcessorPriority = requiresPriority; return annotationProcessor(); diff --git a/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Phase.java b/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Phase.java index e04af505..f68ea30d 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Phase.java +++ b/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Phase.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 original authors + * Copyright 2017-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,5 +22,6 @@ public enum Phase { DEVELOPMENT_ONLY, RUNTIME, OPENREWRITE, - BUILD + BUILD, + PROFILE } diff --git a/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Scope.java b/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Scope.java index 0c671e6c..edd2c1dc 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Scope.java +++ b/grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Scope.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 original authors + * Copyright 2017-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ public class Scope { public static final Scope TEST_COMPILE_ONLY = new Scope(Source.TEST, Collections.singletonList(Phase.COMPILATION)); public static final Scope TEST_RUNTIME = new Scope(Source.TEST, Collections.singletonList(Phase.RUNTIME)); public static final Scope OPENREWRITE = new Scope(Source.MAIN, Collections.singletonList(Phase.OPENREWRITE)); + public static final Scope PROFILE = new Scope(Source.MAIN, Collections.singletonList(Phase.PROFILE)); @NonNull private Source source; diff --git a/grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleConfiguration.java b/grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleConfiguration.java index 370c3703..5e2eebb1 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleConfiguration.java +++ b/grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 original authors + * Copyright 2017-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.util.Optional; public enum GradleConfiguration implements Ordered { + PROFILE("profile", -1), BUILD("implementation", 0), ANNOTATION_PROCESSOR("annotationProcessor", 1), KAPT("kapt", 2), @@ -95,6 +96,9 @@ public static Optional of(@NonNull Scope scope, if (scope.getPhases().contains(Phase.OPENREWRITE)) { return Optional.of(GradleConfiguration.OPENREWRITE); } + if (scope.getPhases().contains(Phase.PROFILE)) { + return Optional.of(GradleConfiguration.PROFILE); + } break; case TEST: diff --git a/grails-forge-core/src/main/java/org/grails/forge/feature/FeatureContext.java b/grails-forge-core/src/main/java/org/grails/forge/feature/FeatureContext.java index 9fed50c5..ea47212e 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/feature/FeatureContext.java +++ b/grails-forge-core/src/main/java/org/grails/forge/feature/FeatureContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 original authors + * Copyright 2017-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,9 @@ public Set getFinalFeatures(ConsoleOutput consoleOutput) { return features.stream().filter(feature -> { for (FeaturePredicate predicate: exclusions) { if (predicate.test(feature)) { - predicate.getWarning().ifPresent(message -> { throw new IllegalArgumentException(message); }); + predicate.getWarning().ifPresent(message -> { + throw new IllegalArgumentException(message); + }); return false; } } diff --git a/grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapper.java b/grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapper.java new file mode 100644 index 00000000..3d237fa2 --- /dev/null +++ b/grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapper.java @@ -0,0 +1,71 @@ +/* + * Copyright 2017-2024 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. + */ +package org.grails.forge.feature.grailsWrapper; + +import jakarta.inject.Singleton; +import org.grails.forge.application.ApplicationType; +import org.grails.forge.application.OperatingSystem; +import org.grails.forge.application.generator.GeneratorContext; +import org.grails.forge.build.dependencies.Dependency; +import org.grails.forge.build.dependencies.Scope; +import org.grails.forge.template.BinaryTemplate; + +@Singleton +public class GrailsWrapper implements GrailsWrapperFeature { + + @Override + public String getName() { + return "grails-wrapper"; + } + + @Override + public String getTitle() { + return "Grails Wrapper for Grails"; + } + + @Override + public String getDescription() { + return "Gives you the ability to run grails shell from terminal."; + } + + @Override + public boolean isVisible() { + return true; + } + + @Override + public void apply(GeneratorContext generatorContext) { + OperatingSystem operatingSystem = generatorContext.getOperatingSystem(); + + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + generatorContext.addTemplate("grailsWrapperJar", new BinaryTemplate("grails-wrapper.jar", classLoader.getResource("grails-wrapper/grails-wrapper.jar"))); + generatorContext.addTemplate("grailsWrapper", new BinaryTemplate("grailsw", classLoader.getResource("grails-wrapper/grailsw"), true)); + generatorContext.addTemplate("grailsWrapperBat", new BinaryTemplate("grailsw.bat", classLoader.getResource("grails-wrapper/grailsw.bat"), false)); + + ApplicationType applicationType = generatorContext.getApplicationType(); + + generatorContext.addDependency(Dependency.builder() + .groupId("org.grails.profiles") + .artifactId(applicationType.getName()) + .scope(Scope.PROFILE)); + } + + @Override + public boolean supports(ApplicationType applicationType) { + return true; + } +} diff --git a/grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapperFeature.java b/grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapperFeature.java new file mode 100644 index 00000000..965c8f98 --- /dev/null +++ b/grails-forge-core/src/main/java/org/grails/forge/feature/grailsWrapper/GrailsWrapperFeature.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017-2024 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. + */ +package org.grails.forge.feature.grailsWrapper; + +import org.grails.forge.application.ApplicationType; +import org.grails.forge.feature.Category; +import org.grails.forge.feature.OneOfFeature; + +public interface GrailsWrapperFeature extends OneOfFeature { + + @Override + default Class getFeatureClass() { + return GrailsWrapperFeature.class; + } + + @Override + default boolean supports(ApplicationType applicationType) { + return true; + } + + @Override + default String getCategory() { + return Category.DEV_TOOLS; + } +} diff --git a/grails-forge-core/src/main/resources/grails-wrapper/grails-wrapper.jar b/grails-forge-core/src/main/resources/grails-wrapper/grails-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..181fc9700ec829fdc7db8cde1f022643056c47a8 GIT binary patch literal 5536 zcma)=1yoe+y2p_cNnvO~kdC2-Zjh1~I;Fc|7-9ek=@da4DG`ZLkP?P26=7hI5D=sp zq+1vXJ#fD`ex7^oy3byFzk9Fs|3CYA_u9|9*89`d#K9%R!XhBR>WLyY!@3OYtIK8F zxIDoshKhXZ+Nu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ge-core/src/main/resources/grails-wrapper/grailsw b/grails-forge-core/src/main/resources/grails-wrapper/grailsw new file mode 100644 index 00000000..8d0cc123 --- /dev/null +++ b/grails-forge-core/src/main/resources/grails-wrapper/grailsw @@ -0,0 +1,152 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Grails start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRAILS_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" "-XX:CICompilerCount=3"' + + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +JAR_PATH=$APP_HOME/grails-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + JAVACMD=`cygpath --unix "$JAVACMD"` + JAR_PATH=`cygpath --path --mixed "$JAR_PATH"` + + # 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 [ "$GRAILS_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRAILS_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRAILS_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRAILS_OPTS + +exec "$JAVACMD" -jar "${JVM_OPTS[@]}" "$JAR_PATH" "$@" diff --git a/grails-forge-core/src/main/resources/grails-wrapper/grailsw.bat b/grails-forge-core/src/main/resources/grails-wrapper/grailsw.bat new file mode 100644 index 00000000..14734e44 --- /dev/null +++ b/grails-forge-core/src/main/resources/grails-wrapper/grailsw.bat @@ -0,0 +1,89 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Grails startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRAILS_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" "-XX:CICompilerCount=3" + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_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=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line +set JAR_PATH=%APP_HOME%/grails-wrapper.jar + +@rem Execute Grails +"%JAVA_EXE%" -jar %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRAILS_OPTS% %JAR_PATH% %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRAILS_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRAILS_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/grails-forge-core/src/test/groovy/org/grails/forge/feature/grailsWrapper/GrailsWrapperSpec.groovy b/grails-forge-core/src/test/groovy/org/grails/forge/feature/grailsWrapper/GrailsWrapperSpec.groovy new file mode 100644 index 00000000..7949ab1f --- /dev/null +++ b/grails-forge-core/src/test/groovy/org/grails/forge/feature/grailsWrapper/GrailsWrapperSpec.groovy @@ -0,0 +1,40 @@ +package org.grails.forge.feature.grailsWrapper + +import org.grails.forge.ApplicationContextSpec +import org.grails.forge.application.ApplicationType +import org.grails.forge.fixture.CommandOutputFixture +import org.grails.forge.options.JdkVersion +import org.grails.forge.options.Options +import org.grails.forge.options.TestFramework +import spock.lang.Unroll + +class GrailsWrapperSpec extends ApplicationContextSpec implements CommandOutputFixture { + + @Unroll + void "test grails-wrapper.jar, grailsw and grailsw.bat files are present for #applicationType application"() { + when: + def output = generate(applicationType, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ['grails-wrapper']) + + then: + output.containsKey("grails-wrapper.jar") + output.containsKey("grailsw") + output.containsKey("grailsw.bat") + + where: + applicationType << ApplicationType.values().toList() + } + + @Unroll + void "test profile dependency is present for #applicationType application"() { + when: + def output = generate(applicationType, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ['grails-wrapper']) + + then: + output.containsKey("build.gradle") + def build = output.get("build.gradle") + build.contains("profile(\"org.grails.profiles:$applicationType.name\")") + + where: + applicationType << ApplicationType.values().toList() + } +}