本文整理汇总了Java中java.nio.file.Path.resolve方法的典型用法代码示例。如果您正苦于以下问题:Java Path.resolve方法的具体用法?Java Path.resolve怎么用?Java Path.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Path
的用法示例。
在下文中一共展示了Path.resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.nio.file.Path; //导入方法依赖的package包/类
void test(Path base, String name) throws IOException {
Path file = base.resolve(name);
Path javaFile = base.resolve("HelloWorld.java");
tb.writeFile(file,
"public class HelloWorld {\n"
+ " public static void main(String... args) {\n"
+ " System.err.println(\"Hello World!\");\n"
+ " }\n"
+ "}");
try {
Files.createSymbolicLink(javaFile, file.getFileName());
} catch (FileSystemException fse) {
System.err.println("warning: test passes vacuously, sym-link could not be created");
System.err.println(fse.getMessage());
return;
}
Path classes = Files.createDirectories(base.resolve("classes"));
new JavacTask(tb)
.outdir(classes)
.files(javaFile)
.run()
.writeAll();
}
示例2: createGitHubRepositoryWithContent
import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void createGitHubRepositoryWithContent() throws Exception {
// given
final String repositoryName = generateRepositoryName();
Path tempDirectory = Files.createTempDirectory("test");
Path file = tempDirectory.resolve("README.md");
Files.write(file, Collections.singletonList("Read me to know more"), Charset.forName("UTF-8"));
// when
final GitRepository targetRepo = getGitHubService().createRepository(repositoryName, MY_GITHUB_REPO_DESCRIPTION);
getGitHubService().push(targetRepo, tempDirectory.toFile());
// then
Assert.assertEquals(GitHubTestCredentials.getUsername() + "/" + repositoryName, targetRepo.getFullName());
URI readmeUri = UriBuilder.fromUri("https://raw.githubusercontent.com/")
.path(GitHubTestCredentials.getUsername())
.path(repositoryName)
.path("/master/README.md").build();
HttpURLConnection connection = (HttpURLConnection) readmeUri.toURL().openConnection();
Assert.assertEquals("README.md should have been pushed to the repo", 200, connection.getResponseCode());
FileUtils.forceDelete(tempDirectory.toFile());
}
示例3: testMissingService
import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testMissingService(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"module m { provides p.Missing with p.C; }",
"package p; public class C extends p.Missing { }");
List<String> output = new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(Files.createDirectories(base.resolve("classes")))
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
List<String> expected = Arrays.asList(
"C.java:1:36: compiler.err.cant.resolve.location: kindname.class, Missing, , , (compiler.misc.location: kindname.package, p, null)",
"module-info.java:1:22: compiler.err.cant.resolve.location: kindname.class, Missing, , , (compiler.misc.location: kindname.package, p, null)",
"2 errors");
if (!output.containsAll(expected)) {
throw new Exception("Expected output not found");
}
}
示例4: writeModule
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Writes a module-info.class. If {@code targetPlatform} is not null then
* it includes the ModuleTarget class file attribute with the target platform.
*/
static Path writeModule(ModuleDescriptor descriptor, String targetPlatform)
throws IOException
{
ModuleTarget target;
if (targetPlatform != null) {
target = new ModuleTarget(targetPlatform);
} else {
target = null;
}
String name = descriptor.name();
Path dir = Files.createTempDirectory(Paths.get(""), name);
Path mi = dir.resolve("module-info.class");
try (OutputStream out = Files.newOutputStream(mi)) {
ModuleInfoWriter.write(descriptor, target, out);
}
return dir;
}
示例5: testNotADirOnPath_1
import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testNotADirOnPath_1(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, "class C { }");
tb.writeFile("dummy.txt", "");
String log = new JavacTask(tb, Task.Mode.CMDLINE)
.options("-XDrawDiagnostics",
"--module-path", "dummy.txt")
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, dummy.txt"))
throw new Exception("expected output not found");
}
示例6: runTest
import java.nio.file.Path; //导入方法依赖的package包/类
private void runTest(CompilationMode mode)
throws IOException, CompilationException, ExecutionException {
final Path inputPath = Paths.get(ToolHelper.EXAMPLES_BUILD_DIR + "/rewrite.jar");
Path outputPath = tmpOutputDir.newFolder().toPath();
compileWithD8(inputPath, outputPath, mode);
Path dexPath = outputPath.resolve("classes.dex");
DexInspector dexInspector = new DexInspector(dexPath);
ClassSubject classSubject = dexInspector.clazz("rewrite.RequireNonNull");
MethodSubject methodSubject = classSubject
.method("java.lang.Object", "nonnullRemove", Collections.emptyList());
Iterator<InvokeInstructionSubject> iterator =
methodSubject.iterateInstructions(InstructionSubject::isInvoke);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals("getClass", iterator.next().invokedMethod().name.toString());
Assert.assertFalse(iterator.hasNext());
runTest(inputPath, dexPath);
}
示例7: testDuplicateRequires
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Verify that duplicate requires are detected.
*/
@Test
public void testDuplicateRequires(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1x");
tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }");
Path src_m2 = src.resolve("m2x");
tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires m1x; requires m1x; }");
Path classes = base.resolve("classes");
Files.createDirectories(classes);
String log = new JavacTask(tb)
.options("-XDrawDiagnostics", "--module-source-path", src.toString())
.outdir(classes)
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
if (!log.contains("module-info.java:1:37: compiler.err.duplicate.requires: m1x"))
throw new Exception("expected output not found");
}
示例8: testMissingModuleWithSourcePath
import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testMissingModuleWithSourcePath(Path base) throws Exception {
Path src = base.resolve("src");
Path mod = src.resolve("m1");
ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
mb1.comment("The first module.")
.exports("m1pub")
.requires("m2")
.classes("package m1pub; /** Class A */ public class A {}")
.classes("package m1pro; /** Class B */ public class B {}")
.write(src);
Path javafile = Paths.get(mod.toString(), "m1pub/A.java");
execNegativeTask("--source-path", mod.toString(),
javafile.toString());
assertMessagePresent("error: cannot access module-info");
assertMessageNotPresent("error - fatal error encountered");
}
示例9: verify
import java.nio.file.Path; //导入方法依赖的package包/类
/** Load information about the plugin, and verify it can be installed with no errors. */
private PluginInfo verify(Terminal terminal, Path pluginRoot, boolean isBatch, Environment env) throws Exception {
// read and validate the plugin descriptor
PluginInfo info = PluginInfo.readFromProperties(pluginRoot);
// checking for existing version of the plugin
final Path destination = env.pluginsFile().resolve(info.getName());
if (Files.exists(destination)) {
final String message = String.format(
Locale.ROOT,
"plugin directory [%s] already exists; if you need to update the plugin, uninstall it first using command 'remove %s'",
destination.toAbsolutePath(),
info.getName());
throw new UserException(ExitCodes.CONFIG, message);
}
terminal.println(VERBOSE, info.toString());
// don't let user install plugin as a module...
// they might be unavoidably in maven central and are packaged up the same way)
if (MODULES.contains(info.getName())) {
throw new UserException(
ExitCodes.USAGE, "plugin '" + info.getName() + "' cannot be installed like this, it is a system module");
}
// check for jar hell before any copying
jarHellCheck(pluginRoot, env.pluginsFile());
// read optional security policy (extra permissions)
// if it exists, confirm or warn the user
Path policy = pluginRoot.resolve(PluginInfo.ES_PLUGIN_POLICY);
if (Files.exists(policy)) {
PluginSecurity.readPolicy(policy, terminal, env, isBatch);
}
return info;
}
示例10: main
import java.nio.file.Path; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
Path root = Paths.get(IncCompInheritance.class.getSimpleName() + "Test");
Path src = root.resolve("src");
Path classes = root.resolve("classes");
// Prep source files: A <- B <- C
String a = "package pkga; public class A { public void m() {} }";
String b = "package pkgb; public class B extends pkga.A {}";
String c = "package pkgc; public class C extends pkgb.B {{ new pkgb.B().m(); }}";
toolbox.writeFile(src.resolve("pkga/A.java"), a);
toolbox.writeFile(src.resolve("pkgb/B.java"), b);
toolbox.writeFile(src.resolve("pkgc/C.java"), c);
// Initial compile (should succeed)
int rc1 = compile("-d", classes, "--state-dir=" + classes, src);
if (rc1 != 0)
throw new AssertionError("Compilation failed unexpectedly");
// Remove method A.m
Thread.sleep(2500); // Make sure we get a new timestamp
String aModified = "package pkga; public class A { }";
toolbox.writeFile(src.resolve("pkga/A.java"), aModified);
// Incremental compile (C should now be recompiled even though it
// depends on A only through inheritance via B).
// Since A.m is removed, this should fail.
int rc2 = compile("-d", classes, "--state-dir=" + classes, src);
if (rc2 == 0)
throw new AssertionError("Compilation succeeded unexpectedly");
}
示例11: setup
import java.nio.file.Path; //导入方法依赖的package包/类
private static void setup(Path userDir) throws IOException {
Path src = Paths.get(System.getProperty("test.src"));
Path testJar = src.resolve(ARCHIVE_NAME);
Path policy = src.resolve(POLICY_FILE);
Path testClass = Paths.get(System.getProperty("test.classes"),
TEST_NAME + ".class");
Files.copy(testJar, userDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);
Files.copy(policy, userDir.resolve(POLICY_FILE), REPLACE_EXISTING);
Files.copy(testClass, userDir.resolve(TEST_NAME + ".class"),
REPLACE_EXISTING);
Files.createDirectories(userDir.resolve("tmp"));
}
示例12: testEnsureRegularFile
import java.nio.file.Path; //导入方法依赖的package包/类
public void testEnsureRegularFile() throws IOException {
Path p = createTempDir();
// regular file
Path regularFile = p.resolve("regular");
Files.createFile(regularFile);
try {
Security.ensureDirectoryExists(regularFile);
fail("didn't get expected exception");
} catch (IOException expected) {}
}
示例13: testAPMultiModule
import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testAPMultiModule(Path base) throws Exception {
Path moduleSrc = base.resolve("module-src");
Path m1 = moduleSrc.resolve("m1x");
Path m2 = moduleSrc.resolve("m2x");
Path classes = base.resolve("classes");
Files.createDirectories(classes);
tb.writeJavaFiles(m1,
"module m1x { }",
"package impl1; public class Impl1 { }");
tb.writeJavaFiles(m2,
"module m2x { }",
"package impl2; public class Impl2 { }");
String log = new JavacTask(tb)
.options("--module-source-path", moduleSrc.toString(),
"-processor", AP.class.getName(),
"-AexpectedEnclosedElements=m1x=>impl1,m2x=>impl2")
.outdir(classes)
.files(findJavaFiles(moduleSrc))
.run()
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
if (!log.isEmpty())
throw new AssertionError("Unexpected output: " + log);
}
示例14: testRequiresSelf
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Verify that a simple loop is detected.
*/
@Test
public void testRequiresSelf(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, "module M { requires M; }");
String log = new JavacTask(tb)
.options("-XDrawDiagnostics")
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
if (!log.contains("module-info.java:1:21: compiler.err.cyclic.requires: M"))
throw new Exception("expected output not found");
}
示例15: prepareTestJar
import java.nio.file.Path; //导入方法依赖的package包/类
private Path prepareTestJar(Path base) throws Exception {
Path legacySrc = base.resolve("legacy-src");
tb.writeJavaFiles(legacySrc,
"package api; public abstract class Api {}");
Path legacyClasses = base.resolve("legacy-classes");
Files.createDirectories(legacyClasses);
String log = new JavacTask(tb)
.options()
.outdir(legacyClasses)
.files(findJavaFiles(legacySrc))
.run()
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
if (!log.isEmpty()) {
throw new Exception("unexpected output: " + log);
}
Path lib = base.resolve("lib");
Files.createDirectories(lib);
Path jar = lib.resolve("test-api-1.0.jar");
new JarTask(tb, jar)
.baseDir(legacyClasses)
.files("api/Api.class")
.run();
return jar;
}