Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #86, Adapt to new wildfly-cli fat client shaded model #87

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}