From 96521f2234d1aea23cfa9678a928f81c5e2f4e13 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 26 Aug 2022 12:08:47 +0800 Subject: [PATCH] Add more tests for Gradle plugin in Github workflows (#13280) * add more tests for gradle plugin * update gradlew to 6.8.3 * fix typo * update comment --- .github/workflows/openapi-generator.yaml | 4 ++- .../samples/local-spec/README.md | 3 ++- .../samples/local-spec/build.gradle | 19 +++++++++++++ .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../samples/local-spec/gradlew | 6 ++--- .../samples/local-spec/gradlew.bat | 27 ++++++------------- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/.github/workflows/openapi-generator.yaml b/.github/workflows/openapi-generator.yaml index bd062d7d037..e7053340e0a 100644 --- a/.github/workflows/openapi-generator.yaml +++ b/.github/workflows/openapi-generator.yaml @@ -217,5 +217,7 @@ jobs: - name: Run tests run: | mvn --no-snapshot-updates --batch-mode --quiet install -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=error - (cd modules/openapi-generator-gradle-plugin/samples/local-spec && ./gradlew buildGoSdk) + (cd modules/openapi-generator-gradle-plugin/samples/local-spec && ./gradlew buildGoSdk) # using gradle-6.8.3 via wrapper (cd modules/openapi-generator-gradle-plugin/samples/local-spec && ./gradlew openApiGenerate) + (cd modules/openapi-generator-gradle-plugin/samples/local-spec && ./gradlew buildDotnetSdk) + (cd modules/openapi-generator-gradle-plugin/samples/local-spec && gradle buildJavaResttemplateSdk) # not using gradle wrapper diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/README.md b/modules/openapi-generator-gradle-plugin/samples/local-spec/README.md index d3ffccdb695..6897651258b 100644 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/README.md +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/README.md @@ -1,6 +1,6 @@ # Local Spec Sample -This example assumes you have Gradle 5.6.4+ installed. No gradle wrapper is provided in samples. +This example assumes you have Gradle 6.8.3+ installed. No gradle wrapper is provided in samples. First, publish the openapi-generator-gradle-plugin locally via `./gradlew assemble publishToMavenLocal` in the module directory. @@ -12,6 +12,7 @@ gradle openApiMeta # expected outcome: BUILD SUCCESSFUL gradle openApiValidate # expected outcome: BUILD FAILED gradle buildGoSdk # expected outcome: BUILD SUCCESSFUL gradle buildDotnetSdk # expected outcome: BUILD SUCCESSFUL +gradle buildJavaResttemplateSdk # expected outcome: BUILD SUCCESSFUL gradle generateGoWithInvalidSpec # expected outcome: BUILD FAILED ``` diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle b/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle index cb99b8838fa..06e7ed8891c 100644 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle @@ -54,6 +54,25 @@ openApiGenerate { enablePostProcessFile = false } +task buildJavaResttemplateSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { + generatorName = "java" + library = "resttemplate" + inputSpec = "$rootDir/petstore-v3.0.yaml".toString() + outputDir = "$buildDir/java-resttemplate-api-client" + apiPackage = "com.example.client" + invokerPackage = "com.example.invoker" + modelPackage = "com.example.cdm" + configOptions = [ + dateLibrary: "java8" + ] + groupId = 'com.example' + id = 'client' + skipValidateSpec = true + logToStderr = true + generateAliasAsModel = false + enablePostProcessFile = false +} + task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){ generatorName = "go" inputSpec = "$rootDir/petstore-v3.0.yaml".toString() diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle/wrapper/gradle-wrapper.properties b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle/wrapper/gradle-wrapper.properties index 5028f28f8e4..442d9132ea3 100644 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle/wrapper/gradle-wrapper.properties +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew index 2fe81a7d95e..20b741fb46c 100755 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew @@ -44,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -82,6 +82,7 @@ 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 @@ -92,14 +93,12 @@ if [ -n "$JAVA_HOME" ] ; then 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 @@ -129,6 +128,7 @@ fi 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 diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew.bat b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew.bat index 9618d8d9607..6a68175eb70 100644 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew.bat +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradlew.bat @@ -29,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" +set DEFAULT_JVM_OPTS=-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +54,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,28 +64,14 @@ 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