Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-existing class and resource paths during JVM test #28186

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public void testExtensionRemovedResources() throws Exception {
assertThat(result.getProcess().waitFor()).isEqualTo(0);
}

@Test
public void testExtensionTestWithNoMain() throws Exception {
testDir = initProject("projects/extension-test-with-no-main");
running = new RunningInvoker(testDir, false);
final MavenProcessInvocationResult result = running.execute(List.of("verify"), Map.of());
assertThat(result.getProcess().waitFor()).isEqualTo(0);
}

@Test
public void testUberJarMavenPluginConfiguration()
throws MavenInvocationException, IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>extension-test-with-no-main</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>runtime-deployment</artifactId>
<name>Extension test with no main - Deployment</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>runtime</artifactId>
<version>\${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>\${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>extension-test-with-no-main</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>extension-test-with-no-main-integration-tests</artifactId>
<name>Extension test with no main - Integration Tests</name>
<properties>
<skipITs>true</skipITs>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>runtime</artifactId>
<version>\${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>\${project.build.directory}/\${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>\${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class ExampleTest {

@Test
public void test() {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>extension-test-with-no-main</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Extension test with no main</name>
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-tests</module>
</modules>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<failsafe-plugin.version>${surefire-plugin.version}</failsafe-plugin.version>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>@project.version@</quarkus.version>
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>\${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>\${quarkus.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>\${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
<maven.repo>\${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>\${failsafe-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
<maven.repo>\${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>\${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>extension-test-with-no-main</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>runtime</artifactId>
<name>Extension test with no main - Runtime</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>\${quarkus.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>extension-descriptor</goal>
</goals>
<configuration>
<deployment>\${project.groupId}:\${project.artifactId}-deployment:\${project.version}</deployment>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>\${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javax.enterprise.inject.Alternative;
Expand Down Expand Up @@ -59,20 +60,21 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class<? extend

final PathList.Builder rootBuilder = PathList.builder();

Consumer<Path> addToBuilderIfConditionMet = path -> {
if (path != null && Files.exists(path) && !rootBuilder.contains(path)) {
rootBuilder.add(path);
}
};

if (!appClassLocation.equals(testClassLocation)) {
rootBuilder.add(testClassLocation);
addToBuilderIfConditionMet.accept(testClassLocation);
// if test classes is a dir, we should also check whether test resources dir exists as a separate dir (gradle)
// TODO: this whole app/test path resolution logic is pretty dumb, it needs be re-worked using proper workspace discovery
final Path testResourcesLocation = PathTestHelper.getResourcesForClassesDirOrNull(testClassLocation, "test");
if (testResourcesLocation != null) {
rootBuilder.add(testResourcesLocation);
}
addToBuilderIfConditionMet.accept(testResourcesLocation);
}

originalCl = Thread.currentThread().getContextClassLoader();
Map<String, String> sysPropRestore = new HashMap<>();
sysPropRestore.put(ProfileManager.QUARKUS_TEST_PROFILE_PROP,
System.getProperty(ProfileManager.QUARKUS_TEST_PROFILE_PROP));

// clear the test.url system property as the value leaks into the run when using different profiles
System.clearProperty("test.url");
Expand All @@ -99,17 +101,15 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class<? extend
additional.put(ProfileManager.QUARKUS_TEST_PROFILE_PROP, profileInstance.getConfigProfile());
}
//we just use system properties for now
//its a lot simpler
//it's a lot simpler
shutdownTasks.add(RestorableSystemProperties.setProperties(additional)::close);
}

final Path projectRoot = Paths.get("").normalize().toAbsolutePath();

rootBuilder.add(appClassLocation);
addToBuilderIfConditionMet.accept(appClassLocation);
final Path appResourcesLocation = PathTestHelper.getResourcesForClassesDirOrNull(appClassLocation, "main");
if (appResourcesLocation != null) {
rootBuilder.add(appResourcesLocation);
}
addToBuilderIfConditionMet.accept(appResourcesLocation);

// If gradle project running directly with IDE
if (System.getProperty(BootstrapConstants.SERIALIZED_TEST_APP_MODEL) == null) {
Expand All @@ -120,28 +120,22 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class<? extend
for (SourceDir src : artifactSrc.getSourceDirs()) {
if (Files.exists(src.getOutputDir())) {
final Path classesDir = src.getOutputDir();
if (!rootBuilder.contains(classesDir)) {
rootBuilder.add(classesDir);
}
addToBuilderIfConditionMet.accept(classesDir);
}
}
}
for (SourceDir src : model.getApplicationModule().getMainSources().getSourceDirs()) {
if (Files.exists(src.getOutputDir())) {
final Path classesDir = src.getOutputDir();
if (!rootBuilder.contains(classesDir)) {
rootBuilder.add(classesDir);
}
addToBuilderIfConditionMet.accept(classesDir);
}
}
}
} else if (System.getProperty(BootstrapConstants.OUTPUT_SOURCES_DIR) != null) {
final String[] sourceDirectories = System.getProperty(BootstrapConstants.OUTPUT_SOURCES_DIR).split(",");
for (String sourceDirectory : sourceDirectories) {
final Path directory = Paths.get(sourceDirectory);
if (Files.exists(directory) && !rootBuilder.contains(directory)) {
rootBuilder.add(directory);
}
addToBuilderIfConditionMet.accept(directory);
}
}
CuratedApplication curatedApplication;
Expand Down