Skip to content

Commit

Permalink
Merge pull request #237 from jfdenise/3.x
Browse files Browse the repository at this point in the history
Optional packages and transitive handling
  • Loading branch information
aloubyansky authored Feb 25, 2019
2 parents 3b043ee + 069b51d commit 1c5b5bc
Show file tree
Hide file tree
Showing 23 changed files with 843 additions and 48 deletions.
4 changes: 2 additions & 2 deletions cli/src/main/java/org/jboss/galleon/cli/PmSessionCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -47,7 +47,7 @@ public static void handleException(PmCommandInvocation session, Throwable t) thr
if (session.getPmSession().isExceptionRethrown()) {
throw new CommandException(t);
}
// t.printStackTrace();
//t.printStackTrace();
printException(session.getPmSession(), t);
}

Expand Down
5 changes: 4 additions & 1 deletion cli/src/main/java/org/jboss/galleon/cli/cmd/Headers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,10 +30,13 @@ public class Headers {
public static final String DEFAULT_VALUE = "Default Value";
public static final String DEPENDENCY = "Dependency";
public static final String DEPENDENCIES = "Dependencies";
public static final String FEATURE = "Feature";
public static final String LATEST_BUILD = "Latest Build";
public static final String LAYERS = "Layers";
public static final String NAME = "Name";
public static final String OPTION = "Option";
public static final String PACKAGE = "Package";
public static final String PASSIVE = "Passive";
public static final String PATCH = "Patch";
public static final String PATCHES = "Patches";
public static final String PATCH_FOR = "Patch For";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -35,8 +35,11 @@
import org.jboss.galleon.cli.cmd.CliErrors;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.ALL;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.LAYERS;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.OPTIONAL_PACKAGES;
import org.jboss.galleon.cli.cmd.state.StateInfoUtil;
import org.jboss.galleon.cli.model.ConfigInfo;
import org.jboss.galleon.cli.model.FeatureContainer;
import org.jboss.galleon.cli.model.FeatureContainers;
import static org.jboss.galleon.cli.path.FeatureContainerPathConsumer.CONFIGS;
import static org.jboss.galleon.cli.path.FeatureContainerPathConsumer.DEPENDENCIES;
import static org.jboss.galleon.cli.path.FeatureContainerPathConsumer.OPTIONS;
Expand Down Expand Up @@ -65,7 +68,7 @@ public class InfoTypeCompleter extends AbstractCompleter {
@Override
protected List<String> getItems(PmCompleterInvocation completerInvocation) {
// No patch for un-customized FP.
return Arrays.asList(ALL, CONFIGS, DEPENDENCIES, LAYERS, OPTIONS);
return Arrays.asList(ALL, CONFIGS, DEPENDENCIES, LAYERS, OPTIONAL_PACKAGES, OPTIONS);
}

}
Expand Down Expand Up @@ -147,6 +150,9 @@ protected void runCommand(PmCommandInvocation commandInvocation) throws CommandE
if (displayLayers(commandInvocation, layout)) {
commandInvocation.println("");
}
if (displayOptionalPackages(commandInvocation, layout)) {
commandInvocation.println("");
}
displayOptions(commandInvocation, layout);
break;
}
Expand Down Expand Up @@ -174,6 +180,12 @@ protected void runCommand(PmCommandInvocation commandInvocation) throws CommandE
}
break;
}
case OPTIONAL_PACKAGES: {
if (!displayOptionalPackages(commandInvocation, layout)) {
commandInvocation.println(StateInfoUtil.NO_OPTIONAL_PACKAGES);
}
break;
}
default: {
throw new CommandExecutionException(CliErrors.invalidInfoType());
}
Expand Down Expand Up @@ -241,4 +253,23 @@ private boolean displayOptions(PmCommandInvocation commandInvocation,
}
return str != null;
}

private boolean displayOptionalPackages(PmCommandInvocation commandInvocation,
ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
Map<String, List<ConfigInfo>> configs = new HashMap<>();
try (ProvisioningRuntime rt = ProvisioningRuntimeBuilder.
newInstance(commandInvocation.getPmSession().getMessageWriter(false))
.initRtLayout(pLayout.transform(ProvisioningRuntimeBuilder.FP_RT_FACTORY))
.setEncoding(ProvisioningManager.Builder.ENCODING)
.build()) {
FeatureContainer container = FeatureContainers.
fromProvisioningRuntime(commandInvocation.getPmSession(), rt);
String str = StateInfoUtil.buildOptionalPackages(commandInvocation.getPmSession(),
container, pLayout);
if (str != null) {
commandInvocation.print(str);
}
return str != null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -42,13 +42,18 @@ protected void runCommand(PmCommandInvocation invoc, State session) throws IOExc
}

public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecutionException {
ProducerSpec channel = getProducer(session);
if (channel == null) {
ProducerSpec producer = getProducer(session);
if (producer == null) {
return null;
}
ProvisioningConfig config = session.getState().getConfig();
for (FeaturePackConfig dep : config.getFeaturePackDeps()) {
if (dep.getLocation().getProducer().equals(channel)) {
if (dep.getLocation().getProducer().equals(producer)) {
return dep;
}
}
for (FeaturePackConfig dep : config.getTransitiveDeps()) {
if (dep.getLocation().getProducer().equals(producer)) {
return dep;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -35,11 +35,12 @@ public class InfoTypeCompleter extends AbstractCompleter {
public static final String ALL = "all";
public static final String PATCHES = "patches";
public static final String LAYERS = "layers";
public static final String OPTIONAL_PACKAGES = "optional-packages";
public static final String UNIVERSES = "universes";

@Override
protected List<String> getItems(PmCompleterInvocation completerInvocation) {
return Arrays.asList(ALL, CONFIGS, DEPENDENCIES, OPTIONS, LAYERS, PATCHES, UNIVERSES);
return Arrays.asList(ALL, CONFIGS, DEPENDENCIES, OPTIONAL_PACKAGES, OPTIONS, LAYERS, PATCHES, UNIVERSES);
}

}
127 changes: 126 additions & 1 deletion cli/src/main/java/org/jboss/galleon/cli/cmd/state/StateInfoUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -32,13 +32,15 @@
import org.jboss.galleon.ProvisioningOption;
import org.jboss.galleon.cli.CommandExecutionException;
import org.jboss.galleon.cli.PmCommandInvocation;
import org.jboss.galleon.cli.PmSession;
import org.jboss.galleon.cli.cmd.CliErrors;
import org.jboss.galleon.cli.cmd.Headers;
import org.jboss.galleon.cli.cmd.Table;
import org.jboss.galleon.cli.cmd.Table.Cell;
import org.jboss.galleon.cli.cmd.maingrp.LayersConfigBuilder;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.ALL;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.LAYERS;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.OPTIONAL_PACKAGES;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.PATCHES;
import static org.jboss.galleon.cli.cmd.state.InfoTypeCompleter.UNIVERSES;
import org.jboss.galleon.cli.model.ConfigInfo;
Expand Down Expand Up @@ -70,6 +72,7 @@
import org.jboss.galleon.spec.FeatureReferenceSpec;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.FeaturePackLocation.FPID;
import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec;
import org.jboss.galleon.universe.UniverseSpec;

/**
Expand All @@ -83,6 +86,7 @@ public class StateInfoUtil {
public static final String NO_CONFIGURATIONS = "No configurations.";
public static final String NO_DEPENDENCIES = "No dependencies.";
public static final String NO_LAYERS = "No layers.";
public static final String NO_OPTIONAL_PACKAGES = "No optional packages.";
public static final String NO_OPTIONS = "No options.";
public static final String NO_PATCHES = "No patches.";
public static final String NO_UNIVERSES = "No custom universes.";
Expand Down Expand Up @@ -357,6 +361,110 @@ public static String buildConfigs(Map<String, List<ConfigInfo>> configs,
return null;
}

public static String buildOptionalPackages(PmSession session, FeatureContainer container,
ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
String optionValue
= container.getProvisioningConfig().getOption(ProvisioningOption.OPTIONAL_PACKAGES.getName());
if (optionValue == null) {
optionValue = Constants.ALL;
}
Table.Tree t = null;
boolean passivePresent = !container.getPassivePackages().isEmpty()
|| !container.getOrphanPassivePackages().isEmpty();
Set<String> optionalProducers = container.getOptionalPackagesProducers();
if (!optionalProducers.isEmpty()) {
if (passivePresent) {
t = new Table.Tree(Headers.PRODUCT, Headers.FEATURE, Headers.PACKAGE, Headers.PASSIVE);
} else {
t = new Table.Tree(Headers.PRODUCT, Headers.FEATURE, Headers.PACKAGE);
}
for (String producer : optionalProducers) {
String displayProducer = producer;
try {
ProducerSpec pSpec = FeaturePackLocation.fromString(producer).getProducer();
if (session.getUniverse().getBuiltinUniverseSpec().equals(pSpec.getUniverse())) {
displayProducer = pSpec.getName();
}
} catch (Exception ex) {
// Not a producerSpec, keep original one.
}
Table.Node producerNode = new Table.Node(displayProducer);
t.add(producerNode);
Map<String, Set<String>> optionalPkgs = container.getOptionalPackages().get(producer);
if (optionalPkgs != null && !optionalPkgs.isEmpty()) {
for (Entry<String, Set<String>> entry : optionalPkgs.entrySet()) {
Table.Node feat = new Table.Node(entry.getKey());
producerNode.addNext(feat);
for (String p : entry.getValue()) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
if (passivePresent) {
pkg.addNext(new Table.Node(""));
}
}
Map<String, Set<String>> passivePkgs = container.getPassivePackages().get(producer);
if (passivePkgs != null) {
Set<String> passives = passivePkgs.get(entry.getKey());
if (passives != null) {
for (String p : passives) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
pkg.addNext(new Table.Node("true"));
}
}
}
}
} else {
Map<String, Set<String>> passivePkgs = container.getPassivePackages().get(producer);
if (passivePkgs != null && !passivePkgs.isEmpty()) {
for (Entry<String, Set<String>> entry : passivePkgs.entrySet()) {
Table.Node feat = new Table.Node(entry.getKey());
producerNode.addNext(feat);
for (String p : entry.getValue()) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
pkg.addNext(new Table.Node("true"));
}
}
}
}
Set<String> orphanOptionals = container.getOrphanOptionalPackages().get(producer);
Set<String> orphanPassives = container.getOrphanPassivePackages().get(producer);
if (orphanOptionals != null
|| orphanPassives != null) {
Table.Node feat = new Table.Node("{no-feature}");
producerNode.addNext(feat);

if (orphanOptionals != null) {
for (String p : orphanOptionals) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
if (passivePresent) {
pkg.addNext(new Table.Node(""));
}
}
}
if (orphanPassives != null) {
for (String p : orphanPassives) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
pkg.addNext(new Table.Node("true"));
}
}
}
}
}
StringBuilder builder = new StringBuilder();
builder.append("Optional packages (Provisioning option: " + optionValue + ")"
+ Config.getLineSeparator());
if (t == null) {
builder.append(NO_OPTIONAL_PACKAGES);
} else {
builder.append(t.build());
}
return builder.toString();
}

public static String buildLayers(ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
Map<String, Map<String, Set<String>>> layersMap = LayersConfigBuilder.getAllLayers(pLayout);
if (!layersMap.isEmpty()) {
Expand Down Expand Up @@ -562,6 +670,9 @@ public static void displayInfo(PmCommandInvocation invoc, Path installation,
if (displayLayers(invoc, layout)) {
invoc.println("");
}
if (displayOptionalPackages(invoc, container, layout)) {
invoc.println("");
}
if (displayOptions(invoc, layout)) {
invoc.println("");
}
Expand Down Expand Up @@ -623,6 +734,13 @@ public static void displayInfo(PmCommandInvocation invoc, Path installation,
}
break;
}
case OPTIONAL_PACKAGES: {
FeatureContainer container = supplier.apply(layout);
String packages = buildOptionalPackages(invoc.getPmSession(),
container, layout);
invoc.print(packages);
break;
}
default: {
throw new CommandExecutionException(CliErrors.invalidInfoType());
}
Expand All @@ -648,6 +766,13 @@ private static String buildConfigs(PmCommandInvocation invoc, FeatureContainer c
return buildConfigs(container.getFinalConfigs(), pLayout);
}

private static boolean displayOptionalPackages(PmCommandInvocation invoc, FeatureContainer container,
ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
String str = buildOptionalPackages(invoc.getPmSession(), container, pLayout);
invoc.print(str);
return true;
}

private static void displayFeaturePacks(PmCommandInvocation invoc, Path installation,
ProvisioningConfig config) {
String str = buildFeaturePacks(invoc, installation, config.getFeaturePackDeps());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,7 +19,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.aesh.command.option.Argument;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec;
Expand Down Expand Up @@ -137,11 +136,10 @@ public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecu
String orig = getPackage().substring(0, i);
String name = getPackage().substring(i + 1);
FeaturePackLocation.FPID fpid = null;
for (Entry<String, FeatureContainer> entry : session.getContainer().getFullDependencies().entrySet()) {
FeatureContainer container = entry.getValue();
FeatureContainer container = session.getContainer().getFullDependencies().get(orig);
if (container != null) {
if (container.getAllPackages().containsKey(Identity.fromString(orig, name))) {
fpid = container.getFPID();
break;
}
}
if (fpid == null) {
Expand All @@ -153,9 +151,17 @@ public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecu
break;
}
}
}
if (config == null) {
throw new CommandExecutionException("No feature pack found for " + getPackage());
if (config == null) {
// reset buildID
FeaturePackLocation noBuildLocation = new FeaturePackLocation(fpid.getUniverse(), fpid.getProducer().getName(),
null, null, null);
for (FeaturePackConfig c : session.getState().getConfig().getTransitiveDeps()) {
if (c.getLocation().equals(c.getLocation().hasBuild() ? fpid.getLocation() : noBuildLocation)) {
config = c;
break;
}
}
}
}
return config;
}
Expand Down
Loading

0 comments on commit 1c5b5bc

Please sign in to comment.