From da73aa67f0b051694c97a1738bd78471eb36d311 Mon Sep 17 00:00:00 2001 From: JF Denise Date: Mon, 7 Jun 2021 17:32:24 +0200 Subject: [PATCH] Fix for Issue #325, [WF28] Support for wildfly-ee-galleon-pack --- .../bootablejar/maven/common/Utils.java | 19 ++- .../goals/AbstractBuildBootableJarMojo.java | 31 ++--- .../maven/goals/BuildBootableJarMojo.java | 13 +- .../maven/goals/FeaturePacksUtil.java | 120 ++++++++++++++++++ .../cloud/openshift-interfaces-script.cli | 9 +- pom.xml | 14 +- tests/pom.xml | 100 ++++----------- .../AbstractBootableJarMojoTestCase.java | 10 ++ tests/src/test/resources/poms/test12-pom.xml | 2 +- tests/src/test/resources/poms/test17-pom.xml | 2 +- tests/src/test/resources/poms/test20-pom.xml | 2 +- 11 files changed, 210 insertions(+), 112 deletions(-) create mode 100644 plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/FeaturePacksUtil.java diff --git a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/common/Utils.java b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/common/Utils.java index b50abc24..77ac2d43 100644 --- a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/common/Utils.java +++ b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/common/Utils.java @@ -38,7 +38,8 @@ import org.jboss.galleon.layout.ProvisioningLayout; import org.jboss.galleon.universe.FeaturePackLocation; import org.wildfly.plugins.bootablejar.maven.goals.BuildBootableJarMojo; - +import static org.wildfly.plugins.bootablejar.maven.goals.AbstractBuildBootableJarMojo.STANDALONE; +import static org.wildfly.plugins.bootablejar.maven.goals.AbstractBuildBootableJarMojo.STANDALONE_XML; /** * @author jdenise */ @@ -69,6 +70,22 @@ public static class ProvisioningSpecifics { public String getHealthLayer() { return healthLayer; } + + public ConfigId getDefaultConfig(boolean isCloud) { + if (isCloud) { + if (isMicroprofile) { + return new ConfigId(STANDALONE, "standalone-microprofile-ha.xml"); + } else { + return new ConfigId(STANDALONE, "standalone-ha.xml"); + } + } else { + if (isMicroprofile) { + return new ConfigId(STANDALONE, "standalone-microprofile.xml"); + } else { + return new ConfigId(STANDALONE, STANDALONE_XML); + } + } + } } private static final Pattern WHITESPACE_IF_NOT_QUOTED = Pattern.compile("(\\S+\"[^\"]+\")|\\S+"); diff --git a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java index 6edcdffb..40a7ddae 100644 --- a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java +++ b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java @@ -124,9 +124,8 @@ public abstract class AbstractBuildBootableJarMojo extends AbstractMojo { private static final String BOOT_ARTIFACT_ID = "wildfly-jar-boot"; - private static final String STANDALONE = "standalone"; - private static final String STANDALONE_XML = "standalone.xml"; - private static final String STANDALONE_MICROPROFILE_XML = "standalone-microprofile.xml"; + public static final String STANDALONE = "standalone"; + public static final String STANDALONE_XML = "standalone.xml"; private static final String SERVER_CONFIG = "--server-config"; private static final String MAVEN_REPO_PLUGIN_OPTION = "jboss-maven-repo"; @@ -860,7 +859,8 @@ protected List getExcludedLayers() { return excludedLayers; } - private GalleonConfig buildFeaturePacksConfig(ProvisioningManager pm, boolean hasLayers) throws ProvisioningException, MojoExecutionException { + private GalleonConfig buildFeaturePacksConfig(ProvisioningManager pm, boolean hasLayers, + ConfigId defaultConfig) throws ProvisioningException, MojoExecutionException { ProvisioningConfig.Builder state = ProvisioningConfig.builder(); ConfigId provisionedConfigId = null; for (FeaturePack fp : featurePacks) { @@ -899,7 +899,7 @@ private GalleonConfig buildFeaturePacksConfig(ProvisioningManager pm, boolean ha } else { // We don't have an explicit default config and we have no layers, must include the default one. if (!hasLayers && provisionedConfigId == null) { - provisionedConfigId = getDefaultConfig(); + provisionedConfigId =defaultConfig; fpConfig.includeDefaultConfig(provisionedConfigId); } } @@ -1015,7 +1015,6 @@ public AbstractLayersConfig() throws ProvisioningDescriptionException, Provision } } - /** * Galleon layers based config that uses the set of feature-packs. */ @@ -1137,7 +1136,7 @@ private String formatLocation(String location) { return location; } - private GalleonConfig buildGalleonConfig(ProvisioningManager pm) throws ProvisioningException, MojoExecutionException { + private GalleonConfig buildGalleonConfig(ProvisioningManager pm, ConfigId defaultConfig) throws ProvisioningException, MojoExecutionException { boolean isLayerBasedConfig = !layers.isEmpty(); boolean hasFeaturePack = !featurePacks.isEmpty(); boolean hasProvisioningFile = Files.exists(getProvisioningFile()); @@ -1154,13 +1153,13 @@ private GalleonConfig buildGalleonConfig(ProvisioningManager pm) throws Provisio if (!hasFeaturePack) { throw new ProvisioningException("No server feature-pack location to provision layers, you must set a feature-pack-location"); } - return buildFeaturePacksConfig(pm, true); + return buildFeaturePacksConfig(pm, true, defaultConfig); } // Based on default config if (!featurePacks.isEmpty()) { getLog().info("Provisioning server using feature-packs"); - return buildFeaturePacksConfig(pm, isLayerBasedConfig); + return buildFeaturePacksConfig(pm, isLayerBasedConfig, defaultConfig); } if (hasProvisioningFile) { @@ -1170,13 +1169,13 @@ private GalleonConfig buildGalleonConfig(ProvisioningManager pm) throws Provisio throw new ProvisioningException("Invalid Galleon configuration"); } - private void willProvision(List featurePacks, ProvisioningManager pm) + private ConfigId willProvision(List featurePacks, ProvisioningManager pm) throws MojoExecutionException, ProvisioningException, IOException { ProvisioningSpecifics specifics = Utils.getSpecifics(featurePacks, pm); - willProvision(specifics); + return willProvision(specifics); } - protected abstract void willProvision(ProvisioningSpecifics specifics) throws MojoExecutionException; + protected abstract ConfigId willProvision(ProvisioningSpecifics specifics) throws MojoExecutionException; private Artifact provisionServer(Path home, Path outputProvisioningFile, Path workDir) throws ProvisioningException, MojoExecutionException, IOException, XMLStreamException { @@ -1190,8 +1189,8 @@ private Artifact provisionServer(Path home, Path outputProvisioningFile, Path wo // Prior to build the config, sub classes could have to inject content to the config according to the // provisioned FP. normalizeFeaturePackList(); - willProvision(featurePacks, pm); - ProvisioningConfig config = buildGalleonConfig(pm).buildConfig(); + ConfigId defaultConfig = willProvision(featurePacks, pm); + ProvisioningConfig config = buildGalleonConfig(pm, defaultConfig).buildConfig(); IoUtils.recursiveDelete(home); getLog().info("Building server based on " + config.getFeaturePackDeps() + " galleon feature-packs"); MavenUpgrade mavenUpgrade = null; @@ -1312,10 +1311,6 @@ private Artifact provisionServer(Path home, Path outputProvisioningFile, Path wo } } - protected ConfigId getDefaultConfig() { - return new ConfigId(STANDALONE, STANDALONE_MICROPROFILE_XML); - } - // Get Artifact, syntax comply with WildFly feature-pack versions file. static Artifact getArtifact(String str) { final String[] parts = str.split(":"); diff --git a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/BuildBootableJarMojo.java b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/BuildBootableJarMojo.java index ad1475c7..3fb40e3e 100644 --- a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/BuildBootableJarMojo.java +++ b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/BuildBootableJarMojo.java @@ -64,8 +64,7 @@ protected boolean updateManifest(Manifest manifest) { return false; } - @Override - protected void willProvision(ProvisioningSpecifics specifics) throws + protected ConfigId willProvision(ProvisioningSpecifics specifics) throws MojoExecutionException { if (!isPackageDev()) { if (cloud != null) { @@ -76,6 +75,7 @@ protected void willProvision(ProvisioningSpecifics specifics) throws } } } + return specifics.getDefaultConfig(cloud != null); } @Override @@ -89,15 +89,6 @@ protected void configureCli(List commands) { } } - @Override - protected ConfigId getDefaultConfig() { - if(cloud == null) { - return super.getDefaultConfig(); - } else { - return new ConfigId("standalone", "standalone-microprofile-ha.xml"); - } - } - @Override protected void copyExtraContentInternal(Path wildflyDir, Path contentDir) throws Exception { if (cloud != null) { diff --git a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/FeaturePacksUtil.java b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/FeaturePacksUtil.java new file mode 100644 index 00000000..67eac04c --- /dev/null +++ b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/FeaturePacksUtil.java @@ -0,0 +1,120 @@ +/* + * Copyright 2023 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"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.plugins.bootablejar.maven.goals; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.jboss.galleon.ProvisioningException; +import org.jboss.galleon.ProvisioningManager; +import org.jboss.galleon.config.ConfigId; +import org.jboss.galleon.config.FeaturePackConfig; +import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.layout.FeaturePackLayout; +import org.jboss.galleon.layout.ProvisioningLayout; +import org.jboss.galleon.universe.FeaturePackLocation; +import org.wildfly.plugins.bootablejar.maven.common.FeaturePack; +import static org.wildfly.plugins.bootablejar.maven.goals.AbstractBuildBootableJarMojo.STANDALONE; +import static org.wildfly.plugins.bootablejar.maven.goals.AbstractBuildBootableJarMojo.STANDALONE_XML; + +/** + * + * @author jdenise + */ +public class FeaturePacksUtil { + + private static final String HEALTH = "health"; + private static final String MP_HEALTH = "microprofile-health"; + + public static class ProvisioningSpecifics { + + private final boolean isMicroprofile; + private final String healthLayer; + + ProvisioningSpecifics(Set allLayers) { + if (allLayers.contains(MP_HEALTH)) { + healthLayer = MP_HEALTH; + isMicroprofile = true; + } else { + if (allLayers.contains(HEALTH)) { + healthLayer = HEALTH; + } else { + healthLayer = null; + } + isMicroprofile = false; + } + } + + ConfigId getDefaultConfig(boolean isCloud) { + if (isCloud) { + if (isMicroprofile) { + return new ConfigId(STANDALONE, "standalone-microprofile-ha.xml"); + } else { + return new ConfigId(STANDALONE, "standalone-ha.xml"); + } + } else { + if (isMicroprofile) { + return new ConfigId(STANDALONE, "standalone-microprofile.xml"); + } else { + return new ConfigId(STANDALONE, STANDALONE_XML); + } + } + } + + String getHealthLayer() { + return healthLayer; + } + } + + static ProvisioningSpecifics getSpecifics(List fps, ProvisioningManager pm) throws ProvisioningException, IOException { + return new ProvisioningSpecifics(getAllLayers(fps, pm)); + } + + private static Set getAllLayers(List fps, ProvisioningManager pm) throws ProvisioningException, IOException { + Set allLayers = new HashSet<>(); + for (FeaturePack fp : fps) { + final FeaturePackLocation fpl; + if (fp.getNormalizedPath() != null) { + fpl = pm.getLayoutFactory().addLocal(fp.getNormalizedPath(), false); + } else if (fp.getGroupId() != null && fp.getArtifactId() != null) { + String coords = fp.getMavenCoords(); + fpl = FeaturePackLocation.fromString(coords); + } else { + fpl = FeaturePackLocation.fromString(fp.getLocation()); + } + ProvisioningConfig pConfig = ProvisioningConfig.builder(). + addFeaturePackDep(FeaturePackConfig.builder(fpl).build()).build(); + try (ProvisioningLayout layout = pm. + getLayoutFactory().newConfigLayout(pConfig)) { + allLayers.addAll(getAllLayers(layout)); + } + } + return allLayers; + } + + private static Set getAllLayers(ProvisioningLayout pLayout) + throws ProvisioningException, IOException { + Set layers = new HashSet<>(); + for (FeaturePackLayout fp : pLayout.getOrderedFeaturePacks()) { + for (ConfigId layer : fp.loadLayers()) { + layers.add(layer.getName()); + } + } + return layers; + } +} diff --git a/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-interfaces-script.cli b/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-interfaces-script.cli index 988ad647..2f4ac506 100644 --- a/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-interfaces-script.cli +++ b/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-interfaces-script.cli @@ -27,7 +27,14 @@ if (outcome == success) of /socket-binding-group=standard-sockets/socket-binding /socket-binding-group=standard-sockets/socket-binding=https:write-attribute(name=interface,value=bindall) end-if -#remove ajp +#remove ajp and modcluster +if (outcome == success) of /subsystem=modcluster:read-resource + /subsystem=modcluster:remove +end-if +if (outcome == success) of /subsystem=undertow/server=default-server/ajp-listener=ajp:read-resource + /subsystem=undertow/server=default-server/ajp-listener=ajp:remove +end-if + if (outcome == success) of /socket-binding-group=standard-sockets/socket-binding=ajp:read-resource /socket-binding-group=standard-sockets/socket-binding=ajp:remove end-if diff --git a/pom.xml b/pom.xml index 134288b1..b5aaac49 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ 11 11 - 27.0.0.Final + 28.0.0.Beta1 main 27.0 @@ -64,7 +64,7 @@ 3.6.4 3.6.4 2.0.0 - 5.0.8.Final + 5.0.9.Final 20.0.0.Beta8 1.5.4.Final 4.1.0.Beta4 @@ -87,11 +87,15 @@ false ${maven.test.skip} - - wildfly-ee@maven(org.jboss.universe:community-universe)#${version.wildfly} + + standalone.xml + standalone-ha.xml + standalone-microprofile.xml + standalone-microprofile-ha.xml wildfly@maven(org.jboss.universe:community-universe)#${version.wildfly} + wildfly-ee@maven(org.jboss.universe:community-universe)#${version.wildfly} ${version.wildfly} - 27.0.0.Beta1 + 27.0.1.Final WildFly EE WildFly Full ${version.wildfly} diff --git a/tests/pom.xml b/tests/pom.xml index 2babbaba..83477de4 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -182,7 +182,6 @@ none - default-test-wildfly-ee @@ -193,9 +192,27 @@ ${test.ee.fpl} health + ${test.default.ee.config} + ${test.default.ee.cloud.config} + ${test.patch.ee.product} + + + org.wildfly.plugins.bootablejar.maven.goals.UpgradeArtifactFPLTestCase.java + + org.wildfly.plugins.bootablejar.maven.goals.UpgradeArtifactTestCase.java + - org/wildfly/plugins/bootablejar/maven/goals/OpenShiftConfigurationTestCase.java + + org.wildfly.plugins.bootablejar.maven.goals.DefaultCloudConfigurationExcludeLayerTestCase + org.wildfly.plugins.bootablejar.maven.goals.DefaultCloudConfigurationTestCase + org.wildfly.plugins.bootablejar.maven.goals.DefaultCloudConfigurationWithFPTestCase + org.wildfly.plugins.bootablejar.maven.goals.DefaultConfigurationSecurityManagerTestCase + org.wildfly.plugins.bootablejar.maven.goals.DefaultConfigurationTestCase + org.wildfly.plugins.bootablejar.maven.goals.DefaultConfigurationWithFPTestCase + org.wildfly.plugins.bootablejar.maven.goals.IncludedDefaultConfigurationCloudTestCase + org.wildfly.plugins.bootablejar.maven.goals.IncludedDefaultConfigurationNoLayersTestCase + org.wildfly.plugins.bootablejar.maven.goals.IncludedDefaultConfigurationTestCase @@ -210,7 +227,15 @@ ${test.fpl} ${test.patch.product} microprofile-health + ${test.default.config} + ${test.default.cloud.config} + ${test.patch.product} + + + org.wildfly.plugins.bootablejar.maven.goals.UpgradeArtifactTestCase.java + org.wildfly.plugins.bootablejar.maven.goals.UpgradeArtifactFPLTestCase.java + @@ -224,75 +249,4 @@ - - - - - wildfly-ee - - - - org.apache.maven.plugins - maven-surefire-plugin - - ${client.jvm.jpms.args} - - - - default-test - - test - - none - - - default-test-wildfly-ee - - test - - none - - - default-test-wildfly-full - - test - - none - - - all-test-wildfly-ee - - test - - test - - - ${test.ee.fpl} - health - ${test.patch.ee.product} - - - - - org/wildfly/plugins/bootablejar/maven/goals/UpgradeArtifactFPLTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/PatchExistingMiscTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/DefaultConfigurationSecurityManagerTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/DefaultCloudConfigurationTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/DefaultCloudConfigurationWithFPTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/IncludedDefaultConfigurationCloudTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/DefaultConfigurationTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/IncludedDefaultConfigurationNoLayersTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/IncludedDefaultConfigurationTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/DefaultConfigurationWithFPTestCase.java - org/wildfly/plugins/bootablejar/maven/goals/DefaultCloudConfigurationExcludeLayerTestCase.java - - - - - - - - - diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBootableJarMojoTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBootableJarMojoTestCase.java index 9cbeb3b6..658446fc 100644 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBootableJarMojoTestCase.java +++ b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBootableJarMojoTestCase.java @@ -70,12 +70,16 @@ public abstract class AbstractBootableJarMojoTestCase extends AbstractConfigured static final String WILDFLY_GROUP_ID = "test.groupid.wildfly"; static final String PLUGIN_VERSION = "test.plugin.version"; private static final String TEST_REPLACE = "TEST_REPLACE"; + private static final String TEST_DEFAULT_CONFIG_REPLACE = "TEST_DEFAULT_CONFIG_REPLACE"; + private static final String TEST_DEFAULT_CLOUD_CONFIG_REPLACE = "TEST_DEFAULT_CLOUD_CONFIG_REPLACE"; private static final String TEST_REPLACE_WF_EE_VERSION = "WF_EE_VERSION"; private static final String TEST_REPLACE_WF_GROUPID = "WF_GROUPID"; private static final String TEST_REPLACE_WF_VERSION = "WF_VERSION"; static final String PLUGIN_VERSION_TEST_REPLACE = "PLUGIN_VERSION"; static final String TEST_FILE = "test-" + AbstractBuildBootableJarMojo.BOOTABLE_SUFFIX + ".jar"; static final String HEALTH = System.getProperty("test.health"); + static final String DEFAULT_CONFIG = "test.default.config"; + static final String DEFAULT_CLOUD_CONFIG = "test.default.cloud.config"; private final String projectFile; private final boolean copyWar; private final String provisioning; @@ -166,6 +170,12 @@ protected void patchPomFile(File pom) throws IOException { if (s.contains(TEST_REPLACE_WF_GROUPID)) { s = s.replace(TEST_REPLACE_WF_GROUPID, System.getProperty(WILDFLY_GROUP_ID)); } + if (s.contains(TEST_DEFAULT_CONFIG_REPLACE)) { + s = s.replace(TEST_DEFAULT_CONFIG_REPLACE, System.getProperty(DEFAULT_CONFIG)); + } + if (s.contains(TEST_DEFAULT_CLOUD_CONFIG_REPLACE)) { + s = s.replace(TEST_DEFAULT_CLOUD_CONFIG_REPLACE, System.getProperty(DEFAULT_CLOUD_CONFIG)); + } content.append(s).append(System.lineSeparator()); } Files.write(pom.toPath(), content.toString().getBytes()); diff --git a/tests/src/test/resources/poms/test12-pom.xml b/tests/src/test/resources/poms/test12-pom.xml index f08dfe83..abe74175 100644 --- a/tests/src/test/resources/poms/test12-pom.xml +++ b/tests/src/test/resources/poms/test12-pom.xml @@ -19,7 +19,7 @@ TEST_REPLACE - standalone-microprofile.xml + TEST_DEFAULT_CONFIG_REPLACE diff --git a/tests/src/test/resources/poms/test17-pom.xml b/tests/src/test/resources/poms/test17-pom.xml index 5674a16f..17ecc92f 100644 --- a/tests/src/test/resources/poms/test17-pom.xml +++ b/tests/src/test/resources/poms/test17-pom.xml @@ -19,7 +19,7 @@ TEST_REPLACE - standalone-microprofile.xml + TEST_DEFAULT_CONFIG_REPLACE diff --git a/tests/src/test/resources/poms/test20-pom.xml b/tests/src/test/resources/poms/test20-pom.xml index 9eb3af93..5656affa 100644 --- a/tests/src/test/resources/poms/test20-pom.xml +++ b/tests/src/test/resources/poms/test20-pom.xml @@ -19,7 +19,7 @@ TEST_REPLACE - standalone-microprofile.xml + TEST_DEFAULT_CONFIG_REPLACE