use of org.jboss.galleon.universe.FeaturePackLocation in project wildfly-maven-plugin by wildfly.
the class GalleonUtils method buildDefaultConfig.
/**
* Build a default WildFly provisioning config.
*
* @param version WildFly version, if null latest is used.
* @return
* @throws ProvisioningDescriptionException
*/
public static ProvisioningConfig buildDefaultConfig(String version) throws ProvisioningDescriptionException {
String location = getWildFlyFeaturePackLocation(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());
Map<String, String> options = new HashMap<>();
options.put(FORK_EMBEDDED_PROCESS_OPTION, "true");
state.addOptions(options);
return state.build();
}
use of org.jboss.galleon.universe.FeaturePackLocation 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.universe.FeaturePackLocation 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.universe.FeaturePackLocation in project galleon by wildfly.
the class FPLocationCompleter method doComplete.
private void doComplete(PmCompleterInvocation completerInvocation) throws ProvisioningException {
// Legacy completer first
PmSession pmSession = completerInvocation.getPmSession();
UniverseManager resolver = pmSession.getUniverse();
installation = completerInvocation.getCommand() instanceof CommandWithInstallationDirectory ? ((CommandWithInstallationDirectory) completerInvocation.getCommand()).getInstallationDirectory(completerInvocation.getAeshContext()) : null;
UniverseSpec defaultUniverse = pmSession.getUniverse().getDefaultUniverseSpec(installation);
Set<String> aliases = pmSession.getUniverse().getUniverseNames(installation);
// producer[@universe]:channel/frequency#build
// producer[@factory-id/location]:channel/frequency#build
String buffer = completerInvocation.getGivenCompleteValue();
List<String> candidates = new ArrayList<>();
FPLocationParser.ParsedFPLocation loc = null;
try {
if (buffer.isEmpty()) {
if (defaultUniverse != null) {
getAllProducers(null, defaultUniverse, resolver.getUniverse(defaultUniverse), candidates);
}
for (String name : aliases) {
UniverseSpec u = pmSession.getUniverse().getUniverseSpec(installation, name);
if (u.getFactory().equals(LegacyGalleon1UniverseFactory.ID)) {
continue;
}
if (!u.equals(defaultUniverse)) {
getAllProducers(u.toString(), u, resolver.getUniverse(u), candidates);
}
}
} else {
loc = FPLocationParser.parse(buffer, new FPLocationParser.FPLocationCompletionConsumer() {
@Override
public void completeProducer(String producer) throws FPLocationParserException, ProvisioningException {
// Lookup in all universes for a producer, we don't know the universe yet
if (defaultUniverse != null) {
getProducers(producer, null, resolver.getUniverse(defaultUniverse), candidates);
}
for (String name : aliases) {
UniverseSpec u = pmSession.getUniverse().getUniverseSpec(installation, name);
if (!u.equals(defaultUniverse)) {
getProducers(producer, name, resolver.getUniverse(u), candidates);
}
}
}
@Override
public void completeUniverse(FPLocationParser.ParsedFPLocation parsedLocation, String universe) throws FPLocationParserException, ProvisioningException {
for (String name : aliases) {
UniverseSpec spec = pmSession.getUniverse().getUniverseSpec(installation, name);
if (spec != null && resolver.getUniverse(spec).hasProducer(parsedLocation.getProducer())) {
if (name.equals(universe)) {
candidates.add(name + FeaturePackLocation.CHANNEL_START);
} else if (name.startsWith(universe)) {
candidates.add(name);
}
}
}
}
@Override
public void completeUniverseLocation(FPLocationParser.ParsedFPLocation parsedLocation, String universeLocation) throws FPLocationParserException, ProvisioningException {
for (String name : aliases) {
UniverseSpec spec = pmSession.getUniverse().getUniverseSpec(installation, name);
if (spec == null || spec.getFactory().equals(LegacyGalleon1UniverseFactory.ID)) {
continue;
}
if (!candidates.contains(spec.getLocation())) {
if (spec.getFactory().equals(parsedLocation.getUniverseFactory()) && resolver.getUniverse(spec).hasProducer(parsedLocation.getProducer())) {
if (spec.getLocation().equals(universeLocation)) {
candidates.add(spec.getLocation() + FeaturePackLocation.UNIVERSE_LOCATION_END);
} else if (spec.getLocation().startsWith(universeLocation)) {
candidates.add(spec.getLocation());
}
break;
}
}
}
}
@Override
public void completeChannel(FPLocationParser.ParsedFPLocation parsedLocation, String channel) throws FPLocationParserException, ProvisioningException {
Producer<?> p = getProducer(parsedLocation, pmSession);
if (p == null) {
return;
}
for (Channel c : p.getChannels()) {
if (c.getName().equals(channel)) {
// Do nothing, do not inline separators. Separators are to be added explicitly
// this could be revisited.
candidates.add(channel);
} else if (c.getName().startsWith(channel)) {
candidates.add(c.getName());
}
}
}
@Override
public void completeFrequency(FPLocationParser.ParsedFPLocation parsedLocation, String frequency) throws FPLocationParserException, ProvisioningException {
Producer<?> p = getProducer(parsedLocation, pmSession);
if (p == null) {
return;
}
for (String freq : p.getFrequencies()) {
if (freq.equals(frequency)) {
// Do not inline the build separator, separator is to be added explicitly
// this could be revisited.
candidates.add(freq);
} else if (freq.startsWith(frequency)) {
candidates.add(freq);
}
}
}
@Override
public void completeChannelSeparator(FPLocationParser.ParsedFPLocation parsedLocation) throws FPLocationParserException, ProvisioningException {
candidates.add("" + FeaturePackLocation.CHANNEL_START);
}
@Override
public void completeBuild(FPLocationParser.ParsedFPLocation parsedLocation, String build) throws FPLocationParserException, ProvisioningException {
UniverseSpec spec = null;
if (parsedLocation.getUniverseName() != null) {
spec = pmSession.getUniverse().getUniverseSpec(installation, parsedLocation.getUniverseName());
} else if (parsedLocation.getUniverseFactory() == null) {
spec = pmSession.getUniverse().getDefaultUniverseSpec(installation);
} else {
spec = new UniverseSpec(parsedLocation.getUniverseFactory(), parsedLocation.getUniverseLocation());
}
if (spec != null) {
String latestBuild = null;
// FPID
if (parsedLocation.getFrequency() == null) {
FeaturePackLocation.FPID id = new FeaturePackLocation(spec, parsedLocation.getProducer(), parsedLocation.getChannel(), null, null).getFPID();
latestBuild = pmSession.getUniverse().getUniverse(spec).getProducer(parsedLocation.getProducer()).getChannel(parsedLocation.getChannel()).getLatestBuild(id);
} else {
FeaturePackLocation loc = new FeaturePackLocation(spec, parsedLocation.getProducer(), parsedLocation.getChannel(), parsedLocation.getFrequency(), null);
latestBuild = pmSession.getUniverse().getUniverse(spec).getProducer(parsedLocation.getProducer()).getChannel(parsedLocation.getChannel()).getLatestBuild(loc);
}
if (latestBuild != null) {
if (latestBuild.startsWith(build)) {
candidates.add(latestBuild);
}
}
}
}
});
}
} catch (Exception ex) {
CliLogging.completionException(ex);
return;
}
completerInvocation.addAllCompleterValues(candidates);
if (candidates.size() == 1) {
if (completerInvocation.getGivenCompleteValue().endsWith(candidates.get(0))) {
completerInvocation.setAppendSpace(true);
} else {
completerInvocation.setAppendSpace(false);
}
completerInvocation.setOffset(completerInvocation.getGivenCompleteValue().length() - (loc == null ? 0 : (loc.getMarker() + 1)));
}
}
use of org.jboss.galleon.universe.FeaturePackLocation in project galleon by wildfly.
the class PmSession method getExposedLocation.
public FeaturePackLocation getExposedLocation(Path installation, FeaturePackLocation fplocation) {
// Expose the default or name.
UniverseSpec spec = fplocation.getUniverse();
boolean rewrite = false;
String name = getUniverse().getUniverseName(installation, spec);
if (name != null) {
rewrite = true;
spec = new UniverseSpec(name, null);
} else if (getUniverse().getDefaultUniverseSpec(installation).equals(spec)) {
rewrite = true;
spec = null;
}
if (rewrite) {
fplocation = new FeaturePackLocation(spec, fplocation.getProducerName(), fplocation.getChannelName(), fplocation.getFrequency(), fplocation.getBuild());
}
return fplocation;
}
Aggregations