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;
}
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;
}
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);
}
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();
}
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);
}
}
Aggregations