Search in sources :

Example 86 with ProvisioningException

use of org.jboss.galleon.ProvisioningException 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)

Example 87 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ProvisioningLayout method getFeaturePackUpdate.

/**
 * Query for available version update and patches for the specific producer.
 *
 * @param producer  the producer to check the updates for
 * @return  available updates for the producer
 * @throws ProvisioningException  in case of a failure
 */
public FeaturePackUpdatePlan getFeaturePackUpdate(ProducerSpec producer) throws ProvisioningException {
    final F f = featurePacks.get(producer);
    if (f == null) {
        throw new ProvisioningException(Errors.unknownFeaturePack(producer.getLocation().getFPID()));
    }
    final FeaturePackLocation fpl = f.getFPID().getLocation();
    final Universe<?> universe = layoutFactory.getUniverseResolver().getUniverse(fpl.getUniverse());
    final Channel channel = universe.getProducer(fpl.getProducerName()).getChannel(fpl.getChannelName());
    final List<F> patches = fpPatches.get(fpl.getFPID());
    final Set<FPID> patchIds;
    if (patches == null || patches.isEmpty()) {
        patchIds = Collections.emptySet();
    } else if (patches.size() == 1) {
        patchIds = Collections.singleton(patches.get(0).getFPID());
    } else {
        final Set<FPID> tmp = new HashSet<>(patches.size());
        for (F p : patches) {
            tmp.add(p.getFPID());
        }
        patchIds = CollectionUtils.unmodifiable(tmp);
    }
    return channel.getUpdatePlan(FeaturePackUpdatePlan.request(fpl, patchIds, f.isTransitiveDep()));
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisioningException(org.jboss.galleon.ProvisioningException) Channel(org.jboss.galleon.universe.Channel) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation)

Example 88 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ProvisioningLayout method initBuiltInOptions.

private void initBuiltInOptions(ProvisioningConfig config, Map<String, String> extraOptions) throws ProvisioningException {
    String setValue = extraOptions.get(ProvisioningOption.VERSION_CONVERGENCE.getName());
    if (setValue == null && options.containsKey(ProvisioningOption.VERSION_CONVERGENCE.getName())) {
        setValue = ProvisioningOption.VERSION_CONVERGENCE.getDefaultValue();
    }
    if (setValue == null) {
        setValue = config.getOption(ProvisioningOption.VERSION_CONVERGENCE.getName());
        if (setValue == null && config.hasOption(ProvisioningOption.VERSION_CONVERGENCE.getName())) {
            setValue = ProvisioningOption.VERSION_CONVERGENCE.getDefaultValue();
        }
    }
    failOnConvergence = false;
    if (setValue != null) {
        if (Constants.FAIL.equals(setValue)) {
            failOnConvergence = true;
        } else if (!Constants.FIRST_PROCESSED.equals(setValue)) {
            throw new ProvisioningException(Errors.pluginOptionIllegalValue(ProvisioningOption.VERSION_CONVERGENCE.getName(), setValue, ProvisioningOption.VERSION_CONVERGENCE.getValueSet()));
        }
    }
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 89 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ProvisioningLayoutFactory method addLocal.

/**
 * Adds feature-pack archive to the local provisioning feature-pack cache.
 * Optionally, installs the feature-pack archive to the universe repository.
 *
 * @param featurePack  feature-pack archive
 * @param installInUniverse  whether to install the feature-pack into the universe repository
 * @return  feature-pack location which was added to the local cache
 * @throws ProvisioningException  in case of a failure
 */
public synchronized FeaturePackLocation addLocal(Path featurePack, boolean installInUniverse) throws ProvisioningException {
    final FPID fpid = FeaturePackDescriber.readSpec(featurePack).getFPID();
    put(featurePack, fpid);
    if (!installInUniverse) {
        return fpid.getLocation();
    }
    if (universeInstallers == null) {
        universeInstallers = UniverseFeaturePackInstaller.load();
    }
    final Universe<?> universe = universeResolver.getUniverse(fpid.getUniverse());
    final UniverseFeaturePackInstaller fpInstaller = universeInstallers.get(universe.getFactoryId());
    if (fpInstaller == null) {
        throw new ProvisioningException(Errors.featurePackInstallerNotFound(universe.getFactoryId(), universeInstallers.keySet()));
    }
    fpInstaller.install(universe, fpid, featurePack);
    return fpid.getLocation();
}
Also used : UniverseFeaturePackInstaller(org.jboss.galleon.universe.UniverseFeaturePackInstaller) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 90 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ProvisioningLayoutFactory method put.

private Path put(Path featurePack, FeaturePackLocation.FPID fpid) throws ProvisioningException {
    final FileSystem packFs;
    try {
        packFs = ZipUtils.newFileSystem(featurePack);
    } catch (IOException e) {
        throw new ProvisioningException(Errors.openFile(featurePack), e);
    }
    cachedPacks.put(fpid, packFs);
    return getFpDir(packFs);
}
Also used : FileSystem(java.nio.file.FileSystem) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Aggregations

ProvisioningException (org.jboss.galleon.ProvisioningException)101 IOException (java.io.IOException)45 Path (java.nio.file.Path)35 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)15 XMLStreamException (javax.xml.stream.XMLStreamException)13 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)10 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)10 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)9 ProvisioningManager (org.jboss.galleon.ProvisioningManager)9 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 ConfigId (org.jboss.galleon.config.ConfigId)8 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)8 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 BufferedWriter (java.io.BufferedWriter)6