private static void failedToReadDirectory(Path p, IOException e) throws ProvisioningDescriptionException { throw new ProvisioningDescriptionException(Errors.readDirectory(p), e); } }
private static void deleteHistoryFiles(Path installedHistoryDir) throws ProvisioningException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(installedHistoryDir)) { for (Path entry : stream) { if (Files.isDirectory(entry)) { IoUtils.recursiveDelete(entry); } } } catch (IOException ex) { throw new ProvisioningException(Errors.readDirectory(installedHistoryDir), ex); } } }
protected ClassLoader getPluginsClassLoader() throws ProvisioningException { if(pluginsCl != null) { return pluginsCl; } pluginsCl = Thread.currentThread().getContextClassLoader(); if (pluginsDir != null) { List<java.net.URL> urls = new ArrayList<>(); try (Stream<Path> stream = Files.list(pluginsDir)) { final Iterator<Path> i = stream.iterator(); while(i.hasNext()) { urls.add(i.next().toUri().toURL()); } } catch (IOException e) { throw new ProvisioningException(Errors.readDirectory(pluginsDir), e); } if (!urls.isEmpty()) { closePluginsCl = true; pluginsCl = new java.net.URLClassLoader(urls.toArray( new java.net.URL[urls.size()]), pluginsCl); } } return pluginsCl; }
public static void assertInstallationDir(Path path) throws ProvisioningException { if (!Files.exists(path)) { return; } if (!Files.isDirectory(path)) { throw new ProvisioningException(Errors.notADir(path)); } try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { final Iterator<Path> i = stream.iterator(); if(!i.hasNext()) { return; } while (i.hasNext()) { if (i.next().getFileName().toString().equals(Constants.PROVISIONED_STATE_DIR)) { return; } } throw new ProvisioningException(Errors.homeDirNotUsable(path)); } catch (IOException e) { throw new ProvisioningException(Errors.readDirectory(path)); } }
protected Path newStagedDir() throws ProvisioningException { final Path stagedDir = getWorkDir().resolve(STAGED); if(Files.exists(stagedDir)) { try(DirectoryStream<Path> stream = Files.newDirectoryStream(stagedDir)) { for(Path p : stream) { IoUtils.recursiveDelete(p); } } catch (IOException e) { throw new ProvisioningException(Errors.readDirectory(stagedDir), e); } } else { try { Files.createDirectories(stagedDir); } catch (IOException e) { throw new ProvisioningException(Errors.mkdirs(stagedDir), e); } } return stagedDir; }