Search in sources :

Example 1 with InstallPlugin

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;
}
Also used : Path(java.nio.file.Path) InstallPlugin(org.jboss.galleon.plugin.InstallPlugin) FeaturePackInstallException(org.jboss.galleon.util.FeaturePackInstallException) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 2 with InstallPlugin

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);
}
Also used : InstallPlugin(org.jboss.galleon.plugin.InstallPlugin) ProvisioningOption(org.jboss.galleon.ProvisioningOption) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ProvisioningException (org.jboss.galleon.ProvisioningException)2 InstallPlugin (org.jboss.galleon.plugin.InstallPlugin)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ProvisioningOption (org.jboss.galleon.ProvisioningOption)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1 FeaturePackInstallException (org.jboss.galleon.util.FeaturePackInstallException)1