From da91e0f10dffe21a54defbbcc9989f85ab0f1e82 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Wed, 28 Oct 2020 17:06:40 +0100 Subject: [PATCH] Quarkus JBang project type --- .../code/jbang-resteasy-code/codestart.yml | 13 ++ .../src/{resource.class-name}.tpl.qute.java | 27 +++ .../quarkus-jbang/language/java/codestart.yml | 3 + .../project/quarkus-jbang/base/..gitignore | 30 ++++ .../quarkus-jbang/base/README.tpl.qute.md | 5 + .../project/quarkus-jbang/codestart.yml | 12 ++ .../tooling/jbang-wrapper/base/jbang | 158 ++++++++++++++++++ .../tooling/jbang-wrapper/base/jbang.cmd | 109 ++++++++++++ .../tooling/jbang-wrapper/codestart.yml | 5 + .../buildtool/gradle-kotlin-dsl/codestart.yml | 3 - .../core/buildtool/gradle/codestart.yml | 3 - .../core/buildtool/maven/codestart.yml | 3 - .../core/tooling/gradle-wrapper/codestart.yml | 3 + .../core/tooling/maven-wrapper/codestart.yml | 3 + .../codestarts/CodestartProjectInput.java | 2 +- .../CodestartProjectInputBuilder.java | 2 +- .../codestarts/core/CodestartCatalogs.java | 2 - ...uarkusPlatformCodestartResourceLoader.java | 21 +++ .../jbang/QuarkusJBangCodestartCatalog.java | 64 +++++++ .../QuarkusJBangCodestartProjectInput.java | 29 ++++ ...rkusJBangCodestartProjectInputBuilder.java | 80 +++++++++ .../QuarkusCodestartCatalog.java | 31 +--- .../{ => quarkus}/QuarkusCodestartData.java | 2 +- .../QuarkusCodestartProjectInput.java | 3 +- .../QuarkusCodestartProjectInputBuilder.java | 3 +- .../handlers/CreateProjectCommandHandler.java | 6 +- .../QuarkusJBangCodestartGenerationTest.java | 41 +++++ .../QuarkusCodestartCatalogTest.java | 9 +- .../QuarkusCodestartGenerationTest.java | 50 +++--- .../{ => quarkus}/QuarkusCodestartRunIT.java | 15 +- .../{ => quarkus}/WrapperRunner.java | 2 +- 31 files changed, 663 insertions(+), 76 deletions(-) create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/codestart.yml create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/java/src/{resource.class-name}.tpl.qute.java create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/language/java/codestart.yml create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/..gitignore create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/README.tpl.qute.md create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/codestart.yml create mode 100755 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang.cmd create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/codestart.yml create mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusPlatformCodestartResourceLoader.java create mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java create mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInput.java create mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java rename independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartCatalog.java (88%) rename independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartData.java (99%) rename independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartProjectInput.java (92%) rename independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartProjectInputBuilder.java (96%) create mode 100644 integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartCatalogTest.java (95%) rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartGenerationTest.java (95%) rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/{ => quarkus}/QuarkusCodestartRunIT.java (93%) rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/{ => quarkus}/WrapperRunner.java (98%) diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/codestart.yml new file mode 100644 index 0000000000000..2547e73613c5c --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/codestart.yml @@ -0,0 +1,13 @@ +name: jbang-resteasy-code +ref: resteasy +type: code +language: + base: + data: + resource: + class-name: ExampleResource + path: "/resteasy/hello" + response: "hello" + dependencies: + - io.quarkus:quarkus-resteasy + diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/java/src/{resource.class-name}.tpl.qute.java b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/java/src/{resource.class-name}.tpl.qute.java new file mode 100644 index 0000000000000..03f1d5adaa194 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/code/jbang-resteasy-code/java/src/{resource.class-name}.tpl.qute.java @@ -0,0 +1,27 @@ +//usr/bin/env jbang "$0" "$@" ; exit $? +//REPOS xamdk=https://xam.dk/maven +{#for dep in dependencies} +//DEPS {dep.formatted-ga}:{quarkus.version} +{/for} + +//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager +//Q:CONFIG quarkus.swagger-ui.always-include=true + +import io.quarkus.runtime.Quarkus; +import javax.enterprise.context.ApplicationScoped; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("{resource.path}") +@ApplicationScoped +public class {resource.class-name} { + + @GET + public String sayHello() { + return "{resource.response}"; + } + + public static void main(String[] args) { + Quarkus.run(args); + } +} \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/language/java/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/language/java/codestart.yml new file mode 100644 index 0000000000000..4f1da5b0e1a88 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/language/java/codestart.yml @@ -0,0 +1,3 @@ +name: java +type: language +fallback: true diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/..gitignore b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/..gitignore new file mode 100644 index 0000000000000..ca0fab1daa709 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/..gitignore @@ -0,0 +1,30 @@ +# Eclipse +.project +.classpath +.settings/ +bin/ + +# IntelliJ +.idea +*.ipr +*.iml +*.iws + +# NetBeans +nb-configuration.xml + +# Visual Studio Code +.vscode +.factorypath + +# OSX +.DS_Store + +# Vim +*.swp +*.swo + +# patch +*.orig +*.rej + diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/README.tpl.qute.md b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/README.tpl.qute.md new file mode 100644 index 0000000000000..bbf80ed2427c6 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/base/README.tpl.qute.md @@ -0,0 +1,5 @@ +# JBang Quarkus Project + +```shell script +./jbang src/ExampleResource.java +``` \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/codestart.yml new file mode 100644 index 0000000000000..9b7e1aee929a2 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/project/quarkus-jbang/codestart.yml @@ -0,0 +1,12 @@ +name: quarkus-jbang +type: project +fallback: true +output-strategy: + "README.md": append + "readme.md": forbidden + "README.adoc": forbidden + "readme.adoc": forbidden + ".gitignore": append + "*": fail-on-duplicate + + diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang new file mode 100755 index 0000000000000..22fc978fa0fcd --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang @@ -0,0 +1,158 @@ +#!/usr/bin/env bash + +# +# To run this script remotely type this in your shell +# (where ... are the arguments you want to pass to Jbang): +# curl -Ls https://sh.jbang.dev | bash -s - ... +# + +# The Java version to install when it's not installed on the system yet +javaVersion=${JBANG_DEFAULT_JAVA_VERSION:-11} + +absolute_path() { + # if the given path to the jbang launcher is absolute (i.e. it is either starting with / or a + # 'letter:/' when using gitbash on windows) it is returned unchanged, otherwise we construct an absolute path + [[ $1 = /* ]] || [[ $1 =~ ^[A-z]:/ ]] && echo "$1" || echo "$PWD/${1#./}" +} + +resolve_symlink() { + if [[ $OSTYPE != darwin* ]]; then minusFarg="-f"; fi + sym_resolved=$(readlink ${minusFarg} $1) + + if [[ -n $sym_resolved ]]; then + echo $sym_resolved + else + echo $1 + fi +} + +download() { + if [ -x "$(command -v curl)" ]; then + curl -sLf -H "Accept: application/gzip, application/octet-stream" -o "$2" $1 + retval=$? + elif [ -x "$(command -v wget)" ]; then + wget -q --header="Accept: application/gzip, application/octet-stream" -O "$2" $1 + retval=$? + else + echo "Error: curl or wget not found, please make sure one of them is installed" 1>&2 + exit 1 + fi +} + +abs_jbang_path=/usr/local/Cellar/jbang/0.51.1/libexec/bin/jbang.jar + +case "$(uname -s)" in + Linux*) + os=linux;; + Darwin*) + os=mac;; + CYGWIN*|MINGW*) + os=windows;; + *) echo "Unsupported Operating System: $(uname -s)" 1>&2; exit 1;; +esac + +case "$(uname -m)" in + i?86) + arch=x32;; + x86_64|amd64) + arch=x64;; + aarch64) + arch=aarch64;; + *) + echo "Unsupported Architecture: $(uname -m)" 1>&2; exit 1;; +esac + +## when mingw/git bash or cygwin fall out to just running the bat file. +if [[ $os == windows ]]; then + $(dirname $abs_jbang_path)/jbang.cmd $* + exit $? +fi + +if [[ -z "$JBANG_DIR" ]]; then JBDIR="$HOME/.jbang"; else JBDIR="$JBANG_DIR"; fi +if [[ -z "$JBANG_CACHE_DIR" ]]; then TDIR="$JBDIR/cache"; else TDIR="$JBANG_CACHE_DIR"; fi + +## resolve application jar path from script location +if [ -f "$(dirname $abs_jbang_path)/jbang.jar" ]; then + jarPath=$(dirname $abs_jbang_path)/jbang.jar +elif [ -f "$(dirname $abs_jbang_path)/.jbang/jbang.jar" ]; then + jarPath=$(dirname $abs_jbang_path)/.jbang/jbang.jar +else + if [ ! -f "$JBDIR/bin/jbang.jar" ]; then + echo "Downloading JBang..." 1>&2 + mkdir -p "$TDIR/urls" + jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.tar" + download $jburl "$TDIR/urls/jbang.tar" + if [ $retval -ne 0 ]; then echo "Error downloading JBang" 1>&2; exit $retval; fi + echo "Installing JBang..." 1>&2 + rm -rf "$TDIR/urls/jbang" + tar xf "$TDIR/urls/jbang.tar" -C "$TDIR/urls" + if [ $retval -ne 0 ]; then echo "Error installing JBang" 1>&2; exit $retval; fi + rm -rf "$JBDIR/bin" + mv "$TDIR/urls/jbang/bin" "$JBDIR" + fi + eval "exec $JBDIR/bin/jbang $*" +fi + +# Find/get a JDK +unset JAVA_EXEC +if [[ -n "$JAVA_HOME" ]]; then + # Determine if a (working) JDK is available in JAVA_HOME + if [ -x "$(command -v $JAVA_HOME/bin/javac)" ]; then + JAVA_EXEC="$JAVA_HOME/bin/java"; + else + echo "JAVA_HOME is set but does not seem to point to a valid Java JDK" 1>&2 + fi +fi +if [[ -z "$JAVA_EXEC" ]]; then + # Determine if a (working) JDK is available on the PATH + if [ -x "$(command -v javac)" ]; then + JAVA_EXEC="java"; + elif [ -x "$JBDIR/currentjdk/bin/javac" ]; then + export JAVA_HOME="$JBDIR/currentjdk" + JAVA_EXEC="$JBDIR/currentjdk/bin/java"; + else + export JAVA_HOME="$TDIR/jdks/$javaVersion" + JAVA_EXEC="$JAVA_HOME/bin/java" + # Check if we installed a JDK before + if [ ! -d "$TDIR/jdks/$javaVersion" ]; then + # If not, download and install it + mkdir -p "$TDIR/jdks" + echo "Downloading JDK $javaVersion. Be patient, this can take several minutes..." 1>&2 + jdkurl="https://api.adoptopenjdk.net/v3/binary/latest/$javaVersion/ga/$os/$arch/jdk/hotspot/normal/adoptopenjdk" + download $jdkurl "$TDIR/bootstrap-jdk.tgz" + if [ $retval -ne 0 ]; then echo "Error downloading JDK" 1>&2; exit $retval; fi + echo "Installing JDK $javaVersion..." 1>&2 + rm -rf "$TDIR/jdks/$javaVersion.tmp/" + mkdir -p "$TDIR/jdks/$javaVersion.tmp" + tar xf "$TDIR/bootstrap-jdk.tgz" -C "$TDIR/jdks/$javaVersion.tmp" --strip-components=1 + retval=$? + if [[ $os == mac && $retval -eq 0 ]]; then + mv "$TDIR/jdks/$javaVersion.tmp/Contents/Home/"* "$TDIR/jdks/$javaVersion.tmp/" + retval=$? + fi + if [ $retval -ne 0 ]; then + # Check if the JDK was installed properly + javac -version > /dev/null 2>&1 + retval=$? + fi + if [ $retval -ne 0 ]; then echo "Error installing JDK" 1>&2; exit $retval; fi + # Activate the downloaded JDK giving it its proper name + mv "$TDIR/jdks/$javaVersion.tmp" "$TDIR/jdks/$javaVersion" + # Set the current JDK + ${JAVA_EXEC} -classpath ${jarPath} dev.jbang.Main jdk default $javaVersion + fi + fi +fi + +## https://stackoverflow.com/questions/1668649/how-to-keep-quotes-in-bash-arguments +## attempt to ensure each argument keeps its original quoting + +## run it using command substitution to have just the user process once jbang is done +output=$(CLICOLOR_FORCE=1 ${JAVA_EXEC} ${JBANG_JAVA_OPTIONS} -classpath ${jarPath} dev.jbang.Main "$@") +err=$? +if [ $err -eq 255 ]; then + eval "exec $output" +else + echo "$output" + exit $err +fi diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang.cmd b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang.cmd new file mode 100644 index 0000000000000..3bb58d87be1a1 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/base/jbang.cmd @@ -0,0 +1,109 @@ +@echo off +SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION + + +rem The Java version to install when it's not installed on the system yet +if "%JBANG_DEFAULT_JAVA_VERSION%"=="" (set javaVersion=11) else (set javaVersion=%JBANG_DEFAULT_JAVA_VERSION%) + +set os=windows +set arch=x64 + +set jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.zip" +set jdkurl="https://api.adoptopenjdk.net/v3/binary/latest/%javaVersion%/ga/%os%/%arch%/jdk/hotspot/normal/adoptopenjdk" + +if "%JBANG_DIR%"=="" (set JBDIR=%userprofile%\.jbang) else (set JBDIR=%JBANG_DIR%) +if "%JBANG_CACHE_DIR%"=="" (set TDIR=%JBDIR%\cache) else (set TDIR=%JBANG_CACHE_DIR%) + +rem resolve application jar path from script location and convert to windows path when using cygwin +if exist "%~dp0jbang.jar" ( + set jarPath=%~dp0jbang.jar +) else if exist "%~dp0.jbang\jbang.jar" ( + set jarPath=%~dp0.jbang\jbang.jar +) else ( + if not exist "%JBDIR%\bin\jbang.jar" ( + echo Downloading JBang... 1>&2 + if not exist "%TDIR%\urls" ( mkdir "%TDIR%\urls" ) + powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest %jburl% -OutFile %TDIR%\urls\jbang.zip" + if !ERRORLEVEL! NEQ 0 ( echo Error downloading JBang 1>&2 & exit /b %ERRORLEVEL% ) + echo Installing JBang... 1>&2 + if exist "%TDIR%\urls\jbang" ( rd /s /q "%TDIR%\urls\jbang" > nul 2>&1 ) + powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path %TDIR%\urls\jbang.zip -DestinationPath %TDIR%\urls" + if !ERRORLEVEL! NEQ 0 ( echo Error installing JBang 1>&2 & exit /b %ERRORLEVEL% ) + if exist "%JBDIR%\bin" ( rd /s /q "%JBDIR%\bin" > nul 2>&1 ) + move "%TDIR%\urls\jbang\bin" "%JBDIR%" > nul 2>&1 + ) + call "%JBDIR%\bin\jbang.cmd" %* + exit /b %ERRORLEVEL% +) + +rem Find/get a JDK +set JAVA_EXEC= +if not "%JAVA_HOME%"=="" ( + rem Determine if a (working) JDK is available in JAVA_HOME + if exist "%JAVA_HOME%\bin\javac.exe" ( + set JAVA_EXEC="%JAVA_HOME%\bin\java.exe" + ) else ( + echo JAVA_HOME is set but does not seem to point to a valid Java JDK 1>&2 + ) +) +if "!JAVA_EXEC!"=="" ( + rem Determine if a (working) JDK is available on the PATH + where javac > nul 2>&1 + if !errorlevel! equ 0 ( + set JAVA_EXEC=java.exe + ) else if exist "%JBDIR%\currentjdk\bin\javac" ( + set JAVA_HOME=%JBDIR%\currentjdk + set JAVA_EXEC=%JBDIR%\currentjdk\bin\java + ) else ( + set JAVA_HOME=%TDIR%\jdks\%javaVersion% + set JAVA_EXEC=!JAVA_HOME!\bin\java.exe + rem Check if we installed a JDK before + if not exist "%TDIR%\jdks\%javaVersion%" ( + rem If not, download and install it + if not exist "%TDIR%\jdks" ( mkdir "%TDIR%\jdks" ) + echo Downloading JDK %javaVersion%. Be patient, this can take several minutes... 1>&2 + powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest %jdkurl% -OutFile %TDIR%\bootstrap-jdk.zip" + if !ERRORLEVEL! NEQ 0 ( echo Error downloading JDK 1>&2 & exit /b %ERRORLEVEL% ) + echo Installing JDK %javaVersion%... 1>&2 + if exist "%TDIR%\jdks\%javaVersion%.tmp" ( rd /s /q "%TDIR%\jdks\%javaVersion%.tmp" > nul 2>&1 ) + powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path %TDIR%\bootstrap-jdk.zip -DestinationPath %TDIR%\jdks\%javaVersion%.tmp" + if !ERRORLEVEL! NEQ 0 ( echo Error installing JDK 1>&2 & exit /b %ERRORLEVEL% ) + for /d %%d in (%TDIR%\jdks\%javaVersion%.tmp\*) do ( + powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "Move-Item %%d\* !TDIR!\jdks\%javaVersion%.tmp" + if !ERRORLEVEL! NEQ 0 ( echo Error installing JDK 1>&2 & exit /b %ERRORLEVEL% ) + ) + rem Check if the JDK was installed properly + %TDIR%\jdks\%javaVersion%.tmp\bin\javac -version > nul 2>&1 + if !ERRORLEVEL! NEQ 0 ( echo "Error installing JDK" 1>&2; exit /b %ERRORLEVEL% ) + rem Activate the downloaded JDK giving it its proper name + ren "%TDIR%\jdks\%javaVersion%.tmp" "%javaVersion%" + ) + # Set the current JDK + !JAVA_EXEC! -classpath ${jarPath} dev.jbang.Main jdk default "%javaVersion%" + ) +) + +if not exist "%TDIR%" ( mkdir "%TDIR%" ) +set tmpfile=%TDIR%\%RANDOM%.jbang.tmp +rem execute jbang and pipe to temporary random file +set "CMD=!JAVA_EXEC!" +SETLOCAL DISABLEDELAYEDEXPANSION +%CMD% > "%tmpfile%" %JBANG_JAVA_OPTIONS% -classpath "%jarPath%" dev.jbang.Main %* +set ERROR=%ERRORLEVEL% +rem catch errorlevel straight after; rem or FOR /F swallow would have swallowed the errorlevel + +if %ERROR% EQU 255 ( + rem read generated java command by jang, delete temporary file and execute. + for %%A in ("%tmpfile%") do for /f "usebackq delims=" %%B in (%%A) do ( + set "OUTPUT=%%B" + goto :break + ) +:break + del "%tmpfile%" + %OUTPUT% + exit /b %ERRORLEVEL% +) else ( + type "%tmpfile%" + del "%tmpfile%" + exit /b %ERROR% +) diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/codestart.yml new file mode 100644 index 0000000000000..f74c6c6c37ef8 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus-jbang/tooling/jbang-wrapper/codestart.yml @@ -0,0 +1,5 @@ +name: jbang-wrapper +type: tooling +output-strategy: + "jbang": "executable" + "jbang.cmd": "executable" \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle-kotlin-dsl/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle-kotlin-dsl/codestart.yml index a0be0bbccf847..626e665f403c3 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle-kotlin-dsl/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle-kotlin-dsl/codestart.yml @@ -1,8 +1,5 @@ name: gradle-kotlin-dsl type: buildtool -output-strategy: - "gradlew": "executable" - "gradlew.bat": "executable" language: base: data: diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle/codestart.yml index 1cc103ccd1bae..9c270858246d5 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/gradle/codestart.yml @@ -1,8 +1,5 @@ name: gradle type: buildtool -output-strategy: - "gradlew": "executable" - "gradlew.bat": "executable" language: base: data: diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/maven/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/maven/codestart.yml index f225f4b3296d9..d6f22e887034b 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/maven/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/buildtool/maven/codestart.yml @@ -1,9 +1,6 @@ name: maven type: buildtool fallback: true -output-strategy: - "mvnw": "executable" - "mvnw.cmd": "executable" language: base: data: diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/gradle-wrapper/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/gradle-wrapper/codestart.yml index 27616afdc3296..f3dc5d19f5658 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/gradle-wrapper/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/gradle-wrapper/codestart.yml @@ -1,5 +1,8 @@ name: gradle-wrapper type: tooling +output-strategy: + "gradlew": "executable" + "gradlew.bat": "executable" language: base: data: diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/maven-wrapper/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/maven-wrapper/codestart.yml index 5633ecdaf1965..5146e94641432 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/maven-wrapper/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/tooling/maven-wrapper/codestart.yml @@ -1,5 +1,8 @@ name: maven-wrapper type: tooling +output-strategy: + "mvnw": "executable" + "mvnw.cmd": "executable" language: base: data: diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInput.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInput.java index e0f291b742846..957e672f18881 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInput.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInput.java @@ -13,7 +13,7 @@ public class CodestartProjectInput { private final CodestartsSelection selection; private final MessageWriter messageWriter; - CodestartProjectInput(final CodestartProjectInputBuilder builder) { + protected CodestartProjectInput(final CodestartProjectInputBuilder builder) { this.dependencies = requireNonNull(builder.dependencies, "dependencies is required"); this.selection = requireNonNull(builder.selection, "selection is required"); this.data = NestedMaps.unflatten(requireNonNull(builder.data, "data is required")); diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInputBuilder.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInputBuilder.java index 9ef73f671b28a..125c9a2e2ef61 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInputBuilder.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInputBuilder.java @@ -13,7 +13,7 @@ public class CodestartProjectInputBuilder { Map data = new HashMap<>(); MessageWriter messageWriter = MessageWriter.info(); - CodestartProjectInputBuilder() { + protected CodestartProjectInputBuilder() { } diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartCatalogs.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartCatalogs.java index 403439affc30c..122fe33f72307 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartCatalogs.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartCatalogs.java @@ -1,7 +1,5 @@ package io.quarkus.devtools.codestarts.core; -import static io.quarkus.devtools.codestarts.core.CodestartCatalogs.findLanguageName; - import io.quarkus.devtools.codestarts.Codestart; import io.quarkus.devtools.codestarts.CodestartException; import io.quarkus.devtools.codestarts.CodestartProjectInput; diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusPlatformCodestartResourceLoader.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusPlatformCodestartResourceLoader.java new file mode 100644 index 0000000000000..48a11a54038d4 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusPlatformCodestartResourceLoader.java @@ -0,0 +1,21 @@ +package io.quarkus.devtools.codestarts; + +import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import java.io.IOException; + +public final class QuarkusPlatformCodestartResourceLoader implements CodestartPathLoader { + private QuarkusPlatformDescriptor platformDescr; + + private QuarkusPlatformCodestartResourceLoader(QuarkusPlatformDescriptor platformDescr) { + this.platformDescr = platformDescr; + } + + public static CodestartPathLoader platformPathLoader(QuarkusPlatformDescriptor platformDescr) { + return new QuarkusPlatformCodestartResourceLoader(platformDescr); + } + + @Override + public T loadResourceAsPath(String name, PathConsumer consumer) throws IOException { + return platformDescr.loadResourceAsPath(name, consumer::consume); + } +} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java new file mode 100644 index 0000000000000..716bfa0fd3bf7 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java @@ -0,0 +1,64 @@ +package io.quarkus.devtools.codestarts.jbang; + +import static io.quarkus.devtools.codestarts.QuarkusPlatformCodestartResourceLoader.platformPathLoader; + +import io.quarkus.devtools.codestarts.Codestart; +import io.quarkus.devtools.codestarts.CodestartCatalogLoader; +import io.quarkus.devtools.codestarts.CodestartPathLoader; +import io.quarkus.devtools.codestarts.core.GenericCodestartCatalog; +import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public final class QuarkusJBangCodestartCatalog extends GenericCodestartCatalog { + + public static final String QUARKUS_JBANG_CODESTARTS_DIR = "codestarts/quarkus-jbang"; + + public enum Tooling implements KeySupplier { + JBANG_WRAPPER + } + + private QuarkusJBangCodestartCatalog(Collection codestarts) { + super(codestarts); + } + + public static QuarkusJBangCodestartCatalog fromQuarkusPlatformDescriptor(QuarkusPlatformDescriptor platformDescriptor) + throws IOException { + final CodestartPathLoader pathLoader = platformPathLoader(platformDescriptor); + final Collection codestarts = CodestartCatalogLoader.loadCodestarts(pathLoader, + QUARKUS_JBANG_CODESTARTS_DIR); + return new QuarkusJBangCodestartCatalog(codestarts); + } + + @Override + protected Collection select(QuarkusJBangCodestartProjectInput projectInput) { + + if (projectInput.getDependencies().stream().anyMatch(s -> s.contains("quarkus-picocli"))) { + projectInput.getSelection().addName("picocli"); + } else { + projectInput.getSelection().addName("resteasy"); + } + + // Add codestarts from extension and for tooling + projectInput.getSelection().addNames(getToolingCodestarts(projectInput)); + + return super.select(projectInput); + } + + private List getToolingCodestarts(QuarkusJBangCodestartProjectInput projectInput) { + final List codestarts = new ArrayList<>(); + if (!projectInput.noJBangWrapper()) { + codestarts.add(Tooling.JBANG_WRAPPER.getKey()); + } + return codestarts; + } + + interface KeySupplier { + default String getKey() { + return this.toString().toLowerCase().replace("_", "-"); + } + } + +} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInput.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInput.java new file mode 100644 index 0000000000000..07579f55d0eb8 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInput.java @@ -0,0 +1,29 @@ +package io.quarkus.devtools.codestarts.jbang; + +import io.quarkus.bootstrap.model.AppArtifactCoords; +import io.quarkus.devtools.codestarts.CodestartProjectInput; +import java.util.Collection; + +public final class QuarkusJBangCodestartProjectInput extends CodestartProjectInput { + private final Collection extensions; + private final boolean noJBangWrapper; + + public QuarkusJBangCodestartProjectInput(QuarkusJBangCodestartProjectInputBuilder builder) { + super(builder); + this.extensions = builder.extensions; + this.noJBangWrapper = builder.noJBangWrapper; + } + + public static QuarkusJBangCodestartProjectInputBuilder builder() { + return new QuarkusJBangCodestartProjectInputBuilder(); + } + + public boolean noJBangWrapper() { + return noJBangWrapper; + } + + public Collection getExtensions() { + return extensions; + } + +} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java new file mode 100644 index 0000000000000..1fd1aa3138702 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java @@ -0,0 +1,80 @@ +package io.quarkus.devtools.codestarts.jbang; + +import io.quarkus.bootstrap.model.AppArtifactCoords; +import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.devtools.codestarts.CodestartProjectInputBuilder; +import io.quarkus.devtools.messagewriter.MessageWriter; +import io.quarkus.devtools.project.extensions.Extensions; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +public class QuarkusJBangCodestartProjectInputBuilder extends CodestartProjectInputBuilder { + public Collection extensions = new ArrayList<>(); + + public QuarkusJBangCodestartProjectInputBuilder setNoJBangWrapper(boolean noJBangWrapper) { + this.noJBangWrapper = noJBangWrapper; + return this; + } + + public boolean noJBangWrapper; + + QuarkusJBangCodestartProjectInputBuilder() { + super(); + } + + public QuarkusJBangCodestartProjectInputBuilder addExtensions(Collection extensions) { + this.extensions.addAll(extensions); + super.addDependencies(extensions.stream().map(Extensions::toGAV).collect(Collectors.toList())); + return this; + } + + public QuarkusJBangCodestartProjectInputBuilder addExtension(AppArtifactCoords extension) { + return this.addExtensions(Collections.singletonList(extension)); + } + + public QuarkusJBangCodestartProjectInputBuilder addExtension(AppArtifactKey extension) { + return this.addExtension(Extensions.toCoords(extension, null)); + } + + @Override + public QuarkusJBangCodestartProjectInputBuilder addCodestarts(Collection codestarts) { + super.addCodestarts(codestarts); + return this; + } + + @Override + public QuarkusJBangCodestartProjectInputBuilder addCodestart(String codestart) { + super.addCodestart(codestart); + return this; + } + + @Override + public QuarkusJBangCodestartProjectInputBuilder addData(Map data) { + super.addData(data); + return this; + } + + @Override + public QuarkusJBangCodestartProjectInputBuilder putData(String key, Object value) { + super.putData(key, value); + return this; + } + + @Override + public QuarkusJBangCodestartProjectInputBuilder messageWriter(MessageWriter messageWriter) { + super.messageWriter(messageWriter); + return this; + } + + public boolean noJBangWrapper() { + return noJBangWrapper; + } + + public QuarkusJBangCodestartProjectInput build() { + return new QuarkusJBangCodestartProjectInput(this); + } + +} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartCatalog.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java similarity index 88% rename from independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartCatalog.java rename to independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java index 25d3967a5efd5..d5042030c229a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartCatalog.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java @@ -1,8 +1,15 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; +import static io.quarkus.devtools.codestarts.QuarkusPlatformCodestartResourceLoader.platformPathLoader; import static io.quarkus.devtools.codestarts.core.CodestartCatalogs.findLanguageName; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.codestarts.Codestart; +import io.quarkus.devtools.codestarts.CodestartCatalogLoader; +import io.quarkus.devtools.codestarts.CodestartException; +import io.quarkus.devtools.codestarts.CodestartPathLoader; +import io.quarkus.devtools.codestarts.CodestartStructureException; +import io.quarkus.devtools.codestarts.CodestartType; import io.quarkus.devtools.codestarts.core.GenericCodestartCatalog; import io.quarkus.devtools.project.extensions.Extensions; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; @@ -71,11 +78,6 @@ public static QuarkusCodestartCatalog fromQuarkusPlatformDescriptorAndDirectorie return new QuarkusCodestartCatalog(codestarts, extensionCodestartMapping); } - @Override - public CodestartProjectDefinition createProject(QuarkusCodestartProjectInput projectInput) { - return super.createProject(projectInput); - } - @Override protected Collection select(QuarkusCodestartProjectInput projectInput) { // Add codestarts from extension and for tooling @@ -153,25 +155,8 @@ private List getToolingCodestarts(QuarkusCodestartProjectInput projectIn return codestarts; } - public static CodestartPathLoader platformPathLoader(QuarkusPlatformDescriptor platformDescr) { - return new QuarkusPlatformCodestartResourceLoader(platformDescr); - } - public static boolean isExample(Codestart codestart) { return codestart.getType() == CodestartType.CODE && codestart.getSpec().getTags().contains(Tag.EXAMPLE.getKey()); - } - - private static class QuarkusPlatformCodestartResourceLoader implements CodestartPathLoader { - private QuarkusPlatformDescriptor platformDescr; - - QuarkusPlatformCodestartResourceLoader(QuarkusPlatformDescriptor platformDescr) { - this.platformDescr = platformDescr; - } - - @Override - public T loadResourceAsPath(String name, PathConsumer consumer) throws IOException { - return platformDescr.loadResourceAsPath(name, consumer::consume); - } }; interface KeySupplier { diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java similarity index 99% rename from independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java rename to independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java index 202798f5506aa..d54be2a604af4 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java @@ -1,4 +1,4 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import io.quarkus.devtools.codestarts.utils.NestedMaps; import java.util.HashMap; diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartProjectInput.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartProjectInput.java similarity index 92% rename from independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartProjectInput.java rename to independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartProjectInput.java index 0985a8aa060d1..a37f66a3e4811 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartProjectInput.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartProjectInput.java @@ -1,8 +1,9 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import static java.util.Objects.requireNonNull; import io.quarkus.bootstrap.model.AppArtifactCoords; +import io.quarkus.devtools.codestarts.CodestartProjectInput; import io.quarkus.devtools.project.BuildTool; import java.util.Collection; diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartProjectInputBuilder.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartProjectInputBuilder.java similarity index 96% rename from independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartProjectInputBuilder.java rename to independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartProjectInputBuilder.java index ad28f7360c183..3dba482355365 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartProjectInputBuilder.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartProjectInputBuilder.java @@ -1,9 +1,10 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import static java.util.Objects.requireNonNull; import io.quarkus.bootstrap.model.AppArtifactCoords; import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.devtools.codestarts.CodestartProjectInputBuilder; import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.extensions.Extensions; diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java index 7f323ac277233..7c53c223489ca 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java @@ -13,9 +13,9 @@ import io.quarkus.bootstrap.model.AppArtifactCoords; import io.quarkus.devtools.codestarts.CodestartProjectDefinition; import io.quarkus.devtools.codestarts.CodestartType; -import io.quarkus.devtools.codestarts.QuarkusCodestartCatalog; -import io.quarkus.devtools.codestarts.QuarkusCodestartData.LegacySupport; -import io.quarkus.devtools.codestarts.QuarkusCodestartProjectInput; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.LegacySupport; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartProjectInput; import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java new file mode 100644 index 0000000000000..07c07f09dc820 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java @@ -0,0 +1,41 @@ +package io.quarkus.devtools.codestarts.jbang; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import io.quarkus.devtools.PlatformAwareTestBase; +import io.quarkus.devtools.ProjectTestUtil; + +class QuarkusJBangCodestartGenerationTest extends PlatformAwareTestBase { + + private static final Path testDirPath = Paths.get("target/jbang-codestart-gen-test"); + + @BeforeAll + static void setUp() throws IOException { + ProjectTestUtil.delete(testDirPath.toFile()); + } + + @Test + void generateDefaultProject() throws IOException { + final QuarkusJBangCodestartProjectInput input = QuarkusJBangCodestartProjectInput.builder() + .putData("quarkus.version", "999-SNAPSHOT") + .build(); + final Path projectDir = testDirPath.resolve("default"); + getCatalog().createProject(input).generate(projectDir); + + assertThat(projectDir.resolve("jbang")).exists(); + assertThat(projectDir.resolve("src/ExampleResource.java")).exists(); + + } + + private QuarkusJBangCodestartCatalog getCatalog() throws IOException { + return QuarkusJBangCodestartCatalog.fromQuarkusPlatformDescriptor(getPlatformDescriptor()); + } + +} diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartCatalogTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java similarity index 95% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartCatalogTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java index 0c30e00a9f999..f003bc77e0373 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartCatalogTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java @@ -1,4 +1,4 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import static org.assertj.core.api.Assertions.assertThat; @@ -12,11 +12,14 @@ import io.quarkus.bootstrap.model.AppArtifactKey; import io.quarkus.devtools.PlatformAwareTestBase; import io.quarkus.devtools.ProjectTestUtil; +import io.quarkus.devtools.codestarts.Codestart; +import io.quarkus.devtools.codestarts.CodestartProjectDefinition; +import io.quarkus.devtools.codestarts.CodestartType; import io.quarkus.devtools.project.BuildTool; class QuarkusCodestartCatalogTest extends PlatformAwareTestBase { - private final Path projectPath = Paths.get("target/codestarts-test"); + private final Path projectPath = Paths.get("target/quarkus-codestart-catalog-test"); @BeforeEach void setUp() throws IOException { @@ -24,7 +27,7 @@ void setUp() throws IOException { } @Test - void loadQuarkusCodestartsTest() throws IOException { + void loadTest() throws IOException { final QuarkusCodestartCatalog catalog = getCatalog(); assertThat(catalog.getCodestarts()) .filteredOn(c -> c.getType().isBase()) diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartGenerationTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java similarity index 95% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartGenerationTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java index ebd0ed34cf900..293be76d114d7 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartGenerationTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java @@ -1,7 +1,7 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import static io.quarkus.devtools.ProjectTestUtil.checkContains; -import static io.quarkus.devtools.codestarts.QuarkusCodestartData.DataKey.*; +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.DataKey.*; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; @@ -23,7 +23,7 @@ class QuarkusCodestartGenerationTest extends PlatformAwareTestBase { - private static final Path testDirPath = Paths.get("target/codestarts-test"); + private static final Path testDirPath = Paths.get("target/quarkus-codestart-gen-test"); @BeforeAll static void setUp() throws IOException { @@ -60,14 +60,14 @@ static Map getTestInputData(final QuarkusPlatformDescriptor desc } @Test - void generateProjectEmpty() throws IOException { + void generateDefault() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .noExamples() .noDockerfiles() .noBuildToolWrapper() .addData(getTestInputData()) .build(); - final Path projectDir = testDirPath.resolve("empty"); + final Path projectDir = testDirPath.resolve("default"); getCatalog().createProject(input).generate(projectDir); checkMaven(projectDir); @@ -80,13 +80,13 @@ void generateProjectEmpty() throws IOException { } @Test - void generateProjectCommandMode() throws IOException { + void generateCommandMode() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addCodestart("commandmode") .addData(getTestInputData()) .build(); - final Path projectDir = testDirPath.resolve("default-examples"); + final Path projectDir = testDirPath.resolve("commandmode"); getCatalog().createProject(input).generate(projectDir); checkMaven(projectDir); @@ -98,7 +98,7 @@ void generateProjectCommandMode() throws IOException { } @Test - void generateProjectCommandModeCustom() throws IOException { + void generateCommandModeCustom() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addCodestart("commandmode") .addData(getTestInputData()) @@ -119,7 +119,7 @@ void generateProjectCommandModeCustom() throws IOException { } @Test - void generateProjectRESTEasyJavaCustom() throws IOException { + void generateRESTEasyJavaCustom() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getTestInputData()) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -155,7 +155,7 @@ void generateProjectRESTEasyJavaCustom() throws IOException { } @Test - void generateProjectRESTEasySpringWeb() throws IOException { + void generateRESTEasySpringWeb() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getTestInputData()) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -185,7 +185,7 @@ void generateProjectRESTEasySpringWeb() throws IOException { } @Test - void generateMavenProjectWithCustomDep() throws IOException { + void generateMavenWithCustomDep() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getTestInputData()) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -209,7 +209,7 @@ void generateMavenProjectWithCustomDep() throws IOException { } @Test - void generateProjectRESTEasyKotlinCustom() throws IOException { + void generateRESTEasyKotlinCustom() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getTestInputData()) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -242,7 +242,7 @@ void generateProjectRESTEasyKotlinCustom() throws IOException { } @Test - void generateProjectRESTEasyScalaCustom() throws IOException { + void generateRESTEasyScalaCustom() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getTestInputData()) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -275,7 +275,7 @@ void generateProjectRESTEasyScalaCustom() throws IOException { } @Test - void generateProjectMavenDefaultJava() throws IOException { + void generateMavenDefaultJava() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getTestInputData()) .build(); @@ -293,7 +293,7 @@ void generateProjectMavenDefaultJava() throws IOException { } @Test - void generateProjectMavenResteasyJava() throws IOException { + void generateMavenResteasyJava() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) .addData(getTestInputData()) @@ -312,7 +312,7 @@ void generateProjectMavenResteasyJava() throws IOException { } @Test - void generateProjectMavenConfigYamlJava() throws IOException { + void generateMavenConfigYamlJava() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-config-yaml")) .addData(getTestInputData()) @@ -329,7 +329,7 @@ void generateProjectMavenConfigYamlJava() throws IOException { } @Test - void generateProjectMavenResteasyKotlin() throws IOException { + void generateMavenResteasyKotlin() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-kotlin")) @@ -349,7 +349,7 @@ void generateProjectMavenResteasyKotlin() throws IOException { } @Test - void generateProjectMavenResteasyScala() throws IOException { + void generateMavenResteasyScala() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-scala")) @@ -369,7 +369,7 @@ void generateProjectMavenResteasyScala() throws IOException { } @Test - void generateProjectGradleResteasyJava() throws IOException { + void generateGradleResteasyJava() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .buildTool(BuildTool.GRADLE) .addCodestart("gradle") @@ -390,7 +390,7 @@ void generateProjectGradleResteasyJava() throws IOException { } @Test - void generateProjectGradleResteasyKotlin() throws IOException { + void generateGradleResteasyKotlin() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .buildTool(BuildTool.GRADLE) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -412,7 +412,7 @@ void generateProjectGradleResteasyKotlin() throws IOException { } @Test - void generateProjectGradleResteasyScala() throws IOException { + void generateGradleResteasyScala() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .buildTool(BuildTool.GRADLE) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -433,7 +433,7 @@ void generateProjectGradleResteasyScala() throws IOException { } @Test - void generateProjectGradleWithKotlinDslResteasyJava() throws IOException { + void generateGradleWithKotlinDslResteasyJava() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .buildTool(BuildTool.GRADLE_KOTLIN_DSL) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -451,7 +451,7 @@ void generateProjectGradleWithKotlinDslResteasyJava() throws IOException { } @Test - void generateProjectGradleWithKotlinDslResteasyKotlin() throws IOException { + void generateGradleWithKotlinDslResteasyKotlin() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .buildTool(BuildTool.GRADLE_KOTLIN_DSL) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -470,7 +470,7 @@ void generateProjectGradleWithKotlinDslResteasyKotlin() throws IOException { } @Test - void generateProjectGradleWithKotlinDslResteasyScala() throws IOException { + void generateGradleWithKotlinDslResteasyScala() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .buildTool(BuildTool.GRADLE_KOTLIN_DSL) .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-resteasy")) @@ -489,7 +489,7 @@ void generateProjectGradleWithKotlinDslResteasyScala() throws IOException { } @Test - void generateProjectQute() throws IOException { + void generateQute() throws IOException { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-qute")) .addCodestart("qute") diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartRunIT.java similarity index 93% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartRunIT.java index bc771b037430a..2d5121d9eeded 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartRunIT.java @@ -1,4 +1,4 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import static org.assertj.core.api.Assertions.assertThat; @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -24,14 +25,16 @@ import io.quarkus.devtools.PlatformAwareTestBase; import io.quarkus.devtools.ProjectTestUtil; -import io.quarkus.devtools.codestarts.QuarkusCodestartCatalog.Tag; -import io.quarkus.devtools.codestarts.QuarkusCodestartData.DataKey; +import io.quarkus.devtools.codestarts.Codestart; +import io.quarkus.devtools.codestarts.CodestartProjectDefinition; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Tag; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.DataKey; import io.quarkus.devtools.project.BuildTool; @TestInstance(TestInstance.Lifecycle.PER_CLASS) class QuarkusCodestartRunIT extends PlatformAwareTestBase { - private static final Path testDirPath = Paths.get("target/codestarts-run-test"); + private static final Path testDirPath = Paths.get("target/quarkus-codestart-run-test"); private static final Set EXCLUDED = Sets.newHashSet( "azure-functions-http-example", "commandmode-example"); @@ -161,7 +164,9 @@ private void generateProjectRunTests(String buildToolName, String language, List private String genName(String buildtool, String language, List codestarts) { String name = "project-" + buildtool + "-" + language; if (codestarts.isEmpty()) { - name += "-commandmode"; + name += "-default"; + } else if (codestarts.size() > 2) { + name += "-" + UUID.randomUUID().toString(); } else { name += "-" + String.join("-", codestarts); } diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/WrapperRunner.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/WrapperRunner.java similarity index 98% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/WrapperRunner.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/WrapperRunner.java index 768f29f96ad3f..07411f43e6951 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/WrapperRunner.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/WrapperRunner.java @@ -1,4 +1,4 @@ -package io.quarkus.devtools.codestarts; +package io.quarkus.devtools.codestarts.quarkus; import java.io.IOException; import java.io.UncheckedIOException;