Skip to content

Commit

Permalink
Add an integration test to reproduce #276
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 22, 2021
1 parent 9d40b5b commit 9e4a513
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 0 deletions.
@@ -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);
}
}
@@ -0,0 +1,3 @@
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
-Dmaven.wagon.http.retryHandler.count=10
@@ -0,0 +1,32 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.reproducer</groupId>
<artifactId>bootstrap</artifactId>
<version>1.0.0-SNAPSHOT</version>


<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

</project>
@@ -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)];
}
}
@@ -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";

}
40 changes: 40 additions & 0 deletions integration-tests/src/test/projects/bootstrap-plugin/pom.xml
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>mvn-bootstrap-plugin-reproducer</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>pom</packaging>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<modules>
<module>bootstrap</module>
<module>startup</module>
</modules>

</project>
@@ -0,0 +1,92 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.reproducer</groupId>
<artifactId>startup</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.reproducer</groupId>
<artifactId>bootstrap</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>bootstrap</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.reproducer.BootstrapMain</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads> <!-- cleanupDaemonThreads=false otherwise exec:java will try to shutdown common pool Thread[ForkJoinPool.commonPool-worker- threads -->
<arguments>
<argument>${project.basedir}</argument>
</arguments>
<!-- the following is used to provide a SLF4j binding to the ValidationBootstrapMain and related CP. Set src/test/resources/logback.xml root to DEBUG for debugging -->
<includePluginDependencies>true</includePluginDependencies>
<additionalClasspathElements>
<additionalClasspathElement>${project.basedir}/src/test/resources/</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/bootstrap</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>

</project>
@@ -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);
}

}

0 comments on commit 9e4a513

Please sign in to comment.