Search in sources :

Example 6 with ProvisioningDescriptionException

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

the class ProvisioningLayoutFactory method resolveFeaturePack.

public <F extends FeaturePackLayout> F resolveFeaturePack(FeaturePackLocation location, int type, FeaturePackLayoutFactory<F> factory) throws ProvisioningException {
    final Path fpDir = resolveFeaturePackDir(location);
    final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML);
    if (!Files.exists(fpXml)) {
        throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml));
    }
    try (BufferedReader reader = Files.newBufferedReader(fpXml)) {
        final FeaturePackSpec fpSpec = FeaturePackXmlParser.getInstance().parse(reader);
        if (location.isMavenCoordinates()) {
            final FPID specId = fpSpec.getFPID();
            final FeaturePackLocation fpl = new FeaturePackLocation(specId.getUniverse(), specId.getProducer().getName(), specId.getChannel().getName(), location.getFrequency(), specId.getBuild());
            synchronized (this) {
                cachedPacks.put(fpl.getFPID(), cachedPacks.get(location.getFPID()));
            }
            location = fpl;
        }
        return factory.newFeaturePack(location, fpSpec, fpDir, type);
    } catch (IOException | XMLStreamException e) {
        throw new ProvisioningException(Errors.parseXml(fpXml), e);
    }
}
Also used : Path(java.nio.file.Path) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 7 with ProvisioningDescriptionException

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

the class ProvisioningPlan method update.

public ProvisioningPlan update(FeaturePackUpdatePlan fpPlan) throws ProvisioningDescriptionException {
    final ProducerSpec producer = fpPlan.getInstalledLocation().getProducer();
    if (install.containsKey(producer) || uninstall.contains(producer)) {
        throw new ProvisioningDescriptionException(producer + " has already been added to the plan");
    }
    updates = CollectionUtils.putLinked(updates, producer, fpPlan);
    return this;
}
Also used : ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 8 with ProvisioningDescriptionException

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

the class FeaturePackDescriber method describeFeaturePack.

public static FeaturePackDescription describeFeaturePack(Path fpDir, String encoding) throws ProvisioningDescriptionException {
    assertDirectory(fpDir);
    final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML);
    if (!Files.exists(fpXml)) {
        throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml));
    }
    final FeaturePackDescription.Builder layoutBuilder;
    try (Reader is = Files.newBufferedReader(fpXml, Charset.forName(encoding))) {
        final FeaturePackSpec.Builder specBuilder = FeaturePackSpec.builder();
        XmlParsers.parse(is, specBuilder);
        layoutBuilder = FeaturePackDescription.builder(specBuilder);
    } catch (IOException e) {
        throw new ProvisioningDescriptionException(Errors.openFile(fpXml));
    } catch (XMLStreamException e) {
        throw new ProvisioningDescriptionException(Errors.parseXml(fpXml), e);
    }
    final Path packagesDir = fpDir.resolve(Constants.PACKAGES);
    if (Files.exists(packagesDir)) {
        processPackages(layoutBuilder, packagesDir, encoding);
    }
    return layoutBuilder.build();
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 9 with ProvisioningDescriptionException

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

the class ProvisioningLayout method loadPatch.

private void loadPatch(FPID patchId) throws ProvisioningException {
    final F patchFp = layoutFactory.resolveFeaturePack(patchId.getLocation(), FeaturePackLayout.PATCH, fpFactory);
    final FeaturePackSpec spec = patchFp.getSpec();
    if (!spec.isPatch()) {
        throw new ProvisioningDescriptionException(patchId + " is not a patch but listed as one");
    }
    allPatches = CollectionUtils.put(allPatches, patchId, patchFp);
    if (spec.hasFeaturePackDeps()) {
        for (FeaturePackConfig patchDep : spec.getFeaturePackDeps()) {
            final FPID patchDepId = patchDep.getLocation().getFPID();
            if (allPatches.containsKey(patchDepId)) {
                continue;
            }
            loadPatch(patchDepId);
        }
    }
    final FPID patchFor = spec.getPatchFor();
    List<F> patchList = fpPatches.get(patchFor);
    if (patchList == null) {
        fpPatches = CollectionUtils.put(fpPatches, patchFor, Collections.singletonList(patchFp));
    } else if (patchList.size() == 1) {
        final List<F> tmp = new ArrayList<>(2);
        tmp.add(patchList.get(0));
        tmp.add(patchFp);
        fpPatches = CollectionUtils.put(fpPatches, patchFor, tmp);
    } else {
        patchList.add(patchFp);
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) ArrayList(java.util.ArrayList) List(java.util.List) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 10 with ProvisioningDescriptionException

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

the class ResolvedFeatureId method fromString.

public static ResolvedFeatureId fromString(String str) throws ProvisioningDescriptionException {
    final int length = str.length();
    if (length == 0) {
        formatException(str);
    }
    if (str.charAt(0) != '{') {
        formatException(str);
    }
    int i = str.indexOf('}', 1);
    if (i < 0) {
        formatException(str);
    }
    final int colon = str.indexOf(':', i + 1);
    if (colon - i < 2) {
        formatException(str);
    }
    ResolvedSpecId specId = null;
    try {
        specId = new ResolvedSpecId(FeaturePackLocation.fromString(str.substring(1, i)).getProducer(), str.substring(i + 1, colon));
    } catch (IllegalArgumentException e) {
        throw new ProvisioningDescriptionException("Failed to parse the channel part of feature id '" + str + "'", e);
    }
    int endIndex = str.indexOf(',', colon + 3);
    if (endIndex < 0) {
        final int equals = str.indexOf('=', colon + 1);
        if (equals < 0 || equals == str.length() - 1) {
            formatException(str);
        }
        return new ResolvedFeatureId(specId, Collections.singletonMap(str.substring(colon + 1, equals), str.substring(equals + 1)));
    }
    final Map<String, Object> params = new HashMap<>();
    int lastComma = colon;
    while (endIndex > 0) {
        int equals = str.indexOf('=', lastComma + 1);
        if (equals < 0 || equals == str.length() - 1) {
            formatException(str);
        }
        params.put(str.substring(lastComma + 1, equals), str.substring(equals + 1, endIndex));
        lastComma = endIndex;
        endIndex = str.indexOf(',', endIndex + 1);
    }
    int equals = str.indexOf('=', lastComma + 2);
    if (equals < 0 || equals == str.length() - 1) {
        formatException(str);
    }
    params.put(str.substring(lastComma + 1, equals), str.substring(equals + 1));
    return new ResolvedFeatureId(specId, params);
}
Also used : HashMap(java.util.HashMap) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Aggregations

ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)41 XMLStreamException (javax.xml.stream.XMLStreamException)19 Path (java.nio.file.Path)12 IOException (java.io.IOException)9 ProvisioningException (org.jboss.galleon.ProvisioningException)8 BufferedReader (java.io.BufferedReader)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)6 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)5 HashMap (java.util.HashMap)4 FeatureGroup (org.jboss.galleon.config.FeatureGroup)4 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 UnsatisfiedPackageDependencyException (org.jboss.galleon.UnsatisfiedPackageDependencyException)3 ConfigId (org.jboss.galleon.config.ConfigId)3 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)3 Reader (java.io.Reader)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConfigModel (org.jboss.galleon.config.ConfigModel)2 FeatureConfig (org.jboss.galleon.config.FeatureConfig)2