Search in sources :

Example 6 with ProvisioningException

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

the class StateHistoryUtils method readUndoTasks.

public static Map<String, Boolean> readUndoTasks(Path installDir, MessageWriter log) throws ProvisioningException {
    final Path stateDir = getUndoStateDir(installDir, log);
    if (stateDir == null) {
        return Collections.emptyMap();
    }
    final Path undoTasksFile = stateDir.resolve(Constants.UNDO_TASKS);
    if (!Files.exists(undoTasksFile)) {
        return Collections.emptyMap();
    }
    final Map<String, Boolean> tasks = new LinkedHashMap<>();
    try (BufferedReader reader = Files.newBufferedReader(undoTasksFile)) {
        String line = reader.readLine();
        while (line != null) {
            final String action = reader.readLine();
            if (Constants.KEEP.equals(action)) {
                tasks.put(line, true);
            } else if (Constants.REMOVE.equals(action)) {
                tasks.put(line, false);
            } else {
                throw new ProvisioningException("Unexpected undo task '" + action + "' for " + line);
            }
            line = reader.readLine();
        }
    } catch (IOException e) {
        throw new ProvisioningException(Errors.readFile(undoTasksFile), e);
    }
    return tasks;
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ProvisioningException

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

the class StateHistoryUtils method getUndoStateDir.

public static Path getUndoStateDir(Path installDir, MessageWriter log) throws ProvisioningException {
    final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir);
    if (!Files.exists(installedHistoryDir)) {
        return null;
    }
    final Path installedHistoryList = installedHistoryDir.resolve(Constants.HISTORY_LIST);
    if (!Files.exists(installedHistoryList)) {
        return null;
    }
    final List<String> installedHistory;
    try {
        installedHistory = Files.readAllLines(installedHistoryList);
    } catch (IOException e) {
        throw new ProvisioningException(Errors.readFile(installedHistoryList), e);
    }
    if (installedHistory.size() < 2) {
        return null;
    }
    int i = installedHistory.size() - 1;
    do {
        final Path statePath = installedHistoryDir.resolve(installedHistory.get(i--));
        if (Files.exists(statePath.resolve(Constants.PROVISIONING_XML))) {
            return statePath;
        }
        log.error("The state history of the current installation is corrupted referencing missing states!");
    } while (i >= 1);
    return null;
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 8 with ProvisioningException

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

the class StateHistoryUtils method clearStateHistory.

public static void clearStateHistory(Path installDir, MessageWriter log) throws ProvisioningException {
    final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir);
    if (!Files.exists(installedHistoryDir)) {
        return;
    }
    int limit = readStateHistoryLimit(installDir, log);
    final Path installedHistoryList = installedHistoryDir.resolve(Constants.HISTORY_LIST);
    try (BufferedWriter writer = Files.newBufferedWriter(installedHistoryList)) {
        writer.write(String.valueOf(limit));
        writer.newLine();
    } catch (IOException e) {
        throw new ProvisioningException(Errors.writeFile(installedHistoryList), e);
    }
    deleteHistoryFiles(installedHistoryDir);
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 9 with ProvisioningException

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

the class PersistChangesTestBase method provisionedHomeDir.

@Override
protected DirState provisionedHomeDir() {
    final DirBuilder builder = newDirBuilder();
    provisionedPackagesContent(builder);
    try {
        addConfigFiles(builder);
    } catch (ProvisioningException e) {
        throw new IllegalStateException(e);
    }
    return builder.build();
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) DirBuilder(org.jboss.galleon.test.util.fs.state.DirState.DirBuilder)

Example 10 with ProvisioningException

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

the class PersistChangesTestBase method overwrite.

protected void overwrite(ProvisionedConfig config) throws ProvisioningException {
    Path p = this.installHome.resolve(Constants.CONFIGS);
    if (config.getModel() != null) {
        p = p.resolve(config.getModel());
    }
    p = p.resolve(config.getName());
    try {
        Files.createDirectories(p.getParent());
    } catch (IOException e1) {
        throw new ProvisioningException(Errors.mkdirs(p.getParent()), e1);
    }
    try (BufferedWriter writer = Files.newBufferedWriter(p)) {
        ProvisionedConfigXmlWriter.getInstance().write(config, writer);
    } catch (IOException | XMLStreamException e) {
        throw new ProvisioningException("Failed to store " + new ConfigId(config.getModel(), config.getName()) + " in a string", e);
    }
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException) ConfigId(org.jboss.galleon.config.ConfigId) BufferedWriter(java.io.BufferedWriter)

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