Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/javac/6394683/T6394683.java
41149 views
1
/*
2
* Copyright (c) 2006, 2015, 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
* @bug 6394683
27
* @summary need to resolve different file-type precedence semantics for javac and 269
28
* @modules java.compiler
29
* jdk.compiler
30
*/
31
32
import java.io.*;
33
import javax.tools.*;
34
35
public class T6394683 {
36
static final String testSrc = System.getProperty("test.src", ".");
37
static final File a_java = new File(testSrc, "A.java");
38
static final File a_class = new File("A.class");
39
static final File b_class = new File("B.class");
40
static final File b_java = new File("B.java");
41
42
static abstract class TestFile extends File {
43
TestFile(File file) {
44
super(file.getPath());
45
}
46
47
abstract void create() throws IOException;
48
}
49
50
static class JavaTestFile extends TestFile {
51
JavaTestFile(File file, String text) {
52
super(file);
53
this.text = text;
54
}
55
56
void create() throws IOException {
57
BufferedWriter out = new BufferedWriter(new FileWriter(this));
58
out.write(text);
59
out.newLine();
60
out.close();
61
}
62
63
private String text;
64
}
65
66
static TestFile good_java = new JavaTestFile(b_java, "class B { }");
67
static TestFile bad_java = new JavaTestFile(b_java, "class B");
68
69
static TestFile good_class = new TestFile(b_class) {
70
void create() throws IOException {
71
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
72
int rc = javac.run(null, null, null,
73
"-d", ".",
74
new File(testSrc, "B.java").getPath());
75
if (rc != 0)
76
throw new AssertionError("compilation failed, rc=" + rc + " creating B.class");
77
}
78
};
79
80
static TestFile bad_class = new TestFile(b_class) {
81
void create() throws IOException {
82
FileOutputStream out = new FileOutputStream(b_class);
83
out.close();
84
}
85
};
86
87
88
public static void main(String ... args) throws Exception {
89
boolean ok;
90
91
ok = test("-Xprefer:source", good_java, bad_class);
92
ok &= test("-Xprefer:source", bad_class, good_java);
93
ok &= test("-Xprefer:newer", bad_java, good_class);
94
ok &= test("-Xprefer:newer", bad_class, good_java);
95
96
if (!ok)
97
throw new AssertionError("test failed");
98
}
99
100
static boolean test(String opt, TestFile older, TestFile newer) throws Exception {
101
102
// ensure clean start
103
a_class.delete();
104
b_java.delete();
105
b_class.delete();
106
107
older.create();
108
newer.create();
109
if (!older.exists() || !newer.exists())
110
throw new AssertionError("error creating files");
111
112
int n = 0;
113
while (newer.lastModified() <= older.lastModified()) {
114
if (++n == 5)
115
throw new Error("Cannot create files");
116
Thread.sleep(1000);
117
newer.create();
118
}
119
120
System.err.println("test:"
121
+ "option:" + opt + ", "
122
+ "older:" + older + "[" + older.length() + ":" + older.lastModified() + "], "
123
+ "newer:" + newer + "[" + newer.length() + ":" + newer.lastModified() + "]");
124
for (String s: new File(".").list())
125
System.err.print(" " + s);
126
System.err.println();
127
128
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
129
int rc = javac.run(null, null, null,
130
"-d", ".",
131
"-classpath", ".",
132
"-sourcepath", ".",
133
opt,
134
a_java.getPath());
135
if (rc != 0) {
136
error("compilation failed, rc=" + rc + ", option: " + opt + ", older:" + older + ", newer" + newer);
137
return false;
138
}
139
140
return true;
141
}
142
143
static void error(String msg) {
144
System.err.println(msg);
145
}
146
}
147
148