public static int readStateHistoryLimit(Path installDir, MessageWriter log) throws ProvisioningException { final Path installedHistoryList = PathsUtils.getStateHistoryFile(installDir); if(!Files.exists(installedHistoryList)) { return STATE_HISTORY_LIMIT; } try(BufferedReader reader = Files.newBufferedReader(installedHistoryList)) { final String line = reader.readLine(); if(line != null) { return Integer.parseInt(line); } } catch (IOException e) { throw new ProvisioningException(Errors.readFile(installedHistoryList), e); } return STATE_HISTORY_LIMIT; }
public FeaturePackSpec getSpec() throws ProvisioningException { if(spec == null) { try(BufferedReader reader = Files.newBufferedReader(dir.resolve(Constants.FEATURE_PACK_XML))) { spec = FeaturePackXmlParser.getInstance().parse(reader); } catch (Exception e) { throw new ProvisioningException(Errors.readFile(dir.resolve(Constants.FEATURE_PACK_XML))); } } return spec; }
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; }
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; }
public static boolean isUndoAvailable(Path installDir, MessageWriter log) throws ProvisioningException { final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir); if(!Files.exists(installedHistoryDir)) { return false; } final Path installedHistoryList = PathsUtils.getStateHistoryFile(installDir); if(!Files.exists(installedHistoryList)) { return false; } final List<String> installedHistory; try { installedHistory = Files.readAllLines(installedHistoryList); } catch (IOException e) { throw new ProvisioningException(Errors.readFile(installedHistoryList), e); } if(installedHistory.size() < 2) { return false; } int i = installedHistory.size() - 1; do { if (Files.exists(installedHistoryDir.resolve(installedHistory.get(i--)))) { return true; } log.error("The state history of the current installation is corrupted referencing missing states!"); } while (i >= 1); return false; }
installedHistory = Files.readAllLines(installHistoryList); } catch (IOException e) { throw new ProvisioningException(Errors.readFile(installHistoryList), e);
installedHistory = Files.readAllLines(installHistoryList); } catch (IOException e) { throw new ProvisioningException(Errors.readFile(installHistoryList), e);
public static FeaturePackSpec readSpec(Path artifactZip) throws ProvisioningException { try (FileSystem zipfs = ZipUtils.newFileSystem(artifactZip)) { for(Path zipRoot : zipfs.getRootDirectories()) { final Path p = zipRoot.resolve(Constants.FEATURE_PACK_XML); if(!Files.exists(p)) { throw new ProvisioningException("Feature-pack archive does not contain " + Constants.FEATURE_PACK_XML); } try(BufferedReader reader = Files.newBufferedReader(p)) { return FeaturePackXmlParser.getInstance().parse(reader); } catch (XMLStreamException e) { throw new ProvisioningException(Errors.parseXml(p), e); } } } catch (IOException e) { throw new ProvisioningException(Errors.readFile(artifactZip), e); } return null; }