List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:io.spikex.core.integration.MainTest.java
@Test public void testConfModified() throws InterruptedException, ResourceException, IOException { Path homePath = Paths.get("build/resources/test/node1"); System.setProperty("spikex.home", homePath.toAbsolutePath().toString()); new Main().start(new String[0]); ////from w ww . j a va 2s . com // Update Spike.x configuration (simulate update of module) // Thread.sleep(5500L); // Wait 5.5 seconds - re-init is throttled URI base = homePath.resolve("conf").toAbsolutePath().toUri(); YamlResource confResource = YamlResource.builder(base).name("spikex").version(Version.none()).build() .load(); List<Map> modules = new ArrayList(); Map<String, String> module1 = new HashMap(); module1.put("id", "io.spikex~spikex-test2~0.8.0"); modules.add(module1); Map<String, String> module2 = new HashMap(); module2.put("id", "io.spikex~spikex-test1~0.8.0"); modules.add(module2); YamlDocument conf = confResource.getData().get(0); conf.setValue("modules", modules); confResource.save(); Thread.sleep(2000L); // Wait a while so that file change is noticed }
From source file:it.sonarlint.cli.tools.SonarlintCli.java
public int run(Path workingDir, String... args) { LOG.info("Running SonarLint CLI in '{}'", workingDir.toAbsolutePath()); try {/*from w w w .jav a 2 s . co m*/ exec = new CommandExecutor(script); return exec.execute(args, workingDir.toAbsolutePath(), env); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:com.google.devtools.build.android.PackedResourceTarExpander.java
@Override public ImmutableList<Path> modify(ImmutableList<Path> resourceRoots) { final Builder<Path> outDirs = ImmutableList.builder(); for (final Path unresolvedRoot : resourceRoots) { Path root = unresolvedRoot.toAbsolutePath(); try {//from ww w .j a v a 2 s .co m final Path packedResources = root.resolve("raw/blaze_internal_packed_resources.tar"); if (Files.exists(packedResources)) { Preconditions.checkArgument(root.startsWith(workingDirectory), "%s is not under %s", root, workingDirectory); final Path resourcePrefix = workingDirectory.relativize(root); final Path targetDirectory = out.resolve(resourcePrefix); outDirs.add(targetDirectory); copyRemainingResources(root, packedResources); // Group the unpacked resource by the path they came from. final Path tarOut = out.resolve("blaze_internal_packed_resources").resolve(resourcePrefix); unTarPackedResources(tarOut, packedResources); outDirs.add(tarOut); } else { outDirs.add(root); } } catch (IOException e) { Throwables.propagate(e); } } return outDirs.build(); }
From source file:org.sakuli.starter.helper.SakuliFolderHelper.java
/** * Validates the path to the test suite folder and ensure that it contains the files: * <ul>/* w ww . j av a 2 s. co m*/ * <li>testsuite.properties</li> * <li>testsuite.suite</li> * </ul> * After all checks were succefull,the values will be set to the {@link SakuliPropertyPlaceholderConfigurer}. * * @param testSuiteFolderPath path to test suite folder * @param tempLogCache temporary string for later logging * @return the updated tempLogCache String. * @throws FileNotFoundException if some of the above files are missing */ public static String checkTestSuiteFolderAndSetContextVariables(String testSuiteFolderPath, String tempLogCache) throws FileNotFoundException { Path testSuiteFolder = normalizePath(testSuiteFolderPath); Path propertyFile = Paths.get(testSuiteFolder + TestSuiteProperties.TEST_SUITE_PROPERTIES_FILE_APPENDER); Path suiteFile = Paths.get(testSuiteFolder + TestSuiteProperties.TEST_SUITE_SUITE_FILE_APPENDER); if (testSuiteFolder == null || !Files.exists(testSuiteFolder)) { throw new FileNotFoundException( "sakuli test suite folder \"" + testSuiteFolderPath + "\" does not exist!"); } else if (!Files.exists(propertyFile)) { throw new FileNotFoundException("property file \"" + TestSuiteProperties.TEST_SUITE_PROPERTIES_FILE_NAME + "\" does not exist in folder: " + testSuiteFolderPath); } else if (!Files.exists(suiteFile)) { throw new FileNotFoundException("suite file \"" + TestSuiteProperties.TEST_SUITE_SUITE_FILE_NAME + "\" does not exist in folder: " + testSuiteFolderPath); } SakuliPropertyPlaceholderConfigurer.TEST_SUITE_FOLDER_VALUE = testSuiteFolder.toAbsolutePath().toString(); return tempLogCache + "\nset property '" + TestSuiteProperties.TEST_SUITE_FOLDER + "' to \"" + SakuliPropertyPlaceholderConfigurer.TEST_SUITE_FOLDER_VALUE + "\""; }
From source file:com.marklogic.entityservices.examples.ExamplesBase.java
public ExamplesBase() { props = new Properties(); try {/*w w w .ja va 2s . co m*/ props.load(this.getClass().getClassLoader().getResourceAsStream("application.properties")); } catch (IOException e) { throw new RuntimeException("Error reading application.properties file"); } client = DatabaseClientFactory.newClient(props.getProperty("mlHost"), Integer.parseInt(props.getProperty("mlRestPort")), new DatabaseClientFactory.DigestAuthContext( props.getProperty("mlUsername"), props.getProperty("mlPassword"))); Path currentRelativePath = Paths.get(""); projectDir = currentRelativePath.toAbsolutePath().toString(); logger.debug("Current relative path is: " + projectDir); // FIXME this is a hack for intellij. if (!projectDir.endsWith("examples")) projectDir += "/entity-services-examples"; moveMgr = DataMovementManager.newInstance().withClient(client); mapper = new ObjectMapper(); }
From source file:com.digitalpebble.stormcrawler.spout.FileSpout.java
public FileSpout(String dir, String filter, Scheme scheme) { Path pdir = Paths.get(dir); _inputFiles = new LinkedList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(pdir, filter)) { for (Path entry : stream) { String inputFile = entry.toAbsolutePath().toString(); _inputFiles.add(inputFile);/* w ww .j a va 2 s . c o m*/ LOG.info("Input : {}", inputFile); } } catch (IOException ioe) { LOG.error("IOException: %s%n", ioe); } _scheme = scheme; }
From source file:com.marklogic.entityservices.e2e.ExamplesBase.java
public ExamplesBase() { props = new Properties(); try {/*from w ww. j ava 2s .co m*/ props.load(this.getClass().getClassLoader().getResourceAsStream("application.properties")); } catch (IOException e) { throw new RuntimeException("Error reading application.properties file"); } client = DatabaseClientFactory.newClient(props.getProperty("mlHost"), Integer.parseInt(props.getProperty("mlRestPort")), new DatabaseClientFactory.DigestAuthContext( props.getProperty("mlUsername"), props.getProperty("mlPassword"))); Path currentRelativePath = Paths.get(""); projectDir = currentRelativePath.toAbsolutePath().toString(); logger.debug("Current relative path is: " + projectDir); // FIXME this is a hack for intellij. if (!projectDir.endsWith("e2e")) projectDir += "/entity-services-e2e"; moveMgr = DataMovementManager.newInstance().withClient(client); mapper = new ObjectMapper(); }
From source file:it.polimi.diceH2020.launcher.FileService.java
public Stream<Path> getBaseSolutionsPath() { String strDir = settings.getSolInstanceDir(); Path dir = FileSystems.getDefault().getPath(strDir); if (Files.notExists(dir)) { Path currentRelativePath = Paths.get(""); dir = FileSystems.getDefault() .getPath(currentRelativePath.toAbsolutePath().toString() + File.pathSeparator + strDir); }/*w ww . j a va 2 s. c om*/ DirectoryStream<Path> stream; try { stream = Files.newDirectoryStream(dir, "*.{json}"); return StreamSupport.stream(stream.spliterator(), false); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:car_counter.storage.sqlite.SqliteStorage.java
public SqliteStorage(Wini ini) { try {/* w w w . j a va 2 s .c om*/ Class.forName("org.sqlite.JDBC"); } catch (Exception e) { throw new IllegalStateException("Error loading sqlite driver.", e); } try { String database = ini.get("Storage", "database", String.class); Preconditions.checkState(StringUtils.isNotBlank(database), "A database file is required"); Path dbFile = Paths.get(database); connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s", dbFile.toAbsolutePath())); initialiseTables(); } catch (SQLException e) { throw new IllegalStateException("Error opening database", e); } }
From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java
License:asdf
public static <T> void assertOutputFiles(T[] elems, final String header, final String footer, Coder<T> coder, int numShards, Path rootLocation, String outputName, String shardNameTemplate) throws Exception { List<File> expectedFiles = new ArrayList<>(); if (numShards == 0) { String pattern = resolve(rootLocation.toAbsolutePath().toString(), outputName + "*"); for (String expected : IOChannelUtils.getFactory(pattern).match(pattern)) { expectedFiles.add(new File(expected)); }/*w w w. j av a 2s . com*/ } else { for (int i = 0; i < numShards; i++) { expectedFiles.add(new File(rootLocation.toString(), IOChannelUtils.constructName(outputName, shardNameTemplate, "", i, numShards))); } } List<List<String>> actual = new ArrayList<>(); for (File tmpFile : expectedFiles) { try (BufferedReader reader = new BufferedReader(new FileReader(tmpFile))) { List<String> currentFile = new ArrayList<>(); for (;;) { String line = reader.readLine(); if (line == null) { break; } currentFile.add(line); } actual.add(currentFile); } } List<String> expectedElements = new ArrayList<>(elems.length); for (T elem : elems) { byte[] encodedElem = CoderUtils.encodeToByteArray(coder, elem); String line = new String(encodedElem); expectedElements.add(line); } List<String> actualElements = Lists.newArrayList(Iterables .concat(FluentIterable.from(actual).transform(removeHeaderAndFooter(header, footer)).toList())); assertThat(actualElements, containsInAnyOrder(expectedElements.toArray())); assertTrue(Iterables.all(actual, haveProperHeaderAndFooter(header, footer))); }