From 9e4a51314abdbc2ad027d016a7aaff711b99da74 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 18 Dec 2020 09:52:29 +0100 Subject: [PATCH] Add an integration test to reproduce #276 --- .../mvnd/it/BootstrapPluginTest.java | 60 ++++++++++++ .../bootstrap-plugin/.mvn/maven.config | 3 + .../bootstrap-plugin/bootstrap/pom.xml | 32 +++++++ .../java/org/reproducer/BootstrapMain.java | 75 +++++++++++++++ .../main/resources/org/reproducer/Model.java | 23 +++++ .../test/projects/bootstrap-plugin/pom.xml | 40 ++++++++ .../projects/bootstrap-plugin/startup/pom.xml | 92 +++++++++++++++++++ .../main/java/org/reproducer/MainClass.java | 26 ++++++ 8 files changed, 351 insertions(+) create mode 100644 integration-tests/src/test/java/org/mvndaemon/mvnd/it/BootstrapPluginTest.java create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/.mvn/maven.config create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/bootstrap/pom.xml create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/java/org/reproducer/BootstrapMain.java create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/resources/org/reproducer/Model.java create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/pom.xml create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/startup/pom.xml create mode 100644 integration-tests/src/test/projects/bootstrap-plugin/startup/src/main/java/org/reproducer/MainClass.java diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/BootstrapPluginTest.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/BootstrapPluginTest.java new file mode 100644 index 000000000..3beca66db --- /dev/null +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/BootstrapPluginTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2020 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.mvndaemon.mvnd.it; + +import java.io.IOException; +import javax.inject.Inject; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mvndaemon.mvnd.assertj.TestClientOutput; +import org.mvndaemon.mvnd.client.Client; +import org.mvndaemon.mvnd.client.DaemonParameters; +import org.mvndaemon.mvnd.junit.MvndTest; +import org.mvndaemon.mvnd.junit.TestRegistry; + +@MvndTest(projectDir = "src/test/projects/bootstrap-plugin") +public class BootstrapPluginTest { + + @Inject + Client client; + + @Inject + TestRegistry registry; + + @Inject + DaemonParameters parameters; + + @Test + void cleanInstall() throws IOException, InterruptedException { + assertDaemonRegistrySize(0); + + final TestClientOutput output1 = new TestClientOutput(); + client.execute(output1, "clean", "install", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess(); + + assertDaemonRegistrySize(1); + + final TestClientOutput output2 = new TestClientOutput(); + client.execute(output2, "clean", "install", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess(); + + assertDaemonRegistrySize(1); + } + + private void assertDaemonRegistrySize(int size) { + Assertions.assertThat(registry.getAll().size()) + .as("Daemon registry size should be " + size) + .isEqualTo(size); + } +} diff --git a/integration-tests/src/test/projects/bootstrap-plugin/.mvn/maven.config b/integration-tests/src/test/projects/bootstrap-plugin/.mvn/maven.config new file mode 100644 index 000000000..4230c2417 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/.mvn/maven.config @@ -0,0 +1,3 @@ +-Dmaven.wagon.httpconnectionManager.ttlSeconds=120 +-Dmaven.wagon.http.retryHandler.requestSentEnabled=true +-Dmaven.wagon.http.retryHandler.count=10 diff --git a/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/pom.xml b/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/pom.xml new file mode 100644 index 000000000..e06415bb3 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + org.reproducer + bootstrap + 1.0.0-SNAPSHOT + + + + 11 + 11 + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/java/org/reproducer/BootstrapMain.java b/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/java/org/reproducer/BootstrapMain.java new file mode 100644 index 000000000..c38e67617 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/java/org/reproducer/BootstrapMain.java @@ -0,0 +1,75 @@ +/* + * Copyright 2020 Red Hat, Inc. and/or its affiliates. + * + * 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.reproducer; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class BootstrapMain { + + public static void main(String[] args) throws IOException { + File baseDir = new File(args[0]); + + String vbMain = new String(readBytesFromInputStream(BootstrapMain.class.getResourceAsStream("Model.java"))); + vbMain = vbMain.replaceAll("REPLACETHIS", "Hello world"); + + final Path file = Paths.get(baseDir.getAbsolutePath(), + "target", + "generated-sources", + "bootstrap", + "org", "reproducer", "Model.java"); + + try { + Files.deleteIfExists(file); + Files.createDirectories(file.getParent()); + Files.copy(new ByteArrayInputStream(vbMain.getBytes()), file, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Unable to write file", e); + } + } + + public static byte[] readBytesFromInputStream(InputStream input) throws IOException { + try { + byte[] buffer = createBytesBuffer(input); + ByteArrayOutputStream output = new ByteArrayOutputStream(buffer.length); + + int n = 0; + while (-1 != (n = input.read(buffer))) { + output.write(buffer, 0, n); + } + return output.toByteArray(); + } finally { + try { + input.close(); + } catch (Exception e) { + // ignore + } + } + } + + private static byte[] createBytesBuffer(InputStream input) throws IOException { + return new byte[Math.max(input.available(), 8192)]; + } +} diff --git a/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/resources/org/reproducer/Model.java b/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/resources/org/reproducer/Model.java new file mode 100644 index 000000000..fa4d40ed4 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/bootstrap/src/main/resources/org/reproducer/Model.java @@ -0,0 +1,23 @@ +/* + * Copyright 2020 Red Hat, Inc. and/or its affiliates. + * + * 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.reproducer; + +public class Model { + + public static final String hello = "REPLACETHIS"; + +} diff --git a/integration-tests/src/test/projects/bootstrap-plugin/pom.xml b/integration-tests/src/test/projects/bootstrap-plugin/pom.xml new file mode 100644 index 000000000..fc81f8210 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/pom.xml @@ -0,0 +1,40 @@ + + + + 4.0.0 + + org.example + mvn-bootstrap-plugin-reproducer + 1.0-SNAPSHOT + + pom + + + 11 + 11 + + + + bootstrap + startup + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/bootstrap-plugin/startup/pom.xml b/integration-tests/src/test/projects/bootstrap-plugin/startup/pom.xml new file mode 100644 index 000000000..7d8349090 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/startup/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + org.reproducer + startup + 1.0.0-SNAPSHOT + jar + + + 11 + 11 + + + + + org.reproducer + bootstrap + 1.0.0-SNAPSHOT + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + bootstrap + generate-sources + + java + + + + + org.reproducer.BootstrapMain + false + + ${project.basedir} + + + true + + ${project.basedir}/src/test/resources/ + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + generate-sources + + add-source + + + + ${project.build.directory}/generated-sources/bootstrap + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/bootstrap-plugin/startup/src/main/java/org/reproducer/MainClass.java b/integration-tests/src/test/projects/bootstrap-plugin/startup/src/main/java/org/reproducer/MainClass.java new file mode 100644 index 000000000..e9094b549 --- /dev/null +++ b/integration-tests/src/test/projects/bootstrap-plugin/startup/src/main/java/org/reproducer/MainClass.java @@ -0,0 +1,26 @@ +/* + * Copyright 2020 Red Hat, Inc. and/or its affiliates. + * + * 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.reproducer; + +public class MainClass { + + public static void main(String[] args) { + String helloWorld = org.reproducer.Model.hello; + System.out.println(helloWorld); + } + +}