List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:com.netflix.spinnaker.clouddriver.artifacts.helm.HelmArtifactCredentialsTest.java
@Test void downloadWithBasicAuthFromFile(@TempDirectory.TempDir Path tempDir, @WiremockResolver.Wiremock WireMockServer server) throws IOException { Path authFile = tempDir.resolve("auth-file"); Files.write(authFile, "someuser:somepassw0rd!".getBytes()); HelmArtifactAccount account = new HelmArtifactAccount(); account.setRepository(server.baseUrl() + "/" + REPOSITORY); account.setName("my-helm-account"); account.setUsernamePasswordFile(authFile.toAbsolutePath().toString()); runTestCase(server, account, m -> m.withBasicAuth("someuser", "somepassw0rd!")); }
From source file:com.github.kaklakariada.aws.sam.PluginTest.java
private Properties loadTestProperties() { final Path propertiesPath = Paths.get("test.properties"); final Properties properties = new Properties(); try {// w w w .j a va2 s.c o m properties.load(Files.newInputStream(propertiesPath)); } catch (final IOException e) { throw new AssertionError("Error loading " + propertiesPath.toAbsolutePath(), e); } return properties; }
From source file:com.qwazr.library.poi.PptxParser.java
@Override public void parseContent(final MultivaluedMap<String, String> parameters, final Path filePath, final String extension, final String mimeType, final ParserResultBuilder resultBuilder) throws Exception { final XSLFSlideShow pptSlideShow = new XSLFSlideShow(filePath.toAbsolutePath().toString()); final XMLSlideShow slideshow = new XMLSlideShow(pptSlideShow.getPackage()); final ParserFieldsBuilder metas = resultBuilder.metas(); metas.set(MIME_TYPE, findMimeType(extension, mimeType, this::findMimeTypeUsingDefault)); // Extract metadata try (XSLFPowerPointExtractor poiExtractor = new XSLFPowerPointExtractor(slideshow)) { final CoreProperties info = poiExtractor.getCoreProperties(); if (info != null) { metas.add(TITLE, info.getTitle()); metas.add(CREATOR, info.getCreator()); metas.add(SUBJECT, info.getSubject()); metas.add(DESCRIPTION, info.getDescription()); metas.add(KEYWORDS, info.getKeywords()); metas.add(CREATION_DATE, info.getCreated()); metas.add(MODIFICATION_DATE, info.getModified()); }// w w w . j a v a 2 s . com } extractSides(slideshow, resultBuilder); }
From source file:org.jmingo.query.watch.QuerySetWatchService.java
/** * Register watcher for specified path./*from w ww . ja v a2s. com*/ * If path references to a file then the parent folder of this file is registered. * * @param path the path to file or folder to watch */ public void regiser(Path path) { Validate.notNull(path, "path to watch cannot be null"); try { lock.lock(); if (!path.isAbsolute()) { path = path.toAbsolutePath(); } Path dir = path; // check if specified path is referencing to file if (Files.isRegularFile(path)) { dir = path.getParent();//takes parent dir to register in watch service } if (needToRegister(path)) { LOGGER.debug("create watcher for dir: {}", dir); Watcher watcher = new Watcher(watchService, watchEventHandler, dir); executorService.submit(watcher); } else { LOGGER.debug("a watcher for dir: {} is already created", dir); } // add path to the registered collection event if this path wasn't registered in watchService // because we need to know for which files the new event should be posted in event bus and filter altered files properly registered.add(path); } finally { lock.unlock(); } }
From source file:org.sonarsource.scanner.cli.ConfTest.java
@Test public void should_load_global_settings_by_home() throws Exception { Path home = Paths.get(getClass().getResource("ConfTest/shouldLoadRunnerSettingsByHome/").toURI()); args.setProperty("scanner.home", home.toAbsolutePath().toString()); Properties properties = conf.properties(); assertThat(properties.get("sonar.prop")).isEqualTo("value"); }
From source file:org.lable.oss.dynamicconfig.core.ConcurrencyIT.java
@Test public void concurrencyTest() throws IOException, InterruptedException, ConfigurationException { final int threadCount = 20; final Path configFile = Files.createTempFile("config", ".yaml"); Files.write(configFile, "test: 0\n".getBytes()); System.setProperty(ConfigurationInitializer.LIBRARY_PREFIX + ".type", "file"); System.setProperty(ConfigurationInitializer.LIBRARY_PREFIX + ".file.path", configFile.toAbsolutePath().toString()); HierarchicalConfiguration defaults = new HierarchicalConfiguration(); defaults.setProperty("test", -1); final Configuration configuration = ConfigurationInitializer.configureFromProperties(defaults, new YamlDeserializer()); final CountDownLatch ready = new CountDownLatch(threadCount + 1); final CountDownLatch start = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(threadCount + 1); final Map<Integer, Long> result = new ConcurrentHashMap<>(threadCount); final long stopTime = System.currentTimeMillis() + 1_000; for (int i = 0; i < threadCount; i++) { final Integer number = 10 + i; new Thread(() -> { ready.countDown();/* w w w . ja v a2 s .co m*/ try { result.put(number, 0L); start.await(); while (System.currentTimeMillis() < stopTime) { System.out.println(configuration.getLong("test")); result.put(number, result.get(number) + 1); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } done.countDown(); }, String.valueOf(number)).start(); } new Thread(() -> { long count = 1; ready.countDown(); try { start.await(); while (System.currentTimeMillis() < stopTime) { String contents = "test: " + count + "\n"; Files.write(configFile, contents.getBytes()); count++; Thread.sleep(10); } } catch (Exception e) { fail(e.getMessage()); } done.countDown(); }, "setter").start(); ready.await(); start.countDown(); done.await(); for (Map.Entry<Integer, Long> entry : result.entrySet()) { System.out.println("Thread " + entry.getKey() + ": " + entry.getValue()); } }
From source file:com.garyclayburg.attributes.AttributeService.java
public void removeGroovyClass(Path path) { if (path.toString().endsWith(".groovy")) { String absolutePath = path.toAbsolutePath().toString(); synchronized (groovyClassMap) { log.info("re-loading all groovy because file removed: " + absolutePath); scanGroovyClasses();/* w ww.j a v a2s .co m*/ /* todo: this won't work well because gse by itself does not delete classes. if we really want to support this and have it work for multiple classes per file, we need tighter integration to gse and the scriptcache it keeps, or punt and just re-initialize gse each time a delete file event occurs, which would be expensive */ } policyChangeController.firePolicyChangedEvent(); } }
From source file:com.garyclayburg.attributes.AttributeService.java
public void reloadGroovyClass(Path path) { if (path.toString().endsWith(".groovy")) { String absolutePath = path.toAbsolutePath().toString(); synchronized (groovyClassMap) { log.info("re-loading all groovy because file changed: " + absolutePath); /* all scripts are scanned so that we can catch any files that contain multiple classes. This could be optimized for speed if needed */ scanGroovyClasses();/*from w w w . j ava 2 s. co m*/ } policyChangeController.firePolicyChangedEvent(); } }
From source file:com.nridge.connector.fs.con_fs.core.FileCrawler.java
private String generateDocumentId(Path aPath) { String pathFileName = aPath.toAbsolutePath().toString(); return mIdValuePrefix + Content.hashId(pathFileName); }
From source file:edu.pitt.dbmi.ccd.queue.service.AlgorithmSlurmService.java
private void deleteRunSlurmScript(JobQueueInfo jobQueueInfo) { Long queueId = jobQueueInfo.getId(); Set<UserAccount> userAccounts = jobQueueInfo.getUserAccounts(); UserAccount userAccount = (UserAccount) userAccounts.toArray()[0]; String username = userAccount.getUsername(); Path scriptPath = Paths.get(remoteworkspace, username, runSlurmJobScript); String scriptDir = scriptPath.toAbsolutePath().toString() + queueId + ".sh"; if (client.remoteFileExistes(scriptDir)) { client.deleteRemoteFile(scriptDir); }/* w w w . j a va2s .c o m*/ }