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

Upgrade to latest Galleon. Some fixes in the channel support. #62

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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 @@ -16,6 +16,7 @@
*/
package org.wildfly.glow.cli.commands;

import org.wildfly.glow.ProvisioningUtils;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
Expand All @@ -26,8 +27,8 @@
import org.wildfly.glow.Arguments;
import org.wildfly.glow.Layer;
import org.wildfly.glow.LayerMapping;
import org.wildfly.glow.cli.commands.CommandsUtils.ProvisioningConsumer;

import org.wildfly.glow.ProvisioningUtils.ProvisioningConsumer;
import org.wildfly.glow.maven.MavenResolver;
import picocli.CommandLine;

@CommandLine.Command(
Expand All @@ -48,14 +49,27 @@ public class ShowAddOnsCommand extends AbstractCommand {
@CommandLine.Option(names = Constants.INPUT_FEATURE_PACKS_FILE_OPTION, paramLabel = Constants.INPUT_FEATURE_PACKS_FILE_OPTION_LABEL)
Optional<Path> provisioningXml;

@CommandLine.Option(names = {Constants.CHANNELS_FILE_OPTION_SHORT, Constants.CHANNELS_FILE_OPTION}, paramLabel = Constants.CHANNELS_FILE_OPTION_LABEL)
Optional<Path> channelsFile;

@Override
public Integer call() throws Exception {
print("Wildfly Glow is retrieving add-ons...");
String context = Arguments.BARE_METAL_EXECUTION_CONTEXT;
if (cloud.orElse(false)) {
context = Arguments.CLOUD_EXECUTION_CONTEXT;
}
CommandsUtils.ProvisioningConsumer consumer = new ProvisioningConsumer() {
if (wildflyPreview.orElse(false)) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_FILE_OPTION + " is set.");
}
}
if (wildflyServerVersion.isPresent()) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_FILE_OPTION + " is set.");
}
}
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningConsumer() {
@Override
public void consume(GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) {
Expand All @@ -74,7 +88,8 @@ public void consume(GalleonProvisioningConfig provisioning, Map<String, Layer> a
}

};
CommandsUtils.buildProvisioning(consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), context, wildflyPreview.orElse(false));
ProvisioningUtils.traverseProvisioning(consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null),
wildflyPreview.orElse(false), MavenResolver.buildMavenResolver(channelsFile.orElse(null)));
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.wildfly.glow.cli.commands;

import org.wildfly.glow.ProvisioningUtils;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
Expand All @@ -26,6 +28,9 @@
import org.jboss.galleon.api.config.GalleonFeaturePackConfig;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.FeaturePackLocation.FPID;
import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec;
import org.wildfly.glow.maven.MavenResolver;
import org.wildfly.glow.Arguments;
import org.wildfly.glow.FeaturePacks;
import org.wildfly.glow.Layer;
Expand All @@ -52,6 +57,9 @@ public class ShowConfigurationCommand extends AbstractCommand {
@CommandLine.Option(names = Constants.INPUT_FEATURE_PACKS_FILE_OPTION, paramLabel = Constants.INPUT_FEATURE_PACKS_FILE_OPTION_LABEL)
Optional<Path> provisioningXml;

@CommandLine.Option(names = {Constants.CHANNELS_FILE_OPTION_SHORT, Constants.CHANNELS_FILE_OPTION}, paramLabel = Constants.CHANNELS_FILE_OPTION_LABEL)
Optional<Path> channelsFile;

@Override
public Integer call() throws Exception {
print("Wildfly Glow is retrieving known provisioning configuration...");
Expand All @@ -66,41 +74,63 @@ public Integer call() throws Exception {
if (cloud.orElse(false)) {
context = Arguments.CLOUD_EXECUTION_CONTEXT;
}
if (wildflyPreview.orElse(false)) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_FILE_OPTION + " is set.");
}
}
if (wildflyServerVersion.isPresent()) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_FILE_OPTION + " is set.");
}
}
String finalContext = context;
boolean isLatest = wildflyServerVersion.isEmpty();
String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : FeaturePacks.getLatestVersion();
CommandsUtils.ProvisioningConsumer consumer = new CommandsUtils.ProvisioningConsumer() {
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() {
@Override
public void consume(GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) throws Exception {
String configStr = dumpConfiguration(fpDependencies, finalContext, vers, all,
mapping, provisioning, isLatest, wildflyPreview.orElse(false));
mapping, provisioning, isLatest, wildflyPreview.orElse(false), provisioningXml.orElse(null));
print(configStr);
}
};
CommandsUtils.buildProvisioning(consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), context, wildflyPreview.orElse(false));
ProvisioningUtils.traverseProvisioning(consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), MavenResolver.buildMavenResolver(channelsFile.orElse(null)));

return 0;
}

private static String dumpConfiguration(Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies,
String context, String serverVersion, Map<String, Layer> allLayers,
LayerMapping mapping, GalleonProvisioningConfig config, boolean isLatest, boolean techPreview) throws Exception {
LayerMapping mapping, GalleonProvisioningConfig config, boolean isLatest, boolean techPreview, Path provisioningXml) throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("Execution context: ").append(context).append("\n");
builder.append("Server version: ").append(serverVersion).append(isLatest ? " (latest)" : "").append("\n");
builder.append("Tech Preview: ").append(techPreview).append("\n");
if (provisioningXml == null) {
builder.append("Execution context: ").append(context).append("\n");
builder.append("Server version: ").append(serverVersion).append(isLatest ? " (latest)" : "").append("\n");
builder.append("Tech Preview: ").append(techPreview).append("\n");
} else {
builder.append("Input provisioning.xml file: ").append(provisioningXml).append("\n");
}
Set<FeaturePackLocation.ProducerSpec> topLevel = new LinkedHashSet<>();
Map<ProducerSpec, FPID> featurepacks = new LinkedHashMap<>();
for(GalleonFeaturePackConfig fp : config.getFeaturePackDeps()) {
topLevel.add(fp.getLocation().getProducer());
for(FPID fpid : fpDependencies.keySet()) {
if(fpid.getProducer().equals(fp.getLocation().getProducer())) {
featurepacks.put(fp.getLocation().getProducer(), fpid);
break;
}
}
}
for(GalleonFeaturePackConfig fp : config.getFeaturePackDeps()) {
builder.append("\nFeature-pack: ").append("@|bold ").append(fp.getLocation().getFPID()).append("|@\n");
for(ProducerSpec p : featurepacks.keySet()) {
FPID id = featurepacks.get(p);
builder.append("\nFeature-pack: ").append("@|bold ").append(id).append("|@\n");
builder.append("Contained layers: ");
Set<String> layers = new TreeSet<>();
Set<FeaturePackLocation.ProducerSpec> deps = fpDependencies.get(fp.getLocation().getFPID());
Set<FeaturePackLocation.ProducerSpec> deps = fpDependencies.get(id);
for(Layer l : allLayers.values()) {
if(l.getFeaturePacks().contains(fp.getLocation().getFPID())) {
if(l.getFeaturePacks().contains(id)) {
layers.add(l.getName());
}
if(deps != null) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/wildfly/glow/GlowSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public ScanResults scan() throws Exception {
= Utils.getAllLayers(config, universeResolver, provisioning, fpDependencies);
LayerMapping mapping = Utils.buildMapping(all, arguments.getExecutionProfiles());
if (mapping.getDefaultBaseLayer() == null) {
throw new IllegalArgumentException("No base layer found, WildFly Glow doesn't support WildFly server version. "
+ "You must upgrade to a more recent WildFly version.");
throw new IllegalArgumentException("No base layer found, server version is not supported. "
+ "You must upgrade to a more recent server version.");
}
// END BUILD MODEL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.glow.cli.commands;
package org.wildfly.glow;

import java.nio.file.Path;
import java.util.Collections;
Expand All @@ -28,33 +28,26 @@
import org.jboss.galleon.universe.UniverseResolver;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.util.IoUtils;
import org.wildfly.glow.FeaturePacks;
import org.wildfly.glow.GlowMessageWriter;
import static org.wildfly.glow.GlowSession.OFFLINE_CONTENT;
import org.wildfly.glow.Layer;
import org.wildfly.glow.LayerMapping;
import org.wildfly.glow.Utils;
import org.wildfly.glow.maven.MavenResolver;

/**
*
* @author jdenise
*/
public class CommandsUtils {
public class ProvisioningUtils {

public interface ProvisioningConsumer {

void consume(GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) throws Exception;
}

public static void buildProvisioning(ProvisioningConsumer consumer,
String executionContext, Path provisioningXML, boolean isLatest, String wildflyServerVersion, boolean wildflyPreview) throws Exception {
MavenRepoManager resolver = MavenResolver.newMavenResolver();
public static void traverseProvisioning(ProvisioningConsumer consumer,
String executionContext, Path provisioningXML, boolean isLatest, String wildflyServerVersion, boolean wildflyPreview, MavenRepoManager resolver) throws Exception {
UniverseResolver universeResolver = UniverseResolver.builder().addArtifactResolver(resolver).build();
GalleonBuilder provider = new GalleonBuilder();
provider.addArtifactResolver(resolver);
String vers = wildflyServerVersion == null ? wildflyServerVersion : FeaturePacks.getLatestVersion();
String vers = wildflyServerVersion != null ? wildflyServerVersion : FeaturePacks.getLatestVersion();
Provisioning provisioning = null;
try {
GalleonProvisioningConfig config = Utils.buildOfflineProvisioningConfig(provider, GlowMessageWriter.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ static RepositorySystem newRepositorySystem() {
return locator.getService(RepositorySystem.class);
}

public static MavenRepoManager buildMavenResolver(Path channelsFile) throws Exception {
MavenRepoManager resolver = null;
if (channelsFile != null) {
if (!Files.exists(channelsFile)) {
throw new Exception(channelsFile + " file doesn't exist");
}
ChannelSession session = buildChannelSession(channelsFile);
resolver = new ChannelMavenArtifactRepositoryManager(session);
} else {
resolver = MavenResolver.newMavenResolver();
}
return resolver;
}

public static ChannelSession buildChannelSession(Path path) throws Exception {
String content = Files.readString(path);
List<Channel> channels = ChannelMapper.fromString(content);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<version.org.apache.maven>3.8.6</version.org.apache.maven>
<version.org.apache.maven.checkstyle>3.0.0</version.org.apache.maven.checkstyle>
<version.org.apache.maven.resolver>1.6.3</version.org.apache.maven.resolver>
<version.org.jboss.galleon>6.0.0.Beta5</version.org.jboss.galleon>
<version.org.jboss.galleon>6.0.0.Beta6</version.org.jboss.galleon>
<version.org.wildfly.channel>1.0.5.Final</version.org.wildfly.channel>
<version.org.wildfly.core>24.0.0.Beta1</version.org.wildfly.core>
<version.org.jboss.logging.slf4j-jboss-logging>1.2.1.Final</version.org.jboss.logging.slf4j-jboss-logging>
Expand Down Expand Up @@ -57,7 +57,7 @@
<galleon.fork.embedded>true</galleon.fork.embedded>

<!-- Test dependency versions -->
<version.org.wildfly.galleon-plugins>7.0.0.Beta5</version.org.wildfly.galleon-plugins>
<version.org.wildfly.galleon-plugins>7.0.0.Beta7</version.org.wildfly.galleon-plugins>
<version.jakarta.annotation.jakarta-annotation-api>2.1.1</version.jakarta.annotation.jakarta-annotation-api>
<version.jakarta.ejb.jakarta-ejb-api>4.0.1</version.jakarta.ejb.jakarta-ejb-api>
<version.jakarta.enterprise.cdi-api>4.0.1</version.jakarta.enterprise.cdi-api>
Expand Down
Loading