Skip to content

Commit

Permalink
Merge pull request #25794 from aloubyansky/test-classpath-excludes
Browse files Browse the repository at this point in the history
Support surefire plugin's classpathDependencyExcludes and additionalClasspathElements
  • Loading branch information
aloubyansky authored May 26, 2022
2 parents bdbd55c + f7d0c2f commit 29467c3
Show file tree
Hide file tree
Showing 23 changed files with 631 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public StartupActionImpl(CuratedApplication curatedApplication, BuildResult buil
//test mode only has a single class loader, while dev uses a disposable runtime class loader
//that is discarded between restarts
Map<String, byte[]> resources = new HashMap<>(extractGeneratedResources(true));
if (curatedApplication.getQuarkusBootstrap().isFlatClassPath()) {
if (curatedApplication.isFlatClassPath()) {
resources.putAll(extractGeneratedResources(false));
baseClassLoader.reset(resources, transformedClasses);
runtimeClassLoader = baseClassLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -45,6 +45,7 @@
import org.gradle.util.GradleVersion;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.app.ConfiguredClassLoading;
import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.devmode.DependenciesFilter;
import io.quarkus.bootstrap.model.ApplicationModel;
Expand Down Expand Up @@ -304,17 +305,18 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
resourceDirs.add(resourceDir.getOutputDir());
}

Set<ArtifactKey> configuredParentFirst = QuarkusBootstrap.createClassLoadingConfig(PathsCollection.from(resourceDirs),
QuarkusBootstrap.Mode.DEV, Collections.emptyList()).parentFirstArtifacts;

Set<ArtifactKey> parentFirstArtifactKeys = new HashSet<>(configuredParentFirst);
parentFirstArtifactKeys.addAll(appModel.getParentFirst());
final Collection<ArtifactKey> configuredParentFirst = ConfiguredClassLoading.builder()
.setApplicationModel(appModel)
.setApplicationRoot(PathsCollection.from(resourceDirs))
.setMode(QuarkusBootstrap.Mode.DEV)
.addParentFirstArtifacts(appModel.getParentFirst())
.build().getParentFirstArtifacts();

for (io.quarkus.maven.dependency.ResolvedDependency artifact : appModel.getDependencies()) {
if (!projectDependencies.contains(artifact.getKey())) {
artifact.getResolvedPaths().forEach(p -> {
File file = p.toFile();
if (file.exists() && parentFirstArtifactKeys.contains(artifact.getKey())
if (file.exists() && configuredParentFirst.contains(artifact.getKey())
&& filesIncludedInClasspath.add(file)) {
getProject().getLogger().debug("Adding dependency {}", file);
builder.classpathEntry(file);
Expand Down
13 changes: 8 additions & 5 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.fusesource.jansi.internal.WindowsSupport;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.app.ConfiguredClassLoading;
import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.devmode.DependenciesFilter;
import io.quarkus.bootstrap.model.ApplicationModel;
Expand Down Expand Up @@ -1075,21 +1076,23 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
Path path = Paths.get(dir);
resourceDirs.add(path);
}
Set<ArtifactKey> configuredParentFirst = QuarkusBootstrap.createClassLoadingConfig(PathsCollection.from(resourceDirs),
QuarkusBootstrap.Mode.DEV, Collections.emptyList()).parentFirstArtifacts;

//in most cases these are not used, however they need to be present for some
//parent-first cases such as logging
//first we go through and get all the parent first artifacts
Set<ArtifactKey> parentFirstArtifacts = new HashSet<>(configuredParentFirst);
parentFirstArtifacts.addAll(appModel.getParentFirst());
final Collection<ArtifactKey> configuredParentFirst = ConfiguredClassLoading.builder()
.setApplicationModel(appModel)
.setApplicationRoot(PathsCollection.from(resourceDirs))
.setMode(QuarkusBootstrap.Mode.DEV)
.addParentFirstArtifacts(appModel.getParentFirst())
.build().getParentFirstArtifacts();

for (Artifact appDep : project.getArtifacts()) {
// only add the artifact if it's present in the dev mode context
// we need this to avoid having jars on the classpath multiple times
ArtifactKey key = ArtifactKey.gact(appDep.getGroupId(), appDep.getArtifactId(),
appDep.getClassifier(), appDep.getArtifactHandler().getExtension());
if (!builder.isLocal(key) && parentFirstArtifacts.contains(key)) {
if (!builder.isLocal(key) && configuredParentFirst.contains(key)) {
builder.classpathEntry(appDep.getFile());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ public boolean hasTestSources() {
return DefaultWorkspaceModule.this.sourcesSets.containsKey(ArtifactSources.TEST);
}

@Override
public Builder setTestClasspathDependencyExclusions(Collection<String> excludes) {
DefaultWorkspaceModule.this.testClasspathDependencyExclusions = excludes;
return this;
}

@Override
public Builder setAdditionalTestClasspathElements(Collection<String> elements) {
DefaultWorkspaceModule.this.additionalTestClasspathElements = elements;
return this;
}

@Override
public WorkspaceModule build() {
final DefaultWorkspaceModule module = DefaultWorkspaceModule.this;
Expand Down Expand Up @@ -154,6 +166,16 @@ public Collection<Dependency> getDirectDependencyConstraints() {
public Collection<Dependency> getDirectDependencies() {
return DefaultWorkspaceModule.this.getDirectDependencies();
}

@Override
public Collection<String> getTestClasspathDependencyExclusions() {
return DefaultWorkspaceModule.this.testClasspathDependencyExclusions;
}

@Override
public Collection<String> getAdditionalTestClasspathElements() {
return DefaultWorkspaceModule.this.additionalTestClasspathElements;
}
}

private WorkspaceModuleId id;
Expand All @@ -163,6 +185,8 @@ public Collection<Dependency> getDirectDependencies() {
private Map<String, ArtifactSources> sourcesSets = new HashMap<>();
private List<Dependency> directDepConstraints;
private List<Dependency> directDeps;
private Collection<String> testClasspathDependencyExclusions = List.of();
private Collection<String> additionalTestClasspathElements = List.of();

private DefaultWorkspaceModule() {
}
Expand Down Expand Up @@ -202,10 +226,6 @@ public File getBuildDir() {
return buildDir;
}

public void addArtifactSources(ArtifactSources src) {
sourcesSets.put(src.getClassifier(), src);
}

@Override
public boolean hasSources(String classifier) {
return sourcesSets.containsKey(classifier);
Expand Down Expand Up @@ -235,24 +255,19 @@ public Collection<Dependency> getDirectDependencyConstraints() {
return directDepConstraints == null ? Collections.emptyList() : directDepConstraints;
}

public void setDirectDependencyConstraints(List<Dependency> directDepConstraints) {
this.directDepConstraints = directDepConstraints;
}

@Override
public Collection<Dependency> getDirectDependencies() {
return directDeps == null ? Collections.emptyList() : directDeps;
}

public void setDirectDependencies(List<Dependency> directDeps) {
this.directDeps = directDeps;
@Override
public Collection<String> getTestClasspathDependencyExclusions() {
return testClasspathDependencyExclusions;
}

public void addDirectDependency(Dependency directDep) {
if (directDeps == null || directDeps.isEmpty()) {
directDeps = new ArrayList<>();
}
this.directDeps.add(directDep);
@Override
public Collection<String> getAdditionalTestClasspathElements() {
return additionalTestClasspathElements;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ default PathTree getContentTree(String classifier) {

Collection<Dependency> getDirectDependencies();

Collection<String> getTestClasspathDependencyExclusions();

Collection<String> getAdditionalTestClasspathElements();

Mutable mutable();

interface Mutable extends WorkspaceModule {
Expand All @@ -77,6 +81,10 @@ interface Mutable extends WorkspaceModule {

Mutable addArtifactSources(ArtifactSources sources);

Mutable setTestClasspathDependencyExclusions(Collection<String> excludes);

Mutable setAdditionalTestClasspathElements(Collection<String> elements);

WorkspaceModule build();

default Mutable mutable() {
Expand Down
Loading

0 comments on commit 29467c3

Please sign in to comment.