Skip to content

Commit

Permalink
Common utility to parse conditional dependency config
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Jul 21, 2021
1 parent e7e74b8 commit 4b66d16
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
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

0 comments on commit 4b66d16

Please sign in to comment.