Search in sources :

Example 81 with ProvisioningException

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

the class ProvisioningRuntimeBuilder method processIncludedFeatures.

void processIncludedFeatures(final ResolvedFeatureGroupConfig pushedFgConfig) throws ProvisioningException {
    if (pushedFgConfig.includedFeatures.isEmpty()) {
        return;
    }
    for (Map.Entry<ResolvedFeatureId, FeatureConfig> feature : pushedFgConfig.includedFeatures.entrySet()) {
        final FeatureConfig includedFc = feature.getValue();
        if (includedFc != null && includedFc.hasParams()) {
            final ResolvedFeatureId includedId = feature.getKey();
            if (pushedFgConfig.configStack.isFilteredOut(includedId.specId, includedId)) {
                continue;
            }
            // make sure the included ID is in fact present on the feature group branch
            if (!pushedFgConfig.configStack.includes(includedId)) {
                throw new ProvisioningException(Errors.featureNotInScope(includedId, pushedFgConfig.fg.getId() == null ? "'anonymous'" : pushedFgConfig.fg.getId().toString(), currentOrigin == null ? null : currentOrigin.producer.getLocation().getFPID()));
            }
            resolveFeature(pushedFgConfig.configStack, includedFc);
        }
    }
}
Also used : FeatureConfig(org.jboss.galleon.config.FeatureConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 82 with ProvisioningException

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

the class ProvisioningRuntimeBuilder method resolveConfigLayer.

private ConfigModelStack resolveConfigLayer(ConfigId layerId) throws ProvisioningException {
    ConfigModelStack layerStack = layers.get(layerId);
    if (layerStack == null) {
        layerStack = new ConfigModelStack(layerId, this);
        boolean resolved = false;
        for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) {
            resolved |= resolveConfigLayer(fpConfig.getLocation().getProducer(), layerStack, layerId);
        }
        clearFlag(FeaturePackRuntimeBuilder.RESOLVE_LAYER);
        if (!resolved) {
            throw new ProvisioningException(Errors.layerNotFound(layerId));
        }
        layers = CollectionUtils.put(layers, layerId, layerStack);
    }
    return layerStack;
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 83 with ProvisioningException

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

the class ProvisioningRuntimeBuilder method processConfigLayer.

private void processConfigLayer(ConfigModelStack configStack, FeatureGroupSupport layer) throws ProvisioningException {
    this.configStack = configStack;
    try {
        if (layer.hasPackageDeps()) {
            processPackageDeps(layer, null);
        }
        processConfigItemContainer(layer);
        this.configStack = null;
    } catch (ProvisioningException e) {
        throw new ProvisioningException(Errors.failedToResolveConfigLayer(configStack.id.getModel(), layer.getName()), e);
    }
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 84 with ProvisioningException

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

the class FsDiff method addFsEntry.

private static Map<String, Boolean> addFsEntry(Path home, FsEntry added, Map<String, Boolean> undoTasks, MessageWriter log) throws ProvisioningException {
    final Path target = home.resolve(added.getRelativePath());
    char action = ADDED;
    String warning = null;
    if (Files.exists(target)) {
        if (added.isDir()) {
            for (FsEntry child : added.getChildren()) {
                if (child.isDiffStatusSuppressed()) {
                    continue;
                }
                undoTasks = addFsEntry(home, child, undoTasks, log);
            }
            return undoTasks;
        }
        final byte[] targetHash;
        try {
            targetHash = HashUtils.hashPath(target);
        } catch (IOException e) {
            throw new ProvisioningException(Errors.hashCalculation(target), e);
        }
        if (Arrays.equals(added.getHash(), targetHash)) {
            if (!addedPathMatchesExisting(added)) {
                action = REPLAY_SKIP;
            } else {
                warning = MATCHES_THE_UPDATED_VERSION;
                action = MODIFIED;
            }
            undoTasks = CollectionUtils.putLinked(undoTasks, added.getRelativePath(), true);
        } else if (addedPathConflict(added) && !added.isDir()) {
            warning = CONFLICTS_WITH_THE_UPDATED_VERSION;
            glnew(target);
            action = MODIFIED;
        }
    }
    if (action != REPLAY_SKIP) {
        log.print(formatMessage(action, added.getRelativePath(), warning));
        try {
            IoUtils.copy(added.getPath(), target);
        } catch (IOException e) {
            throw new ProvisioningException(Errors.copyFile(added.getPath(), target), e);
        }
    }
    return undoTasks;
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 85 with ProvisioningException

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

the class FsDiff method replay.

public static Map<String, Boolean> replay(FsDiff diff, Path home, MessageWriter log) throws ProvisioningException {
    log.print("Replaying your changes on top");
    Map<String, Boolean> undoTasks = Collections.emptyMap();
    if (diff.hasRemovedEntries()) {
        for (FsEntry removed : diff.getRemovedEntries()) {
            if (removed.isDiffStatusSuppressed()) {
                continue;
            }
            final Path target = home.resolve(removed.getRelativePath());
            if (Files.exists(target)) {
                log.print(formatMessage(REMOVED, removed.getRelativePath(), null));
                IoUtils.recursiveDelete(target);
            } else {
                log.verbose(formatMessage(REMOVED, removed.getRelativePath(), HAS_BEEN_REMOVED_FROM_THE_UPDATED_VERSION));
                undoTasks = CollectionUtils.putLinked(undoTasks, removed.getRelativePath(), false);
            }
        }
    }
    if (diff.hasAddedEntries()) {
        for (FsEntry added : diff.getAddedEntries()) {
            if (added.isDiffStatusSuppressed()) {
                continue;
            }
            undoTasks = addFsEntry(home, added, undoTasks, log);
        }
    }
    if (diff.hasModifiedEntries()) {
        for (FsEntry[] modified : diff.getModifiedEntries()) {
            if (modified[0].isDiffStatusSuppressed()) {
                continue;
            }
            final FsEntry update = modified[1];
            final Path target = home.resolve(update.getRelativePath());
            char action = MODIFIED;
            String warning = null;
            if (Files.exists(target)) {
                final byte[] targetHash;
                try {
                    targetHash = HashUtils.hashPath(target);
                } catch (IOException e) {
                    throw new ProvisioningException(Errors.hashCalculation(target), e);
                }
                if (Arrays.equals(update.getHash(), targetHash)) {
                    if (!modifiedPathMatchesExisting(update)) {
                        action = REPLAY_SKIP;
                    }
                    undoTasks = CollectionUtils.putLinked(undoTasks, update.getRelativePath(), true);
                } else if (!Arrays.equals(modified[0].getHash(), targetHash)) {
                    if (modifiedPathUpdated(update)) {
                        warning = HAS_CHANGED_IN_THE_UPDATED_VERSION;
                        glnew(target);
                    } else {
                        action = REPLAY_SKIP;
                    }
                } else if (modifiedPathConflict(update)) {
                    glnew(target);
                } else {
                    action = REPLAY_SKIP;
                }
            } else if (modifiedPathNotPresent(update)) {
                warning = HAS_BEEN_REMOVED_FROM_THE_UPDATED_VERSION;
                action = ADDED;
            } else {
                action = REPLAY_SKIP;
            }
            if (action != REPLAY_SKIP) {
                log.print(formatMessage(action, update.getRelativePath(), warning));
                try {
                    IoUtils.copy(update.getPath(), target);
                } catch (IOException e) {
                    throw new ProvisioningException(Errors.copyFile(update.getPath(), target), e);
                }
            }
        }
    }
    return undoTasks;
}
Also used : Path(java.nio.file.Path) 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