List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:de.undercouch.vertx.lang.typescript.TestExamplesRunner.java
private void compile(File script, TypeScriptCompiler compiler, SourceFactory parentSourceFactory, File pathToTypings) throws IOException { String name = FilenameUtils.separatorsToUnix(script.getPath().replaceFirst("\\.js$", ".ts")); compiler.compile(name, new SourceFactory() { @Override/* w ww. java2 s . c o m*/ public Source getSource(String filename, String baseFilename) throws IOException { if (FilenameUtils.equalsNormalized(filename, name)) { Source src = Source.fromFile(script, StandardCharsets.UTF_8); String srcStr = src.toString(); // find all required vertx modules Pattern requireVertx = Pattern .compile("var\\s+.+?=\\s*require\\s*\\(\\s*\"(vertx-.+?)\"\\s*\\)"); Matcher requireVertxMatcher = requireVertx.matcher(srcStr); List<String> modules = new ArrayList<>(); modules.add("vertx-js/vertx.d.ts"); modules.add("vertx-js/java.d.ts"); while (requireVertxMatcher.find()) { String mod = requireVertxMatcher.group(1); modules.add(mod); } // add default type definitions Path relPathToTypings = script.toPath().getParent().relativize(pathToTypings.toPath()); for (String mod : modules) { srcStr = "/// <reference path=\"" + FilenameUtils.separatorsToUnix(relPathToTypings.resolve(mod).toString()) + "\" />\n" + srcStr; } // replace 'var x = require("...")' by 'import x = require("...")' srcStr = srcStr.replaceAll("var\\s+(.+?=\\s*require\\s*\\(.+?\\))", "import $1"); return new Source(script.toURI(), srcStr); } return parentSourceFactory.getSource(filename, baseFilename); } }); }
From source file:com.datastax.loader.CqlDelimLoadTask.java
private void cleanup(boolean success) throws IOException { if (null != badParsePrinter) { if (format.equalsIgnoreCase("jsonarray")) badParsePrinter.println("]"); badParsePrinter.close();/*from ww w . j av a 2s. c o m*/ } if (null != badInsertPrinter) { if (format.equalsIgnoreCase("jsonarray")) badInsertPrinter.println("]"); badInsertPrinter.close(); } if (null != logPrinter) logPrinter.close(); if (success) { if (null != successDir) { Path src = infile.toPath(); Path dst = Paths.get(successDir); Files.move(src, dst.resolve(src.getFileName()), StandardCopyOption.REPLACE_EXISTING); } } else { if (null != failureDir) { Path src = infile.toPath(); Path dst = Paths.get(failureDir); Files.move(src, dst.resolve(src.getFileName()), StandardCopyOption.REPLACE_EXISTING); } } }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemPath.java
@Override public Path subpath(int beginIndex, int endIndex) { Path r = null; int i = 0;//from ww w . j a v a 2 s . co m for (Path p : this) { if (i++ == beginIndex) r = p; else if (i > beginIndex && i <= endIndex) { r = r.resolve(p); } } return r; }
From source file:com.facebook.buck.java.JarDirectoryStepTest.java
@Test public void timesAreSanitized() throws IOException { Path zipup = folder.newFolder("dir-zip"); // Create a jar file with a file and a directory. Path subdir = zipup.resolve("dir"); Files.createDirectories(subdir); Files.write(subdir.resolve("a.txt"), "cake".getBytes()); Path outputJar = folder.getRoot().resolve("output.jar"); JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(folder.getRoot()), outputJar, ImmutableSet.of(zipup), /* main class */ null, /* manifest file */ null); ExecutionContext context = TestExecutionContext.newInstance(); int returnCode = step.execute(context); assertEquals(0, returnCode);/* w w w . j a va 2 s .com*/ // Iterate over each of the entries, expecting to see all zeros in the time fields. assertTrue(Files.exists(outputJar)); Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_EPOCH_START)); try (ZipInputStream is = new ZipInputStream(new FileInputStream(outputJar.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime())); } } }
From source file:codes.thischwa.c5c.impl.LocalConnector.java
@Override public void upload(String urlDirectory, String sanitizedName, InputStream in) throws C5CException { Path parentFolder = buildRealPathAndCheck(urlDirectory); Path fileToSave = parentFolder.resolve(sanitizedName); try {//from w w w .ja va 2 s .com Files.deleteIfExists(fileToSave); Files.copy(in, fileToSave, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new FilemanagerException(FilemanagerAction.UPLOAD, FilemanagerException.Key.InvalidFileUpload, sanitizedName); } }
From source file:codes.writeonce.maven.plugins.soy.CompileMojo.java
private Path getJavaSourceOutputPath() { final Path javaOutputPath = javaOutputDirectory.toPath(); final Path javapackageSubpath = javaOutputPath.getFileSystem().getPath("", javaPackage.split("\\.")); return javaOutputPath.resolve(javapackageSubpath); }
From source file:codes.thischwa.c5c.impl.LocalConnector.java
@Override public void createFolder(String backendDirectory, String sanitizedFolderName) throws C5CException { Path parentFolder = buildRealPathAndCheck(backendDirectory); Path newFolder = parentFolder.resolve(sanitizedFolderName); try {//from w w w . jav a2 s . c o m Files.createDirectories(newFolder); } catch (FileSystemAlreadyExistsException e) { logger.warn("Destination file already exists: {}", newFolder.toAbsolutePath()); throw new FilemanagerException(FilemanagerAction.CREATEFOLDER, Key.DirectoryAlreadyExists, sanitizedFolderName); } catch (SecurityException | IOException e) { throw new FilemanagerException(FilemanagerAction.RENAME, FilemanagerException.Key.UnableToCreateDirectory, sanitizedFolderName); } }
From source file:org.elasticsearch.packaging.test.ArchiveTestCase.java
public void test70CustomPathConfAndJvmOptions() throws IOException { assumeThat(installation, is(notNullValue())); final Path tempConf = getTempDir().resolve("esconf-alternate"); try {/*from w ww .j ava 2s .co m*/ mkdir(tempConf); cp(installation.config("elasticsearch.yml"), tempConf.resolve("elasticsearch.yml")); cp(installation.config("log4j2.properties"), tempConf.resolve("log4j2.properties")); // we have to disable Log4j from using JMX lest it will hit a security // manager exception before we have configured logging; this will fail // startup since we detect usages of logging before it is configured final String jvmOptions = "-Xms512m\n" + "-Xmx512m\n" + "-Dlog4j2.disable.jmx=true\n"; append(tempConf.resolve("jvm.options"), jvmOptions); final Shell sh = new Shell(); Platforms.onLinux(() -> sh.run("chown -R elasticsearch:elasticsearch " + tempConf)); Platforms.onWindows(() -> sh.run("$account = New-Object System.Security.Principal.NTAccount 'vagrant'; " + "$tempConf = Get-ChildItem '" + tempConf + "' -Recurse; " + "$tempConf += Get-Item '" + tempConf + "'; " + "$tempConf | ForEach-Object { " + "$acl = Get-Acl $_.FullName; " + "$acl.SetOwner($account); " + "Set-Acl $_.FullName $acl " + "}")); final Shell serverShell = new Shell(); serverShell.getEnv().put("ES_PATH_CONF", tempConf.toString()); serverShell.getEnv().put("ES_JAVA_OPTS", "-XX:-UseCompressedOops"); Archives.runElasticsearch(installation, serverShell); final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes")); assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912")); assertThat(nodesResponse, containsString("\"using_compressed_ordinary_object_pointers\":\"false\"")); Archives.stopElasticsearch(installation); } finally { rm(tempConf); } }
From source file:com.liferay.blade.cli.command.InstallExtensionCommandTest.java
@Test public void testInstallCustomGithubExtension() throws Exception { Assume.assumeFalse(_isWindows());/*w w w.j av a 2 s.c om*/ String[] args = { "extension", "install", "https://github.com/gamerson/blade-sample-command" }; BladeTestResults bladeTestResults = TestUtil.runBlade(_rootDir, _extensionsDir, args); String output = bladeTestResults.getOutput(); Assert.assertTrue("Expected output to contain \"successful\"\n" + output, output.contains(" successful")); Path rootPath = _rootDir.toPath(); Path extensionJarPath = rootPath .resolve(Paths.get(".blade", "extensions", "blade-sample-command-master.jar")); boolean pathExists = Files.exists(extensionJarPath); Assert.assertTrue(extensionJarPath.toAbsolutePath() + " does not exist", pathExists); }
From source file:de.ks.flatadocdb.defaults.SingleFolderGenerator.java
@Override public Path getFolder(Repository repository, @Nullable Path ownerPath, Object object) { Path rootFolder = super.getFolder(repository, ownerPath, object); EntityDescriptor descriptor = repository.getMetaModel().getEntityDescriptor(object.getClass()); Object naturalId = descriptor.getNaturalId(object); if (naturalId != null) { String naturalIdString = NameStripper.stripName(String.valueOf(naturalId)); String retval = naturalIdString; Path targetFolder = rootFolder.resolve(retval); targetFolder.toFile().mkdir();// w w w . j av a 2 s .c om log.trace("Using folder \"{}\" via natural id for {}", targetFolder, object); return targetFolder; } else { String hexString = parseHashCode(object); String retval = hexString; Path targetFolder = rootFolder.resolve(retval); targetFolder.toFile().mkdir(); log.trace("Using folder \"{}\" via hashcode for {}", targetFolder, object); return targetFolder; } }