From 3f16f525bf4b0afc87948f76a135b4234699031b Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Tue, 23 Jan 2024 14:09:27 +0100 Subject: [PATCH] [WFGP-272] Handle feature-pack and package stability --- .../generator/FeatureSpecNode.java | 10 ++++-- .../galleon/plugin/WfInstallPlugin.java | 13 ++----- .../maven/AbstractFeaturePackBuildMojo.java | 36 +++++++++++++++---- .../galleon/maven/ModuleParseResult.java | 18 ++++++++++ .../galleon/maven/ModuleXmlParser.java | 5 +++ .../galleon/maven/WfFeaturePackBuildMojo.java | 8 ----- pom.xml | 4 +-- 7 files changed, 64 insertions(+), 30 deletions(-) diff --git a/feature-spec-gen/src/main/java/org/wildfly/galleon/plugin/featurespec/generator/FeatureSpecNode.java b/feature-spec-gen/src/main/java/org/wildfly/galleon/plugin/featurespec/generator/FeatureSpecNode.java index 9f09a144..6732ba3c 100644 --- a/feature-spec-gen/src/main/java/org/wildfly/galleon/plugin/featurespec/generator/FeatureSpecNode.java +++ b/feature-spec-gen/src/main/java/org/wildfly/galleon/plugin/featurespec/generator/FeatureSpecNode.java @@ -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"); @@ -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()); @@ -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()); } } diff --git a/galleon-plugins/src/main/java/org/wildfly/galleon/plugin/WfInstallPlugin.java b/galleon-plugins/src/main/java/org/wildfly/galleon/plugin/WfInstallPlugin.java index f2d374ca..3dc3c026 100644 --- a/galleon-plugins/src/main/java/org/wildfly/galleon/plugin/WfInstallPlugin.java +++ b/galleon-plugins/src/main/java/org/wildfly/galleon/plugin/WfInstallPlugin.java @@ -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; @@ -207,7 +201,7 @@ protected List 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() { @@ -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; } diff --git a/maven-plugin/src/main/java/org/wildfly/galleon/maven/AbstractFeaturePackBuildMojo.java b/maven-plugin/src/main/java/org/wildfly/galleon/maven/AbstractFeaturePackBuildMojo.java index 783b850d..0344721f 100644 --- a/maven-plugin/src/main/java/org/wildfly/galleon/maven/AbstractFeaturePackBuildMojo.java +++ b/maven-plugin/src/main/java/org/wildfly/galleon/maven/AbstractFeaturePackBuildMojo.java @@ -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; @@ -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 fpDependencies = Collections.emptyMap(); @@ -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) { @@ -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) { @@ -705,16 +717,26 @@ private void packageModules(FeaturePackDescription.Builder fpBuilder, for (Map.Entry 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(); @@ -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 diff --git a/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleParseResult.java b/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleParseResult.java index 254f9384..04cd6604 100644 --- a/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleParseResult.java +++ b/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleParseResult.java @@ -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; @@ -33,11 +34,28 @@ class ModuleParseResult { final Document document; ModuleIdentifier identifier; ArtifactName versionArtifactName; + private final Map 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 getProperties() { + return props; + } + List getDependencies() { return dependencies; } diff --git a/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleXmlParser.java b/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleXmlParser.java index fb933d4d..ab377a0b 100644 --- a/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleXmlParser.java +++ b/maven-plugin/src/main/java/org/wildfly/galleon/maven/ModuleXmlParser.java @@ -118,6 +118,11 @@ private static void parseModule(Element element, ModuleParseResult result, Map 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()); diff --git a/maven-plugin/src/main/java/org/wildfly/galleon/maven/WfFeaturePackBuildMojo.java b/maven-plugin/src/main/java/org/wildfly/galleon/maven/WfFeaturePackBuildMojo.java index 79a7e101..f8c5f93d 100644 --- a/maven-plugin/src/main/java/org/wildfly/galleon/maven/WfFeaturePackBuildMojo.java +++ b/maven-plugin/src/main/java/org/wildfly/galleon/maven/WfFeaturePackBuildMojo.java @@ -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 extendedPackages = Collections.emptyMap(); diff --git a/pom.xml b/pom.xml index 97b1d9b9..84d15c53 100644 --- a/pom.xml +++ b/pom.xml @@ -76,11 +76,11 @@ 1.0.1 3.1.0 1.1.0 - 6.0.0.Beta2 + 6.0.0.Beta3 1.5.0.Final 1.0.5.Final - 22.0.0.Final + 24.0.0.Beta1 2.0.0.Final 1.3.7