Skip to content

Commit

Permalink
Fix DEV mode test when specific classes are selected
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik authored and mjurc committed Apr 29, 2024
1 parent 7cf11c2 commit a1c430e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.services.quarkus;

import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY;
import static org.junit.jupiter.api.Assertions.fail;

import java.lang.annotation.Annotation;
import java.nio.file.Path;
Expand All @@ -11,7 +10,6 @@
import io.quarkus.test.security.certificate.CertificateBuilder;
import io.quarkus.test.services.DevModeQuarkusApplication;
import io.quarkus.test.services.quarkus.model.QuarkusProperties;
import io.quarkus.test.utils.FileUtils;

public class DevModeQuarkusApplicationManagedResourceBuilder extends QuarkusApplicationManagedResourceBuilder {

Expand Down Expand Up @@ -45,11 +43,6 @@ public ManagedResource build(ServiceContext context) {
}

protected void build() {
try {
FileUtils.copyCurrentDirectoryTo(getContext().getServiceFolder());
copyResourcesToAppFolder();
} catch (Exception ex) {
fail("Failed to build Quarkus artifacts. Caused by " + ex);
}
new QuarkusMavenPluginBuildHelper(this, null).prepareApplicationFolder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static io.quarkus.test.utils.PropertiesUtils.toMvnSystemProperty;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.Collectors.toUnmodifiableSet;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
Expand All @@ -20,6 +21,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -62,9 +64,11 @@ class QuarkusMavenPluginBuildHelper {
private final boolean buildWithAllClasses;
private final boolean customBuildRequired;
private final Path targetFolderForLocalArtifacts;
private final QuarkusApplicationManagedResourceBuilder resourceBuilder;

QuarkusMavenPluginBuildHelper(QuarkusApplicationManagedResourceBuilder resourceBuilder,
Path targetFolderForLocalArtifacts) {
this.resourceBuilder = resourceBuilder;
resourceBuilder.createSnapshotOfBuildProperties();
this.appFolder = resourceBuilder.getApplicationFolder();
this.appClassNames = Arrays.stream(resourceBuilder.getAppClasses()).map(Class::getName).collect(toUnmodifiableSet());
Expand Down Expand Up @@ -109,7 +113,19 @@ private static Set<String> findMavenCommandLineArgs() {
throw new IllegalStateException("Failed to detect mvn command line arguments");
}

Optional<Path> buildNativeExecutable() {
void prepareApplicationFolder() {
var mavenProjectRoot = prepareMavenProject();

try {
FileUtils.copyDirectoryTo(mavenProjectRoot, appFolder);
FileUtils.deleteFile(mavenProjectRoot.toFile());
resourceBuilder.copyResourcesToAppFolder();
} catch (Exception ex) {
fail("Failed to build Quarkus artifacts. Caused by " + ex);
}
}

private Path prepareMavenProject() {
// create new project root
Path mavenBuildProjectRoot = appFolder.resolve("mvn-build");
FileUtils.recreateDirectory(mavenBuildProjectRoot);
Expand Down Expand Up @@ -145,6 +161,13 @@ Optional<Path> buildNativeExecutable() {
// add enhanced application.properties and META-INF to the new project
addEnhancedAppPropsAndMetaInf(mavenBuildProjectRoot);

return mavenBuildProjectRoot;
}

Optional<Path> buildNativeExecutable() {
Objects.requireNonNull(targetFolderForLocalArtifacts);
var mavenBuildProjectRoot = prepareMavenProject();

// build artifact with Quarkus Maven Plugin
try {
new Command(getBuildNativeExecutableCmd()).onDirectory(mavenBuildProjectRoot).runAndWait();
Expand Down

0 comments on commit a1c430e

Please sign in to comment.