From 76e5df4e0833d9cd4573d48882af6c4e06c75a71 Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Mon, 29 Oct 2018 11:03:17 +0100 Subject: [PATCH 1/2] Fix for GAL-202, Make passive the default when layers are installed --- .../java/org/jboss/galleon/cli/cmd/Table.java | 5 +++++ .../galleon/cli/cmd/maingrp/InstallCommand.java | 7 ++++++- .../galleon/cli/cmd/state/StateInfoUtil.java | 16 +++++++++++++--- .../org/jboss/galleon/cli/LayersTestCase.java | 5 +++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cli/src/main/java/org/jboss/galleon/cli/cmd/Table.java b/cli/src/main/java/org/jboss/galleon/cli/cmd/Table.java index af679ddc7..c481cc7ff 100644 --- a/cli/src/main/java/org/jboss/galleon/cli/cmd/Table.java +++ b/cli/src/main/java/org/jboss/galleon/cli/cmd/Table.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -273,6 +274,10 @@ public void add(Node line) { trees.add(line); } + public void addAll(Collection nodes) { + trees.addAll(nodes); + } + public String build() { builder = new StringBuilder(); columnsWidth.clear(); diff --git a/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java b/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java index 2e0490ae0..44c743a3b 100644 --- a/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java +++ b/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java @@ -34,6 +34,7 @@ import org.aesh.command.impl.internal.ProcessedOptionBuilder; import org.aesh.command.parser.OptionParserException; import org.aesh.readline.AeshContext; +import org.jboss.galleon.Constants; import org.jboss.galleon.ProvisioningException; import org.jboss.galleon.ProvisioningManager; import org.jboss.galleon.ProvisioningOption; @@ -139,6 +140,9 @@ protected void runCommand(PmCommandInvocation session, Map optio if (layers == null) { manager.install(loc, options); } else { + if (!options.containsKey(Constants.OPTIONAL_PACKAGES)) { + options.put(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE); + } manager.provision(new LayersConfigBuilder(pmSession, layers.split(","), (String) getValue(MODEL_OPTION_NAME), (String) getValue(CONFIG_OPTION_NAME), loc).build(), options); @@ -213,7 +217,8 @@ protected List getOtherOptions() throws OptionParserException { hasValue(true). type(String.class). optionType(OptionType.NORMAL). - completer(LayersCompleter.class). + // Disable completion. Re-activate when layers show-up in WF. + //completer(LayersCompleter.class). description(HelpDescriptions.INSTALL_LAYERS). build(); options.add(layers); diff --git a/cli/src/main/java/org/jboss/galleon/cli/cmd/state/StateInfoUtil.java b/cli/src/main/java/org/jboss/galleon/cli/cmd/state/StateInfoUtil.java index 66615df0c..e2b7bc204 100644 --- a/cli/src/main/java/org/jboss/galleon/cli/cmd/state/StateInfoUtil.java +++ b/cli/src/main/java/org/jboss/galleon/cli/cmd/state/StateInfoUtil.java @@ -297,12 +297,13 @@ private static void displayPackage(PmCommandInvocation session, Group grp) throw public static String buildConfigs(Map> configs, ProvisioningLayout pLayout) throws ProvisioningException, IOException { if (!configs.isEmpty()) { + boolean hasLayers = false; + List nodes = new ArrayList<>(); Map>> layers = LayersConfigBuilder.getAllLayers(pLayout); - Table.Tree table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME, Headers.LAYERS); for (Entry> entry : configs.entrySet()) { if (!entry.getValue().isEmpty()) { Table.Node model = new Table.Node(entry.getKey()); - table.add(model); + nodes.add(model); for (ConfigInfo name : entry.getValue()) { Table.Node nameNode = new Table.Node(name.getName()); model.addNext(nameNode); @@ -325,13 +326,15 @@ public static String buildConfigs(Map> configs, } } if (!foundAsDependency) { + hasLayers = true; nameNode.addNext(new Table.Node(id.getName())); } } ConfigModel m = pLayout.getConfig().getDefinedConfig(name.getId()); if(m != null) { if(m.hasExcludedLayers()) { - for(String ex : m.getExcludedLayers()) { + for (String ex : m.getExcludedLayers()) { + hasLayers = true; nameNode.addNext(new Table.Node(ex+"(excluded)")); } } @@ -339,6 +342,13 @@ public static String buildConfigs(Map> configs, } } } + Table.Tree table; + if (hasLayers) { + table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME, Headers.LAYERS); + } else { + table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME); + } + table.addAll(nodes); return "Configurations" + Config.getLineSeparator() + table.build(); } return null; diff --git a/testsuite/src/test/java/org/jboss/galleon/cli/LayersTestCase.java b/testsuite/src/test/java/org/jboss/galleon/cli/LayersTestCase.java index 6b9adf27d..ac87a4f8d 100644 --- a/testsuite/src/test/java/org/jboss/galleon/cli/LayersTestCase.java +++ b/testsuite/src/test/java/org/jboss/galleon/cli/LayersTestCase.java @@ -19,6 +19,7 @@ import java.nio.file.Path; import java.util.Arrays; import org.aesh.command.CommandException; +import org.jboss.galleon.Constants; import org.jboss.galleon.ProvisioningManager; import static org.jboss.galleon.cli.CliTestUtils.PRODUCER1; import static org.jboss.galleon.cli.CliTestUtils.UNIVERSE_NAME; @@ -29,6 +30,7 @@ import org.jboss.galleon.universe.MvnUniverse; import org.jboss.galleon.universe.UniverseSpec; import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -97,6 +99,9 @@ public void test() throws Exception { assertTrue(conf.getIncludedLayers().size() == 2); assertTrue(conf.getIncludedLayers().contains("layerA-" + PRODUCER1)); assertTrue(conf.getIncludedLayers().contains("layerC-" + PRODUCER1)); + String opt = config.getPluginOption(Constants.OPTIONAL_PACKAGES); + assertNotNull(opt); + assertEquals(Constants.PASSIVE, opt); cli.execute("get-info --dir=" + path + " --type=configs"); assertTrue(cli.getOutput(), cli.getOutput().contains("layerA-" + PRODUCER1)); From 23ddf561a78878d2abfd066b593b3c2b9ad19ae9 Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Mon, 29 Oct 2018 13:51:10 +0100 Subject: [PATCH 2/2] Follow-up on Fix for GAL-201, rename Config to be Configuration, conflict with config element used when including config in FP --- .../org/jboss/galleon/maven/plugin/ProvisionStateMojo.java | 6 +++--- .../maven/plugin/util/{Config.java => Configuration.java} | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/{Config.java => Configuration.java} (97%) diff --git a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java index 1cc9cd106..a9e42dd31 100644 --- a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java +++ b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java @@ -48,7 +48,7 @@ import org.jboss.galleon.config.ConfigModel; import org.jboss.galleon.config.FeaturePackConfig; import org.jboss.galleon.config.ProvisioningConfig; -import org.jboss.galleon.maven.plugin.util.Config; +import org.jboss.galleon.maven.plugin.util.Configuration; import org.jboss.galleon.maven.plugin.util.ConfigurationId; import org.jboss.galleon.maven.plugin.util.FeaturePack; import org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager; @@ -119,7 +119,7 @@ public class ProvisionStateMojo extends AbstractMojo { * A list of custom configurations to install. */ @Parameter(alias = "configurations", required = false) - private List configs = Collections.emptyList(); + private List configs = Collections.emptyList(); /** * Whether to use offline mode when the plugin resolves an artifact. @@ -223,7 +223,7 @@ private void doProvision() throws MojoExecutionException, ProvisioningException } boolean hasLayers = false; - for (Config config : configs) { + for (Configuration config : configs) { ConfigModel.Builder configBuilder = ConfigModel. builder(config.getModel(), config.getName()); for (String layer : config.getLayers()) { diff --git a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/Config.java b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/Configuration.java similarity index 97% rename from maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/Config.java rename to maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/Configuration.java index c685968f0..b798841f2 100644 --- a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/Config.java +++ b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/Configuration.java @@ -22,7 +22,7 @@ * * @author jdenise@redhat.com */ -public class Config { +public class Configuration { private String model; private String name;