From 1ae10022c8b3249054a6feba5b6d028304e82a8e Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Wed, 22 Nov 2023 18:35:18 +0100 Subject: [PATCH] Rework of Galleon integration using API introduced in Galleon 6.0.0.Beta1 --- core/pom.xml | 6 +- .../wildfly/plugin/core/ConfigurationId.java | 52 ---- .../org/wildfly/plugin/core/FeaturePack.java | 250 ------------------ .../org/wildfly/plugin/core/GalleonUtils.java | 83 +++--- .../plugin/core/PluginProgressTracker.java | 15 +- plugin/pom.xml | 4 + .../java/org/wildfly/plugin/common/Utils.java | 24 +- .../java/org/wildfly/plugin/dev/DevMojo.java | 67 +++-- .../AbstractProvisionServerMojo.java | 42 ++- ...ChannelMavenArtifactRepositoryManager.java | 18 +- .../plugin/provision/PackageServerMojo.java | 15 +- pom.xml | 11 +- tests/shared/pom.xml | 4 + 13 files changed, 156 insertions(+), 435 deletions(-) delete mode 100644 core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java delete mode 100644 core/src/main/java/org/wildfly/plugin/core/FeaturePack.java diff --git a/core/pom.xml b/core/pom.xml index 3ea294b4..208e8814 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -58,11 +58,7 @@ org.jboss.galleon - galleon-core - - - org.jboss.galleon - galleon-maven-universe + galleon-api org.apache.maven.shared diff --git a/core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java b/core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java deleted file mode 100644 index 7a383f6c..00000000 --- a/core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.plugin.core; - -import org.jboss.galleon.config.ConfigId; - -/** - * Simple wrapper for configuration ids. - * - * @author Emmanuel Hugonnet (c) 2018 Red Hat, inc. - */ -public class ConfigurationId { - - private String name; - private String model; - - public ConfigurationId() { - } - - public void setName(String name) { - this.name = name; - } - - public void setModel(String model) { - this.model = model; - } - - public ConfigId getId() { - return new ConfigId(model, name); - } - - public boolean isModelOnly() { - return name == null || name.isEmpty(); - } - - public String toString() { - final StringBuilder buf = new StringBuilder(); - buf.append("{"); - if (model != null) { - buf.append("model=").append(model); - } - if (name != null) { - if (buf.length() > 1) { - buf.append(' '); - } - buf.append("name=").append(name); - } - return buf.append('}').toString(); - } -} diff --git a/core/src/main/java/org/wildfly/plugin/core/FeaturePack.java b/core/src/main/java/org/wildfly/plugin/core/FeaturePack.java deleted file mode 100644 index e6206507..00000000 --- a/core/src/main/java/org/wildfly/plugin/core/FeaturePack.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.plugin.core; - -import java.io.File; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - -import org.apache.maven.shared.artifact.ArtifactCoordinate; -import org.apache.maven.shared.dependencies.DependableCoordinate; -import org.jboss.galleon.util.StringUtils; - -/** - * - * @author Alexey Loubyanssky - */ -public class FeaturePack implements DependableCoordinate, ArtifactCoordinate { - - private String groupId; - private String artifactId; - private String version; - private String type = "zip"; - private String classifier; - private String extension = "zip"; - - private boolean transitiveDep; - private String location; - - private Boolean inheritConfigs; - private List includedConfigs = Collections.emptyList(); - private List excludedConfigs = Collections.emptyList(); - - private Boolean inheritPackages; - private List excludedPackages = Collections.emptyList(); - private List includedPackages = Collections.emptyList(); - - private Path path; - - @Override - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - assertMavenCoordinates(); - this.groupId = groupId; - } - - @Override - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - assertMavenCoordinates(); - this.artifactId = artifactId; - } - - @Override - public String getVersion() { - return version; - } - - public void setVersion(String version) { - assertMavenCoordinates(); - this.version = version; - } - - @Override - public String getType() { - return type; - } - - public void setType(String type) { - assertMavenCoordinates(); - this.type = type; - } - - @Override - public String getClassifier() { - return classifier; - } - - public void setClassifier(String classifier) { - assertMavenCoordinates(); - this.classifier = classifier; - } - - @Override - public String getExtension() { - return extension; - } - - public void setExtension(String extension) { - assertMavenCoordinates(); - this.extension = extension; - } - - public boolean isTransitive() { - return transitiveDep; - } - - public void setTransitive(boolean transitiveDep) { - this.transitiveDep = transitiveDep; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - assertLocation(); - if (location == null) { - throw new IllegalStateException("Feature-pack location can't be null"); - } - location = location.trim(); - if (location.isEmpty()) { - throw new IllegalStateException("Feature-pack location can't be empty"); - } - this.location = location; - } - - public Boolean isInheritPackages() { - return inheritPackages; - } - - public void setInheritPackages(boolean inheritPackages) { - this.inheritPackages = inheritPackages; - } - - public Boolean isInheritConfigs() { - return inheritConfigs; - } - - public void setInheritConfigs(boolean inheritConfigs) { - this.inheritConfigs = inheritConfigs; - } - - public List getIncludedConfigs() { - return includedConfigs; - } - - public void setIncludedConfigs(List includedConfigs) { - this.includedConfigs = includedConfigs; - } - - public List getExcludedConfigs() { - return excludedConfigs; - } - - public void setExcludedConfigs(List excludedConfigs) { - this.excludedConfigs = excludedConfigs; - } - - public List getExcludedPackages() { - return excludedPackages; - } - - public void setExcludedPackages(List excludedPackages) { - this.excludedPackages = excludedPackages; - } - - public List getIncludedPackages() { - return includedPackages; - } - - public void setIncludedPackages(List includedPackages) { - this.includedPackages = includedPackages; - } - - public void setPath(File path) { - assertPathLocation(); - this.path = path.toPath().normalize(); - } - - public Path getNormalizedPath() { - return path; - } - - @Override - public String toString() { - final StringBuilder buf = new StringBuilder(); - buf.append('{'); - if (transitiveDep) { - buf.append("transitive "); - } - if (location != null) { - buf.append(location); - } else { - buf.append(groupId).append(':').append(artifactId).append(':').append(version); - } - buf.append(" inherit-packages=").append(inheritPackages); - if (!includedPackages.isEmpty()) { - buf.append(" included-packages="); - StringUtils.appendList(buf, includedPackages); - } - if (!excludedPackages.isEmpty()) { - buf.append(" excluded-packages="); - StringUtils.appendList(buf, excludedPackages); - } - buf.append(" inherit-configs=").append(inheritConfigs); - if (!includedConfigs.isEmpty()) { - buf.append(" included-configs="); - StringUtils.appendList(buf, includedConfigs); - } - if (!excludedConfigs.isEmpty()) { - buf.append(" excluded-configs="); - StringUtils.appendList(buf, excludedConfigs); - } - return buf.append('}').toString(); - } - - private void assertPathLocation() { - if (groupId != null || artifactId != null || version != null) { - throw new IllegalStateException( - "feature-pack Path cannot be used: feature-pack Maven coordinates have already been initialized"); - } - if (location != null) { - throw new IllegalStateException("feature-pack Path cannot be used: location has already been initialized"); - } - } - - private void assertLocation() { - if (groupId != null || artifactId != null || version != null) { - throw new IllegalStateException( - "Location can't bet set, feature-pack Maven coordinates have already been initialized"); - } - if (path != null) { - throw new IllegalStateException("Location can't bet set, feature-pack Path has already been initialized"); - } - } - - private void assertMavenCoordinates() { - if (location != null) { - throw new IllegalStateException( - "Feature-pack Maven coordinates cannot be used: feature-pack location has already been initialized"); - } - if (path != null) { - throw new IllegalStateException( - "Feature-pack Maven coordinates cannot be used: feature-pack Path has already been initialized"); - } - } - - public void set(String location) { - setLocation(location); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java b/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java index 9ef37620..5beec61b 100644 --- a/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java +++ b/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java @@ -15,15 +15,16 @@ import java.util.Objects; import org.jboss.galleon.Constants; -import org.jboss.galleon.ProvisioningDescriptionException; import org.jboss.galleon.ProvisioningException; -import org.jboss.galleon.ProvisioningManager; -import org.jboss.galleon.config.ConfigModel; -import org.jboss.galleon.config.FeaturePackConfig; -import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.api.ConfigurationId; +import org.jboss.galleon.api.GalleonBuilder; +import org.jboss.galleon.api.GalleonFeaturePack; +import org.jboss.galleon.api.Provisioning; +import org.jboss.galleon.api.config.GalleonConfigurationWithLayersBuilder; +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.maven.repo.MavenRepoManager; -import org.jboss.galleon.xml.ProvisioningXmlParser; /** * @author jdenise @@ -43,10 +44,11 @@ public class GalleonUtils { */ public static void provision(Path jbossHome, String featurePackLocation, String version, MavenRepoManager artifactResolver) throws ProvisioningException { - try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver) + GalleonProvisioningConfig config = buildDefaultConfig(featurePackLocation, version); + try (Provisioning pm = new GalleonBuilder().addArtifactResolver(artifactResolver).newProvisioningBuilder(config) .setInstallationHome(jbossHome) .build()) { - pm.provision(buildDefaultConfig(featurePackLocation, version)); + pm.provision(config); } } @@ -54,9 +56,9 @@ public static void provision(Path jbossHome, String featurePackLocation, String * Build a default WildFly provisioning config. * * @return - * @throws ProvisioningDescriptionException + * @throws ProvisioningException */ - public static ProvisioningConfig buildDefaultConfig() throws ProvisioningDescriptionException { + public static GalleonProvisioningConfig buildDefaultConfig() throws ProvisioningException { return buildDefaultConfig(WILDFLY_DEFAULT_FEATURE_PACK_LOCATION, null); } @@ -65,35 +67,22 @@ public static ProvisioningConfig buildDefaultConfig() throws ProvisioningDescrip * * @param version WildFly version, if null latest is used. * @return - * @throws ProvisioningDescriptionException + * @throws ProvisioningException */ - public static ProvisioningConfig buildDefaultConfig(String featurePackLocation, String version) - throws ProvisioningDescriptionException { + public static GalleonProvisioningConfig buildDefaultConfig(String featurePackLocation, String version) + throws ProvisioningException { String location = getWildFlyFeaturePackLocation(featurePackLocation, version); - ProvisioningConfig.Builder state = ProvisioningConfig.builder(); - FeaturePackLocation fpl = FeaturePackLocation.fromString(location); - FeaturePackConfig.Builder fpConfig = FeaturePackConfig.builder(fpl); - fpConfig.setInheritConfigs(true); - fpConfig.setInheritPackages(true); - state.addFeaturePackDep(fpConfig.build()); + GalleonProvisioningConfig.Builder state = GalleonProvisioningConfig.builder(); + GalleonFeaturePackConfig.Builder fp = GalleonFeaturePackConfig.builder(FeaturePackLocation.fromString(location)); + fp.setInheritConfigs(true); + fp.setInheritPackages(true); + state.addFeaturePackDep(fp.build()); Map options = new HashMap<>(); options.put(FORK_EMBEDDED_PROCESS_OPTION, "true"); state.addOptions(options); return state.build(); } - /** - * Build a Galleon provisioning configuration based on a provisioning.xml - * file. - * - * @param provisioningFile - * @return The provisioning config. - * @throws ProvisioningException - */ - public static ProvisioningConfig buildConfig(Path provisioningFile) throws ProvisioningException { - return ProvisioningXmlParser.parse(provisioningFile); - } - /** * Build a Galleon provisioning configuration. * @@ -106,18 +95,18 @@ public static ProvisioningConfig buildConfig(Path provisioningFile) throws Provi * @return The provisioning config. * @throws ProvisioningException */ - public static ProvisioningConfig buildConfig(ProvisioningManager pm, - List featurePacks, + public static GalleonProvisioningConfig buildConfig(GalleonBuilder pm, + List featurePacks, List layers, List excludedLayers, Map pluginOptions, String layersConfigFileName) throws ProvisioningException, IllegalArgumentException { - final ProvisioningConfig.Builder state = ProvisioningConfig.builder(); + final GalleonProvisioningConfig.Builder state = GalleonProvisioningConfig.builder(); boolean hasLayers = !layers.isEmpty(); boolean fpWithDefaults = true; if (!hasLayers) { // Check we have all feature-packs with default values only. - for (FeaturePack fp : featurePacks) { + for (GalleonFeaturePack fp : featurePacks) { if (fp.isInheritConfigs() != null || fp.isInheritPackages() != null || !fp.getIncludedConfigs().isEmpty() || @@ -131,7 +120,7 @@ public static ProvisioningConfig buildConfig(ProvisioningManager pm, } } - for (FeaturePack fp : featurePacks) { + for (GalleonFeaturePack fp : featurePacks) { if (fp.getLocation() == null && (fp.getGroupId() == null || fp.getArtifactId() == null) && fp.getNormalizedPath() == null) { throw new IllegalArgumentException("Feature-pack location, Maven GAV or feature pack path is missing"); @@ -139,7 +128,7 @@ public static ProvisioningConfig buildConfig(ProvisioningManager pm, final FeaturePackLocation fpl; if (fp.getNormalizedPath() != null) { - fpl = pm.getLayoutFactory().addLocal(fp.getNormalizedPath(), false); + fpl = pm.addLocal(fp.getNormalizedPath(), false); } else if (fp.getGroupId() != null && fp.getArtifactId() != null) { String coords = getMavenCoords(fp); fpl = FeaturePackLocation.fromString(coords); @@ -155,8 +144,9 @@ public static ProvisioningConfig buildConfig(ProvisioningManager pm, fpl = FeaturePackLocation.fromString(location); } - final FeaturePackConfig.Builder fpConfig = fp.isTransitive() ? FeaturePackConfig.transitiveBuilder(fpl) - : FeaturePackConfig.builder(fpl); + final GalleonFeaturePackConfig.Builder fpConfig = fp.isTransitive() + ? GalleonFeaturePackConfig.transitiveBuilder(fpl) + : GalleonFeaturePackConfig.builder(fpl); if (fp.isInheritConfigs() == null) { if (hasLayers) { fpConfig.setInheritConfigs(false); @@ -215,14 +205,15 @@ public static ProvisioningConfig buildConfig(ProvisioningManager pm, } if (!layers.isEmpty()) { - ConfigModel.Builder configBuilder = ConfigModel.builder(STANDALONE, layersConfigFileName); - for (String layer : layers) { - configBuilder.includeLayer(layer); + GalleonConfigurationWithLayersBuilder config = GalleonConfigurationWithLayersBuilder.builder(STANDALONE, + layersConfigFileName); + for (String l : layers) { + config.includeLayer(l); } - for (String layer : excludedLayers) { - configBuilder.excludeLayer(layer); + for (String l : excludedLayers) { + config.excludeLayer(l); } - state.addConfig(configBuilder.build()); + state.addConfig(config.build()); if (pluginOptions.isEmpty()) { pluginOptions = Collections.singletonMap(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS); } else if (!pluginOptions.containsKey(Constants.OPTIONAL_PACKAGES)) { @@ -235,7 +226,7 @@ public static ProvisioningConfig buildConfig(ProvisioningManager pm, return state.build(); } - private static String getMavenCoords(FeaturePack fp) { + private static String getMavenCoords(GalleonFeaturePack fp) { StringBuilder builder = new StringBuilder(); builder.append(fp.getGroupId()).append(":").append(fp.getArtifactId()); String type = fp.getExtension() == null ? fp.getType() : fp.getExtension(); diff --git a/core/src/main/java/org/wildfly/plugin/core/PluginProgressTracker.java b/core/src/main/java/org/wildfly/plugin/core/PluginProgressTracker.java index 29aa26d2..4fa04c0e 100644 --- a/core/src/main/java/org/wildfly/plugin/core/PluginProgressTracker.java +++ b/core/src/main/java/org/wildfly/plugin/core/PluginProgressTracker.java @@ -5,8 +5,7 @@ package org.wildfly.plugin.core; import org.apache.maven.plugin.logging.Log; -import org.jboss.galleon.ProvisioningManager; -import org.jboss.galleon.layout.ProvisioningLayoutFactory; +import org.jboss.galleon.api.Provisioning; import org.jboss.galleon.progresstracking.ProgressCallback; import org.jboss.galleon.progresstracking.ProgressTracker; @@ -66,16 +65,16 @@ public void pulse(ProgressTracker tracker) { public void complete(ProgressTracker tracker) { } - public static void initTrackers(ProvisioningManager pm, Log log) { - pm.getLayoutFactory().setProgressCallback(ProvisioningLayoutFactory.TRACK_PACKAGES, + public static void initTrackers(Provisioning pm, Log log) { + pm.setProgressCallback(org.jboss.galleon.Constants.TRACK_PACKAGES, new PluginProgressTracker(log, "Installing packages", false)); - pm.getLayoutFactory().setProgressCallback(ProvisioningLayoutFactory.TRACK_CONFIGS, + pm.setProgressCallback(org.jboss.galleon.Constants.TRACK_CONFIGS, new PluginProgressTracker(log, "Generating configurations", true)); - pm.getLayoutFactory().setProgressCallback(ProvisioningLayoutFactory.TRACK_LAYOUT_BUILD, + pm.setProgressCallback(org.jboss.galleon.Constants.TRACK_LAYOUT_BUILD, new PluginProgressTracker(log, "Resolving feature-packs", false)); - pm.getLayoutFactory().setProgressCallback("JBMODULES", + pm.setProgressCallback("JBMODULES", new PluginProgressTracker(log, "Resolving artifacts", false)); - pm.getLayoutFactory().setProgressCallback("JBEXTRACONFIGS", + pm.setProgressCallback("JBEXTRACONFIGS", new PluginProgressTracker(log, "Generating extra configurations", true)); } } diff --git a/plugin/pom.xml b/plugin/pom.xml index c72ab1af..b5a8394e 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -131,6 +131,10 @@ org.jboss.galleon galleon-maven-plugin + + org.jboss.galleon + galleon-api + org.twdata.maven diff --git a/plugin/src/main/java/org/wildfly/plugin/common/Utils.java b/plugin/src/main/java/org/wildfly/plugin/common/Utils.java index a74c0c6f..dccaf92a 100644 --- a/plugin/src/main/java/org/wildfly/plugin/common/Utils.java +++ b/plugin/src/main/java/org/wildfly/plugin/common/Utils.java @@ -5,7 +5,6 @@ package org.wildfly.plugin.common; -import java.io.FileWriter; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -17,14 +16,14 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; -import org.jboss.galleon.ProvisioningManager; -import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.api.GalleonBuilder; +import org.jboss.galleon.api.GalleonFeaturePack; +import org.jboss.galleon.api.Provisioning; +import org.jboss.galleon.api.config.GalleonProvisioningConfig; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; -import org.jboss.galleon.xml.ProvisioningXmlWriter; import org.wildfly.glow.Arguments; import org.wildfly.glow.GlowSession; import org.wildfly.glow.ScanResults; -import org.wildfly.plugin.core.FeaturePack; import org.wildfly.plugin.core.GalleonUtils; import org.wildfly.plugin.provision.GlowConfig; @@ -105,13 +104,13 @@ public static List splitArguments(final CharSequence arguments) { public static ScanResults scanDeployment(GlowConfig discoverProvisioningInfo, List layers, List excludedLayers, - List featurePacks, + List featurePacks, boolean dryRun, Log log, Path deploymentContent, MavenRepoManager artifactResolver, Path outputFolder, - ProvisioningManager pm, + GalleonBuilder pm, Map galleonOptions, String layersConfigurationFileName) throws Exception { if (!layers.isEmpty()) { @@ -127,11 +126,12 @@ public static ScanResults scanDeployment(GlowConfig discoverProvisioningInfo, Path glowOutputFolder = outputFolder.resolve("glow-scan"); Files.createDirectories(glowOutputFolder); if (!featurePacks.isEmpty()) { - ProvisioningConfig in = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, + GalleonProvisioningConfig in = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, layersConfigurationFileName); inProvisioningFile = glowOutputFolder.resolve("glow-in-provisioning.xml"); - try (FileWriter fileWriter = new FileWriter(inProvisioningFile.toFile())) { - ProvisioningXmlWriter.getInstance().write(in, fileWriter); + pm.newProvisioningBuilder(in).build().storeProvisioningConfig(in, outputFolder); + try (Provisioning p = pm.newProvisioningBuilder(in).build()) { + p.storeProvisioningConfig(in, inProvisioningFile); } } Arguments arguments = discoverProvisioningInfo.toArguments(deploymentContent, inProvisioningFile); @@ -148,13 +148,15 @@ public static ScanResults scanDeployment(GlowConfig discoverProvisioningInfo, try { results.outputInformation(writer); } catch (Exception ex) { + results.close(); throw new MojoExecutionException(ex.getLocalizedMessage(), ex); } if (!dryRun) { - results.outputConfig(glowOutputFolder, false); + results.outputConfig(glowOutputFolder, null); } if (results.getErrorSession().hasErrors()) { if (discoverProvisioningInfo.isFailsOnError()) { + results.close(); throw new MojoExecutionException("Error detected by WildFly Glow. Aborting."); } else { log.warn("Some erros have been identified, check logs."); diff --git a/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java b/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java index 2b2e780c..57ee6ca1 100644 --- a/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java @@ -60,8 +60,11 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.galleon.ProvisioningException; -import org.jboss.galleon.ProvisioningManager; -import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.api.GalleonBuilder; +import org.jboss.galleon.api.GalleonFeaturePack; +import org.jboss.galleon.api.Provisioning; +import org.jboss.galleon.api.ProvisioningBuilder; +import org.jboss.galleon.api.config.GalleonProvisioningConfig; import org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager; import org.jboss.galleon.maven.plugin.util.MvnMessageWriter; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; @@ -79,7 +82,6 @@ import org.wildfly.plugin.core.Deployment; import org.wildfly.plugin.core.DeploymentManager; import org.wildfly.plugin.core.DeploymentResult; -import org.wildfly.plugin.core.FeaturePack; import org.wildfly.plugin.core.GalleonUtils; import org.wildfly.plugin.core.PluginProgressTracker; import org.wildfly.plugin.core.ServerHelper; @@ -314,7 +316,7 @@ public class DevMojo extends AbstractServerStartMojo { * {@code wildfly.provisioning.feature-packs} to provide a comma separated list of feature-packs. */ @Parameter(alias = "feature-packs", property = PropertyNames.WILDFLY_PROVISIONING_FEATURE_PACKS) - private List featurePacks = Collections.emptyList(); + private List featurePacks = Collections.emptyList(); /** * A list of Galleon layers to provision. Can be used when feature-pack-location or feature-packs are set. @@ -544,18 +546,15 @@ private boolean isDiscoveryEnabled() { return discoverProvisioningInfo != null; } - ProvisioningConfig shouldReprovision() { + GalleonProvisioningConfig shouldReprovision() { // Remote or no initial Glow scanning if (remote || results == null) { return null; } - // References a dummy installation directory - Path tmpInstallDir = Paths.get(project.getBuild().getDirectory()).resolve("glow-tmp"); - try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(mavenRepoManager) - .setInstallationHome(tmpInstallDir) - .setMessageWriter(new MvnMessageWriter(getLog())) - .build()) { - ScanResults newResults = scanDeployment(pm); + try { + GalleonBuilder galleonBuilder = new GalleonBuilder(); + galleonBuilder.addArtifactResolver(mavenRepoManager); + ScanResults newResults = scanDeployment(galleonBuilder); try { if (!results.getDecorators().equals(newResults.getDecorators())) { getLog().info("Set of discovered layers changed, needs to re-provision. New layers: " @@ -568,6 +567,9 @@ ProvisioningConfig shouldReprovision() { return newResults.getProvisioningConfig(); } } finally { + if (results != null) { + results.close(); + } results = newResults; } } catch (Exception ex) { @@ -578,7 +580,7 @@ ProvisioningConfig shouldReprovision() { boolean reprovisionAndStart() throws IOException, InterruptedException, MojoExecutionException, MojoFailureException, ProvisioningException { - ProvisioningConfig newConfig = shouldReprovision(); + GalleonProvisioningConfig newConfig = shouldReprovision(); if (newConfig == null) { return false; } @@ -588,7 +590,10 @@ boolean reprovisionAndStart() debug("Deleting existing installation " + installDir); IoUtils.recursiveDelete(installDir); } - try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(mavenRepoManager) + GalleonBuilder galleonBuilder = new GalleonBuilder(); + galleonBuilder.addArtifactResolver(mavenRepoManager); + ProvisioningBuilder builder = galleonBuilder.newProvisioningBuilder(newConfig); + try (Provisioning pm = builder .setInstallationHome(installDir) .setMessageWriter(new MvnMessageWriter(getLog())) .build()) { @@ -610,30 +615,42 @@ protected Path provisionIfRequired(final Path installDir) throws MojoFailureExce if (Files.exists(installDir)) { IoUtils.recursiveDelete(installDir); } - try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(mavenRepoManager) - .setInstallationHome(installDir) - .setMessageWriter(new MvnMessageWriter(getLog())) - .build()) { - ProvisioningConfig config; + try { + GalleonBuilder provider = new GalleonBuilder(); + provider.addArtifactResolver(mavenRepoManager); + GalleonProvisioningConfig config; if (featurePacks.isEmpty() && !isDiscoveryEnabled()) { return super.provisionIfRequired(installDir); } else { if (!isDiscoveryEnabled()) { - config = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, - serverConfig); + config = GalleonUtils.buildConfig(provider, featurePacks, layers, excludedLayers, galleonOptions, + serverConfig == null ? "standalone.xml" : serverConfig); } else { - results = scanDeployment(pm); + results = scanDeployment(provider); config = results.getProvisioningConfig(); } } - provisionServer(pm, config); + getLog().info("Provisioning server in " + installDir); + try (Provisioning pm = provider.newProvisioningBuilder(config) + .setInstallationHome(installDir) + .setMessageWriter(new MvnMessageWriter(getLog())) + .build()) { + PluginProgressTracker.initTrackers(pm, getLog()); + pm.provision(config); + // Check that at least the standalone or domain directories have been generated. + if (Files.notExists(installDir.resolve("standalone")) && Files.notExists(installDir.resolve("domain"))) { + getLog().error("Invalid galleon provisioning, no server provisioned in " + installDir + ". Make sure " + + "that the list of Galleon feature-packs and Galleon layers are properly configured."); + throw new MojoExecutionException("Invalid plugin configuration, no server provisioned."); + } + } } catch (Exception e) { throw new MojoFailureException(e.getLocalizedMessage(), e); } return installDir; } - private ScanResults scanDeployment(ProvisioningManager pm) throws Exception { + private ScanResults scanDeployment(GalleonBuilder pm) throws Exception { return Utils.scanDeployment(discoverProvisioningInfo, layers, excludedLayers, featurePacks, false, getLog(), @@ -645,7 +662,7 @@ private ScanResults scanDeployment(ProvisioningManager pm) throws Exception { serverConfig); } - private void provisionServer(ProvisioningManager pm, ProvisioningConfig config) + private void provisionServer(Provisioning pm, GalleonProvisioningConfig config) throws ProvisioningException, MojoExecutionException { getLog().info("Provisioning server in " + installDir); PluginProgressTracker.initTrackers(pm, getLog()); diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java index b6ade624..79375ccd 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java @@ -7,12 +7,9 @@ import static org.wildfly.plugin.core.Constants.PLUGIN_PROVISIONING_FILE; import static org.wildfly.plugin.core.Constants.STANDALONE_XML; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.net.MalformedURLException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -33,19 +30,19 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; -import org.jboss.galleon.ProvisioningDescriptionException; import org.jboss.galleon.ProvisioningException; -import org.jboss.galleon.ProvisioningManager; -import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.api.GalleonBuilder; +import org.jboss.galleon.api.GalleonFeaturePack; +import org.jboss.galleon.api.Provisioning; +import org.jboss.galleon.api.ProvisioningBuilder; +import org.jboss.galleon.api.config.GalleonProvisioningConfig; import org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager; import org.jboss.galleon.maven.plugin.util.MvnMessageWriter; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.jboss.galleon.util.IoUtils; -import org.jboss.galleon.xml.ProvisioningXmlWriter; import org.wildfly.channel.UnresolvedMavenArtifactException; import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.Utils; -import org.wildfly.plugin.core.FeaturePack; import org.wildfly.plugin.core.GalleonUtils; import org.wildfly.plugin.core.MavenRepositoriesEnricher; import org.wildfly.plugin.core.PluginProgressTracker; @@ -138,7 +135,7 @@ abstract class AbstractProvisionServerMojo extends AbstractMojo { * Use the System property {@code wildfly.provisioning.feature-packs} to provide a comma separated list of feature-packs. */ @Parameter(required = false, alias = "feature-packs", property = PropertyNames.WILDFLY_PROVISIONING_FEATURE_PACKS) - List featurePacks = Collections.emptyList(); + List featurePacks = Collections.emptyList(); /** * A list of Galleon layers to provision. Can be used when @@ -286,20 +283,21 @@ protected void enrichRepositories() throws MojoExecutionException { private void provisionServer(Path home) throws ProvisioningException, MojoExecutionException, IOException, XMLStreamException { - try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver) + GalleonBuilder galleonBuilder = new GalleonBuilder(); + galleonBuilder.addArtifactResolver(artifactResolver); + GalleonProvisioningConfig config = buildGalleonConfig(galleonBuilder); + ProvisioningBuilder builder = galleonBuilder.newProvisioningBuilder(config); + try (Provisioning pm = builder .setInstallationHome(home) .setMessageWriter(new MvnMessageWriter(getLog())) .setLogTime(logProvisioningTime) .setRecordState(recordProvisioningState) .build()) { - ProvisioningConfig config = buildGalleonConfig(pm); if (dryRun) { Path targetPath = Paths.get(project.getBuild().getDirectory()); Path file = targetPath.resolve(PLUGIN_PROVISIONING_FILE); getLog().info("Dry-run execution, generating provisioning.xml file: " + file); - try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { - ProvisioningXmlWriter.getInstance().write(config, writer); - } + pm.storeProvisioningConfig(config, targetPath); return; } getLog().info("Provisioning server in " + home); @@ -313,22 +311,22 @@ private void provisionServer(Path home) throws ProvisioningException, } if (!recordProvisioningState) { Path file = home.resolve(PLUGIN_PROVISIONING_FILE); - try (FileWriter writer = new FileWriter(file.toFile())) { - ProvisioningXmlWriter.getInstance().write(config, writer); - } + pm.storeProvisioningConfig(config, file); } } } - protected ProvisioningConfig buildGalleonConfig(ProvisioningManager pm) + protected GalleonProvisioningConfig buildGalleonConfig(GalleonBuilder galleonBuilder) throws MojoExecutionException, ProvisioningException { - ProvisioningConfig config = null; + GalleonProvisioningConfig config; Path resolvedProvisioningFile = resolvePath(project, provisioningFile.toPath()); boolean provisioningFileExists = Files.exists(resolvedProvisioningFile); if (featurePacks.isEmpty()) { if (provisioningFileExists) { getLog().info("Provisioning server using " + resolvedProvisioningFile + " file."); - config = GalleonUtils.buildConfig(resolvedProvisioningFile); + try (Provisioning p = galleonBuilder.newProvisioningBuilder(resolvedProvisioningFile).build()) { + config = p.loadProvisioningConfig(resolvedProvisioningFile); + } } else { config = getDefaultConfig(); if (config == null) { @@ -344,13 +342,13 @@ protected ProvisioningConfig buildGalleonConfig(ProvisioningManager pm) throw new MojoExecutionException( "layers-configuration-file-name has been set although no layers are defined."); } - config = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, + config = GalleonUtils.buildConfig(galleonBuilder, featurePacks, layers, excludedLayers, galleonOptions, layersConfigurationFileName); } return config; } - protected ProvisioningConfig getDefaultConfig() throws ProvisioningDescriptionException { + protected GalleonProvisioningConfig getDefaultConfig() throws ProvisioningException { return GalleonUtils.buildDefaultConfig(); } diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/ChannelMavenArtifactRepositoryManager.java b/plugin/src/main/java/org/wildfly/plugin/provision/ChannelMavenArtifactRepositoryManager.java index dfe171be..a2d3d4db 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/ChannelMavenArtifactRepositoryManager.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/ChannelMavenArtifactRepositoryManager.java @@ -27,8 +27,8 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; -import org.jboss.galleon.ProvisioningException; -import org.jboss.galleon.layout.FeaturePackDescriber; +import org.jboss.galleon.api.MavenStreamResolver; +import org.jboss.galleon.api.Provisioning; import org.jboss.galleon.universe.maven.MavenArtifact; import org.jboss.galleon.universe.maven.MavenUniverseException; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; @@ -40,13 +40,14 @@ import org.wildfly.channel.NoStreamFoundException; import org.wildfly.channel.Repository; import org.wildfly.channel.UnresolvedMavenArtifactException; +import org.wildfly.channel.VersionResult; import org.wildfly.channel.maven.VersionResolverFactory; import org.wildfly.channel.spi.ChannelResolvable; import org.wildfly.prospero.metadata.ManifestVersionRecord; import org.wildfly.prospero.metadata.ManifestVersionResolver; import org.wildfly.prospero.metadata.ProsperoMetadataUtils; -public class ChannelMavenArtifactRepositoryManager implements MavenRepoManager, ChannelResolvable { +public class ChannelMavenArtifactRepositoryManager implements MavenRepoManager, ChannelResolvable, MavenStreamResolver { private static final String REQUIRE_CHANNEL_FOR_ALL_ARTIFACT = "org.wildfly.plugins.galleon.all.artifact.requires.channel.resolution"; @@ -146,10 +147,7 @@ private boolean fpRequireChannel(MavenArtifact artifact) throws Exception { artifact.getExtension(), artifact.getClassifier(), artifact.getVersion()); - try { - FeaturePackDescriber.readSpec(mavenArtifact.getFile().toPath()); - } catch (ProvisioningException ex) { - // Not a feature-pack + if (!Provisioning.isFeaturePack(mavenArtifact.getFile().toPath())) { return requireChannel; } try (FileSystem fs = ZipUtils.newFileSystem(mavenArtifact.getFile().toPath())) { @@ -244,4 +242,10 @@ public void install(MavenArtifact artifact, Path path) throws MavenUniverseExcep throw new MavenUniverseException("Channel resolution can't be applied to Galleon universe"); } + @Override + public String getLatestVersion(String groupId, String artifactId, String extension, String classifier, String baseVersion) { + VersionResult res = channelSession.findLatestMavenArtifactVersion(groupId, artifactId, extension, classifier, + baseVersion); + return res.getVersion(); + } } diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java index 17da826a..51f4bf70 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java @@ -28,9 +28,10 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.jboss.galleon.ProvisioningException; -import org.jboss.galleon.ProvisioningManager; -import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.api.GalleonBuilder; +import org.jboss.galleon.api.config.GalleonProvisioningConfig; import org.jboss.galleon.util.IoUtils; +import org.wildfly.glow.ScanResults; import org.wildfly.plugin.cli.BaseCommandConfiguration; import org.wildfly.plugin.cli.CliSession; import org.wildfly.plugin.cli.OfflineCommandExecutor; @@ -215,18 +216,18 @@ public class PackageServerMojo extends AbstractProvisionServerMojo { private OfflineCommandExecutor commandExecutor; @Override - protected ProvisioningConfig getDefaultConfig() { + protected GalleonProvisioningConfig getDefaultConfig() throws ProvisioningException { return null; } @Override - protected ProvisioningConfig buildGalleonConfig(ProvisioningManager pm) + protected GalleonProvisioningConfig buildGalleonConfig(GalleonBuilder pm) throws MojoExecutionException, ProvisioningException { if (discoverProvisioningInfo == null) { return super.buildGalleonConfig(pm); } try { - return Utils.scanDeployment(discoverProvisioningInfo, + try (ScanResults results = Utils.scanDeployment(discoverProvisioningInfo, layers, excludedLayers, featurePacks, @@ -237,7 +238,9 @@ protected ProvisioningConfig buildGalleonConfig(ProvisioningManager pm) Paths.get(project.getBuild().getDirectory()), pm, galleonOptions, - layersConfigurationFileName).getProvisioningConfig(); + layersConfigurationFileName)) { + return results.getProvisioningConfig(); + } } catch (Exception ex) { throw new MojoExecutionException(ex.getLocalizedMessage(), ex); } diff --git a/pom.xml b/pom.xml index 2ed1cdd1..881cd5d8 100644 --- a/pom.xml +++ b/pom.xml @@ -106,8 +106,8 @@ 11 - 5.2.2.Final - 1.0.0.Alpha6 + 6.0.0.Beta1 + 1.0.0.Alpha12 true 1.2.1.Final @@ -313,7 +313,7 @@ org.jboss.galleon - galleon-core + galleon-api ${version.org.jboss.galleon} @@ -421,6 +421,11 @@ ${version.org.wildfly.glow} + + org.jboss.galleon + galleon-core + ${version.org.jboss.galleon} + junit junit diff --git a/tests/shared/pom.xml b/tests/shared/pom.xml index 0e463815..a8efae43 100644 --- a/tests/shared/pom.xml +++ b/tests/shared/pom.xml @@ -23,6 +23,10 @@ + + org.jboss.galleon + galleon-core + org.wildfly.plugins wildfly-maven-plugin