Skip to content

Commit

Permalink
Merge pull request #585 from jfdenise/WFMP-278
Browse files Browse the repository at this point in the history
Fix for WFMP-278, Enforce that cloud option shouldn't be used when packaging a bootable JAR
  • Loading branch information
jamezp authored Oct 18, 2024
2 parents 8efb827 + 37c5a84 commit d43fdb7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@SuppressWarnings("unused")
public class GlowConfig {

static final String CLOUD_CONTEXT = "cloud";

private String context = "bare-metal";
private String profile;
private Set<String> addOns = Set.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ public class PackageServerMojo extends AbstractProvisionServerMojo {
* <ul>
* <li>addOns: List of addOn to enable. An addOn brings extra galleon layers to the provisioning (eg: {@code wildfly-cli} to
* include CLI.</li>
* <li>context: {@code bare-metal} or (@code cloud}. Default to {@code bare-metal}</li>
* <li>context: {@code bare-metal} or {@code cloud}. Default to {@code bare-metal}. Note that if the context is set to
* {@code cloud}
* and the plugin option {@code bootable-jar} is set, the plugin execution will abort.</li>
* <li>failsOnError: true|false. If errors are detected (missing datasource, missing messaging broker, ambiguous JNDI call,
* provisioning is aborted. Default to {@code false}</li>
* <li>layersForJndi: List of Galleon layers required by some JNDI calls located in your application.</li>
Expand Down Expand Up @@ -232,7 +234,9 @@ public class PackageServerMojo extends AbstractProvisionServerMojo {

/**
* Package the provisioned server into a WildFly Bootable JAR. In order to produce a hollow jar (a jar that doesn't contain
* a deployment) set the { @code skipDeployment } parameter.
* a deployment) set the { @code skipDeployment } parameter. A server packaged as bootable JAR is suited to run on
* bare-metal.
* When provisioning a server for the cloud, this option shouldn't be set.
* <p>
* Note that the produced fat JAR is ignored when running the {@code dev},{@code image},{@code start} or {@code run} goals.
* </p>
Expand Down Expand Up @@ -281,6 +285,12 @@ protected GalleonProvisioningConfig buildGalleonConfig(GalleonBuilder pm)
config = super.buildGalleonConfig(pm);
return config;
}
if (discoverProvisioningInfo.getContext() != null &&
GlowConfig.CLOUD_CONTEXT.equals(discoverProvisioningInfo.getContext()) &&
bootableJar) {
throw new MojoExecutionException("The option 'bootableJar' must not be set when "
+ "discovering provisioning information for the 'cloud' execution context.");
}
try {
try (ScanResults results = Utils.scanDeployment(discoverProvisioningInfo,
layers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.file.Path;

import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.wildfly.plugin.tests.AbstractProvisionConfiguredMojoTestCase;
import org.wildfly.plugin.tests.AbstractWildFlyMojoTest;
Expand Down Expand Up @@ -61,4 +62,19 @@ public void testGlowPackage() throws Exception {
checkJar(AbstractWildFlyMojoTest.getBaseDir(), BOOTABLE_JAR_NAME, deploymentName,
true, layers, null, true);
}

@Test
public void testGlowCloudPackage() throws Exception {

final Mojo packageMojo = lookupConfiguredMojo(
AbstractWildFlyMojoTest.getPomFile("package-bootable-glow-cloud-pom.xml").toFile(), "package");
try {
packageMojo.execute();
throw new Exception("Should have failed!");
} catch (MojoExecutionException ex) {
// XXX OK expected
assertEquals("The option 'bootableJar' must not be set when " +
"discovering provisioning information for the 'cloud' execution context.", ex.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testing</groupId>
<artifactId>testing</artifactId>
<version>0.1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<filename>test.war</filename>
<record-provisioning-state>true</record-provisioning-state>
<provisioning-dir>packaged-bootable-glow-server</provisioning-dir>
<bootable-jar>true</bootable-jar>
<bootable-jar-name>server-bootable.jar</bootable-jar-name>
<discover-provisioning-info>
<context>cloud</context>
</discover-provisioning-info>
</configuration>
</plugin>
</plugins>
</build>

</project>

0 comments on commit d43fdb7

Please sign in to comment.