Skip to content

Commit

Permalink
[WFGP-272] Handle feature-pack and package stability
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Feb 16, 2024
1 parent 7e9f5b9 commit 3f16f52
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 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 @@ -377,7 +377,10 @@ private void persistSpec(String name, ModelNode descr, int model) throws Provisi
if(branchId != null) {
builder.addAnnotation(FeatureAnnotation.featureBranch(branchId));
}

if(descr.hasDefined("stability")) {
String stability = descr.get("stability").asString();
builder.setStability(stability);
}
if (descr.hasDefined("requires")) {
for (ModelNode capability : descr.require("requires").asList()) {
builder.requiresCapability(capability.get("name").asString(), capability.hasDefined("optional") && capability.get("optional").asBoolean());
Expand Down Expand Up @@ -451,6 +454,9 @@ private void persistSpec(String name, ModelNode descr, int model) throws Provisi
if (param.hasDefined("type")) {
featureParamSpecBuilder.setType(param.get("type").asString());
}
if (param.hasDefined("stability")) {
featureParamSpecBuilder.setStability(param.get("stability").asString());
}
builder.addParam(featureParamSpecBuilder.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ interface ArtifactResolver {
private static final ProvisioningOption OPTION_RECORD_ARTIFACTS = ProvisioningOption.builder("jboss-resolved-artifacts-cache")
.setDefaultValue(".installation" + File.separator + ".cache")
.build();
private static final ProvisioningOption OPTION_STABILITY_LEVEL = ProvisioningOption.builder("jboss-stability-level")
.addToValueSet("experimental")
.addToValueSet("preview")
.addToValueSet("community")
.addToValueSet("default")
.build();
private ProvisioningRuntime runtime;
MessageWriter log;

Expand Down Expand Up @@ -207,7 +201,7 @@ protected List<ProvisioningOption> initPluginOptions() {
OPTION_FORK_EMBEDDED, OPTION_MVN_REPO,
OPTION_RESET_EMBEDDED_SYSTEM_PROPERTIES,
OPTION_OVERRIDDEN_ARTIFACTS, OPTION_BULK_RESOLVE_ARTIFACTS,
OPTION_RECORD_ARTIFACTS, OPTION_STABILITY_LEVEL);
OPTION_RECORD_ARTIFACTS);
}

public ProvisioningRuntime getRuntime() {
Expand Down Expand Up @@ -254,10 +248,7 @@ private String isResetEmbeddedSystemProperties() throws ProvisioningException {
}

private String getStabilityLevel() throws ProvisioningException {
if (!runtime.isOptionSet(OPTION_STABILITY_LEVEL)) {
return "";
}
final String value = runtime.getOptionValue(OPTION_STABILITY_LEVEL);
final String value = runtime.getLowestStability();
return value == null ? "" : value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.jboss.galleon.Errors;
import org.jboss.galleon.ProvisioningDescriptionException;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.Stability;
import org.jboss.galleon.config.ConfigModel;
import org.jboss.galleon.config.FeaturePackConfig;
import org.jboss.galleon.layout.FeaturePackDescriber;
Expand Down Expand Up @@ -203,6 +204,14 @@ static boolean isProvided(String module) {
@Component
private MavenProjectHelper projectHelper;

/**
* The minimum stability level of the WildFly processes used to generate feature specs.
* Set this if you need to generate feature specs for features with a lower stability level
* than the default level of the WildFly process being used for feature-spec generation.
*/
@Parameter(alias = "minimum-stability", required = false)
protected String minimumStability;

private MavenProjectArtifactVersions artifactVersions;

private Map<String, FeaturePackDescription> fpDependencies = Collections.emptyMap();
Expand All @@ -213,10 +222,12 @@ static boolean isProvided(String module) {
private Path resourcesWildFly;
private Path fpResourcesDir;
private Path resourcesDir;
private Stability stability;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
stability = minimumStability == null ? null : Stability.fromString(minimumStability);
artifactVersions = MavenProjectArtifactVersions.getInstance(project);
doExecute();
} catch (RuntimeException | Error | MojoExecutionException | MojoFailureException e) {
Expand Down Expand Up @@ -367,6 +378,7 @@ protected void buildFeaturePack(FeaturePackDescription.Builder fpBuilder, WildFl

final FeaturePackDescription fpLayout;
try {
fpBuilder.getSpecBuilder().setMinStability(stability);
fpLayout = fpBuilder.build();
FeaturePackXmlWriter.getInstance().write(fpLayout.getSpec(), getFpDir().resolve(Constants.FEATURE_PACK_XML));
} catch (XMLStreamException | IOException | ProvisioningDescriptionException e) {
Expand Down Expand Up @@ -705,16 +717,26 @@ private void packageModules(FeaturePackDescription.Builder fpBuilder,
for (Map.Entry<String, Path> module : moduleXmlByPkgName.entrySet()) {
final String packageName = module.getKey();
final Path moduleXml = module.getValue();

final Path packageDir = getPackagesDir().resolve(packageName);
final Path targetXml = packageDir.resolve(WfConstants.PM).resolve(WfConstants.WILDFLY).resolve(WfConstants.MODULE).resolve(resourcesDir.relativize(moduleXml));
mkdirs(targetXml.getParent());
IoUtils.copy(moduleXml.getParent(), targetXml.getParent());

final PackageSpec.Builder pkgSpecBuilder = PackageSpec.builder(packageName);
final ModuleParseResult parsedModule;
try {
parsedModule = ModuleXmlParser.parse(targetXml, WfConstants.UTF8, targetToAlias);
parsedModule = ModuleXmlParser.parse(moduleXml, WfConstants.UTF8, targetToAlias);
String packageStability = parsedModule.getProperty("org.jboss.stability");
if (packageStability != null) {
Stability stab = Stability.fromString(packageStability);
if (stability != null && !stability.enables(stab)) {
getLog().warn("JBoss Modules module " + parsedModule.getIdentifier() + " is not included in the feature-pack. "
+ "Package stability '" +
packageStability + "' is not enabled by the '" + stability +
"' stability level that is the feature-pack minimum stability level.");
continue;
}
pkgSpecBuilder.setStability(stab);
}
final Path targetXml = packageDir.resolve(WfConstants.PM).resolve(WfConstants.WILDFLY).resolve(WfConstants.MODULE).resolve(resourcesDir.relativize(moduleXml));
mkdirs(targetXml.getParent());
IoUtils.copy(moduleXml.getParent(), targetXml.getParent());
if (!parsedModule.dependencies.isEmpty()) {
for (ModuleParseResult.ModuleDependency moduleDep : parsedModule.dependencies) {
final ModuleIdentifier moduleId = moduleDep.getModuleId();
Expand Down Expand Up @@ -763,7 +785,7 @@ private void packageModules(FeaturePackDescription.Builder fpBuilder,
}
}
} catch (ParsingException e) {
throw new IOException(Errors.parseXml(targetXml), e);
throw new IOException(Errors.parseXml(moduleXml), e);
}

final PackageSpec pkgSpec = pkgSpecBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.wildfly.galleon.maven;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -33,11 +34,28 @@ class ModuleParseResult {
final Document document;
ModuleIdentifier identifier;
ArtifactName versionArtifactName;
private final Map<String, String> props = new HashMap<>();

ModuleParseResult(final Document document) {
this.document = document;
}

boolean hasProperties() {
return !props.isEmpty();
}

boolean hasProperty(String name) {
return props.containsKey(name);
}

String getProperty(String name) {
return props.get(name);
}

Map<String, String> getProperties() {
return props;
}

List<ModuleDependency> getDependencies() {
return dependencies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ private static void parseModule(Element element, ModuleParseResult result, Map<M
if (versionAttribute != null) {
result.versionArtifactName = parseOptionalArtifactName(versionAttribute.getValue(), versionAttribute);
}
final Element props = element.getFirstChildElement("properties", element.getNamespaceURI());
if (props != null) {
Map<String, String> properties = parseProperties(props);
result.getProperties().putAll(properties);
}
final Element dependencies = element.getFirstChildElement("dependencies", element.getNamespaceURI());
if (dependencies != null) parseDependencies(dependencies, result);
final Element resources = element.getFirstChildElement("resources", element.getNamespaceURI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,6 @@ public boolean accept(Path path) {
@Parameter(alias = "feature-specs-output", defaultValue = "${project.build.directory}/resources/features", required = true)
protected File featureSpecsOutput;

/**
* The minimum stability level of the WildFly processes used to generate feature specs.
* Set this if you need to generate feature specs for features with a lower stability level
* than the default level of the WildFly process being used for feature-spec generation.
*/
@Parameter(alias = "minimum-stability", required = false)
protected String minimumStability;

private WildFlyFeaturePackBuild buildConfig;
private Map<String, PackageSpec.Builder> extendedPackages = Collections.emptyMap();

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
<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.0.Beta2</version.org.jboss.galleon>
<version.org.jboss.galleon>6.0.0.Beta3</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>
<version.org.wildfly.core.wildfly-core>22.0.0.Final</version.org.wildfly.core.wildfly-core>
<version.org.wildfly.core.wildfly-core>24.0.0.Beta1</version.org.wildfly.core.wildfly-core>
<version.org.wildfly.maven.plugins>2.0.0.Final</version.org.wildfly.maven.plugins>

<version.xom>1.3.7</version.xom>
Expand Down

0 comments on commit 3f16f52

Please sign in to comment.