diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/ModuleAndPluginNativeIT.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/ModuleAndPluginNativeIT.java new file mode 100644 index 00000000..07238911 --- /dev/null +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/ModuleAndPluginNativeIT.java @@ -0,0 +1,85 @@ +/* + * 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.stream.Stream; + +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.client.ClientOutput; +import org.jboss.fuse.mvnd.junit.MvndNativeTest; +import org.jboss.fuse.mvnd.junit.MvndTest; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@MvndNativeTest(projectDir = "src/test/projects/module-and-plugin") +public class ModuleAndPluginNativeIT { + + @Inject + Client client; + + @Inject + ClientLayout layout; + + @Test + void cleanInstall() throws IOException, InterruptedException { + final Path helloPath = layout.multiModuleProjectDirectory().resolve("hello/target/hello.txt"); + try { + Files.deleteIfExists(helloPath); + } catch (IOException e) { + throw new RuntimeException("Could not delete " + helloPath); + } + + final Path localMavenRepo = layout.getLocalMavenRepository(); + final Path[] installedJars = { + localMavenRepo.resolve("org/jboss/fuse/mvnd/test/module-and-plugin/module-and-plugin-maven-plugin/0.0.1-SNAPSHOT/module-and-plugin-maven-plugin-0.0.1-SNAPSHOT.jar"), + }; + Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).doesNotExist()); + + /* Build #1: with "Hello" output to target/hello.txt */ + { + final ClientOutput output = Mockito.mock(ClientOutput.class); + client.execute(output, "clean", "install", "-e").assertSuccess(); + + Assertions.assertThat(helloPath).exists(); + Assertions.assertThat(helloPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hello"); + Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).exists()); + } + + /* Build #2: with the mojo source changed to output "Hi" to target/hello.txt */ + { + final Path mojoPath = layout.multiModuleProjectDirectory().resolve("plugin/src/main/java/org/jboss/fuse/mvnd/test/module/plugin/mojo/HelloMojo.java"); + String mojoSource = new String(Files.readAllBytes(mojoPath), StandardCharsets.UTF_8); + mojoSource = mojoSource.replace("\"Hello\".getBytes", "\"Hi\".getBytes"); + Files.write(mojoPath, mojoSource.getBytes(StandardCharsets.UTF_8)); + + final ClientOutput output = Mockito.mock(ClientOutput.class); + client.execute(output, "clean", "install", "-e").assertSuccess(); + + Assertions.assertThat(helloPath).exists(); + Assertions.assertThat(helloPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hi"); + Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).exists()); + } + + } +} diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/ModuleAndPluginTest.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/ModuleAndPluginTest.java new file mode 100644 index 00000000..9ca1875c --- /dev/null +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/ModuleAndPluginTest.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/module-and-plugin") +public class ModuleAndPluginTest extends ModuleAndPluginNativeIT { + +} diff --git a/integration-tests/src/test/projects/module-and-plugin/hello/pom.xml b/integration-tests/src/test/projects/module-and-plugin/hello/pom.xml new file mode 100644 index 00000000..cbb208fd --- /dev/null +++ b/integration-tests/src/test/projects/module-and-plugin/hello/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + org.jboss.fuse.mvnd.test.module-and-plugin + module-and-plugin + 0.0.1-SNAPSHOT + ../pom.xml + + + module-and-plugin-hello + + + + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + test + + + + + + + org.jboss.fuse.mvnd.test.module-and-plugin + module-and-plugin-maven-plugin + 0.0.1-SNAPSHOT + + + hello + + hello + + compile + + ${basedir}/target/hello.txt + + + + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/module-and-plugin/hello/src/main/java/org/jboss/fuse/mvnd/test/multi/module/hello/Hello.java b/integration-tests/src/test/projects/module-and-plugin/hello/src/main/java/org/jboss/fuse/mvnd/test/multi/module/hello/Hello.java new file mode 100644 index 00000000..81a5e823 --- /dev/null +++ b/integration-tests/src/test/projects/module-and-plugin/hello/src/main/java/org/jboss/fuse/mvnd/test/multi/module/hello/Hello.java @@ -0,0 +1,9 @@ +package org.jboss.fuse.mvnd.test.multi.module.hello; + +public class Hello { + + public String greet() { + return "Hello"; + } + +} diff --git a/integration-tests/src/test/projects/module-and-plugin/hello/src/test/java/org/jboss/fuse/mvnd/test/multi/module/hello/HelloTest.java b/integration-tests/src/test/projects/module-and-plugin/hello/src/test/java/org/jboss/fuse/mvnd/test/multi/module/hello/HelloTest.java new file mode 100644 index 00000000..1a25ffed --- /dev/null +++ b/integration-tests/src/test/projects/module-and-plugin/hello/src/test/java/org/jboss/fuse/mvnd/test/multi/module/hello/HelloTest.java @@ -0,0 +1,23 @@ +package org.jboss.fuse.mvnd.test.multi.module.hello; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class HelloTest { + + @Test + void greet() throws IOException { + final String actual = new Hello().greet(); + Assertions.assertEquals("Hello", actual); + + /* Make sure the plugin was run before this test */ + final String content = new String(Files.readAllBytes(Paths.get("target/hello.txt")), StandardCharsets.UTF_8); + Assertions.assertTrue("Hi".equals(content) || "Hello".equals(content)); + } + +} diff --git a/integration-tests/src/test/projects/module-and-plugin/plugin/pom.xml b/integration-tests/src/test/projects/module-and-plugin/plugin/pom.xml new file mode 100644 index 00000000..0554e0e9 --- /dev/null +++ b/integration-tests/src/test/projects/module-and-plugin/plugin/pom.xml @@ -0,0 +1,29 @@ + + 4.0.0 + + org.jboss.fuse.mvnd.test.module-and-plugin + module-and-plugin + 0.0.1-SNAPSHOT + ../pom.xml + + + module-and-plugin-maven-plugin + maven-plugin + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + 3.5 + + + org.apache.maven + maven-plugin-api + 3.6.0 + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/module-and-plugin/plugin/src/main/java/org/jboss/fuse/mvnd/test/module/plugin/mojo/HelloMojo.java b/integration-tests/src/test/projects/module-and-plugin/plugin/src/main/java/org/jboss/fuse/mvnd/test/module/plugin/mojo/HelloMojo.java new file mode 100644 index 00000000..fc0728ac --- /dev/null +++ b/integration-tests/src/test/projects/module-and-plugin/plugin/src/main/java/org/jboss/fuse/mvnd/test/module/plugin/mojo/HelloMojo.java @@ -0,0 +1,36 @@ +package org.jboss.fuse.mvnd.test.module.plugin.mojo; + +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); + } + + } + +} diff --git a/integration-tests/src/test/projects/module-and-plugin/pom.xml b/integration-tests/src/test/projects/module-and-plugin/pom.xml new file mode 100644 index 00000000..6fe5d0c6 --- /dev/null +++ b/integration-tests/src/test/projects/module-and-plugin/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + org.jboss.fuse.mvnd.test.module-and-plugin + module-and-plugin + 0.0.1-SNAPSHOT + pom + + + UTF-8 + 1.8 + 1.8 + + 2.5 + 3.1 + 2.4 + 2.6 + 3.0.0-M4 + + + + hello + plugin + + + + + + + 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} + + + + + + \ No newline at end of file