use of org.jboss.galleon.config.ProvisioningConfig 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.config.ProvisioningConfig 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.config.ProvisioningConfig 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.config.ProvisioningConfig in project galleon by wildfly.
the class LayersConfigBuilder method build.
ProvisioningConfig build() throws ProvisioningException, IOException {
// Reuse existing configuration builder.
ProvisioningConfig existing = mgr.getProvisioningConfig();
ProvisioningConfig.Builder builder = null;
FeaturePackConfig.Builder fpBuilder = null;
ConfigModel.Builder configBuilder = null;
if (existing != null) {
builder = ProvisioningConfig.builder(existing);
ConfigId id = new ConfigId(model, config);
if (existing.hasDefinedConfig(id)) {
ConfigModel cmodel = existing.getDefinedConfig(id);
configBuilder = ConfigModel.builder(cmodel);
handleLayers(configBuilder, cmodel);
builder.removeConfig(id);
}
if (builder.hasFeaturePackDep(loc.getProducer())) {
FeaturePackConfig fp = existing.getFeaturePackDep(loc.getProducer());
fpBuilder = FeaturePackConfig.builder(fp);
builder.removeFeaturePackDep(fp.getLocation());
}
}
if (builder == null) {
builder = ProvisioningConfig.builder();
}
if (configBuilder == null) {
configBuilder = ConfigModel.builder(model, config);
handleLayers(configBuilder, null);
}
if (fpBuilder == null) {
fpBuilder = FeaturePackConfig.builder(loc).setInheritConfigs(false).setInheritPackages(false);
}
builder.addConfig(configBuilder.build());
builder.addFeaturePackDep(fpBuilder.build());
return builder.build();
}
use of org.jboss.galleon.config.ProvisioningConfig in project galleon by wildfly.
the class ProvisionCommand method getDynamicOptions.
@Override
protected List<DynamicOption> getDynamicOptions(State state) throws Exception {
List<DynamicOption> options = new ArrayList<>();
Set<ProvisioningOption> opts;
String file = getFile();
if (file == null) {
return Collections.emptyList();
}
ProvisioningConfig config = ProvisioningXmlParser.parse(getAbsolutePath(file, pmSession.getAeshContext()));
opts = pmSession.getResolver().get(null, PluginResolver.newResolver(pmSession, config)).getInstall();
for (ProvisioningOption opt : opts) {
DynamicOption dynOption = new DynamicOption(opt.getName(), opt.isRequired());
options.add(dynOption);
}
return options;
}
Aggregations