Skip to content

Commit

Permalink
Revert "Propagate parent-first flag"
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet authored Jan 17, 2023
1 parent b3e01e0 commit fe36e10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 280 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.Properties;
import java.util.stream.Collectors;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.DependencyFlags;

public class TsQuarkusExt {

Expand All @@ -20,7 +16,6 @@ public class TsQuarkusExt {
protected final TsJar rtContent;
protected final PropsBuilder rtDescr = PropsBuilder.newInstance();
private boolean installed;
private Map<Integer, List<ArtifactKey>> flags = new HashMap<>();

public TsQuarkusExt(String artifactId) {
this(artifactId, TsArtifact.DEFAULT_VERSION);
Expand All @@ -35,11 +30,6 @@ public TsQuarkusExt(String artifactId, String version) {
rtDescr.set(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT, deployment.toString());
}

public TsQuarkusExt setDependencyFlag(ArtifactKey dep, int flag) {
this.flags.computeIfAbsent(flag, k -> new ArrayList<>()).add(dep);
return this;
}

public TsQuarkusExt setConditionalDeps(TsQuarkusExt... exts) {
final StringBuilder buf = new StringBuilder();
int i = 0;
Expand Down Expand Up @@ -93,25 +83,15 @@ public void install(TsRepoBuilder repo) {
}
installed = true;

rtContent.addEntry(rtDescr.build(), BootstrapConstants.DESCRIPTOR_PATH);

if (!extDeps.isEmpty()) {
for (TsQuarkusExt e : extDeps) {
e.install(repo);
}
}
for (Map.Entry<Integer, List<ArtifactKey>> e : flags.entrySet()) {
switch (e.getKey()) {
case DependencyFlags.CLASSLOADER_PARENT_FIRST:
final StringJoiner sj = new StringJoiner(",");
for (ArtifactKey k : e.getValue()) {
sj.add(k.toString());
}
rtDescr.set(BootstrapConstants.PARENT_FIRST_ARTIFACTS, sj.toString());
break;
default:
throw new RuntimeException("Not yet supported flag " + e.getKey());
}
}
rtContent.addEntry(rtDescr.build(), BootstrapConstants.DESCRIPTOR_PATH);
Properties props = rtDescr.build();
rtContent.addEntry(props, BootstrapConstants.DESCRIPTOR_PATH);
deployment.install(repo);
runtime.install(repo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.DependencyFlags;
import io.quarkus.maven.dependency.GACT;
import io.quarkus.maven.dependency.ResolvedDependencyBuilder;
import io.quarkus.paths.PathList;
import io.quarkus.paths.PathTree;
Expand Down Expand Up @@ -210,42 +209,21 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
buildTreeConsumer);
buildDepsVisitor.visit(root);

for (ExtensionInfo e : allExtensions.values()) {
if (!e.activated) {
continue;
}
e.handleExtensionProperties();
}

if (!CONVERGED_TREE_ONLY) {
if (collectReloadableModules) {
for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) {
if (!db.isFlagSet(DependencyFlags.RELOADABLE | DependencyFlags.VISITED)) {
propagateFlags(db, DependencyFlags.RELOADABLE, 0);
}
if (!CONVERGED_TREE_ONLY && collectReloadableModules) {
for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) {
if (db.isFlagSet(DependencyFlags.RELOADABLE | DependencyFlags.VISITED)) {
continue;
}
clearVisitedFlag();
}
propagateFlag(DependencyFlags.CLASSLOADER_PARENT_FIRST);
propagateFlag(DependencyFlags.CLASSLOADER_RUNNER_PARENT_FIRST);
}

collectPlatformProperties();
}

private void propagateFlag(int flag) {
for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) {
if (db.isFlagSet(flag) && !db.isFlagSet(DependencyFlags.VISITED)) {
propagateFlags(db, 0, flag);
clearReloadableFlag(db);
}
}
clearVisitedFlag();
}

private void clearVisitedFlag() {
for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) {
db.clearFlag(DependencyFlags.VISITED);
appBuilder.addDependency(db);
}

collectPlatformProperties();
}

private void collectPlatformProperties() throws AppModelResolverException {
Expand All @@ -267,7 +245,7 @@ private void collectPlatformProperties() throws AppModelResolverException {
appBuilder.setPlatformImports(platformReleases);
}

private void propagateFlags(ResolvedDependencyBuilder db, int toClear, int toSet) {
private void clearReloadableFlag(ResolvedDependencyBuilder db) {
final Set<ArtifactKey> deps = artifactDeps.get(db.getArtifactCoords());
if (deps == null || deps.isEmpty()) {
return;
Expand All @@ -277,9 +255,9 @@ private void propagateFlags(ResolvedDependencyBuilder db, int toClear, int toSet
if (dep == null || dep.isFlagSet(DependencyFlags.VISITED)) {
continue;
}
dep.setFlags(DependencyFlags.VISITED | toSet);
dep.clearFlag(toClear);
propagateFlags(dep, toClear, toSet);
dep.setFlags(DependencyFlags.VISITED);
dep.clearFlag(DependencyFlags.RELOADABLE);
clearReloadableFlag(dep);
}
}

Expand Down Expand Up @@ -695,79 +673,13 @@ private class ExtensionInfo {
.parseDependencyCondition(props.getProperty(BootstrapConstants.DEPENDENCY_CONDITION));
}

public void handleExtensionProperties() {
for (Map.Entry<Object, Object> prop : props.entrySet()) {
if (prop.getValue() == null) {
continue;
}
final String value = prop.getValue().toString();
if (value.isBlank()) {
continue;
}
final String name = prop.getKey().toString();
switch (name) {
case ApplicationModelBuilder.PARENT_FIRST_ARTIFACTS:
for (String artifact : value.split(",")) {
final ResolvedDependencyBuilder d = appBuilder.getDependency(new GACT(artifact.split(":")));
if (d != null) {
d.setFlags(DependencyFlags.CLASSLOADER_PARENT_FIRST);
}
}
break;
case ApplicationModelBuilder.RUNNER_PARENT_FIRST_ARTIFACTS:
for (String artifact : value.split(",")) {
final ResolvedDependencyBuilder d = appBuilder.getDependency(new GACT(artifact.split(":")));
if (d != null) {
d.setFlags(DependencyFlags.CLASSLOADER_RUNNER_PARENT_FIRST);
}
}
break;
case ApplicationModelBuilder.LESSER_PRIORITY_ARTIFACTS:
String[] artifacts = value.split(",");
for (String artifact : artifacts) {
final ResolvedDependencyBuilder d = appBuilder.getDependency(new GACT(artifact.split(":")));
if (d != null) {
log.debugf("Extension %s is making %s a lesser priority artifact", runtimeArtifact, artifact);
d.setFlags(DependencyFlags.CLASSLOADER_LESSER_PRIORITY);
}
}
break;
case ApplicationModelBuilder.EXCLUDED_ARTIFACTS:
for (String artifact : value.split(",")) {
appBuilder.addExcludedArtifact(new GACT(artifact.split(":")));
log.debugf("Extension %s is excluding %s", runtimeArtifact, artifact);
}
break;
default:
if (name.startsWith(ApplicationModelBuilder.REMOVED_RESOURCES_DOT)) {
final String keyStr = name.substring(ApplicationModelBuilder.REMOVED_RESOURCES_DOT.length());
if (!keyStr.isBlank()) {
ArtifactKey key = null;
try {
key = ArtifactKey.fromString(keyStr);
} catch (IllegalArgumentException e) {
log.warnf("Failed to parse artifact key %s in %s from descriptor of extension %s", keyStr,
name,
runtimeArtifact);
}
if (key != null) {
final Set<String> resources = Set.of(value.split(","));
appBuilder.addRemovedResources(key, resources);
log.debugf("Extension %s is excluding resources %s from artifact %s", runtimeArtifact,
resources,
key);
}
}
}
}
}
}

void ensureActivated() {
if (activated) {
return;
}
activated = true;
appBuilder.handleExtensionProperties(props, runtimeArtifact.toString());

final String providesCapabilities = props.getProperty(BootstrapConstants.PROP_PROVIDES_CAPABILITIES);
final String requiresCapabilities = props.getProperty(BootstrapConstants.PROP_REQUIRES_CAPABILITIES);
if (providesCapabilities != null || requiresCapabilities != null) {
Expand Down

0 comments on commit fe36e10

Please sign in to comment.