Skip to content

Commit

Permalink
Collect and expose compile-only dependencies through ApplicationModel
Browse files Browse the repository at this point in the history
with DependencyFlag.COMPILE_ONLY flag set (Maven provided scope)
  • Loading branch information
aloubyansky committed Jan 4, 2024
1 parent 2e6fe10 commit 967cc8a
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsDependency;
Expand Down Expand Up @@ -35,25 +37,29 @@ protected TsArtifact composeApplication() {
addToExpectedLib(extA.getRuntime());
extA.getRuntime()
.addDependency(extADep)
.addDependency(new TsDependency(extAProvidedDep, "provided"));
.addDependency(new TsDependency(extAProvidedDep, JavaScopes.PROVIDED));
extA.getDeployment()
.addDependency(extADeploymentDep)
.addDependency(new TsDependency(extAOptionalDeploymentDep, "provided"));
.addDependency(new TsDependency(extAOptionalDeploymentDep, JavaScopes.PROVIDED));

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
this.install(extB);

final TsArtifact directProvidedDep = TsArtifact.jar("direct-provided-dep");

final TsArtifact depC2 = TsArtifact.jar("dep-c", "2");
// make sure provided dependencies don't override compile/runtime dependencies
directProvidedDep.addDependency(depC2);

final TsArtifact transitiveProvidedDep = TsArtifact.jar("transitive-provided-dep");
directProvidedDep.addDependency(transitiveProvidedDep);

return TsArtifact.jar("app")
.addManagedDependency(platformDescriptor())
.addManagedDependency(platformProperties())
.addDependency(extA)
.addDependency(extB, "provided")
.addDependency(new TsDependency(directProvidedDep, "provided"));
.addDependency(extB, JavaScopes.PROVIDED)
.addDependency(new TsDependency(directProvidedDep, JavaScopes.PROVIDED));
}

@Override
Expand All @@ -64,5 +70,36 @@ protected void assertAppModel(ApplicationModel model) throws Exception {
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment-dep", "1"),
DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, getDeploymentOnlyDeps(model));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-dep", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "dep-c", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.RUNTIME_CP));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.DIRECT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "direct-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DIRECT,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.COMPILE_ONLY));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.COMPILE_ONLY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package io.quarkus.deployment.runnerjar;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsDependency;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactDependency;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.maven.dependency.DependencyFlags;

public class ProvidedExtensionDepsTestModeTest extends BootstrapFromOriginalJarTestBase {

@Override
protected boolean isBootstrapForTestMode() {
return true;
}

@Override
protected TsArtifact composeApplication() {

final TsArtifact extADep = TsArtifact.jar("ext-a-dep");
addToExpectedLib(extADep);

final TsArtifact depC1 = TsArtifact.jar("dep-c");
//addToExpectedLib(depC1);
extADep.addDependency(depC1);

final TsArtifact extAProvidedDep = TsArtifact.jar("ext-a-provided-dep");

final TsArtifact extADeploymentDep = TsArtifact.jar("ext-a-deployment-dep");
final TsArtifact extAOptionalDeploymentDep = TsArtifact.jar("ext-a-provided-deployment-dep");

final TsQuarkusExt extA = new TsQuarkusExt("ext-a");
addToExpectedLib(extA.getRuntime());
extA.getRuntime()
.addDependency(extADep)
.addDependency(new TsDependency(extAProvidedDep, JavaScopes.PROVIDED));
extA.getDeployment()
.addDependency(extADeploymentDep)
.addDependency(new TsDependency(extAOptionalDeploymentDep, JavaScopes.PROVIDED));

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
addToExpectedLib(extB.getRuntime());
this.install(extB);

final TsArtifact directProvidedDep = TsArtifact.jar("direct-provided-dep");
addToExpectedLib(directProvidedDep);

final TsArtifact depC2 = TsArtifact.jar("dep-c", "2");
// here provided dependencies will override compile/runtime ones during version convergence
addToExpectedLib(depC2);
directProvidedDep.addDependency(depC2);

final TsArtifact transitiveProvidedDep = TsArtifact.jar("transitive-provided-dep");
addToExpectedLib(transitiveProvidedDep);
directProvidedDep.addDependency(transitiveProvidedDep);

return TsArtifact.jar("app")
.addManagedDependency(platformDescriptor())
.addManagedDependency(platformProperties())
.addDependency(extA)
.addDependency(extB, JavaScopes.PROVIDED)
.addDependency(new TsDependency(directProvidedDep, JavaScopes.PROVIDED));
}

@Override
protected void assertAppModel(ApplicationModel model) throws Exception {
Set<Dependency> expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment", "1"),
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment-dep", "1"),
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b-deployment", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, getDeploymentOnlyDeps(model));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-dep", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "dep-c", "2"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.DIRECT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "direct-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.RUNTIME_CP));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.DIRECT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "direct-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.COMPILE_ONLY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

import io.quarkus.maven.dependency.ArtifactKey;
Expand Down Expand Up @@ -148,4 +149,15 @@ private void moveOn() {
};
}
}

public static void main(String[] args) throws Exception {

var func = new BiFunction<ResolvedDependency, Integer, Boolean>() {
@Override
public Boolean apply(ResolvedDependency d, Integer flags) {
return (d.getFlags() & flags) == flags;
}
};
System.out.println("hello");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,43 @@ default boolean isClassLoaderParentFirst() {
return isFlagSet(DependencyFlags.CLASSLOADER_PARENT_FIRST);
}

/**
* Checks whether a dependency has a given flag set.
*
* @param flag flag to check
* @return true if the flag is set, otherwise false
*/
default boolean isFlagSet(int flag) {
return (getFlags() & flag) > 0;
return (getFlags() & flag) == flag;
}

/**
* Checks whether any of the flags are set on a dependency
*
* @param flags flags to check
* @return true if any of the flags are set, otherwise false
*/
default boolean hasAnyFlag(int... flags) {
for (var flag : flags) {
if (isFlagSet(flag)) {
return true;
}
}
return false;
}

/**
* Checks whether all the passed in flags are set on a dependency
*
* @param flags flags to check
* @return true if all the passed in flags are set on a dependency, otherwise false
*/
default boolean hasAllFlags(int... flags) {
for (var flag : flags) {
if (!isFlagSet(flag)) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public interface DependencyFlags {
// once the processing of the whole tree has completed.
int VISITED = 0b00100000000000;

/**
* Compile-only dependencies are those that are configured in the project
* to be included only in the compile phase ({@code provided} dependency scope in Maven,
* {@code compileOnly} configuration in Gradle).
* <p>
* These dependencies will not be present on the Quarkus application runtime or
* augmentation (deployment) classpath when the application is bootstrapped in production mode
* ({@code io.quarkus.runtime.LaunchMode.NORMAL}).
* <p>
* Compile-only dependencies will be present on both the runtime and the augmentation classpath
* of a Quarkus application launched in test and dev modes.
* <p>
* In any case though, these dependencies will be available during augmentation for processing
* using {@link io.quarkus.bootstrap.model.ApplicationModel#getDependencies(int)} by passing
* this flag as an argument.
*/
int COMPILE_ONLY = 0b01000000000000;
/* @formatter:on */

}
Loading

0 comments on commit 967cc8a

Please sign in to comment.