Search in sources :

Example 26 with ProvisioningException

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

the class SpecOnlyConfigArranger method orderCapabilityProviders.

private List<CircularRefInfo> orderCapabilityProviders(ResolvedFeature feature, List<CircularRefInfo> circularRefs) throws ProvisioningException {
    for (CapabilitySpec capSpec : feature.spec.xmlSpec.getRequiredCapabilities()) {
        final List<String> resolvedCaps = capResolver.resolve(capSpec, feature);
        if (resolvedCaps.isEmpty()) {
            continue;
        }
        for (String resolvedCap : resolvedCaps) {
            final CapabilityProviders providers;
            try {
                providers = getProviders(resolvedCap, false);
            } catch (ProvisioningException e) {
                throw new ProvisioningException(Errors.noCapabilityProvider(feature, capSpec, resolvedCap));
            }
            final List<CircularRefInfo> circles = orderProviders(providers);
            if (circularRefs == null) {
                circularRefs = circles;
            } else {
                if (circularRefs.size() == 1) {
                    final CircularRefInfo first = circularRefs.get(0);
                    circularRefs = new ArrayList<>(1 + circles.size());
                    circularRefs.add(first);
                }
                circularRefs.addAll(circles);
            }
        }
    }
    return circularRefs;
}
Also used : CapabilitySpec(org.jboss.galleon.spec.CapabilitySpec) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 27 with ProvisioningException

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

the class FeaturePackBuilder method build.

void build() throws ProvisioningException {
    final FeaturePackLocation fps = fpBuilder.getFPID().getLocation();
    if (fps == null) {
        throw new ProvisioningDescriptionException("Feature-pack location has not been set");
    }
    if (fps.getProducerName() == null) {
        throw new ProvisioningDescriptionException("Feature-pack producer has not been set");
    }
    /*
        if(fps.getChannelName() == null) {
            throw new ProvisioningDescriptionException("Feature-pack channel has not been set");
        }
        */
    if (fps.getBuild() == null) {
        throw new ProvisioningDescriptionException("Feature-pack build number has not been set");
    }
    final Path fpWorkDir = LayoutUtils.getFeaturePackDir(creator.getWorkDir(), fps.getFPID(), false);
    final FeaturePackSpec fpSpec;
    try {
        ensureDir(fpWorkDir);
        for (PackageBuilder pkg : pkgs) {
            final PackageSpec pkgDescr = pkg.build(fpWorkDir);
            if (pkg.isDefault()) {
                fpBuilder.addDefaultPackage(pkgDescr.getName());
            }
        }
        if (!specs.isEmpty()) {
            final Path featuresDir = fpWorkDir.resolve(Constants.FEATURES);
            final FeatureSpecXmlWriter specWriter = FeatureSpecXmlWriter.getInstance();
            for (FeatureSpec spec : specs.values()) {
                final Path featureDir = featuresDir.resolve(spec.getName());
                ensureDir(featureDir);
                specWriter.write(spec, featureDir.resolve(Constants.SPEC_XML));
            }
        }
        if (!featureGroups.isEmpty()) {
            final Path fgsDir = fpWorkDir.resolve(Constants.FEATURE_GROUPS);
            ensureDir(fgsDir);
            final FeatureGroupXmlWriter fgWriter = FeatureGroupXmlWriter.getInstance();
            for (FeatureGroup fg : featureGroups.values()) {
                fgWriter.write(fg, fgsDir.resolve(fg.getName() + ".xml"));
            }
        }
        if (!classes.isEmpty()) {
            createPluginJar(classes, services, fpWorkDir.resolve(Constants.PLUGINS).resolve(pluginFileName));
        }
        if (!plugins.isEmpty()) {
            final Path pluginsDir = fpWorkDir.resolve(Constants.PLUGINS);
            ensureDir(pluginsDir);
            for (Path plugin : plugins) {
                Files.copy(plugin, pluginsDir.resolve(plugin.getFileName()));
            }
        }
        if (!layers.isEmpty()) {
            for (Map.Entry<ConfigId, ConfigLayerSpec> entry : layers.entrySet()) {
                final ConfigId id = entry.getKey();
                final Path xml = LayoutUtils.getLayerSpecXml(fpWorkDir, id.getModel(), id.getName(), false);
                if (Files.exists(xml)) {
                    throw new ProvisioningException("Failed to create feature-pack: " + xml + " already exists");
                }
                ConfigLayerXmlWriter.getInstance().write(entry.getValue(), xml);
            }
        }
        if (!configs.isEmpty()) {
            for (ConfigModel config : configs.values()) {
                final Path modelXml = LayoutUtils.getConfigXml(fpWorkDir, config.getId(), false);
                if (Files.exists(modelXml)) {
                    throw new ProvisioningException("Failed to create feature-pack: " + modelXml + " already exists");
                }
                ConfigXmlWriter.getInstance().write(config, modelXml);
            }
        }
        fpSpec = fpBuilder.build();
        final FeaturePackXmlWriter writer = FeaturePackXmlWriter.getInstance();
        writer.write(fpSpec, fpWorkDir.resolve(Constants.FEATURE_PACK_XML));
        if (tasks != null && !tasks.isEmpty()) {
            tasks.execute(FsTaskContext.builder().setTargetRoot(fpWorkDir.resolve(Constants.RESOURCES)).build());
        }
        creator.install(fps.getFPID(), fpWorkDir);
    } catch (ProvisioningDescriptionException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    } finally {
        IoUtils.recursiveDelete(fpWorkDir);
    }
}
Also used : Path(java.nio.file.Path) FeatureSpec(org.jboss.galleon.spec.FeatureSpec) FeatureGroup(org.jboss.galleon.config.FeatureGroup) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) FeaturePackXmlWriter(org.jboss.galleon.xml.FeaturePackXmlWriter) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigModel(org.jboss.galleon.config.ConfigModel) PackageSpec(org.jboss.galleon.spec.PackageSpec) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeatureSpecXmlWriter(org.jboss.galleon.xml.FeatureSpecXmlWriter) ConfigId(org.jboss.galleon.config.ConfigId) FeatureGroupXmlWriter(org.jboss.galleon.xml.FeatureGroupXmlWriter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with ProvisioningException

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

the class FeaturePackCreator method install.

void install(FeaturePackLocation.FPID fpid, Path fpContentDir) throws ProvisioningException {
    Universe<?> universe = null;
    UniverseFeaturePackInstaller ufpInstaller = null;
    if (universeResolution) {
        universe = universeResolver.getUniverse(fpid.getLocation().getUniverse());
        ufpInstaller = ufpInstallers.get(universe.getFactoryId());
        if (ufpInstaller == null) {
            throw new ProvisioningException(Errors.featurePackInstallerNotFound(universe.getFactoryId(), ufpInstallers.keySet()));
        }
    }
    final Path fpZip = getBuildDir().resolve(LayoutUtils.ensureValidFileName(fpid.toString()));
    try {
        ZipUtils.zip(fpContentDir, fpZip);
    } catch (IOException e) {
        throw new ProvisioningException("Failed to create feature-pack archive", e);
    }
    if (ufpInstaller != null) {
        ufpInstaller.install(universe, fpid, fpZip);
    }
}
Also used : Path(java.nio.file.Path) UniverseFeaturePackInstaller(org.jboss.galleon.universe.UniverseFeaturePackInstaller) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 29 with ProvisioningException

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

the class FeaturePackRuntimeBuilder method getFeatureSpec.

public ResolvedFeatureSpec getFeatureSpec(String name) throws ProvisioningException {
    if (featureSpecs != null) {
        final ResolvedFeatureSpec resolvedSpec = featureSpecs.get(name);
        if (resolvedSpec != null) {
            return resolvedSpec;
        }
    }
    final Path specXml = dir.resolve(Constants.FEATURES).resolve(name).resolve(Constants.SPEC_XML);
    if (!Files.exists(specXml)) {
        return null;
    }
    try (BufferedReader reader = Files.newBufferedReader(specXml)) {
        final FeatureSpec xmlSpec = FeatureSpecXmlParser.getInstance().parse(reader);
        if (!xmlSpec.getName().equals(name)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " feature spec " + xmlSpec.getName() + " does not match the requested feature spec name " + name);
        }
        final ResolvedFeatureSpec resolvedSpec = new ResolvedFeatureSpec(new ResolvedSpecId(producer, xmlSpec.getName()), featureParamTypeProvider, xmlSpec);
        if (featureSpecs == null) {
            featureSpecs = new HashMap<>();
        }
        featureSpecs.put(name, resolvedSpec);
        return resolvedSpec;
    } catch (Exception e) {
        throw new ProvisioningDescriptionException(Errors.parseXml(specXml), e);
    }
}
Also used : Path(java.nio.file.Path) FeatureSpec(org.jboss.galleon.spec.FeatureSpec) 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 30 with ProvisioningException

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

the class FeaturePackRuntimeBuilder method getConfig.

ConfigModel getConfig(ConfigId configId) throws ProvisioningException {
    if (configs != null) {
        final ConfigModel config = configs.get(configId);
        if (config != null) {
            return config;
        }
    }
    final Path p = LayoutUtils.getConfigXml(dir, configId, false);
    if (!Files.exists(p)) {
        return null;
    }
    try (BufferedReader reader = Files.newBufferedReader(p)) {
        final ConfigModel config = ConfigXmlParser.getInstance().parse(reader);
        if (configs == null) {
            configs = new HashMap<>();
        }
        configs.put(config.getId(), config);
        return config;
    } catch (Exception e) {
        throw new ProvisioningException(Errors.parseXml(p), e);
    }
}
Also used : Path(java.nio.file.Path) ConfigModel(org.jboss.galleon.config.ConfigModel) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

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