Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/sjavac/OverlappingSrcDst.java
41144 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @summary Make sure sjavac doesn't allow overlapping source and destination
27
* directories.
28
* @bug 8061320
29
* @library /tools/lib
30
* @modules jdk.compiler/com.sun.tools.javac.api
31
* jdk.compiler/com.sun.tools.javac.main
32
* jdk.compiler/com.sun.tools.sjavac
33
* @build Wrapper toolbox.ToolBox
34
* @run main Wrapper OverlappingSrcDst
35
*/
36
37
import java.io.File;
38
import java.nio.file.Paths;
39
40
import toolbox.ToolBox;
41
42
public class OverlappingSrcDst extends SJavacTester {
43
public static void main(String... args) {
44
new OverlappingSrcDst().run();
45
}
46
47
public void run() {
48
String abs = ToolBox.currDir.toAbsolutePath().toString();
49
50
// Relative vs relative
51
test("dir", "dir", false);
52
test("dir", "dir/dst", false);
53
test("dir/src", "dir", false);
54
test("src", "dst", true);
55
56
// Absolute vs absolute
57
test(abs + "/dir", abs + "/dir", false);
58
test(abs + "/dir", abs + "/dir/dst", false);
59
test(abs + "/dir/src", abs + "/dir", false);
60
test(abs + "/src", abs + "/dst", true);
61
62
// Absolute vs relative
63
test(abs + "/dir", "dir", false);
64
test(abs + "/dir", "dir/dst", false);
65
test(abs + "/dir/src", "dir", false);
66
test(abs + "/src", "dst", true);
67
68
// Relative vs absolute
69
test("dir", abs + "/dir", false);
70
test("dir", abs + "/dir/dst", false);
71
test("dir/src", abs + "/dir", false);
72
test("src", abs + "/dst", true);
73
}
74
75
private void test(String srcDir, String dstDir, boolean shouldSucceed) {
76
boolean succeeded = testCompilation(srcDir, dstDir);
77
if (shouldSucceed != succeeded) {
78
throw new AssertionError(
79
String.format("Test failed for "
80
+ "srcDir=\"%s\", "
81
+ "dstDir=\"%s\". "
82
+ "Compilation was expected to %s but %s.",
83
srcDir,
84
dstDir,
85
shouldSucceed ? "succeed" : "fail",
86
succeeded ? "succeeded" : "failed"));
87
}
88
}
89
90
private boolean testCompilation(String srcDir, String dstDir) {
91
try {
92
srcDir = srcDir.replace('/', File.separatorChar);
93
dstDir = dstDir.replace('/', File.separatorChar);
94
tb.writeFile(Paths.get(srcDir, "pkg", "A.java"), "package pkg; class A {}");
95
compile("--state-dir=state", "-src", srcDir, "-d", dstDir);
96
return true;
97
} catch (Exception e) {
98
return false;
99
}
100
}
101
}
102
103