Skip to content

Commit

Permalink
Merge pull request #299 from jfdenise/WFGP-282
Browse files Browse the repository at this point in the history
Fix for WFGP-282, Ignore package dependency with attached stability when building feature-pack
  • Loading branch information
jfdenise authored Jul 17, 2024
2 parents 9390c1d + 75ea3a7 commit d3d28fe
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@
*/
public abstract class AbstractFeaturePackBuildMojo extends AbstractMojo {

private static final String MSG_PACKAGE_NOT_INCLUDED = " This package has not been included in the feature-pack due to its stability level being lower than the feature-pack minimum stability level.";
private static final String MSG_PACKAGE_IGNORED = " This package dependency will be ignored at provisioning time.";
private static final String MSG_PACKAGE_ERROR = " This package dependency will fail at provisioning time. You should remove this package dependency or add the 'valid-for-stability' attribute to this package dependency.";
private static final String PACKAGE = "package";
private static final String FEATURE = "feature";
private static final String LAYER = "layer";
private static final String CONFIG = "config";

static final String ARTIFACT_LIST_CLASSIFIER = "artifact-list";
static final String ARTIFACT_LIST_EXTENSION = "txt";

Expand Down Expand Up @@ -502,7 +510,7 @@ protected void buildFeaturePack(FeaturePackDescription.Builder fpBuilder, WildFl
try {
//Validate that we can parse this feature-pack...
FeaturePackDescription desc = FeaturePackDescriber.describeFeaturePack(versionDir, "UTF-8");
checkFeaturePackContentStability(forbidLowerStatibilityLevelPackageReference, lowerStabilityPackages,
checkFeaturePackContentStability(buildTimestabilityLevel, forbidLowerStatibilityLevelPackageReference, lowerStabilityPackages,
desc.getPackages(), desc.getLayers(), desc.getFeatures(), desc.getConfigs(), getLog());
} catch (Exception ex) {
throw new RuntimeException(ex);
Expand Down Expand Up @@ -535,7 +543,19 @@ protected void buildFeaturePack(FeaturePackDescription.Builder fpBuilder, WildFl
}
}

static void checkFeaturePackContentStability(boolean forbidLowerStatibilityLevelPackageReference,
private static String formatIgnoreMessage(String kind, String name, String pkgName) {
return formatMessage(kind, name, pkgName, MSG_PACKAGE_IGNORED);
}

private static String formatErrorMessage(String kind, String name, String pkgName) {
return formatMessage(kind, name, pkgName, MSG_PACKAGE_ERROR);
}

private static String formatMessage(String kind, String name, String pkgName, String solution) {
return kind + name + " depends on the package " + pkgName + "." + MSG_PACKAGE_NOT_INCLUDED + solution;
}

static void checkFeaturePackContentStability(Stability buildTimestabilityLevel, boolean forbidLowerStatibilityLevelPackageReference,
Set<String> lowerStabilityPackages,
Collection<PackageSpec> packages,
Collection<ConfigLayerSpec> layers,
Expand All @@ -547,12 +567,19 @@ static void checkFeaturePackContentStability(boolean forbidLowerStatibilityLevel
if (spec.hasLocalPackageDeps()) {
for (PackageDependencySpec pds : spec.getLocalPackageDeps()) {
if (lowerStabilityPackages.contains(pds.getName())) {
String message = "package " + spec.getName() + " references the package " + pds.getName()
+ " that has not been packaged due to its stability level being lower than the feature-pack minimum stability level. You should remove this reference.";
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
String validForStability = pds.getValidForStability();
if (validForStability != null) {
Stability minStability = Stability.fromString(validForStability);
if (!buildTimestabilityLevel.enables(minStability)) {
log.debug(formatIgnoreMessage(PACKAGE, spec.getName(), pds.getName()));
}
} else {
log.warn(message);
String message = formatErrorMessage(PACKAGE, spec.getName(), pds.getName());
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
} else {
log.warn(message);
}
}
}
}
Expand All @@ -562,12 +589,19 @@ static void checkFeaturePackContentStability(boolean forbidLowerStatibilityLevel
if (spec.hasLocalPackageDeps()) {
for (PackageDependencySpec pds : spec.getLocalPackageDeps()) {
if (lowerStabilityPackages.contains(pds.getName())) {
String message = "package " + spec.getName() + " references the package " + pds.getName()
+ " that has not been packaged due to its stability level being lower than the feature-pack minimum stability level. You should remove this reference.";
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
String validForStability = pds.getValidForStability();
if (validForStability != null) {
Stability minStability = Stability.fromString(validForStability);
if (!buildTimestabilityLevel.enables(minStability)) {
log.debug(formatIgnoreMessage(LAYER, spec.getName(), pds.getName()));
}
} else {
log.warn(message);
String message = formatErrorMessage(LAYER, spec.getName(), pds.getName());
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
} else {
log.warn(message);
}
}
}
}
Expand All @@ -577,12 +611,19 @@ static void checkFeaturePackContentStability(boolean forbidLowerStatibilityLevel
if (spec.hasLocalPackageDeps()) {
for (PackageDependencySpec pds : spec.getLocalPackageDeps()) {
if (lowerStabilityPackages.contains(pds.getName())) {
String message = "feature " + spec.getName() + " references the package " + pds.getName()
+ " that has not been packaged due to its stability level being lower than the feature-pack minimum stability level. You should remove this reference.";
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
String validForStability = pds.getValidForStability();
if (validForStability != null) {
Stability minStability = Stability.fromString(validForStability);
if (!buildTimestabilityLevel.enables(minStability)) {
log.debug(formatIgnoreMessage(FEATURE, spec.getName(), pds.getName()));
}
} else {
log.warn(message);
String message = formatErrorMessage(FEATURE, spec.getName(), pds.getName());
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
} else {
log.warn(message);
}
}
}
}
Expand All @@ -596,12 +637,19 @@ static void checkFeaturePackContentStability(boolean forbidLowerStatibilityLevel
if (config.hasLocalPackageDeps()) {
for (PackageDependencySpec pds : config.getLocalPackageDeps()) {
if (lowerStabilityPackages.contains(pds.getName())) {
String message = "config " + modelName + "/" + configName + " references the package " + pds.getName()
+ " that has not been packaged due to its stability level being lower than the feature-pack minimum stability level. You should remove this reference.";
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
String validForStability = pds.getValidForStability();
if (validForStability != null) {
Stability minStability = Stability.fromString(validForStability);
if (!buildTimestabilityLevel.enables(minStability)) {
log.debug(formatIgnoreMessage(CONFIG, modelName + "/" + configName, pds.getName()));
}
} else {
log.warn(message);
String message = formatErrorMessage(CONFIG, modelName + "/" + configName, pds.getName());
if (forbidLowerStatibilityLevelPackageReference) {
throw new Exception(message);
} else {
log.warn(message);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;
import org.apache.maven.plugin.logging.Log;
import org.jboss.galleon.Constants;
import org.jboss.galleon.Stability;
import org.jboss.galleon.config.ConfigModel;
import org.jboss.galleon.spec.ConfigLayerSpec;
import org.jboss.galleon.spec.FeatureSpec;
Expand Down Expand Up @@ -133,7 +134,8 @@ public void error(Throwable thrwbl) {
}
};
// No check, should pass
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(false,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
false,
lowerStabilityPackages,
packages,
layers,
Expand All @@ -142,7 +144,8 @@ public void error(Throwable thrwbl) {
log);

// No package at lower stability level, should pass
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(false,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
false,
Collections.emptySet(),
packages,
layers,
Expand All @@ -153,7 +156,8 @@ public void error(Throwable thrwbl) {
{
boolean failed = false;
try {
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(true,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
true,
lowerStabilityPackages,
packages,
Collections.emptySet(),
Expand All @@ -171,7 +175,8 @@ public void error(Throwable thrwbl) {
{
boolean failed = false;
try {
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(true,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
true,
lowerStabilityPackages,
Collections.emptySet(),
layers,
Expand All @@ -189,7 +194,8 @@ public void error(Throwable thrwbl) {
{
boolean failed = false;
try {
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(true,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
true,
lowerStabilityPackages,
Collections.emptySet(),
Collections.emptySet(),
Expand All @@ -207,7 +213,8 @@ public void error(Throwable thrwbl) {
{
boolean failed = false;
try {
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(true,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
true,
lowerStabilityPackages,
Collections.emptySet(),
Collections.emptySet(),
Expand All @@ -225,7 +232,8 @@ public void error(Throwable thrwbl) {
{
boolean failed = false;
try {
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(true,
AbstractFeaturePackBuildMojo.checkFeaturePackContentStability(Stability.EXPERIMENTAL,
true,
lowerStabilityPackages,
packages,
layers,
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<version.org.codehaus.mojo.xml-maven-plugin>1.0.1</version.org.codehaus.mojo.xml-maven-plugin>
<version.org.codehaus.plexus.plexus-utils>3.1.0</version.org.codehaus.plexus.plexus-utils>
<version.org.eclipse.aether>1.1.0</version.org.eclipse.aether>
<version.org.jboss.galleon>6.0.1.Final</version.org.jboss.galleon>
<version.org.jboss.galleon>6.0.2.Final</version.org.jboss.galleon>
<version.org.jboss.dmr>1.5.0.Final</version.org.jboss.dmr>

<version.org.wildfly.channel>1.0.5.Final</version.org.wildfly.channel>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<config xmlns="urn:jboss:galleon:config:1.0" model="standalone">
<packages>
<package name="test.community.package" optional="true" valid-for-stability="community"/>
</packages>
</config>

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<param name="interface" value="test-default"/>
<param name="inet-address" value="127.0.0.1"/>
</feature>
<packages>
<package name="test.community.package" optional="true" valid-for-stability="community"/>
</packages>
</layer-spec>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
~ SPDX-License-Identifier: Apache-2.0
-->

<package-spec xmlns="urn:jboss:galleon:package:3.0" name="test.default.package"/>
<package-spec xmlns="urn:jboss:galleon:package:3.0" name="test.default.package">
<dependencies>
<package name="test.community.package" optional="true" valid-for-stability="community"/>
</dependencies>
</package-spec>

0 comments on commit d3d28fe

Please sign in to comment.