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

Common utility to parse conditional dependency config #18915

Merged
merged 1 commit into from
Jul 22, 2021
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 @@ -7,6 +7,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -25,6 +26,7 @@
import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.util.BootstrapUtils;
import io.quarkus.bootstrap.util.ZipUtils;

public class ConditionalDependenciesEnabler {
Expand Down Expand Up @@ -191,20 +193,21 @@ private ExtensionDependency loadExtensionInfo(Path descriptorPath, ModuleVersion
}
AppArtifactCoords deploymentModule = AppArtifactCoords
.fromString(extensionProperties.getProperty(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT));
List<Dependency> conditionalDependencies = new ArrayList<>();
final List<Dependency> conditionalDependencies;
if (extensionProperties.containsKey(BootstrapConstants.CONDITIONAL_DEPENDENCIES)) {
String conditionalDeps = extensionProperties.get(BootstrapConstants.CONDITIONAL_DEPENDENCIES).toString();
for (String conditionalDep : conditionalDeps.split("\\s+")) {
final String[] deps = BootstrapUtils
.splitByWhitespace(extensionProperties.getProperty(BootstrapConstants.CONDITIONAL_DEPENDENCIES));
conditionalDependencies = new ArrayList<>(deps.length);
for (String conditionalDep : deps) {
conditionalDependencies.add(DependencyUtils.create(project.getDependencies(), conditionalDep));
}
} else {
conditionalDependencies = Collections.emptyList();
}
List<AppArtifactKey> constraints = new ArrayList<>();
if (extensionProperties.containsKey(BootstrapConstants.DEPENDENCY_CONDITION)) {
String constraintDeps = extensionProperties.getProperty(BootstrapConstants.DEPENDENCY_CONDITION);
for (String constraint : constraintDeps.split("\\s+")) {
constraints.add(AppArtifactKey.fromString(constraint));
}
}
return new ExtensionDependency(exentionId, deploymentModule, conditionalDependencies, constraints);

final AppArtifactKey[] constraints = BootstrapUtils
.parseDependencyCondition(extensionProperties.getProperty(BootstrapConstants.DEPENDENCY_CONDITION));
return new ExtensionDependency(exentionId, deploymentModule, conditionalDependencies,
constraints == null ? Collections.emptyList() : Arrays.asList(constraints));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.bootstrap.util;

import io.quarkus.bootstrap.model.AppArtifactKey;
import java.util.regex.Pattern;

public class BootstrapUtils {

private static Pattern splitByWs;

public static String[] splitByWhitespace(String s) {
if (s == null) {
return null;
}
if (splitByWs == null) {
splitByWs = Pattern.compile("\\s+");
}
return splitByWs.split(s);
}

public static AppArtifactKey[] parseDependencyCondition(String s) {
final String[] strArr = splitByWhitespace(s);
if (strArr == null) {
return null;
}
final AppArtifactKey[] keys = new AppArtifactKey[strArr.length];
for (int i = 0; i < strArr.length; ++i) {
keys[i] = AppArtifactKey.fromString(strArr[i]);
}
return keys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.quarkus.bootstrap.model.CapabilityContract;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.util.BootstrapUtils;
import io.quarkus.bootstrap.util.DependencyNodeUtils;
import io.quarkus.bootstrap.util.ZipUtils;
import java.io.BufferedReader;
Expand Down Expand Up @@ -438,7 +439,7 @@ private class ExtensionInfo {

value = props.getProperty(BootstrapConstants.CONDITIONAL_DEPENDENCIES);
if (value != null) {
final String[] deps = value.split("\\s+");
final String[] deps = BootstrapUtils.splitByWhitespace(value);
conditionalDeps = new Artifact[deps.length];
for (int i = 0; i < deps.length; ++i) {
try {
Expand All @@ -452,17 +453,8 @@ private class ExtensionInfo {
conditionalDeps = NO_ARTIFACTS;
}

value = props.getProperty(BootstrapConstants.DEPENDENCY_CONDITION);
if (value != null) {
final String[] split = value.split("\\s+");
dependencyCondition = new AppArtifactKey[split.length];
for (int i = 0; i < split.length; ++i) {
final String trigger = split[i];
dependencyCondition[i] = AppArtifactKey.fromString(trigger);
}
} else {
dependencyCondition = null;
}
dependencyCondition = BootstrapUtils
.parseDependencyCondition(props.getProperty(BootstrapConstants.DEPENDENCY_CONDITION));
}

void ensureActivated() {
Expand Down