diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ShowAddOnsCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ShowAddOnsCommand.java index e5ce762e..2027c946 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ShowAddOnsCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ShowAddOnsCommand.java @@ -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; @@ -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( @@ -48,6 +49,9 @@ public class ShowAddOnsCommand extends AbstractCommand { @CommandLine.Option(names = Constants.INPUT_FEATURE_PACKS_FILE_OPTION, paramLabel = Constants.INPUT_FEATURE_PACKS_FILE_OPTION_LABEL) Optional provisioningXml; + @CommandLine.Option(names = {Constants.CHANNELS_FILE_OPTION_SHORT, Constants.CHANNELS_FILE_OPTION}, paramLabel = Constants.CHANNELS_FILE_OPTION_LABEL) + Optional channelsFile; + @Override public Integer call() throws Exception { print("Wildfly Glow is retrieving add-ons..."); @@ -55,7 +59,17 @@ public Integer call() throws Exception { 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 all, LayerMapping mapping, Map> fpDependencies) { @@ -74,7 +88,8 @@ public void consume(GalleonProvisioningConfig provisioning, Map 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; } } diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ShowConfigurationCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ShowConfigurationCommand.java index 0c83a1a5..88673a94 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ShowConfigurationCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ShowConfigurationCommand.java @@ -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; @@ -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; @@ -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 provisioningXml; + @CommandLine.Option(names = {Constants.CHANNELS_FILE_OPTION_SHORT, Constants.CHANNELS_FILE_OPTION}, paramLabel = Constants.CHANNELS_FILE_OPTION_LABEL) + Optional channelsFile; + @Override public Integer call() throws Exception { print("Wildfly Glow is retrieving known provisioning configuration..."); @@ -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 all, LayerMapping mapping, Map> 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> fpDependencies, String context, String serverVersion, Map 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 topLevel = new LinkedHashSet<>(); + Map 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 layers = new TreeSet<>(); - Set deps = fpDependencies.get(fp.getLocation().getFPID()); + Set 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) { diff --git a/core/src/main/java/org/wildfly/glow/GlowSession.java b/core/src/main/java/org/wildfly/glow/GlowSession.java index 47d3183e..770cbe86 100644 --- a/core/src/main/java/org/wildfly/glow/GlowSession.java +++ b/core/src/main/java/org/wildfly/glow/GlowSession.java @@ -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 diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/CommandsUtils.java b/core/src/main/java/org/wildfly/glow/ProvisioningUtils.java similarity index 85% rename from cli/src/main/java/org/wildfly/glow/cli/commands/CommandsUtils.java rename to core/src/main/java/org/wildfly/glow/ProvisioningUtils.java index 7bd7af5c..586f00e3 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/CommandsUtils.java +++ b/core/src/main/java/org/wildfly/glow/ProvisioningUtils.java @@ -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; @@ -28,19 +28,13 @@ 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 { @@ -48,13 +42,12 @@ void consume(GalleonProvisioningConfig provisioning, Map all, LayerMapping mapping, Map> 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); diff --git a/maven-resolver/src/main/java/org/wildfly/glow/maven/MavenResolver.java b/maven-resolver/src/main/java/org/wildfly/glow/maven/MavenResolver.java index ceb475a7..9b3ef1ff 100644 --- a/maven-resolver/src/main/java/org/wildfly/glow/maven/MavenResolver.java +++ b/maven-resolver/src/main/java/org/wildfly/glow/maven/MavenResolver.java @@ -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 channels = ChannelMapper.fromString(content); diff --git a/pom.xml b/pom.xml index 574b5d25..fc5ffc1c 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 3.8.6 3.0.0 1.6.3 - 6.0.0.Beta5 + 6.0.0.Beta6 1.0.5.Final 24.0.0.Beta1 1.2.1.Final @@ -57,7 +57,7 @@ true - 7.0.0.Beta5 + 7.0.0.Beta7 2.1.1 4.0.1 4.0.1