From 834759d970ec5a16bb1a6c88b53393c8ae5b0309 Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Wed, 15 Jan 2025 13:01:41 +0100 Subject: [PATCH] Fix for Issue #108, Glow Metadata should be retrieved from Maven --- .../glow/cli/commands/ShowAddOnsCommand.java | 82 +++++++------- .../commands/ShowConfigurationCommand.java | 104 ++++++++++-------- .../commands/ShowServerVersionsCommand.java | 25 +++-- .../main/java/org/wildfly/glow/Arguments.java | 13 ++- .../wildfly/glow/BaseArgumentsBuilder.java | 4 +- .../java/org/wildfly/glow/FeaturePacks.java | 41 ++++--- .../java/org/wildfly/glow/GlowSession.java | 43 ++++++-- .../org/wildfly/glow/MetadataProvider.java | 40 +++++++ .../org/wildfly/glow/ProvisioningUtils.java | 6 +- .../java/org/wildfly/glow/ScanArguments.java | 6 + .../java/org/wildfly/glow/ScanResults.java | 10 +- .../glow/WildFlyMavenMetadataProvider.java | 85 ++++++++++++++ .../wildfly/glow/WildFlyMetadataProvider.java | 69 ++++++++++++ .../org/wildfly/glow/glow.properties | 2 - .../wildfly/glow/plugin/doc/GenerateMojo.java | 100 +++++++++++++++++ .../wildfly/glow/plugin/doc/ScanDocMojo.java | 80 ++++++++------ maven-resolver/pom.xml | 4 + pom.xml | 7 +- .../DataSourceDefinitionTestCase.java | 10 +- .../exploded/ExplodedArchiveTestCase.java | 7 +- .../resource/ejb/EJBLiteResourceTestCase.java | 5 + .../resource/ejb/EJBResourceTestCase.java | 6 +- 22 files changed, 576 insertions(+), 173 deletions(-) create mode 100644 core/src/main/java/org/wildfly/glow/MetadataProvider.java create mode 100644 core/src/main/java/org/wildfly/glow/WildFlyMavenMetadataProvider.java create mode 100644 core/src/main/java/org/wildfly/glow/WildFlyMetadataProvider.java create mode 100644 doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/GenerateMojo.java 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 a22a5bab..b31abe1d 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 @@ -30,16 +30,18 @@ import org.jboss.galleon.universe.FeaturePackLocation; import org.jboss.galleon.universe.FeaturePackLocation.FPID; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.jboss.galleon.util.IoUtils; import org.wildfly.channel.Channel; import org.wildfly.channel.ChannelMapper; import org.wildfly.glow.AddOn; import org.wildfly.glow.Arguments; -import org.wildfly.glow.FeaturePacks; import org.wildfly.glow.Layer; import org.wildfly.glow.LayerMapping; +import org.wildfly.glow.MetadataProvider; import org.wildfly.glow.ProvisioningUtils; import org.wildfly.glow.ScanArguments; import org.wildfly.glow.Space; +import org.wildfly.glow.WildFlyMavenMetadataProvider; import org.wildfly.glow.cli.support.CLIConfigurationResolver; import org.wildfly.glow.maven.MavenResolver; import picocli.CommandLine; @@ -73,38 +75,55 @@ public class ShowAddOnsCommand extends AbstractCommand { @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; + ScanArguments.Builder builder = Arguments.scanBuilder(); + MavenRepoManager repoManager; + List channels = Collections.emptyList(); + if (channelsFile.isPresent()) { + String content = Files.readString(channelsFile.get()); + channels = ChannelMapper.fromString(content); + builder.setChannels(channels); + repoManager = MavenResolver.newMavenResolver(channels); + } else { + repoManager = MavenResolver.newMavenResolver(); } - if (wildflyPreview.orElse(false)) { - if (channelsFile.isPresent()) { - throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set."); + Path tmpMetadataDirectory = Files.createTempDirectory("glow-metadata"); + try { + MetadataProvider metadataProvider = new WildFlyMavenMetadataProvider(repoManager, tmpMetadataDirectory); + String context = Arguments.BARE_METAL_EXECUTION_CONTEXT; + if (cloud.orElse(false)) { + context = Arguments.CLOUD_EXECUTION_CONTEXT; } - } - if (wildflyServerVersion.isPresent()) { - if (channelsFile.isPresent()) { - throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set."); + if (wildflyPreview.orElse(false)) { + if (channelsFile.isPresent()) { + throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set."); + } } - } - showAddOns(Space.DEFAULT, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null), - wildflyPreview.orElse(false), channelsFile.orElse(null)); - String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : FeaturePacks.getLatestVersion(); - for(String spaceName : spaces) { - Set versions = FeaturePacks.getAllVersions(spaceName); - if (versions.contains(vers)) { - Space space = FeaturePacks.getSpace(spaceName); - showAddOns(space, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null), - wildflyPreview.orElse(false), channelsFile.orElse(null)); + if (wildflyServerVersion.isPresent()) { + if (channelsFile.isPresent()) { + throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set."); + } } - } - print("@|bold Add-ons can be set using the|@ @|fg(yellow) %s=|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.ADD_ONS_OPTION, Constants.SCAN_COMMAND); + showAddOns(Space.DEFAULT, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null), + wildflyPreview.orElse(false), channels, repoManager, metadataProvider); + String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : metadataProvider.getLatestVersion(); + for (String spaceName : spaces) { + Set versions = metadataProvider.getAllVersions(spaceName); + if (versions.contains(vers)) { + Space space = metadataProvider.getSpace(spaceName); + showAddOns(space, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null), + wildflyPreview.orElse(false), channels, repoManager, metadataProvider); + } + } + print("@|bold Add-ons can be set using the|@ @|fg(yellow) %s=|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.ADD_ONS_OPTION, Constants.SCAN_COMMAND); - return 0; + return 0; + } finally { + IoUtils.recursiveDelete(tmpMetadataDirectory); + } } public void showAddOns(Space space, String context, Path provisioningXml, boolean isLatest, - String serverVersion, boolean isPreview, Path channelsFile) throws Exception { + String serverVersion, boolean isPreview, List channels, MavenRepoManager repoManager, MetadataProvider metadataProvider) throws Exception { CLIConfigurationResolver resolver = new CLIConfigurationResolver(); ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() { @Override @@ -161,18 +180,7 @@ public void consume(Space space, GalleonProvisioningConfig provisioning, Map channels = Collections.emptyList(); - if (channelsFile != null) { - String content = Files.readString(channelsFile); - channels = ChannelMapper.fromString(content); - builder.setChannels(channels); - repoManager = MavenResolver.newMavenResolver(channels); - } else { - repoManager = MavenResolver.newMavenResolver(); - } ProvisioningUtils.traverseProvisioning(space, consumer, context, provisioningXml, isLatest, serverVersion, - isPreview, channels, repoManager); + isPreview, channels, repoManager, metadataProvider); } } 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 020b9bba..8c634dd7 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 @@ -36,15 +36,17 @@ import org.jboss.galleon.universe.FeaturePackLocation.FPID; import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.jboss.galleon.util.IoUtils; import org.wildfly.channel.Channel; import org.wildfly.channel.ChannelMapper; import org.wildfly.glow.maven.MavenResolver; import org.wildfly.glow.Arguments; -import org.wildfly.glow.FeaturePacks; import org.wildfly.glow.Layer; import org.wildfly.glow.LayerMapping; +import org.wildfly.glow.MetadataProvider; import org.wildfly.glow.ScanArguments; import org.wildfly.glow.Space; +import org.wildfly.glow.WildFlyMavenMetadataProvider; import org.wildfly.glow.deployment.openshift.api.Deployer; import picocli.CommandLine; @@ -79,47 +81,6 @@ public class ShowConfigurationCommand extends AbstractCommand { public Integer call() throws Exception { print("Wildfly Glow is retrieving known provisioning configuration..."); StringBuilder ocBuilder = new StringBuilder(); - ocBuilder.append("\nDeployers enabled when provisioning to OpenShift:\n"); - for (Deployer d : ServiceLoader.load(Deployer.class)) { - ocBuilder.append("* @|bold " + d.getName() + "|@. Enabled when the layer(s) " + d.getSupportedLayers() + " is/are discovered.\n"); - } - print(ocBuilder.toString()); - StringBuilder spacesBuilder = new StringBuilder(); - spacesBuilder.append("\nSpaces from which more feature-packs can be used when scanning deployments (use the " + Constants.SPACES_OPTION + " option to enable the space(s):\n"); - for(Space space : FeaturePacks.getAllSpaces()) { - spacesBuilder.append("* @|bold " + space.getName() + "|@. " + space.getDescription() + "\n"); - } - print(spacesBuilder.toString()); - - String context = Arguments.BARE_METAL_EXECUTION_CONTEXT; - 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_OPTION + " is set."); - } - } - if (wildflyServerVersion.isPresent()) { - if (channelsFile.isPresent()) { - throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set."); - } - } - String finalContext = context; - boolean isLatest = wildflyServerVersion.isEmpty(); - String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : FeaturePacks.getLatestVersion(); - ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() { - @Override - public void consume(Space space, GalleonProvisioningConfig provisioning, Map all, - LayerMapping mapping, Map> fpDependencies) throws Exception { - if (Space.DEFAULT.equals(space)) { - defaultSpaceFpDependencies = fpDependencies; - } - String configStr = dumpConfiguration(space, fpDependencies, finalContext, vers, all, - mapping, provisioning, isLatest, wildflyPreview.orElse(false), provisioningXml.orElse(null)); - print(configStr); - } - }; ScanArguments.Builder builder = Arguments.scanBuilder(); MavenRepoManager repoManager; List channels = Collections.emptyList(); @@ -131,13 +92,60 @@ public void consume(Space space, GalleonProvisioningConfig provisioning, Map versions = FeaturePacks.getAllVersions(spaceName); - if (versions.contains(vers)) { - Space space = FeaturePacks.getSpace(spaceName); - ProvisioningUtils.traverseProvisioning(space, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager); + Path tmpMetadataDirectory = Files.createTempDirectory("glow-metadata"); + try { + MetadataProvider metadataProvider = new WildFlyMavenMetadataProvider(repoManager, tmpMetadataDirectory); + ocBuilder.append("\nDeployers enabled when provisioning to OpenShift:\n"); + for (Deployer d : ServiceLoader.load(Deployer.class)) { + ocBuilder.append("* @|bold " + d.getName() + "|@. Enabled when the layer(s) " + d.getSupportedLayers() + " is/are discovered.\n"); + } + print(ocBuilder.toString()); + StringBuilder spacesBuilder = new StringBuilder(); + spacesBuilder.append("\nSpaces from which more feature-packs can be used when scanning deployments (use the " + Constants.SPACES_OPTION + " option to enable the space(s):\n"); + for (Space space : metadataProvider.getAllSpaces()) { + spacesBuilder.append("* @|bold " + space.getName() + "|@. " + space.getDescription() + "\n"); + } + print(spacesBuilder.toString()); + + String context = Arguments.BARE_METAL_EXECUTION_CONTEXT; + 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_OPTION + " is set."); + } + } + if (wildflyServerVersion.isPresent()) { + if (channelsFile.isPresent()) { + throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set."); + } + } + String finalContext = context; + boolean isLatest = wildflyServerVersion.isEmpty(); + String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : metadataProvider.getLatestVersion(); + ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() { + @Override + public void consume(Space space, GalleonProvisioningConfig provisioning, Map all, + LayerMapping mapping, Map> fpDependencies) throws Exception { + if (Space.DEFAULT.equals(space)) { + defaultSpaceFpDependencies = fpDependencies; + } + String configStr = dumpConfiguration(space, fpDependencies, finalContext, vers, all, + mapping, provisioning, isLatest, wildflyPreview.orElse(false), provisioningXml.orElse(null)); + print(configStr); + } + }; + ProvisioningUtils.traverseProvisioning(Space.DEFAULT, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager, metadataProvider); + for (String spaceName : spaces) { + Set versions = metadataProvider.getAllVersions(spaceName); + if (versions.contains(vers)) { + Space space = metadataProvider.getSpace(spaceName); + ProvisioningUtils.traverseProvisioning(space, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager, metadataProvider); + } } + } finally { + IoUtils.recursiveDelete(tmpMetadataDirectory); } return 0; } diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ShowServerVersionsCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ShowServerVersionsCommand.java index 643d9916..af49f74f 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ShowServerVersionsCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ShowServerVersionsCommand.java @@ -16,12 +16,17 @@ */ package org.wildfly.glow.cli.commands; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.LinkedHashSet; import java.util.Set; +import org.jboss.galleon.util.IoUtils; import org.wildfly.glow.cli.support.AbstractCommand; import org.wildfly.glow.cli.support.Constants; -import org.wildfly.glow.FeaturePacks; +import org.wildfly.glow.MetadataProvider; import org.wildfly.glow.Space; +import org.wildfly.glow.WildFlyMavenMetadataProvider; +import org.wildfly.glow.maven.MavenResolver; import picocli.CommandLine; @CommandLine.Command( @@ -36,12 +41,18 @@ public class ShowServerVersionsCommand extends AbstractCommand { @Override public Integer call() throws Exception { print("WildFly server versions in the " + Space.DEFAULT.getName() + " space:"); - print(FeaturePacks.getAllVersions()); - for(String space : spaces) { - print("WildFly server versions in the " + space + " space:"); - print(FeaturePacks.getAllVersions(space)); + Path tmpMetadataDirectory = Files.createTempDirectory("glow-metadata"); + try { + MetadataProvider metadataProvider = new WildFlyMavenMetadataProvider(MavenResolver.newMavenResolver(), tmpMetadataDirectory); + print(metadataProvider.getAllVersions()); + for (String space : spaces) { + print("WildFly server versions in the " + space + " space:"); + print(metadataProvider.getAllVersions(space)); + } + print("@|bold WildFly server version can be set using the|@ @|fg(yellow) %s=|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.SERVER_VERSION_OPTION, Constants.SCAN_COMMAND); + return 0; + } finally { + IoUtils.recursiveDelete(tmpMetadataDirectory); } - print("@|bold WildFly server version can be set using the|@ @|fg(yellow) %s=|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.SERVER_VERSION_OPTION, Constants.SCAN_COMMAND); - return 0; } } diff --git a/core/src/main/java/org/wildfly/glow/Arguments.java b/core/src/main/java/org/wildfly/glow/Arguments.java index a6cd2061..35d3d43e 100644 --- a/core/src/main/java/org/wildfly/glow/Arguments.java +++ b/core/src/main/java/org/wildfly/glow/Arguments.java @@ -39,6 +39,7 @@ public class Arguments implements GoOfflineArguments, ScanArguments { private final boolean isCli; private final List channels; private final Set spaces; + private final MetadataProvider metadataProvider; protected Arguments( String executionContext, @@ -59,7 +60,8 @@ protected Arguments( String defaultConfigStability, boolean isCli, List channels, - Set spaces) { + Set spaces, + MetadataProvider metadataProvider) { this.executionProfiles = executionProfiles; this.userEnabledAddOns = userEnabledAddOns; this.binaries = binaries; @@ -87,6 +89,7 @@ protected Arguments( this.isCli = isCli; this.channels = channels; this.spaces = spaces == null ? Collections.emptySet() : spaces; + this.metadataProvider = metadataProvider; } /** @@ -231,6 +234,14 @@ public Set getSpaces() { return spaces; } + /** + * @return the metadata provider + */ + @Override + public MetadataProvider getMetadataProvider() { + return metadataProvider; + } + static GoOfflineArguments.Builder goOfflineBuilder() { return new GoOfflineArguments.Builder(); } diff --git a/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java b/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java index f9ffe62b..937540bd 100644 --- a/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java +++ b/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java @@ -46,6 +46,7 @@ public class BaseArgumentsBuilder { protected boolean isCli; protected List channels; protected Set spaces; + protected MetadataProvider metadataProvider; protected BaseArgumentsBuilder() { @@ -75,6 +76,7 @@ public Arguments build() { defaultConfigStability, isCli, channels, - spaces); + spaces, + metadataProvider); } } diff --git a/core/src/main/java/org/wildfly/glow/FeaturePacks.java b/core/src/main/java/org/wildfly/glow/FeaturePacks.java index a1eb384b..a2d22013 100644 --- a/core/src/main/java/org/wildfly/glow/FeaturePacks.java +++ b/core/src/main/java/org/wildfly/glow/FeaturePacks.java @@ -45,11 +45,17 @@ public class FeaturePacks { public static final String URL_PROPERTY = "wildfly-glow-galleon-feature-packs-url"; - public static Path getFeaturePacks(String version, String context, boolean techPreview) throws Exception { + private final URI rootURI; + + public FeaturePacks(URI rootURI) { + this.rootURI = rootURI; + } + + public Path getFeaturePacks(String version, String context, boolean techPreview) throws Exception { return getFeaturePacks(Space.DEFAULT, version, context, techPreview); } - public static Path getFeaturePacks(Space space, String version, String context, boolean techPreview) throws Exception { + public Path getFeaturePacks(Space space, String version, String context, boolean techPreview) throws Exception { try { String rootURL = getFeaturePacksURL(space); Yaml yaml = new Yaml(); @@ -81,15 +87,12 @@ public static Path getFeaturePacks(Space space, String version, String context, } } - public static String getFeaturePacksURL() throws Exception { + private String getFeaturePacksURL() throws Exception { return getFeaturePacksURL(Space.DEFAULT); } - public static String getFeaturePacksURL(Space space) throws Exception { - String rootURL = Utils.getConfigEntry(URL_PROPERTY); - if (rootURL == null) { - throw new Exception("No " + URL_PROPERTY + " entry found"); - } + private String getFeaturePacksURL(Space space) throws Exception { + String rootURL = rootURI.toString(); if (!rootURL.endsWith("/")) { rootURL = rootURL + "/"; } @@ -99,18 +102,11 @@ public static String getFeaturePacksURL(Space space) throws Exception { return rootURL; } - public static Set getAllVersions() throws Exception { - String rootURL = getFeaturePacksURL(); - Set set = new TreeSet<>(); - Yaml yaml = new Yaml(); - Map map = yaml.load(new URI(rootURL + VERSIONS).toURL().openStream()); - for(String v : Arrays.asList(map.get("versions").split(","))) { - set.add(v.trim()); - } - return set; + public Set getAllVersions() throws Exception { + return getAllVersions(Space.DEFAULT.getName()); } - public static Set getAllVersions(String spaceName) throws Exception { + public Set getAllVersions(String spaceName) throws Exception { Space space = getSpace(spaceName); String rootURL = getFeaturePacksURL(space); Set set = new TreeSet<>(); @@ -122,7 +118,7 @@ public static Set getAllVersions(String spaceName) throws Exception { return set; } - public static List getAllSpaces() throws Exception { + public List getAllSpaces() throws Exception { String rootURL = getFeaturePacksURL(); List lst = new ArrayList<>(); Yaml yaml = new Yaml(); @@ -134,7 +130,10 @@ public static List getAllSpaces() throws Exception { return lst; } - public static Space getSpace(String spaceName) throws Exception { + public Space getSpace(String spaceName) throws Exception { + if (Space.DEFAULT.getName().equals(spaceName)) { + return Space.DEFAULT; + } String rootURL = getFeaturePacksURL(); List lst = new ArrayList<>(); Yaml yaml = new Yaml(); @@ -153,7 +152,7 @@ public static Space getSpace(String spaceName) throws Exception { throw new Exception("Space " + spaceName + " doesn't exist. Known spaces are: " + builder.toString()); } - public static String getLatestVersion() throws Exception { + public String getLatestVersion() throws Exception { String rootURL = getFeaturePacksURL(); Yaml yaml = new Yaml(); Map map = yaml.load(new URI(rootURL + VERSIONS).toURL().openStream()); diff --git a/core/src/main/java/org/wildfly/glow/GlowSession.java b/core/src/main/java/org/wildfly/glow/GlowSession.java index 255535ab..8855da82 100644 --- a/core/src/main/java/org/wildfly/glow/GlowSession.java +++ b/core/src/main/java/org/wildfly/glow/GlowSession.java @@ -65,6 +65,7 @@ import org.jboss.galleon.universe.maven.MavenArtifact; import org.wildfly.channel.Channel; import org.wildfly.channel.ChannelMapper; +import static org.wildfly.glow.FeaturePacks.URL_PROPERTY; import static org.wildfly.glow.error.ErrorLevel.ERROR; import org.wildfly.plugin.tools.bootablejar.BootableJarSupport; @@ -84,6 +85,9 @@ public class GlowSession { private final Arguments arguments; private final GlowMessageWriter writer; private final List channels = new ArrayList<>(); + private final MetadataProvider metadataProvider; + private final Path tmpMetadataDirectory; + private GlowSession(MavenRepoManager resolver, Arguments arguments, GlowMessageWriter writer) throws Exception { this.arguments = arguments; this.writer = writer; @@ -94,6 +98,20 @@ private GlowSession(MavenRepoManager resolver, Arguments arguments, GlowMessageW } } this.resolver = repoManager; + if (arguments.getMetadataProvider() == null) { + String prop = System.getProperty(URL_PROPERTY); + if (prop == null) { + tmpMetadataDirectory = Files.createTempDirectory("wildfly-glow-metadata"); + this.metadataProvider = new WildFlyMavenMetadataProvider(resolver, tmpMetadataDirectory); + } else { + tmpMetadataDirectory = null; + this.metadataProvider = new WildFlyMetadataProvider(new URI(prop)); + } + } else { + tmpMetadataDirectory = null; + this.metadataProvider = arguments.getMetadataProvider(); + } + } public static void goOffline(MavenRepoManager resolver, GoOfflineArguments arguments, GlowMessageWriter writer) throws Exception { @@ -118,7 +136,7 @@ private void goOffline() throws Exception { if (config == null) { Path provisioningXML = arguments.getProvisioningXML(); if (provisioningXML == null) { - provisioningXML = FeaturePacks.getFeaturePacks(arguments.getVersion(), arguments.getExecutionContext(), arguments.isTechPreview()); + provisioningXML = metadataProvider.getFeaturePacks(arguments.getVersion(), arguments.getExecutionContext(), arguments.isTechPreview()); } provisioning = provider.newProvisioningBuilder(provisioningXML).setInstallationHome(fakeHome).build(); config = provisioning.loadProvisioningConfig(provisioningXML); @@ -133,6 +151,9 @@ private void goOffline() throws Exception { provisioning.close(); } IoUtils.recursiveDelete(fakeHome); + if (tmpMetadataDirectory != null) { + IoUtils.recursiveDelete(tmpMetadataDirectory); + } } Files.deleteIfExists(OFFLINE_ZIP); ZipUtils.zip(OFFLINE_CONTENT, OFFLINE_ZIP); @@ -151,11 +172,11 @@ private GalleonProvisioningConfig mergeSpaces(GalleonBuilder provider, GalleonPr if (!arguments.getSpaces().isEmpty()) { GalleonProvisioningConfig.Builder mergedConfigBuilder = GalleonProvisioningConfig.builder(defaultConfig); for (String spaceName : arguments.getSpaces()) { - Space space = FeaturePacks.getSpace(spaceName); - Set versions = FeaturePacks.getAllVersions(spaceName); - String vers = arguments.getVersion() == null ? FeaturePacks.getLatestVersion() : arguments.getVersion(); + Space space = metadataProvider.getSpace(spaceName); + Set versions = metadataProvider.getAllVersions(spaceName); + String vers = arguments.getVersion() == null ? metadataProvider.getLatestVersion() : arguments.getVersion(); if (versions.contains(vers)) { - Path spaceProvisioningXML = FeaturePacks.getFeaturePacks(space, + Path spaceProvisioningXML = metadataProvider.getFeaturePacks(space, arguments.getVersion(), arguments.getExecutionContext(), arguments.isTechPreview()); try (Provisioning spaceProvisioning = provider.newProvisioningBuilder(spaceProvisioningXML).build()) { GalleonProvisioningConfig spaceConfig = spaceProvisioning.loadProvisioningConfig(spaceProvisioningXML); @@ -190,7 +211,7 @@ public ScanResults scan() throws Exception { if (config == null) { Path provisioningXML = arguments.getProvisioningXML(); if (provisioningXML == null) { - provisioningXML = FeaturePacks.getFeaturePacks(arguments.getVersion(), arguments.getExecutionContext(), arguments.isTechPreview()); + provisioningXML = metadataProvider.getFeaturePacks(arguments.getVersion(), arguments.getExecutionContext(), arguments.isTechPreview()); } provisioning = provider.newProvisioningBuilder(provisioningXML).setInstallationHome(fakeHome).build(); config = provisioning.loadProvisioningConfig(provisioningXML); @@ -662,10 +683,16 @@ public ScanResults scan() throws Exception { excludedPackages, excludedFeatures, fpVersions, - channels + channels, + tmpMetadataDirectory ); return scanResults; + } catch (Exception ex) { + if (tmpMetadataDirectory != null) { + IoUtils.recursiveDelete(tmpMetadataDirectory); + } + throw ex; } finally { IoUtils.recursiveDelete(OFFLINE_CONTENT); IoUtils.recursiveDelete(fakeHome); @@ -807,7 +834,7 @@ private Path provisionServer(List binaries, GalleonProvisioningConfig acti } else { bootableJarName = "hollow"; } - String vers = arguments.getVersion() == null ? FeaturePacks.getLatestVersion() : arguments.getVersion(); + String vers = arguments.getVersion() == null ? metadataProvider.getLatestVersion() : arguments.getVersion(); Path targetJarFile = originalTarget.toAbsolutePath().resolve(bootableJarName + "-" + vers + "-" + BootableJarSupport.BOOTABLE_SUFFIX + ".jar"); ret = targetJarFile; Files.deleteIfExists(targetJarFile); diff --git a/core/src/main/java/org/wildfly/glow/MetadataProvider.java b/core/src/main/java/org/wildfly/glow/MetadataProvider.java new file mode 100644 index 00000000..1c543178 --- /dev/null +++ b/core/src/main/java/org/wildfly/glow/MetadataProvider.java @@ -0,0 +1,40 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2025 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow; + +import java.nio.file.Path; +import java.util.List; +import java.util.Set; + +/** + * + * @author jdenise + */ +public interface MetadataProvider { + + Path getFeaturePacks(Space space, String version, String context, boolean techPreview) throws Exception; + default Path getFeaturePacks(String version, String context, boolean techPreview) throws Exception { + return getFeaturePacks(Space.DEFAULT, version, context, techPreview); + } + default Set getAllVersions() throws Exception { + return getAllVersions(Space.DEFAULT.getName()); + } + Set getAllVersions(String spaceName) throws Exception; + Space getSpace(String spaceName) throws Exception; + String getLatestVersion() throws Exception; + List getAllSpaces() throws Exception; +} diff --git a/core/src/main/java/org/wildfly/glow/ProvisioningUtils.java b/core/src/main/java/org/wildfly/glow/ProvisioningUtils.java index 2d17e91f..8274e892 100644 --- a/core/src/main/java/org/wildfly/glow/ProvisioningUtils.java +++ b/core/src/main/java/org/wildfly/glow/ProvisioningUtils.java @@ -45,17 +45,17 @@ void consume(Space space, GalleonProvisioningConfig provisioning, Map channels, MavenRepoManager resolver) throws Exception { + String executionContext, Path provisioningXML, boolean isLatest, String wildflyServerVersion, boolean wildflyPreview, List channels, MavenRepoManager resolver, MetadataProvider metadataProvider) 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 : metadataProvider.getLatestVersion(); Provisioning provisioning = null; try { GalleonProvisioningConfig config = Utils.buildOfflineProvisioningConfig(provider, GlowMessageWriter.DEFAULT); if (config == null) { if (provisioningXML == null) { - provisioningXML = FeaturePacks.getFeaturePacks(space, vers, executionContext, wildflyPreview); + provisioningXML = metadataProvider.getFeaturePacks(space, vers, executionContext, wildflyPreview); } provisioning = provider.newProvisioningBuilder(provisioningXML).build(); config = provisioning.loadProvisioningConfig(provisioningXML); diff --git a/core/src/main/java/org/wildfly/glow/ScanArguments.java b/core/src/main/java/org/wildfly/glow/ScanArguments.java index 00c1088c..b6b108e0 100644 --- a/core/src/main/java/org/wildfly/glow/ScanArguments.java +++ b/core/src/main/java/org/wildfly/glow/ScanArguments.java @@ -81,6 +81,8 @@ public interface ScanArguments { boolean isCli(); List getChannels(); Set getSpaces(); + MetadataProvider getMetadataProvider(); + default Builder createScanArgumentsBuilder() { return new Builder(); } @@ -183,5 +185,9 @@ public Builder setSpaces(Set spaces) { this.spaces = spaces; return this; } + public Builder setMetadataProider(MetadataProvider metadataProvider) { + this.metadataProvider = metadataProvider; + return this; + } } } diff --git a/core/src/main/java/org/wildfly/glow/ScanResults.java b/core/src/main/java/org/wildfly/glow/ScanResults.java index 48a87050..7e3d0c3a 100644 --- a/core/src/main/java/org/wildfly/glow/ScanResults.java +++ b/core/src/main/java/org/wildfly/glow/ScanResults.java @@ -26,6 +26,7 @@ import org.jboss.galleon.api.config.GalleonProvisioningConfig; import org.jboss.galleon.universe.FeaturePackLocation.FPID; import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec; +import org.jboss.galleon.util.IoUtils; import org.wildfly.channel.Channel; public class ScanResults implements AutoCloseable { @@ -46,6 +47,8 @@ public class ScanResults implements AutoCloseable { private final Map> excludedFeatures; private final Map fpVersions; private final List channels; + private final Path tmpMetadataDirectory; + ScanResults(GlowSession glowSession, Set discoveredLayers, Set excludedLayers, @@ -61,7 +64,8 @@ public class ScanResults implements AutoCloseable { Set excludedPackages, Map> excludedFeatures, Map fpVersions, - List channels) { + List channels, + Path tmpMetadataDirectory) { this.glowSession = glowSession; this.discoveredLayers = discoveredLayers; this.excludedLayers = excludedLayers; @@ -78,6 +82,7 @@ public class ScanResults implements AutoCloseable { this.excludedFeatures = excludedFeatures; this.fpVersions = fpVersions; this.channels = channels; + this.tmpMetadataDirectory = tmpMetadataDirectory; } public Set getDiscoveredLayers() { @@ -161,6 +166,9 @@ public String getCompactInformation() throws Exception { @Override public void close() { provisioning.close(); + if (tmpMetadataDirectory != null) { + IoUtils.recursiveDelete(tmpMetadataDirectory); + } } public Set getExcludedPackages() { diff --git a/core/src/main/java/org/wildfly/glow/WildFlyMavenMetadataProvider.java b/core/src/main/java/org/wildfly/glow/WildFlyMavenMetadataProvider.java new file mode 100644 index 00000000..e7e26661 --- /dev/null +++ b/core/src/main/java/org/wildfly/glow/WildFlyMavenMetadataProvider.java @@ -0,0 +1,85 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2025 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow; + +import java.nio.file.Path; +import java.util.List; +import java.util.Set; +import org.jboss.galleon.universe.maven.MavenArtifact; +import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.jboss.galleon.util.ZipUtils; + +/** + * + * @author jdenise + */ +public class WildFlyMavenMetadataProvider implements MetadataProvider { + + private static final String DEFAULT_RANGE = "[0.0,)"; + private static final String METADATA_EXTENSION = "zip"; + private static final String METADATA_GROUP_ID = "org.wildfly.galleon.feature-packs"; + private static final String METADATA_ARTIFACT_ID = "wildfly-galleon-feature-packs-metadata"; + private final MavenRepoManager repo; + private final Path tmpDirectory; + private FeaturePacks featurePacks; + public WildFlyMavenMetadataProvider(MavenRepoManager repo, Path tmpDirectory) { + this.repo = repo; + this.tmpDirectory = tmpDirectory; + } + + private FeaturePacks getResolver() throws Exception { + if (featurePacks == null) { + MavenArtifact artifact = new MavenArtifact(); + artifact.setExtension(METADATA_EXTENSION); + artifact.setArtifactId(METADATA_ARTIFACT_ID); + artifact.setGroupId(METADATA_GROUP_ID); + artifact.setVersionRange(DEFAULT_RANGE); + repo.resolveLatestVersion(artifact, null, false); + Path zip = artifact.getPath(); + Path rootDirectory = tmpDirectory.resolve("glow-metadata"); + ZipUtils.unzip(zip, rootDirectory); + featurePacks = new FeaturePacks(rootDirectory.toUri()); + } + return featurePacks; + } + + @Override + public Path getFeaturePacks(Space space, String version, String context, boolean techPreview) throws Exception { + return getResolver().getFeaturePacks(space, version, context, techPreview); + } + + @Override + public Set getAllVersions(String spaceName) throws Exception { + return getResolver().getAllVersions(spaceName); + } + + @Override + public Space getSpace(String spaceName) throws Exception { + return getResolver().getSpace(spaceName); + } + + @Override + public String getLatestVersion() throws Exception { + return getResolver().getLatestVersion(); + } + + @Override + public List getAllSpaces() throws Exception { + return getResolver().getAllSpaces(); + } + +} diff --git a/core/src/main/java/org/wildfly/glow/WildFlyMetadataProvider.java b/core/src/main/java/org/wildfly/glow/WildFlyMetadataProvider.java new file mode 100644 index 00000000..6856bf27 --- /dev/null +++ b/core/src/main/java/org/wildfly/glow/WildFlyMetadataProvider.java @@ -0,0 +1,69 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2025 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow; + +import java.net.URI; +import java.nio.file.Path; +import java.util.List; +import java.util.Set; + +/** + * + * @author jdenise + */ +public class WildFlyMetadataProvider implements MetadataProvider { + + private final URI uri; + private FeaturePacks featurePacks; + + public WildFlyMetadataProvider(URI uri) { + this.uri = uri; + } + + private FeaturePacks getResolver() throws Exception { + if (featurePacks == null) { + featurePacks = new FeaturePacks(uri); + } + return featurePacks; + } + + @Override + public Path getFeaturePacks(Space space, String version, String context, boolean techPreview) throws Exception { + return getResolver().getFeaturePacks(space, version, context, techPreview); + } + + @Override + public Set getAllVersions(String spaceName) throws Exception { + return getResolver().getAllVersions(spaceName); + } + + @Override + public Space getSpace(String spaceName) throws Exception { + return getResolver().getSpace(spaceName); + } + + @Override + public String getLatestVersion() throws Exception { + return getResolver().getLatestVersion(); + } + + @Override + public List getAllSpaces() throws Exception { + return getResolver().getAllSpaces(); + } + +} diff --git a/core/src/main/resources/org/wildfly/glow/glow.properties b/core/src/main/resources/org/wildfly/glow/glow.properties index e2259932..42f3fd64 100644 --- a/core/src/main/resources/org/wildfly/glow/glow.properties +++ b/core/src/main/resources/org/wildfly/glow/glow.properties @@ -1,3 +1 @@ wildfly-glow-version:${project.version} -wildfly-glow-galleon-feature-packs-url:${wildfly.glow.galleon.feature-packs.url} - diff --git a/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/GenerateMojo.java b/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/GenerateMojo.java new file mode 100644 index 00000000..97c1dca6 --- /dev/null +++ b/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/GenerateMojo.java @@ -0,0 +1,100 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2025 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow.plugin.doc; + +import java.nio.file.Files; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Set; +import org.apache.maven.project.MavenProjectHelper; +import org.jboss.galleon.util.IoUtils; +import org.jboss.galleon.util.ZipUtils; +import org.wildfly.glow.MetadataProvider; +import org.wildfly.glow.WildFlyMetadataProvider; + +/** + * + * @author jdenise + */ +@Mojo(name = "generate-maven-metadata", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, defaultPhase = LifecyclePhase.PACKAGE) +public class GenerateMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true, required = true) + MavenProject project; + @Component + RepositorySystem repoSystem; + + @Component + private MavenProjectHelper projectHelper; + + @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) + RepositorySystemSession repoSession; + + @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true) + List repositories; + + @Parameter(defaultValue = "glow-maven-metadata.zip") + String generatedFile; + + @Parameter(defaultValue = "${project.build.directory}") + String targetDir; + + @Parameter(required = true) + String repoPath; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + try { + Path rootDir = Paths.get(repoPath); + MetadataProvider provider = new WildFlyMetadataProvider(rootDir.toFile().getAbsoluteFile().toURI()); + Set versions = provider.getAllVersions(); + Path dir = Paths.get(targetDir); + Path generatedFilePath = dir.resolve(generatedFile); + Path versionsFile = rootDir.resolve("versions.yaml"); + Path metadataDir = dir.resolve("metadata"); + Files.createDirectories(metadataDir); + Files.copy(versionsFile, metadataDir.resolve("versions.yaml")); + for (String version : versions) { + Path versionDir = rootDir.resolve(version); + Path versionTargetDir = metadataDir.resolve(version); + IoUtils.copy(versionDir, versionTargetDir); + } + Path spacesDir = rootDir.resolve("spaces"); + Path spacesTargetDir = metadataDir.resolve("spaces"); + IoUtils.copy(spacesDir, spacesTargetDir); + ZipUtils.zip(metadataDir, generatedFilePath); + getLog().debug("Attaching maven metadata " + generatedFilePath + " as a project artifact"); + projectHelper.attachArtifact(project, "zip", generatedFilePath.toFile()); + } catch (Exception ex) { + throw new MojoExecutionException(ex); + } + } +} diff --git a/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/ScanDocMojo.java b/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/ScanDocMojo.java index c7efe6e5..10f7a947 100644 --- a/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/ScanDocMojo.java +++ b/doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/ScanDocMojo.java @@ -18,6 +18,7 @@ package org.wildfly.glow.plugin.doc; import java.io.FileInputStream; +import java.net.URI; import java.nio.file.Files; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.BuildPluginManager; @@ -53,13 +54,16 @@ import org.jboss.galleon.universe.FeaturePackLocation.FPID; import org.jboss.galleon.universe.UniverseResolver; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.jboss.galleon.util.IoUtils; import org.wildfly.channel.Channel; import org.wildfly.glow.AddOn; -import org.wildfly.glow.FeaturePacks; import org.wildfly.glow.LayerMapping; import org.wildfly.glow.LayerMetadata; +import org.wildfly.glow.MetadataProvider; import org.wildfly.glow.Space; import org.wildfly.glow.Utils; +import org.wildfly.glow.WildFlyMavenMetadataProvider; +import org.wildfly.glow.WildFlyMetadataProvider; /** * @@ -165,14 +169,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { rulesBuilder.append("|===\n"); } if (generateKnownFeaturePacks) { - if (repoPath != null) { - Path p = Paths.get(repoPath); - String repoUrl = "file://" + p.toAbsolutePath(); - System.out.println("Using repo url " + repoUrl); - System.setProperty(FeaturePacks.URL_PROPERTY, repoUrl); - } + Path tmpDirectory = null; try { - //Typically under target + MetadataProvider metadataProvider; MavenRepoManager artifactResolver; if (channels != null && !channels.isEmpty()) { getLog().debug("WildFly channel enabled."); @@ -184,56 +183,65 @@ public void execute() throws MojoExecutionException, MojoFailureException { } else { artifactResolver = new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories); } + if (repoPath != null) { + Path p = Paths.get(repoPath); + String repoUrl = "file://" + p.toAbsolutePath(); + System.out.println("Using repo url " + repoUrl); + metadataProvider = new WildFlyMetadataProvider(new URI(repoUrl)); + } else { + tmpDirectory = Files.createTempDirectory("wildfly-glow-metadata"); + metadataProvider = new WildFlyMavenMetadataProvider(artifactResolver, tmpDirectory); + } UniverseResolver universeResolver = UniverseResolver.builder().addArtifactResolver(artifactResolver).build(); GalleonBuilder provider = new GalleonBuilder(); provider.addArtifactResolver(artifactResolver); Map> rules = new TreeMap<>(); - getRules(Space.DEFAULT, provider, "bare-metal", universeResolver, rules, false); + getRules(Space.DEFAULT, provider, "bare-metal", universeResolver, rules, false, metadataProvider); Map> cloudRules = new TreeMap<>(); - getRules(Space.DEFAULT, provider,"cloud", universeResolver, cloudRules, false); - rulesBuilder.append("## Support for " + serverType + " " + FeaturePacks.getLatestVersion() + "\n\n"); - rulesBuilder.append(buildTable(Space.DEFAULT, provider,"bare-metal", rules, false)); - rulesBuilder.append(buildTable(Space.DEFAULT, provider,"cloud", cloudRules, false)); + getRules(Space.DEFAULT, provider,"cloud", universeResolver, cloudRules, false, metadataProvider); + rulesBuilder.append("## Support for " + serverType + " " + metadataProvider.getLatestVersion() + "\n\n"); + rulesBuilder.append(buildTable(Space.DEFAULT, provider,"bare-metal", rules, false, metadataProvider)); + rulesBuilder.append(buildTable(Space.DEFAULT, provider,"cloud", cloudRules, false, metadataProvider)); if (preview) { Map> previewRules = new TreeMap<>(); - getRules(Space.DEFAULT, provider, "bare-metal", universeResolver, previewRules, true); + getRules(Space.DEFAULT, provider, "bare-metal", universeResolver, previewRules, true, metadataProvider); Map> previewCloudRules = new TreeMap<>(); - getRules(Space.DEFAULT, provider,"cloud", universeResolver, previewCloudRules, true); - rulesBuilder.append("## Support for WildFly Preview " + FeaturePacks.getLatestVersion() + "\n\n"); - rulesBuilder.append(buildTable(Space.DEFAULT, provider, "bare-metal", previewRules, true)); - rulesBuilder.append(buildTable(Space.DEFAULT, provider, "cloud", previewCloudRules, true)); + getRules(Space.DEFAULT, provider,"cloud", universeResolver, previewCloudRules, true, metadataProvider); + rulesBuilder.append("## Support for WildFly Preview " + metadataProvider.getLatestVersion() + "\n\n"); + rulesBuilder.append(buildTable(Space.DEFAULT, provider, "bare-metal", previewRules, true, metadataProvider)); + rulesBuilder.append(buildTable(Space.DEFAULT, provider, "cloud", previewCloudRules, true, metadataProvider)); } if (spaces) { - for (Space space : FeaturePacks.getAllSpaces()) { - if (FeaturePacks.getAllVersions(space.getName()).contains(FeaturePacks.getLatestVersion())) { + for (Space space : metadataProvider.getAllSpaces()) { + if (metadataProvider.getAllVersions(space.getName()).contains(metadataProvider.getLatestVersion())) { Map> spaceRules = new TreeMap<>(); - getRules(space, provider, "bare-metal", universeResolver, spaceRules, false); + getRules(space, provider, "bare-metal", universeResolver, spaceRules, false, metadataProvider); Map> spaceCloudRules = new TreeMap<>(); - getRules(space, provider, "cloud", universeResolver, spaceCloudRules, false); + getRules(space, provider, "cloud", universeResolver, spaceCloudRules, false, metadataProvider); if (!spaceRules.isEmpty() || !spaceCloudRules.isEmpty()) { rulesBuilder.append("## Additional '" + space.getName() + "' space\n\n"); rulesBuilder.append(space.getDescription() + "\n\n"); - rulesBuilder.append("### Support for " + serverType + " " + FeaturePacks.getLatestVersion() + "\n\n"); + rulesBuilder.append("### Support for " + serverType + " " + metadataProvider.getLatestVersion() + "\n\n"); } if (!spaceRules.isEmpty()) { - rulesBuilder.append(buildTable(space, provider, "bare-metal", spaceRules, false)); + rulesBuilder.append(buildTable(space, provider, "bare-metal", spaceRules, false, metadataProvider)); } if (!spaceCloudRules.isEmpty()) { - rulesBuilder.append(buildTable(space, provider, "cloud", spaceCloudRules, false)); + rulesBuilder.append(buildTable(space, provider, "cloud", spaceCloudRules, false, metadataProvider)); } if (preview) { Map> spacePreviewRules = new TreeMap<>(); - getRules(space, provider, "bare-metal", universeResolver, spacePreviewRules, true); + getRules(space, provider, "bare-metal", universeResolver, spacePreviewRules, true, metadataProvider); Map> spacePreviewCloudRules = new TreeMap<>(); - getRules(space, provider, "cloud", universeResolver, spacePreviewCloudRules, true); + getRules(space, provider, "cloud", universeResolver, spacePreviewCloudRules, true, metadataProvider); if (!spacePreviewRules.isEmpty() || !spacePreviewCloudRules.isEmpty()) { - rulesBuilder.append("### Support for WildFly Preview " + FeaturePacks.getLatestVersion() + "\n\n"); + rulesBuilder.append("### Support for WildFly Preview " + metadataProvider.getLatestVersion() + "\n\n"); if (!spacePreviewRules.isEmpty()) { - rulesBuilder.append(buildTable(space, provider, "bare-metal", spacePreviewRules, true)); + rulesBuilder.append(buildTable(space, provider, "bare-metal", spacePreviewRules, true, metadataProvider)); } if (!spacePreviewCloudRules.isEmpty()) { - rulesBuilder.append(buildTable(space, provider, "cloud", spacePreviewCloudRules, true)); + rulesBuilder.append(buildTable(space, provider, "cloud", spacePreviewCloudRules, true, metadataProvider)); } } } @@ -241,7 +249,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } } finally { - System.clearProperty(FeaturePacks.URL_PROPERTY); + if(tmpDirectory != null) { + IoUtils.recursiveDelete(tmpDirectory); + } } } Path dir = Paths.get(targetDir); @@ -252,12 +262,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - private String buildTable(Space space, GalleonBuilder provider, String context, Map> rules, boolean preview) throws Exception { + private String buildTable(Space space, GalleonBuilder provider, String context, Map> rules, boolean preview, MetadataProvider metadataProvider) throws Exception { StringBuilder rulesBuilder = new StringBuilder(); rulesBuilder.append("\n### " + context + "\n"); rulesBuilder.append("\n#### Supported Galleon feature-packs \n"); - Path provisioningXML = FeaturePacks.getFeaturePacks(space, null, context, preview); + Path provisioningXML = metadataProvider.getFeaturePacks(space, null, context, preview); try (Provisioning p = provider.newProvisioningBuilder(provisioningXML).build()) { GalleonProvisioningConfig pConfig = p.loadProvisioningConfig(provisioningXML); for (GalleonFeaturePackConfig c : pConfig.getFeaturePackDeps()) { @@ -310,8 +320,8 @@ private String buildTable(Space space, GalleonBuilder provider, String context, } private LayerMapping getRules(Space space, GalleonBuilder provider, String context, UniverseResolver universeResolver, - Map> rules, boolean preview) throws Exception { - Path provisioningXML = FeaturePacks.getFeaturePacks(space, null, context, preview); + Map> rules, boolean preview, MetadataProvider metadataProvider) throws Exception { + Path provisioningXML = metadataProvider.getFeaturePacks(space, null, context, preview); Map all; try (Provisioning p = provider.newProvisioningBuilder(provisioningXML).build()) { GalleonProvisioningConfig config = p.loadProvisioningConfig(provisioningXML); diff --git a/maven-resolver/pom.xml b/maven-resolver/pom.xml index 9a970f6a..02373d38 100644 --- a/maven-resolver/pom.xml +++ b/maven-resolver/pom.xml @@ -41,6 +41,10 @@ org.apache.maven.resolver maven-resolver-transport-http + + org.apache.maven.resolver + maven-resolver-util + org.apache.maven maven-resolver-provider diff --git a/pom.xml b/pom.xml index 74cfa07f..771d84d8 100644 --- a/pom.xml +++ b/pom.xml @@ -18,8 +18,6 @@ ${maven.compiler.release} ${maven.compiler.release} - https://raw.githubusercontent.com/wildfly/wildfly-galleon-feature-packs/release/ - 4.7.5 9.7.1 @@ -369,6 +367,11 @@ maven-resolver-api ${version.org.apache.maven.resolver} + + org.apache.maven.resolver + maven-resolver-util + ${version.org.apache.maven.resolver} + org.apache.maven.resolver maven-resolver-impl diff --git a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/datasource/DataSourceDefinitionTestCase.java b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/datasource/DataSourceDefinitionTestCase.java index 09712b47..3b66d91a 100644 --- a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/datasource/DataSourceDefinitionTestCase.java +++ b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/datasource/DataSourceDefinitionTestCase.java @@ -15,7 +15,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.junit.Ignore; +import org.junit.After; /** * Tests that timer service etc. are considered strongly typed @@ -26,11 +26,15 @@ user="sa", password="sa" ) -// Will un-ignore this test for WildFly 35 Final -@Ignore + public class DataSourceDefinitionTestCase { private final TestPackager testPackager = new TestPackager(); + @After + public void reset() { + testPackager.reset(); + } + @Test public void h2DriverUsage() throws Exception { ScanResults scanResults = testPackager.packageTestAsArchiveAndScan(DataSourceDefinitionTestCase.class); diff --git a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/exploded/ExplodedArchiveTestCase.java b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/exploded/ExplodedArchiveTestCase.java index 677c6181..e645b204 100644 --- a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/exploded/ExplodedArchiveTestCase.java +++ b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/exploded/ExplodedArchiveTestCase.java @@ -295,9 +295,10 @@ public void testEarWithExclusions() throws Exception { setBinaries(Collections.singletonList(archivePath)) .setExcludeArchivesFromScan("*.jar", "web.war") .build(); - ScanResults scanResults = GlowSession.scan(MavenResolver.newMavenResolver(), arguments, GlowMessageWriter.DEFAULT); - String layers = scanResults.getCompactInformation(); - Assert.assertEquals("[resource-adapters, sar]==>ee-core-profile-server,resource-adapters,sar", layers); + try (ScanResults scanResults = GlowSession.scan(MavenResolver.newMavenResolver(), arguments, GlowMessageWriter.DEFAULT)) { + String layers = scanResults.getCompactInformation(); + Assert.assertEquals("[resource-adapters, sar]==>ee-core-profile-server,resource-adapters,sar", layers); + } } diff --git a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBLiteResourceTestCase.java b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBLiteResourceTestCase.java index aaa91ad5..bb673e50 100644 --- a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBLiteResourceTestCase.java +++ b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBLiteResourceTestCase.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.junit.After; /** * Tests that timer service etc. are considered strongly typed @@ -64,5 +65,9 @@ public void EjbResourcesNotWeaklyTyped() throws Exception { Assert.assertFalse(layers.contains("ejb")); } + @After + public void reset() { + testPackager.reset(); + } } diff --git a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBResourceTestCase.java b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBResourceTestCase.java index f3fbe958..f8562a3e 100644 --- a/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBResourceTestCase.java +++ b/tests/glow-tests/src/test/java/org/wildfly/glow/test/core/resource/ejb/EJBResourceTestCase.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.junit.After; /** * Tests that timer service etc. are considered strongly typed @@ -56,5 +57,8 @@ public void EjbResourcesNotWeaklyTyped() throws Exception { Assert.assertTrue(layers.contains("ejb")); } - + @After + public void reset() { + testPackager.reset(); + } }