Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test to reproduce #276
- Loading branch information
Showing
8 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
integration-tests/src/test/java/org/mvndaemon/mvnd/it/BootstrapPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
@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); | ||
|
||
for (int i = 0; i < 100; i++) { | ||
final TestClientOutput output = new TestClientOutput(); | ||
try { | ||
client.execute(output, "clean", "install", "-X", "-Dmvnd.log.level=DEBUG").assertSuccess(); | ||
} catch (Exception e) { | ||
output.getMessages().forEach(System.out::println); | ||
fail("Error", e); | ||
} | ||
assertDaemonRegistrySize(1); | ||
} | ||
} | ||
|
||
private void assertDaemonRegistrySize(int size) { | ||
Assertions.assertThat(registry.getAll().size()) | ||
.as("Daemon registry size should be " + size) | ||
.isEqualTo(size); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-tests/src/test/projects/bootstrap-plugin/.mvn/maven.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120 | ||
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true | ||
-Dmaven.wagon.http.retryHandler.count=10 |
32 changes: 32 additions & 0 deletions
32
integration-tests/src/test/projects/bootstrap-plugin/bootstrap/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
75 changes: 75 additions & 0 deletions
75
.../test/projects/bootstrap-plugin/bootstrap/src/main/java/org/reproducer/BootstrapMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)]; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...src/test/projects/bootstrap-plugin/bootstrap/src/main/resources/org/reproducer/Model.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
40
integration-tests/src/test/projects/bootstrap-plugin/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
92 changes: 92 additions & 0 deletions
92
integration-tests/src/test/projects/bootstrap-plugin/startup/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
26 changes: 26 additions & 0 deletions
26
...ts/src/test/projects/bootstrap-plugin/startup/src/main/java/org/reproducer/MainClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |