use of org.jboss.galleon.plugin.InstallPlugin in project galleon by wildfly.
the class ProvisioningRuntime method provision.
public void provision() throws ProvisioningException {
layout.visitPlugins(new FeaturePackPluginVisitor<InstallPlugin>() {
@Override
public void visitPlugin(InstallPlugin plugin) throws ProvisioningException {
plugin.preInstall(ProvisioningRuntime.this);
}
}, InstallPlugin.class);
// copy package content
for (FeaturePackRuntime fp : layout.getOrderedFeaturePacks()) {
messageWriter.verbose("Installing %s", fp.getFPID());
for (PackageRuntime pkg : fp.getPackages()) {
final Path pkgSrcDir = pkg.getContentDir();
if (Files.exists(pkgSrcDir)) {
try {
IoUtils.copy(pkgSrcDir, stagedDir);
} catch (IOException e) {
throw new FeaturePackInstallException(Errors.packageContentCopyFailed(pkg.getName()), e);
}
}
}
}
layout.visitPlugins(new FeaturePackPluginVisitor<InstallPlugin>() {
@Override
public void visitPlugin(InstallPlugin plugin) throws ProvisioningException {
plugin.postInstall(ProvisioningRuntime.this);
}
}, InstallPlugin.class);
if (recordState) {
// save the config
try {
ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir));
} catch (XMLStreamException | IOException e) {
throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e);
}
// save the provisioned state
try {
ProvisionedStateXmlWriter.getInstance().write(this, PathsUtils.getProvisionedStateXml(stagedDir));
} catch (XMLStreamException | IOException e) {
throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisionedStateXml(stagedDir)), e);
}
}
emptyStagedDir = null;
}
use of org.jboss.galleon.plugin.InstallPlugin in project galleon by wildfly.
the class ProvisioningLayout method initPluginOptions.
private void initPluginOptions(Map<String, String> extraOptions, boolean cleanupConfigOptions) throws ProvisioningException {
options = config.getOptions();
if (!extraOptions.isEmpty()) {
options = CollectionUtils.putAll(CollectionUtils.clone(options), extraOptions);
}
final Map<String, ProvisioningOption> recognizedOptions;
final List<ProvisioningOption> overridenOptions;
if (options.isEmpty()) {
recognizedOptions = Collections.emptyMap();
overridenOptions = Collections.emptyList();
} else {
final int size = options.size();
recognizedOptions = new HashMap<>(size);
overridenOptions = new ArrayList<>(size);
}
// process built-in options
processOptions(ProvisioningOption.getStandardList(), extraOptions, recognizedOptions, overridenOptions);
// process plugin options
handle.visitPlugins(new FeaturePackPluginVisitor<InstallPlugin>() {
@Override
public void visitPlugin(InstallPlugin plugin) throws ProvisioningException {
processOptions(plugin.getOptions().values(), extraOptions, recognizedOptions, overridenOptions);
}
}, InstallPlugin.class);
ProvisioningConfig.Builder configBuilder = null;
if (recognizedOptions.size() != options.size()) {
final Set<String> nonRecognized = new HashSet<>(options.keySet());
nonRecognized.removeAll(recognizedOptions.keySet());
if (cleanupConfigOptions) {
final Iterator<String> i = nonRecognized.iterator();
while (i.hasNext()) {
final String optionName = i.next();
if (!config.hasOption(optionName)) {
continue;
}
if (configBuilder == null) {
configBuilder = ProvisioningConfig.builder(config);
}
configBuilder.removeOption(optionName);
i.remove();
}
}
if (!nonRecognized.isEmpty()) {
throw new ProvisioningException(Errors.pluginOptionsNotRecognized(nonRecognized));
}
}
if (!overridenOptions.isEmpty()) {
if (configBuilder == null) {
configBuilder = ProvisioningConfig.builder(config);
}
for (ProvisioningOption option : overridenOptions) {
final String optionName = option.getName();
if (!extraOptions.containsKey(optionName)) {
continue;
}
final String value = extraOptions.get(optionName);
if (option.isPersistent()) {
configBuilder.addOption(optionName, value);
} else if (value == null) {
if (config.getOption(optionName) != null) {
configBuilder.removeOption(optionName);
}
} else if (!value.equals(config.getOption(optionName))) {
configBuilder.removeOption(optionName);
}
}
config = configBuilder.build();
} else if (configBuilder != null) {
config = configBuilder.build();
}
options = CollectionUtils.unmodifiable(options);
}
Aggregations