diff --git a/daemon/src/main/distro/bin/mvn.cmd b/daemon/src/main/distro/bin/mvn.cmd new file mode 100644 index 00000000..9b30b480 --- /dev/null +++ b/daemon/src/main/distro/bin/mvn.cmd @@ -0,0 +1,207 @@ +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. + +@REM ----------------------------------------------------------------------------- +@REM Apache Maven Startup Script +@REM +@REM Environment Variable Prerequisites +@REM +@REM JAVA_HOME Must point at your Java Development Kit installation. +@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands. +@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending. +@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed. +@REM MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. +@REM ----------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%"=="on" echo %MAVEN_BATCH_ECHO% + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%"=="" goto OkJHome +for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" +goto checkJCmd + +:OkJHome +set "JAVACMD=%JAVA_HOME%\bin\java.exe" + +:checkJCmd +if exist "%JAVACMD%" goto chkMHome + +echo The JAVA_HOME environment variable is not defined correctly >&2 +echo This environment variable is needed to run this program >&2 +echo NB: JAVA_HOME should point to a JDK not a JRE >&2 +goto error + +:chkMHome +set "MAVEN_HOME=%~dp0.." +if not "%MAVEN_HOME%"=="" goto stripMHome +goto error + +:stripMHome +if not "_%MAVEN_HOME:~-1%"=="_\" goto checkMCmd +set "MAVEN_HOME=%MAVEN_HOME:~0,-1%" +goto stripMHome + +:checkMCmd +if exist "%MAVEN_HOME%\bin\mvn.cmd" goto init +goto error +@REM ==== END VALIDATION ==== + +:init + +set MAVEN_CMD_LINE_ARGS=%* + +@REM Find the project basedir, i.e., the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set "MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%" +if not "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set "EXEC_DIR=%CD%" +set "WDIR=%EXEC_DIR%" + +@REM Look for the --file switch and start the search for the .mvn directory from the specified +@REM POM location, if supplied. + +set FILE_ARG= +:arg_loop +if "%~1" == "-f" ( + set "FILE_ARG=%~2" + shift + goto process_file_arg +) +if "%~1" == "--file" ( + set "FILE_ARG=%~2" + shift + goto process_file_arg +) +@REM If none of the above, skip the argument +shift +if not "%~1" == "" ( + goto arg_loop +) else ( + goto findBaseDir +) + +:process_file_arg +if "%FILE_ARG%" == "" ( + goto findBaseDir +) +if not exist "%FILE_ARG%" ( + echo POM file "%FILE_ARG%" specified the -f/--file command-line argument does not exist >&2 + goto error +) +if exist "%FILE_ARG%\*" ( + set "POM_DIR=%FILE_ARG%" +) else ( + call :get_directory_from_file "%FILE_ARG%" +) +if not exist "%POM_DIR%" ( + echo Directory "%POM_DIR%" extracted from the -f/--file command-line argument "%FILE_ARG%" does not exist >&2 + goto error +) +set "WDIR=%POM_DIR%" +goto findBaseDir + +:get_directory_from_file +set "POM_DIR=%~dp1" +:stripPomDir +if not "_%POM_DIR:~-1%"=="_\" goto pomDirStripped +set "POM_DIR=%POM_DIR:~0,-1%" +goto stripPomDir +:pomDirStripped +exit /b + +:findBaseDir +cd /d "%WDIR%" +:findBaseDirLoop +if exist "%WDIR%\.mvn" goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set "WDIR=%CD%" +goto findBaseDirLoop + +:baseDirFound +set "MAVEN_PROJECTBASEDIR=%WDIR%" +cd /d "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +if "_%EXEC_DIR:~-1%"=="_\" set "EXEC_DIR=%EXEC_DIR:~0,-1%" +set "MAVEN_PROJECTBASEDIR=%EXEC_DIR%" +cd "%EXEC_DIR%" + +:endDetectBaseDir + +set "jvmConfig=\.mvn\jvm.config" +if not exist "%MAVEN_PROJECTBASEDIR%%jvmConfig%" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +for %%i in ("%MAVEN_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i" +set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +"%JAVACMD%" ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %CLASSWORLDS_JAR% ^ + "-Dlogback.configurationFile=%MAVEN_HOME%\conf\logging\logback-mvn.xml" ^ + "-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^ + "-Dmvnd.home=%MAVEN_HOME%" ^ + "-Dmaven.home=%MAVEN_HOME%" ^ + "-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS% +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java new file mode 100644 index 00000000..6fc0a00e --- /dev/null +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java @@ -0,0 +1,72 @@ +/* + * Copyright 2019 the original author or 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 + * + * http://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.jboss.fuse.mvnd.it; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.regex.Pattern; +import javax.inject.Inject; +import org.assertj.core.api.Assertions; +import org.jboss.fuse.mvnd.client.Client; +import org.jboss.fuse.mvnd.client.ClientLayout; +import org.jboss.fuse.mvnd.common.logging.ClientOutput; +import org.jboss.fuse.mvnd.junit.MvndNativeTest; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@MvndNativeTest(projectDir = "src/test/projects/invoker") +public class InvokerNativeIT { + + @Inject + Client client; + + @Inject + ClientLayout layout; + + @Test + void cleanInstall() throws IOException, InterruptedException { + + final Path helloPath = layout.multiModuleProjectDirectory().resolve("target/it/invoke-hello/target/hello.txt"); + try { + Files.deleteIfExists(helloPath); + } catch (IOException e) { + throw new RuntimeException("Could not delete " + helloPath); + } + final Path logPath = layout.multiModuleProjectDirectory().resolve("target/it/invoke-hello/build.log"); + try { + Files.deleteIfExists(logPath); + } catch (IOException e) { + throw new RuntimeException("Could not delete " + helloPath); + } + + final ClientOutput output = Mockito.mock(ClientOutput.class); + client.execute(output, "clean", "verify", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess(); + + Assertions.assertThat(helloPath).exists(); + Assertions.assertThat(helloPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hello"); + + Assertions.assertThat(logPath).exists(); + final List logLines = Files.readAllLines(logPath, StandardCharsets.UTF_8); + Assertions.assertThat(logLines.size()).isGreaterThan(0); + + final String lastLine = logLines.get(logLines.size() - 1); + Assertions.assertThat(lastLine).matches(Pattern.compile("\\QFinished post-build script: \\E.*verify.groovy$")); + + } +} diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java new file mode 100644 index 00000000..6ccd6115 --- /dev/null +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 the original author or 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 + * + * http://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.jboss.fuse.mvnd.it; + +import org.jboss.fuse.mvnd.junit.MvndTest; + +@MvndTest(projectDir = "src/test/projects/invoker") +public class InvokerTest extends InvokerNativeIT { + +} diff --git a/integration-tests/src/test/projects/invoker/.mvn/.gitkeep b/integration-tests/src/test/projects/invoker/.mvn/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/integration-tests/src/test/projects/invoker/pom.xml b/integration-tests/src/test/projects/invoker/pom.xml new file mode 100644 index 00000000..fc7bb9a0 --- /dev/null +++ b/integration-tests/src/test/projects/invoker/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + org.jboss.fuse.mvnd.test.invoker + invoker-hello-maven-plugin + 0.0.1-SNAPSHOT + maven-plugin + + + UTF-8 + 1.8 + 1.8 + + 2.5 + 3.8.0 + 2.4 + 2.6 + 3.0.0-M5 + + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + 3.5 + + + org.apache.maven + maven-plugin-api + 3.6.0 + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + maven-invoker-plugin + 3.2.1 + + ${project.build.directory}/it + ${project.build.directory}/local-repo + verify + + + + integration-test + + install + run + verify + + + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties new file mode 100644 index 00000000..14ea3e30 --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties @@ -0,0 +1,15 @@ +# +# Copyright 2017 Decipher Technology Studios LLC +# +# 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 +# +# http://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. +invoker.goals=validate diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml new file mode 100644 index 00000000..40402d22 --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml @@ -0,0 +1,104 @@ + + + 4.0.0 + + org.jboss.fuse.mvnd.test.invoker + invoke-hello + 0.0.1-SNAPSHOT + pom + + + UTF-8 + 1.8 + 1.8 + + 2.5 + 3.8.0 + 2.4 + 2.6 + 3.0.0-M5 + + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + 3.5 + + + org.apache.maven + maven-plugin-api + 3.6.0 + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + org.jboss.fuse.mvnd.test.invoker + invoker-hello-maven-plugin + @project.version@ + + + hello + + hello + + validate + + ${basedir}/target/hello.txt + + + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy new file mode 100644 index 00000000..26c2935e --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy @@ -0,0 +1,24 @@ +/* + * Copyright 2019 the original author or 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 + * + * http://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. + */ +import java.nio.file.Path; +import java.nio.file.Files; + +Path basePath = basedir.toPath() +Path helloPath = basePath.resolve('target/hello.txt') + +assert Files.exists(helloPath) + +assert helloPath.text.equals('Hello') diff --git a/integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java b/integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java new file mode 100644 index 00000000..3205a80e --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019 the original author or 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 + * + * http://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.jboss.fuse.mvnd.test.invoker.hello; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + */ +@Mojo(name = "hello", requiresProject = true) +public class HelloMojo extends AbstractMojo { + + @Parameter + File file; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + try { + final Path path = file.toPath(); + Files.createDirectories(path.getParent()); + Files.write(path, "Hello".getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new RuntimeException("", e); + } + + } + +}