List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:de.teamgrit.grit.preprocess.fetch.SvnFetcher.java
/** * runSVNCommand runs an svn command in the specified directory. * * @param connection/* ww w . j a va2 s . c o m*/ * the connection storing the connection infos for the remote * @param svnCommand * is the command to be executed. Each part of the command must * be a string element. For example: "svn" "checkout" * "file://some/path" * @param workingDir * where the svn command should be executed (must be a * repository). * @return A list of all output lines. * @throws IOException * Thrown when process can't be started or an error occurs * while reading its output */ private static SVNResultData runSVNCommand(Connection connection, List<String> svnCommand, Path workingDir) throws IOException { // add boilerplate to command svnCommand.add("--non-interactive"); svnCommand.add("--no-auth-cache"); svnCommand.add("--force"); if ((connection.getUsername() != null) && !connection.getUsername().isEmpty()) { svnCommand.add("--username"); svnCommand.add(connection.getUsername()); } if ((connection.getPassword() != null) && !connection.getPassword().isEmpty()) { svnCommand.add("--password"); svnCommand.add(connection.getPassword()); } // build process: construct command and set working directory. Process svnProcess = null; ProcessBuilder svnProcessBuilder = new ProcessBuilder(svnCommand); svnProcessBuilder.directory(workingDir.toFile()); svnProcess = svnProcessBuilder.start(); try { svnProcess.waitFor(); } catch (InterruptedException e) { LOGGER.severe("Interrupted while waiting for SVN. " + "Cannot guarantee clean command run!"); return null; } InputStream svnOutputStream = svnProcess.getInputStream(); InputStreamReader svnStreamReader = new InputStreamReader(svnOutputStream); BufferedReader svnOutputBuffer = new BufferedReader(svnStreamReader); String line; List<String> svnOutputLines = new LinkedList<>(); while ((line = svnOutputBuffer.readLine()) != null) { svnOutputLines.add(line); } return new SVNResultData(svnProcess.exitValue(), svnOutputLines); }
From source file:io.seqware.pipeline.whitestar.WhiteStarTest.java
protected static void createAndRunWorkflow(Path settingsFile, boolean metadata) throws Exception, IOException { // create a helloworld Path tempDir = Files.createTempDirectory("tempTestingDirectory"); PluginRunner it = new PluginRunner(); String SEQWARE_VERSION = it.getClass().getPackage().getImplementationVersion(); Assert.assertTrue("unable to detect seqware version", SEQWARE_VERSION != null); Log.info("SeqWare version detected as: " + SEQWARE_VERSION); String archetype = "java-workflow"; String workflow = "seqware-archetype-" + archetype; String workflowName = workflow.replace("-", ""); // generate and install archetypes to local maven repo String command = "mvn archetype:generate -DarchetypeCatalog=local -Dpackage=com.seqware.github -DgroupId=com.github.seqware -DarchetypeArtifactId=" + workflow + " -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=com.github.seqware -DartifactId=" + workflow + " -Dworkflow-name=" + workflowName + " -B -Dgoals=install"; String genOutput = ITUtility.runArbitraryCommand(command, 0, tempDir.toFile()); Log.info(genOutput);//from w ww . j ava2s. c o m // install the workflows to the database and record their information File workflowDir = new File(tempDir.toFile(), workflow); File targetDir = new File(workflowDir, "target"); final String workflow_name = "Workflow_Bundle_" + workflowName + "_1.0-SNAPSHOT_SeqWare_" + SEQWARE_VERSION; File bundleDir = new File(targetDir, workflow_name); Map environment = EnvironmentUtils.getProcEnvironment(); environment.put("SEQWARE_SETTINGS", settingsFile.toAbsolutePath().toString()); // save system environment variables Map<String, String> env = System.getenv(); try { // override for launching Utility.set(environment); List<String> cmd = new ArrayList<>(); cmd.add("bundle"); cmd.add("launch"); cmd.add("--dir"); cmd.add(bundleDir.getAbsolutePath()); if (!metadata) { cmd.add("--no-metadata"); } Main.main(cmd.toArray(new String[cmd.size()])); } finally { Utility.set(env); } }
From source file:com.gooddata.util.ZipHelperTest.java
@Test public void shouldZipDir() throws Exception { Path toZipDir = temporaryFolder.resolve("toZip"); toZipDir.toFile().mkdirs(); File toZipFile = toZipDir.resolve(SOME_FILE_PATH).toFile(); toZipFile.getParentFile().mkdirs();// w w w . jav a 2 s . co m toZipFile.createNewFile(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipHelper.zip(toZipDir.toFile(), output, true); output.close(); verifyZipContent(output, Paths.get("toZip", "a", "b", SOME_FILE).toString()); } }
From source file:com.gooddata.util.ZipHelperTest.java
@Test public void shouldZipDirWithoutRoot() throws Exception { Path toZipDir = temporaryFolder.resolve("toZip"); toZipDir.toFile().mkdirs(); File toZipFile = toZipDir.resolve(SOME_FILE_PATH).toFile(); toZipFile.getParentFile().mkdirs();//from ww w . j ava2 s.c om toZipFile.createNewFile(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipHelper.zip(toZipDir.toFile(), output); output.close(); verifyZipContent(output, Paths.get("a", "b", SOME_FILE).toString()); } }
From source file:com.yahoo.sql4d.indexeragent.sql.SqlFileSniffer.java
@Override public void onCreate(Path path) { addOrUpdateTable(path.toFile()); }
From source file:com.yahoo.sql4d.indexeragent.sql.SqlFileSniffer.java
@Override public void onModify(Path path) { addOrUpdateTable(path.toFile()); }
From source file:io.github.swagger2markup.extensions.SchemaExtensionTest.java
@Test public void testSwagger2AsciiDocSchemaExtension() throws IOException, URISyntaxException { //Given//from ww w . j a v a 2s . co m Path file = Paths.get(SchemaExtensionTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Properties properties = new Properties(); properties.load(SchemaExtensionTest.class.getResourceAsStream("/config/config.properties")); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(properties).build(); Swagger2MarkupExtensionRegistry registry = new Swagger2MarkupExtensionRegistryBuilder() //.withDefinitionsDocumentExtension(new SchemaExtension(Paths.get("src/test/resources/docs/asciidoc/extensions").toUri())) .build(); Swagger2MarkupConverter.from(file).withConfig(config).withExtensionRegistry(registry).build() .toFolder(outputDirectory); //Then assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")))).contains("=== Pet"); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")))) .contains("==== XML Schema"); }
From source file:dk.dma.ais.track.AisTrackServiceConfiguration.java
@Bean public TargetTrackerFileBackupService provideFileBackupService(TargetTracker targetTracker) { if (backupPath == null || backupPath.trim().length() == 0) { LOG.info("dk.dma.ais.track.AisTrackService.backup not available. Can not configure {}", TargetTrackerFileBackupService.class.getSimpleName()); return null; }//from w w w. java 2 s . c o m Path path = Paths.get(backupPath); if (!path.toFile().exists()) { path.toFile().mkdirs(); } TargetTrackerFileBackupService backupService = new TargetTrackerFileBackupService(targetTracker, path); LOG.info("{} configured with path {}.", TargetTrackerFileBackupService.class.getSimpleName(), backupPath); return backupService; }
From source file:alliance.docs.DocumentationTest.java
@Test public void testBrokenAnchorsPresent() throws IOException, URISyntaxException { List<Path> docs = Files.list(getPath()).filter(f -> f.toString().endsWith(HTML_DIRECTORY)) .collect(Collectors.toList()); Set<String> links = new HashSet<>(); Set<String> anchors = new HashSet<>(); for (Path path : docs) { Document doc = Jsoup.parse(path.toFile(), "UTF-8", EMPTY_STRING); String thisDoc = StringUtils.substringAfterLast(path.toString(), File.separator); Elements elements = doc.body().getAllElements(); for (Element element : elements) { if (!element.toString().contains(":") && StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE) != null) { links.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE)); }//from ww w. j av a 2 s. co m anchors.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), ID, CLOSE)); } } links.removeAll(anchors); assertThat("Anchors missing section reference: " + links.toString(), links.isEmpty()); }
From source file:com.netflix.spinnaker.halyard.deploy.config.v1.ConfigParser.java
public <T> T read(Path path, Class<T> tClass) { try {//from w w w .j av a2s. c om InputStream is = new FileInputStream(path.toFile()); Object obj = yamlParser.load(is); return objectMapper.convertValue(obj, tClass); } catch (IllegalArgumentException e) { throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to load " + tClass.getSimpleName() + " config: " + e.getMessage()).build()); } catch (FileNotFoundException e) { throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to find " + tClass.getSimpleName() + " config: " + e.getMessage()).build()); } }