Skip to content

Commit

Permalink
Merge pull request #87 from jfdenise/Issue_86
Browse files Browse the repository at this point in the history
Fix for Issue #86, Adapt to new wildfly-cli fat client shaded model
  • Loading branch information
jamezp authored Nov 11, 2024
2 parents bdbb48c + e219d51 commit 0f71fe5
Showing 1 changed file with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.parsers.DocumentBuilderFactory;

import org.jboss.galleon.MessageWriter;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.api.GalleonBuilder;
import org.jboss.galleon.api.GalleonFeaturePackRuntime;
import org.jboss.galleon.api.GalleonPackageRuntime;
import org.jboss.galleon.api.GalleonProvisioningRuntime;
import org.jboss.galleon.api.Provisioning;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
Expand All @@ -29,6 +34,10 @@
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.util.IoUtils;
import org.jboss.galleon.util.ZipUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.wildfly.common.Assert;
import org.wildfly.plugin.tools.cli.CLIForkedBootConfigGenerator;
import org.wildfly.plugin.tools.cli.ForkedCLIUtil;
Expand All @@ -52,6 +61,7 @@ public class BootableJarSupport {

private static final String BOOT_ARTIFACT_ID = "wildfly-jar-boot";
public static final String WILDFLY_ARTIFACT_VERSIONS_RESOURCE_PATH = "wildfly/artifact-versions.properties";
private static final String PACKAGE_ID_WILDFLY_CLI_SHADED_JAR = "org.wildfly.core.wildfly-cli.shaded";

/**
* Package a server as a bootable JAR.
Expand Down Expand Up @@ -204,19 +214,26 @@ public static ScannedArtifacts scanArtifacts(final Provisioning pm, final Galleo
} catch (Exception ex) {
throw new RuntimeException("Error reading artifact versions", ex);
}
GalleonPackageRuntime shadedModelpackage = fprt.getGalleonPackage(PACKAGE_ID_WILDFLY_CLI_SHADED_JAR);
if (shadedModelpackage != null) {
Path shadedModelFile = shadedModelpackage.getResource("pm", "wildfly", "shaded", "shaded-model.xml");
cliArtifacts.addAll(getArtifacts(shadedModelFile, propsMap));
}
for (Map.Entry<String, String> entry : propsMap.entrySet()) {
String value = entry.getValue();
MavenArtifact a = parseArtifact(value);
if ("wildfly-cli".equals(a.getArtifactId())
&& "org.wildfly.core".equals(a.getGroupId())) {
// We got it.
a.setClassifier("client");
// We got it.
if (writer.isVerboseEnabled()) {
writer.verbose("Found %s in %s", a, fprt.getFPID());
if (cliArtifacts.isEmpty()) {
if ("wildfly-cli".equals(a.getArtifactId())
&& "org.wildfly.core".equals(a.getGroupId())) {
// We got it.
a.setClassifier("client");
// We got it.
if (writer.isVerboseEnabled()) {
writer.verbose("Found %s in %s", a, fprt.getFPID());
}
cliArtifacts.add(a);
continue;
}
cliArtifacts.add(a);
continue;
}
if (JBOSS_MODULES_ARTIFACT_ID.equals(a.getArtifactId())
&& JBOSS_MODULES_GROUP_ID.equals(a.getGroupId())) {
Expand Down Expand Up @@ -301,4 +318,36 @@ private static MavenArtifact parseArtifact(final String artifact) {
ma.setExtension(extension);
return ma;
}

private static List<MavenArtifact> getArtifacts(Path shadedModel, Map<String, String> propsMap)
throws ProvisioningException {
Element rootElement;
try (InputStream srcInput = Files.newInputStream(shadedModel)) {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(srcInput);
rootElement = document.getDocumentElement();
} catch (Exception ex) {
throw new ProvisioningException(ex);
}
List<MavenArtifact> artifacts = new ArrayList<>();
NodeList shadedDependencies = rootElement.getElementsByTagName("dependency");
for (int i = 0; i < shadedDependencies.getLength(); i++) {
Node n = shadedDependencies.item(i);
if (n instanceof Element) {
Element e = (Element) n;
MavenArtifact ma = parseArtifact(e.getTextContent());
StringBuilder keyBuilder = new StringBuilder();
// groupId
keyBuilder.append(ma.getGroupId()).append(":");
// artifactId
keyBuilder.append(ma.getArtifactId());
// classifier
if (ma.getClassifier() != null && !ma.getClassifier().isEmpty()) {
keyBuilder.append("::").append(ma.getClassifier());
}
String withVersion = propsMap.get(keyBuilder.toString());
artifacts.add(parseArtifact(withVersion));
}
}
return artifacts;
}
}

0 comments on commit 0f71fe5

Please sign in to comment.