Search in sources :

Example 76 with ProvisioningException

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

the class FeaturePackInstaller method install.

public void install() {
    try (ProvisioningManager manager = ProvisioningManager.builder().addArtifactResolver(LegacyGalleon1RepositoryManager.newInstance(repoHome)).setInstallationHome(installationDir).setRecordState(recordState).build()) {
        System.setProperty("org.wildfly.logging.skipLogManagerCheck", "true");
        ConfigModel config = null;
        if (customConfig != null && Files.exists(customConfig)) {
            try (BufferedReader reader = Files.newBufferedReader(customConfig)) {
                config = ConfigXmlParser.getInstance().parse(reader);
            } catch (XMLStreamException | IOException ex) {
                throw new IllegalArgumentException("Couldn't load the customization configuration " + customConfig, ex);
            }
        }
        if (localPath != null) {
            fpl = manager.getLayoutFactory().addLocal(localPath, false);
        }
        FeaturePackConfig.Builder fpConfigBuilder = FeaturePackConfig.builder(fpl).setInheritPackages(inheritPackages).setInheritConfigs(inheritConfigs);
        if (includedConfigs != null && !includedConfigs.isEmpty()) {
            for (ConfigurationId configId : includedConfigs) {
                if (configId.isModelOnly()) {
                    fpConfigBuilder.includeConfigModel(configId.getId().getModel());
                } else {
                    fpConfigBuilder.includeDefaultConfig(configId.getId());
                }
            }
        }
        if (config != null) {
            fpConfigBuilder.addConfig(config);
        }
        if (includedPackages != null && !includedPackages.isEmpty()) {
            for (String includedPackage : includedPackages) {
                fpConfigBuilder.includePackage(includedPackage);
            }
        }
        if (excludedPackages != null && !excludedPackages.isEmpty()) {
            for (String excludedPackage : excludedPackages) {
                fpConfigBuilder.excludePackage(excludedPackage);
            }
        }
        manager.install(fpConfigBuilder.build(), pluginOptions);
    } catch (ProvisioningException ex) {
        throw new IllegalArgumentException("Couldn't install feature-pack " + fpl, ex);
    } finally {
        System.clearProperty("org.wildfly.logging.skipLogManagerCheck");
    }
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) ConfigModel(org.jboss.galleon.config.ConfigModel) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 77 with ProvisioningException

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

the class FeaturePackRuntimeBuilder method getFeatureGroupSpec.

FeatureGroup getFeatureGroupSpec(String name) throws ProvisioningException {
    if (fgSpecs != null) {
        final FeatureGroup fgSpec = fgSpecs.get(name);
        if (fgSpec != null) {
            return fgSpec;
        }
    }
    final Path specXml = dir.resolve(Constants.FEATURE_GROUPS).resolve(name + ".xml");
    if (!Files.exists(specXml)) {
        return null;
    }
    try (BufferedReader reader = Files.newBufferedReader(specXml)) {
        final FeatureGroup fgSpec = FeatureGroupXmlParser.getInstance().parse(reader);
        if (!fgSpec.getName().equals(name)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " feature group " + fgSpec.getName() + " does not match the requested feature group name " + name);
        }
        if (fgSpecs == null) {
            fgSpecs = new HashMap<>();
        }
        fgSpecs.put(name, fgSpec);
        return fgSpec;
    } catch (Exception e) {
        throw new ProvisioningException(Errors.parseXml(specXml), e);
    }
}
Also used : Path(java.nio.file.Path) FeatureGroup(org.jboss.galleon.config.FeatureGroup) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 78 with ProvisioningException

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

the class FeaturePackRuntimeBuilder method resolvePackage.

boolean resolvePackage(String pkgName, ProvisioningRuntimeBuilder rt, PackageRuntime.Builder parent, int type) throws ProvisioningException {
    PackageRuntime.Builder pkgBuilder = pkgBuilders.get(pkgName);
    if (pkgBuilder == null) {
        final Path pkgDir = LayoutUtils.getPackageDir(dir, pkgName, false);
        if (!Files.exists(pkgDir)) {
            return false;
        }
        final Path pkgXml = pkgDir.resolve(Constants.PACKAGE_XML);
        if (!Files.exists(pkgXml)) {
            throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(pkgXml));
        }
        try (BufferedReader reader = Files.newBufferedReader(pkgXml)) {
            pkgBuilder = PackageRuntime.builder(this, PackageXmlParser.getInstance().parse(reader), pkgDir, ++rt.pkgsTotal);
        } catch (IOException | XMLStreamException e) {
            throw new ProvisioningException(Errors.parseXml(pkgXml), e);
        }
        if (!pkgBuilder.spec.getName().equals(pkgName)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " package spec name " + pkgBuilder.spec.getName() + " does not match the requested package name " + pkgName);
        }
        pkgBuilders = CollectionUtils.put(pkgBuilders, pkgName, pkgBuilder);
    }
    pkgBuilder.referencedAs(type);
    if (parent == null) {
        pkgBuilder.setFlag(PackageRuntime.ROOT);
        if (type == PackageDependencySpec.REQUIRED) {
            pkgBuilder.include();
        }
    } else if (!parent.isFlagOn(PackageRuntime.SCHEDULED)) {
        parent.addPackageDep(pkgBuilder, type, rt.includedPkgDeps);
    }
    if (!rt.addToPkgDepBranch(pkgBuilder)) {
        // to avoid stack overflow processing circular dependencies
        return true;
    }
    if (pkgBuilder.spec.hasPackageDeps()) {
        final FeaturePackRuntimeBuilder currentOrigin = rt.setOrigin(this);
        try {
            rt.processPackageDeps(pkgBuilder.spec, pkgBuilder);
        } catch (UnsatisfiedPackageDependencyException e) {
            throw new UnsatisfiedPackageDependencyException(getFPID(), pkgName, e);
        } catch (ProvisioningException e) {
            throw new ProvisioningException(Errors.resolvePackage(getFPID(), pkgName), e);
        } finally {
            rt.setOrigin(currentOrigin);
        }
    }
    return true;
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 79 with ProvisioningException

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

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

the class ProvisioningRuntimeBuilder method includeLayer.

private void includeLayer(ConfigModelStack configStack, ConfigId layerId) throws ProvisioningException {
    if (!configStack.addLayer(layerId)) {
        return;
    }
    final ConfigModelStack layerStack = resolveConfigLayer(layerId);
    if (layerStack.hasLayerDeps()) {
        for (ConfigLayerDependency layerDep : layerStack.getLayerDeps()) {
            if (configStack.isLayerExcluded(layerDep.getName())) {
                if (layerDep.isOptional()) {
                    continue;
                }
                throw new ProvisioningException(Errors.unsatisfiedLayerDependency(layerId.getName(), layerDep.getName()));
            }
            includeLayer(configStack, new ConfigId(configStack.id.getModel(), layerDep.getName()));
        }
    }
    configStack.includedLayer(layerId);
    for (ResolvedFeature feature : layerStack.orderFeatures(false)) {
        if (configStack.isFilteredOut(feature.getSpecId(), feature.getId())) {
            continue;
        }
        configStack.includeFeature(feature.id, feature.spec, feature.params, feature.deps, feature.unsetParams, feature.resetParams);
    }
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigLayerDependency(org.jboss.galleon.spec.ConfigLayerDependency) ConfigId(org.jboss.galleon.config.ConfigId)

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