use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class ExportCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
if (file != null) {
final Path targetFile = file.toPath();
try {
getManager(invoc.getPmSession()).exportProvisioningConfig(targetFile);
} catch (ProvisioningException | IOException e) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
}
invoc.println("Provisioning file generated in " + targetFile);
} else {
ByteArrayOutputStream output = null;
try {
ProvisioningConfig config = getManager(invoc.getPmSession()).getProvisioningConfig();
output = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
ProvisioningXmlWriter.getInstance().write(config, writer);
} catch (Exception e) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
}
try {
invoc.println(output.toString(StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
}
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class CheckUpdatesCommand method getUpdatesTable.
static Updates getUpdatesTable(ProvisioningManager mgr, PmCommandInvocation session, boolean includeAll, String fp) throws ProvisioningException, CommandExecutionException {
if (includeAll && fp != null) {
throw new CommandExecutionException(CliErrors.onlyOneOptionOf(FP_OPTION_NAME, ALL_DEPENDENCIES_OPTION_NAME));
}
ProvisioningPlan plan;
if (fp == null) {
plan = mgr.getUpdates(includeAll);
} else {
String[] split = fp.split(",+");
List<ProducerSpec> resolved = new ArrayList<>();
List<FeaturePackLocation> locs = new ArrayList<>();
for (String producer : split) {
FeaturePackLocation loc = session.getPmSession().getResolvedLocation(mgr.getInstallationHome(), producer);
if (loc.hasBuild()) {
locs.add(loc);
} else {
resolved.add(loc.getProducer());
}
}
if (!resolved.isEmpty()) {
ProducerSpec[] arr = new ProducerSpec[resolved.size()];
plan = mgr.getUpdates(resolved.toArray(arr));
} else {
plan = ProvisioningPlan.builder();
}
if (!locs.isEmpty()) {
addCustomUpdates(plan, locs, mgr);
}
}
Updates updates = new Updates();
updates.plan = plan;
if (plan.isEmpty()) {
return updates;
}
boolean hasPatches = false;
for (FeaturePackUpdatePlan p : plan.getUpdates()) {
if (p.hasNewPatches()) {
hasPatches = true;
break;
}
}
List<String> headers = new ArrayList<>();
headers.add(Headers.PRODUCT);
headers.add(Headers.CURRENT_BUILD);
headers.add(Headers.UPDATE);
if (hasPatches) {
headers.add(Headers.PATCHES);
}
if (includeAll) {
headers.add(Headers.DEPENDENCY);
}
headers.add(Headers.UPDATE_CHANNEL);
updates.t = new Table(headers);
for (FeaturePackUpdatePlan p : plan.getUpdates()) {
FeaturePackLocation loc = p.getInstalledLocation();
String update = p.hasNewLocation() ? p.getNewLocation().getBuild() : NONE;
Cell patches = null;
if (hasPatches) {
patches = new Cell();
if (p.hasNewPatches()) {
for (FPID id : p.getNewPatches()) {
patches.addLine(id.getBuild());
}
} else {
patches.addLine(NONE);
}
}
List<Cell> line = new ArrayList<>();
line.add(new Cell(loc.getProducerName()));
line.add(new Cell(loc.getBuild()));
line.add(new Cell(update));
if (hasPatches) {
line.add(patches);
}
if (includeAll) {
line.add(new Cell(p.isTransitive() ? "Y" : "N"));
}
FeaturePackLocation newLocation = session.getPmSession().getExposedLocation(mgr.getInstallationHome(), p.getNewLocation());
line.add(new Cell(StateInfoUtil.formatChannel(newLocation)));
updates.t.addCellsLine(line);
}
updates.t.sort(Table.SortType.ASCENDANT);
return updates;
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class FindCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
if (pattern == null && layerPattern == null) {
throw new CommandExecutionException(CliErrors.missingPattern());
} else {
if (pattern == null) {
pattern = ".Final";
}
Map<UniverseSpec, Set<Result>> results = new HashMap<>();
Map<UniverseSpec, Set<String>> exceptions = new HashMap<>();
if (!pattern.endsWith("*")) {
pattern = pattern + "*";
}
pattern = pattern.replaceAll("\\*", ".*");
List<Pattern> layersCompiledPatterns = new ArrayList<>();
if (layerPattern != null) {
for (String l : layerPattern.split(",")) {
if (!l.endsWith("*")) {
l = l + "*";
}
l = l.replaceAll("\\*", ".*");
layersCompiledPatterns.add(Pattern.compile(l));
}
}
boolean containsFrequency = pattern.contains("" + FeaturePackLocation.FREQUENCY_START);
Pattern compiledPattern = Pattern.compile(pattern);
Integer[] numResults = new Integer[1];
numResults[0] = 0;
ProgressTracker<FPID> track = null;
if (invoc.getPmSession().isTrackersEnabled()) {
track = ProgressTrackers.newFindTracker(invoc);
}
ProgressTracker<FPID> tracker = track;
invoc.getPmSession().unregisterTrackers();
// Search for an installation in the context
Path installation = null;
try {
installation = Util.lookupInstallationDir(invoc.getConfiguration().getAeshContext(), null);
} catch (ProvisioningException ex) {
// XXX OK, no installation.
}
Path finalPath = installation;
try {
Comparator<Result> locComparator = new Comparator<Result>() {
@Override
public int compare(Result o1, Result o2) {
return o1.location.toString().compareTo(o2.location.toString());
}
};
UniverseVisitor visitor = new UniverseVisitor() {
@Override
public void visit(Producer<?> producer, FeaturePackLocation loc) {
try {
if (resolvedOnly && !producer.getChannel(loc.getChannelName()).isResolved(loc)) {
return;
}
} catch (ProvisioningException ex) {
exception(loc.getUniverse(), ex);
return;
}
if (tracker != null) {
tracker.processing(loc.getFPID());
}
// Universe could have been set in the pattern, matches on
// the canonical and exposed (named universe).
FeaturePackLocation exposedLoc = invoc.getPmSession().getExposedLocation(finalPath, loc);
boolean canonicalMatch = compiledPattern.matcher(loc.toString()).matches();
boolean exposedMatch = compiledPattern.matcher(exposedLoc.toString()).matches();
// If no frequency set, matches FPL that don't contain a frequency.
if (canonicalMatch || exposedMatch) {
if ((containsFrequency && loc.getFrequency() != null) || (!containsFrequency && loc.getFrequency() == null)) {
Result result;
if (exposedMatch) {
result = new Result(exposedLoc);
} else {
result = new Result(loc);
}
if (!layersCompiledPatterns.isEmpty()) {
try {
FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
ProvisioningConfig provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
Set<ConfigId> layers = new HashSet<>();
try (ProvisioningLayout<FeaturePackLayout> layout = invoc.getPmSession().getLayoutFactory().newConfigLayout(provisioning)) {
for (FeaturePackLayout l : layout.getOrderedFeaturePacks()) {
layers.addAll(l.loadLayers());
}
}
for (ConfigId l : layers) {
for (Pattern p : layersCompiledPatterns) {
if (p.matcher(l.getName()).matches()) {
result.layers.add(l);
}
}
}
if (!result.layers.isEmpty()) {
Set<Result> locations = results.get(loc.getUniverse());
if (locations == null) {
locations = new TreeSet<>(locComparator);
results.put(loc.getUniverse(), locations);
}
locations.add(result);
numResults[0] = numResults[0] + 1;
}
} catch (IOException | ProvisioningException ex) {
exception(loc.getUniverse(), ex);
}
} else {
Set<Result> locations = results.get(loc.getUniverse());
if (locations == null) {
locations = new TreeSet<>(locComparator);
results.put(loc.getUniverse(), locations);
}
locations.add(result);
numResults[0] = numResults[0] + 1;
}
}
}
}
@Override
public void exception(UniverseSpec spec, Exception ex) {
Set<String> set = exceptions.get(spec);
if (set == null) {
set = new HashSet<>();
exceptions.put(spec, set);
}
set.add(ex.getLocalizedMessage() == null ? ex.getMessage() : ex.getLocalizedMessage());
}
};
if (tracker != null) {
tracker.starting(-1);
}
if (fromUniverse == null) {
invoc.getPmSession().getUniverse().visitAllUniverses(visitor, true, finalPath);
} else {
invoc.getPmSession().getUniverse().visitUniverse(UniverseSpec.fromString(fromUniverse), visitor, true);
}
if (tracker != null) {
tracker.complete();
}
printExceptions(invoc, exceptions);
invoc.println(Config.getLineSeparator() + "Found " + numResults[0] + " feature pack location" + (numResults[0] > 1 ? "s." : "."));
for (Entry<UniverseSpec, Set<Result>> entry : results.entrySet()) {
for (Result loc : entry.getValue()) {
invoc.println(loc.toString());
}
}
} catch (ProvisioningException ex) {
throw new CommandExecutionException(ex.getLocalizedMessage());
}
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class GetChangesCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
try {
ProvisioningManager mgr = getManager(invoc.getPmSession());
FsDiff diff = mgr.getFsDiff();
if (diff.isEmpty()) {
invoc.println("No changes detected");
} else {
Path workingDir = Paths.get(invoc.getConfiguration().getAeshContext().getCurrentWorkingDirectory().getAbsolutePath());
Path installation = mgr.getInstallationHome();
PathResolver resolver = new PathResolver() {
@Override
public String resolve(String relativePath) {
Path absPath = Paths.get(installation.toString(), relativePath);
return workingDir.relativize(absPath).toString();
}
};
FsDiff.log(diff, new Consumer<String>() {
@Override
public void accept(String msg) {
invoc.println(msg);
}
}, resolver);
}
} catch (ProvisioningException ex) {
throw new CommandExecutionException(ex.getMessage());
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class InstallCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation session, Map<String, String> options, FeaturePackLocation loc) throws CommandExecutionException {
try {
String filePath = (String) getValue(FILE_OPTION_NAME);
final ProvisioningManager manager = getManager(session);
String layers = (String) getValue(LAYERS_OPTION_NAME);
if (filePath != null) {
Path p = Util.resolvePath(session.getConfiguration().getAeshContext(), filePath);
loc = session.getPmSession().getLayoutFactory().addLocal(p, true);
}
if (layers == null) {
String configurations = (String) getValue(DEFAULT_CONFIGS_OPTION_NAME);
if (configurations == null) {
manager.install(loc, options);
} else {
FeaturePackConfig.Builder fpConfig = FeaturePackConfig.builder(loc).setInheritConfigs(false);
for (ConfigId c : parseConfigurations(configurations)) {
fpConfig.includeDefaultConfig(c);
}
manager.install(fpConfig.build(), options);
}
} else {
if (!options.containsKey(Constants.OPTIONAL_PACKAGES)) {
options.put(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
}
String configuration = (String) getValue(CONFIG_OPTION_NAME);
String model = null;
String config = null;
if (configuration != null) {
List<ConfigId> configs = parseConfigurations(configuration);
if (configs.size() > 1) {
throw new CommandExecutionException(CliErrors.onlyOneConfigurationWithlayers());
}
if (!configs.isEmpty()) {
ConfigId id = configs.get(0);
model = id.getModel();
config = id.getName();
}
}
manager.provision(new LayersConfigBuilder(manager, pmSession, layers.split(",+"), model, config, loc).build(), options);
}
session.println("Feature pack installed.");
if (manager.isRecordState() && !loc.isMavenCoordinates()) {
if (!loc.hasBuild() || loc.getChannelName() == null) {
loc = manager.getProvisioningConfig().getFeaturePackDep(loc.getProducer()).getLocation();
}
StateInfoUtil.printFeaturePack(session, session.getPmSession().getExposedLocation(manager.getInstallationHome(), loc));
}
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(session.getPmSession(), CliErrors.installFailed(), ex);
}
}
Aggregations