Skip to content

Commit

Permalink
Merge pull request #352 from jfdenise/GAL-367
Browse files Browse the repository at this point in the history
Fix for GAL-367, Allow to depend on an optional package only for a given stability level
  • Loading branch information
jfdenise authored Jul 16, 2024
2 parents 174b3f2 + 36f8b02 commit 60b54e0
Show file tree
Hide file tree
Showing 15 changed files with 1,089 additions and 19 deletions.
6 changes: 5 additions & 1 deletion core/src/main/java/org/jboss/galleon/Errors.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -468,6 +468,10 @@ static String requiredPassiveDependency(String name) {
return "Required dependency on " + name + " cannot be passive";
}

static String requiredDependencyWithStability(String name) {
return "Required dependency on " + name + " cannot be bound to a stability level";
}

static String unexpectedPackageDependencyType(String name, int type) {
return "Unexpected dependency type " + type + " on package " + name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ private void processFpConfig(FeaturePackConfig fpConfig) throws ProvisioningExce
if (fpConfigStack.isPackageFilteredOut(currentOrigin.producer, packageName)) {
continue;
}
resolvePackage(packageName, null, PackageDependencySpec.REQUIRED);
resolvePackage( packageName, null, PackageDependencySpec.REQUIRED, null);
}
}
}
Expand All @@ -473,7 +473,7 @@ private void processFpConfig(FeaturePackConfig fpConfig) throws ProvisioningExce
if (fpConfigStack.isPackageFilteredOut(currentOrigin.producer, pkgName)) {
continue;
}
resolvePackage(pkgName, null, PackageDependencySpec.REQUIRED);
resolvePackage(pkgName, null, PackageDependencySpec.REQUIRED, null);
}
}

Expand Down Expand Up @@ -1098,7 +1098,7 @@ private Map<ResolvedFeatureId, FeatureDependencySpec> resolveFeatureDeps(ConfigM
return resolvedDeps;
}

private void resolvePackage(final String pkgName, PackageRuntime.Builder parent, int type) throws ProvisioningException {
private void resolvePackage(final String pkgName, PackageRuntime.Builder parent, int type, final String dependencyStability) throws ProvisioningException {
final int offset = resolvedPkgBranch.size();
boolean resolved = false;
try {
Expand All @@ -1125,11 +1125,22 @@ private void resolvePackage(final String pkgName, PackageRuntime.Builder parent,
while (i > 0) {
resolvedPkgBranch.remove(offset + --i).clearFlag(PackageRuntime.ON_DEP_BRANCH);
}
if (dependencyStability != null) {
Stability depStability = Stability.fromString(dependencyStability);
Stability fpStability = getPackageStability(currentOrigin.getSpec().getPackageStability());
// Ignore when a dependency is only valid for a level that is not implied by the expected package stability.
if (!fpStability.enables(depStability)) {
getMessageWriter().verbose(" Ignoring dependency on " + pkgName + " that is only valid for stability " + dependencyStability);
resolved = true;
}
}
}
clearFlag(FeaturePackRuntimeBuilder.VISIT);
currentOrigin.clearFlag(FeaturePackRuntimeBuilder.VISIT);
}
throw new ProvisioningDescriptionException(Errors.packageNotFound(currentOrigin.producer.getLocation().getFPID(), pkgName));
if (!resolved) {
throw new ProvisioningDescriptionException(Errors.packageNotFound(currentOrigin.producer.getLocation().getFPID(), pkgName));
}
}

private boolean resolvePackage(FeaturePackRuntimeBuilder origin, String name, PackageRuntime.Builder parent, int type) throws ProvisioningException {
Expand Down Expand Up @@ -1174,7 +1185,7 @@ void processPackageDeps(final PackageDepsSpec pkgDeps, PackageRuntime.Builder pa
continue;
}
if ((pkgDepMask & dep.getType()) > 0) {
resolvePackage(dep.getName(), parent, dep.getType());
resolvePackage(dep.getName(), parent, dep.getType(), dep.getValidForStability());
}
}
}
Expand All @@ -1192,7 +1203,7 @@ void processPackageDeps(final PackageDepsSpec pkgDeps, PackageRuntime.Builder pa
continue;
}
if ((pkgDepMask & dep.getType()) > 0) {
resolvePackage(dep.getName(), parent, dep.getType());
resolvePackage(dep.getName(), parent, dep.getType(), dep.getValidForStability());
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,7 +41,7 @@ public static boolean isOptional(int type) {
* @return dependency spec
*/
public static PackageDependencySpec required(String name) {
return new PackageDependencySpec(name, REQUIRED);
return new PackageDependencySpec(name, REQUIRED, null);
}

/**
Expand All @@ -51,7 +51,19 @@ public static PackageDependencySpec required(String name) {
* @return dependency spec
*/
public static PackageDependencySpec optional(String name) {
return new PackageDependencySpec(name, OPTIONAL);
return new PackageDependencySpec(name, OPTIONAL, null);
}

/**
* Creates an optional dependency on the package for the given stability. At provisioning time,
* if the stability level is not met, such dependency should be ignored.
*
* @param name target package name
* @param validForStability the minimum stability expected for this package dependency to be valid.
* @return dependency spec
*/
public static PackageDependencySpec optional(String name, String validForStability) {
return new PackageDependencySpec(name, OPTIONAL, validForStability);
}

/**
Expand All @@ -61,7 +73,19 @@ public static PackageDependencySpec optional(String name) {
* @return dependency spec
*/
public static PackageDependencySpec passive(String name) {
return new PackageDependencySpec(name, PASSIVE);
return new PackageDependencySpec(name, PASSIVE, null);
}

/**
* Creates a passive dependency on the package. At provisioning time,
* if the stability level is not met, such dependency should be ignored.
*
* @param name target package name
* @param validForStability the minimum stability expected for this package dependency to be valid.
* @return dependency spec
*/
public static PackageDependencySpec passive(String name, String validForStability) {
return new PackageDependencySpec(name, PASSIVE, validForStability);
}

public static PackageDependencySpec newInstance(String packageName, int type) throws ProvisioningDescriptionException {
Expand All @@ -78,13 +102,18 @@ public static PackageDependencySpec newInstance(String packageName, int type) th
}

private final String name;
private final String validForStability;
private final int type;

protected PackageDependencySpec(String name, int type) {
protected PackageDependencySpec(String name, int type, String validForStability) {
this.name = name;
this.type = type;
this.validForStability = validForStability;
}

public String getValidForStability() {
return validForStability;
}
public String getName() {
return name;
}
Expand Down Expand Up @@ -136,6 +165,9 @@ public String toString() {
if(isOptional()) {
buf.append(type == OPTIONAL ? " optional" : " passive");
}
if(validForStability != null) {
buf.append( " " + validForStability);
}
return buf.append(']').toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -49,6 +49,7 @@ protected enum Attribute implements XmlNameProvider {
NAME("name"),
OPTIONAL("optional"),
PASSIVE("passive"),
VALID_FOR_STABILITY("valid-for-stability"),

// default unknown attribute
UNKNOWN(null);
Expand All @@ -60,6 +61,7 @@ protected enum Attribute implements XmlNameProvider {
attributes.put(new QName(NAME.name), NAME);
attributes.put(new QName(OPTIONAL.name), OPTIONAL);
attributes.put(new QName(PASSIVE.name), PASSIVE);
attributes.put(new QName(VALID_FOR_STABILITY.name), VALID_FOR_STABILITY);
attributes.put(null, UNKNOWN);
}

Expand Down Expand Up @@ -129,6 +131,7 @@ public static void parsePackageDeps(XmlNameProvider parent, XMLExtendedStreamRea

private static PackageDependencySpec parsePackageDependency(XMLExtendedStreamReader reader) throws XMLStreamException {
String name = null;
String validForStability = null;
Boolean optional = null;
boolean passive = false;
final int count = reader.getAttributeCount();
Expand All @@ -138,6 +141,9 @@ private static PackageDependencySpec parsePackageDependency(XMLExtendedStreamRea
case NAME:
name = reader.getAttributeValue(i);
break;
case VALID_FOR_STABILITY:
validForStability = reader.getAttributeValue(i);
break;
case OPTIONAL:
optional = Boolean.parseBoolean(reader.getAttributeValue(i));
break;
Expand All @@ -156,9 +162,15 @@ private static PackageDependencySpec parsePackageDependency(XMLExtendedStreamRea
if(optional != null && !optional) {
throw new XMLStreamException(Errors.requiredPassiveDependency(name), reader.getLocation());
}
return PackageDependencySpec.passive(name);
return PackageDependencySpec.passive(name, validForStability);
}
if (optional == null || !optional) {
if (validForStability != null) {
throw new XMLStreamException(Errors.requiredDependencyWithStability(name), reader.getLocation());
}
return PackageDependencySpec.required(name);
}
return optional == null || !optional ? PackageDependencySpec.required(name) : PackageDependencySpec.optional(name);
return PackageDependencySpec.optional(name, validForStability);
}

private static void parseOrigin(XMLExtendedStreamReader reader, PackageDepsSpecBuilder<?> pkgDeps) throws XMLStreamException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ private static void writePackageDependency(ElementNode deps, PackageDependencySp
} else {
addAttribute(depElement, PackageDepsSpecXmlParser.Attribute.OPTIONAL, TRUE);
}
if (depSpec.getValidForStability() != null) {
addAttribute(depElement, PackageDepsSpecXmlParser.Attribute.VALID_FOR_STABILITY, depSpec.getValidForStability());
}
}
}
}
Loading

0 comments on commit 60b54e0

Please sign in to comment.