36526
+ − 1
/*
+ − 2
* Copyright (c) 2015, 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 tests for multi-module mode compilation
+ − 27
* @library /tools/lib
+ − 28
* @modules
+ − 29
* jdk.compiler/com.sun.tools.javac.api
+ − 30
* jdk.compiler/com.sun.tools.javac.main
+ − 31
* jdk.jdeps/com.sun.tools.javap
+ − 32
* @build ToolBox ModuleTestBase
+ − 33
* @run main XModuleTest
+ − 34
*/
+ − 35
+ − 36
import java.nio.file.Path;
+ − 37
import java.util.Arrays;
+ − 38
import java.util.List;
+ − 39
+ − 40
public class XModuleTest extends ModuleTestBase {
+ − 41
+ − 42
public static void main(String... args) throws Exception {
+ − 43
new XModuleTest().runTests();
+ − 44
}
+ − 45
+ − 46
@Test
+ − 47
void testCorrectXModule(Path base) throws Exception {
+ − 48
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 49
Path src = base.resolve("src");
+ − 50
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
+ − 51
Path classes = base.resolve("classes");
+ − 52
tb.createDirectories(classes);
+ − 53
+ − 54
String log = tb.new JavacTask()
+ − 55
.options("-Xmodule:java.compiler")
+ − 56
.outdir(classes)
+ − 57
.files(findJavaFiles(src))
+ − 58
.run()
+ − 59
.writeAll()
+ − 60
.getOutput(ToolBox.OutputKind.DIRECT);
+ − 61
+ − 62
if (!log.isEmpty())
+ − 63
throw new Exception("expected output not found: " + log);
+ − 64
}
+ − 65
+ − 66
@Test
+ − 67
void testSourcePath(Path base) throws Exception {
+ − 68
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 69
Path src = base.resolve("src");
+ − 70
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }");
+ − 71
Path classes = base.resolve("classes");
+ − 72
tb.createDirectories(classes);
+ − 73
+ − 74
String log = tb.new JavacTask()
+ − 75
.options("-Xmodule:java.compiler", "-sourcepath", src.toString())
+ − 76
.outdir(classes)
+ − 77
.files(src.resolve("javax/lang/model/element/Extra.java"))
+ − 78
.run()
+ − 79
.writeAll()
+ − 80
.getOutput(ToolBox.OutputKind.DIRECT);
+ − 81
+ − 82
if (!log.isEmpty())
+ − 83
throw new Exception("expected output not found: " + log);
+ − 84
}
+ − 85
+ − 86
@Test
+ − 87
void testClassPath(Path base) throws Exception {
+ − 88
Path cpSrc = base.resolve("cpSrc");
+ − 89
tb.writeJavaFiles(cpSrc, "package p; public interface Other { }");
+ − 90
Path cpClasses = base.resolve("cpClasses");
+ − 91
tb.createDirectories(cpClasses);
+ − 92
+ − 93
String cpLog = tb.new JavacTask()
+ − 94
.outdir(cpClasses)
+ − 95
.files(findJavaFiles(cpSrc))
+ − 96
.run()
+ − 97
.writeAll()
+ − 98
.getOutput(ToolBox.OutputKind.DIRECT);
+ − 99
+ − 100
if (!cpLog.isEmpty())
+ − 101
throw new Exception("expected output not found: " + cpLog);
+ − 102
+ − 103
Path src = base.resolve("src");
+ − 104
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 105
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }");
+ − 106
Path classes = base.resolve("classes");
+ − 107
tb.createDirectories(classes);
+ − 108
+ − 109
String log = tb.new JavacTask()
+ − 110
.options("-Xmodule:java.compiler", "-classpath", cpClasses.toString())
+ − 111
.outdir(classes)
+ − 112
.files(src.resolve("javax/lang/model/element/Extra.java"))
+ − 113
.run()
+ − 114
.writeAll()
+ − 115
.getOutput(ToolBox.OutputKind.DIRECT);
+ − 116
+ − 117
if (!log.isEmpty())
+ − 118
throw new Exception("expected output not found: " + log);
+ − 119
}
+ − 120
+ − 121
@Test
+ − 122
void testNoModuleInfoOnSourcePath(Path base) throws Exception {
+ − 123
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 124
Path src = base.resolve("src");
+ − 125
tb.writeJavaFiles(src,
+ − 126
"module java.compiler {}",
+ − 127
"package javax.lang.model.element; public interface Extra { }");
+ − 128
Path classes = base.resolve("classes");
+ − 129
tb.createDirectories(classes);
+ − 130
+ − 131
List<String> log = tb.new JavacTask()
+ − 132
.options("-XDrawDiagnostics", "-Xmodule:java.compiler")
+ − 133
.outdir(classes)
+ − 134
.files(findJavaFiles(src))
+ − 135
.run(ToolBox.Expect.FAIL)
+ − 136
.writeAll()
+ − 137
.getOutputLines(ToolBox.OutputKind.DIRECT);
+ − 138
+ − 139
List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.sourcepath",
+ − 140
"1 error");
+ − 141
+ − 142
if (!expected.equals(log))
+ − 143
throw new Exception("expected output not found: " + log);
+ − 144
}
+ − 145
+ − 146
@Test
+ − 147
void testNoModuleInfoInClassOutput(Path base) throws Exception {
+ − 148
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 149
Path srcMod = base.resolve("src-mod");
+ − 150
tb.writeJavaFiles(srcMod,
+ − 151
"module mod {}");
+ − 152
Path classes = base.resolve("classes");
+ − 153
tb.createDirectories(classes);
+ − 154
+ − 155
String logMod = tb.new JavacTask()
+ − 156
.options()
+ − 157
.outdir(classes)
+ − 158
.files(findJavaFiles(srcMod))
+ − 159
.run()
+ − 160
.writeAll()
+ − 161
.getOutput(ToolBox.OutputKind.DIRECT);
+ − 162
+ − 163
if (!logMod.isEmpty())
+ − 164
throw new Exception("unexpected output found: " + logMod);
+ − 165
+ − 166
Path src = base.resolve("src");
+ − 167
tb.writeJavaFiles(src,
+ − 168
"package javax.lang.model.element; public interface Extra { }");
+ − 169
tb.createDirectories(classes);
+ − 170
+ − 171
List<String> log = tb.new JavacTask()
+ − 172
.options("-XDrawDiagnostics", "-Xmodule:java.compiler")
+ − 173
.outdir(classes)
+ − 174
.files(findJavaFiles(src))
+ − 175
.run(ToolBox.Expect.FAIL)
+ − 176
.writeAll()
+ − 177
.getOutputLines(ToolBox.OutputKind.DIRECT);
+ − 178
+ − 179
List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath",
+ − 180
"1 error");
+ − 181
+ − 182
if (!expected.equals(log))
+ − 183
throw new Exception("expected output not found: " + log);
+ − 184
}
+ − 185
+ − 186
@Test
+ − 187
void testModuleSourcePathXModule(Path base) throws Exception {
+ − 188
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 189
Path src = base.resolve("src");
+ − 190
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
+ − 191
Path classes = base.resolve("classes");
+ − 192
tb.createDirectories(classes);
+ − 193
+ − 194
List<String> log = tb.new JavacTask()
+ − 195
.options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-modulesourcepath", src.toString())
+ − 196
.outdir(classes)
+ − 197
.files(findJavaFiles(src))
+ − 198
.run(ToolBox.Expect.FAIL)
+ − 199
.writeAll()
+ − 200
.getOutputLines(ToolBox.OutputKind.DIRECT);
+ − 201
+ − 202
List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath",
+ − 203
"1 error");
+ − 204
+ − 205
if (!expected.equals(log))
+ − 206
throw new Exception("expected output not found: " + log);
+ − 207
}
+ − 208
+ − 209
@Test
+ − 210
void testXModuleTooMany(Path base) throws Exception {
+ − 211
//note: avoiding use of java.base, as that gets special handling on some places:
+ − 212
Path src = base.resolve("src");
+ − 213
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
+ − 214
Path classes = base.resolve("classes");
+ − 215
tb.createDirectories(classes);
+ − 216
+ − 217
List<String> log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
+ − 218
.options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler")
+ − 219
.outdir(classes)
+ − 220
.files(findJavaFiles(src))
+ − 221
.run(ToolBox.Expect.FAIL)
+ − 222
.writeAll()
+ − 223
.getOutputLines(ToolBox.OutputKind.DIRECT);
+ − 224
+ − 225
List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once",
+ − 226
"Usage: javac <options> <source files>",
+ − 227
"use -help for a list of possible options");
+ − 228
+ − 229
if (!expected.equals(log))
+ − 230
throw new Exception("expected output not found: " + log);
+ − 231
}
+ − 232
+ − 233
@Test
+ − 234
void testWithModulePath(Path base) throws Exception {
+ − 235
Path module = base.resolve("modules");
+ − 236
new ModuleBuilder("m1")
+ − 237
.classes("package pkg1; public interface E { }")
+ − 238
.build(module);
+ − 239
+ − 240
Path src = base.resolve("src");
+ − 241
tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
+ − 242
+ − 243
tb.new JavacTask(ToolBox.Mode.CMDLINE)
+ − 244
.options("-modulepath", module.toString(),
+ − 245
"-Xmodule:m1")
+ − 246
.files(findJavaFiles(src))
+ − 247
.run()
+ − 248
.writeAll();
+ − 249
+ − 250
//checks module bounds still exist
+ − 251
new ModuleBuilder("m2")
+ − 252
.classes("package pkg2; public interface D { }")
+ − 253
.build(module);
+ − 254
+ − 255
Path src2 = base.resolve("src2");
+ − 256
tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
+ − 257
+ − 258
List<String> log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
+ − 259
.options("-XDrawDiagnostics",
+ − 260
"-modulepath", module.toString(),
+ − 261
"-Xmodule:m1")
+ − 262
.files(findJavaFiles(src2))
+ − 263
.run(ToolBox.Expect.FAIL)
+ − 264
.writeAll()
+ − 265
.getOutputLines(ToolBox.OutputKind.DIRECT);
+ − 266
+ − 267
List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2",
+ − 268
"1 error");
+ − 269
+ − 270
if (!expected.equals(log))
+ − 271
throw new Exception("expected output not found: " + log);
+ − 272
}
+ − 273
+ − 274
@Test
+ − 275
void testWithUpgradeModulePath(Path base) throws Exception {
+ − 276
Path module = base.resolve("modules");
+ − 277
new ModuleBuilder("m1")
+ − 278
.classes("package pkg1; public interface E { }")
+ − 279
.build(module);
+ − 280
+ − 281
Path upgrade = base.resolve("upgrade");
+ − 282
new ModuleBuilder("m1")
+ − 283
.classes("package pkg1; public interface D { }")
+ − 284
.build(upgrade);
+ − 285
+ − 286
Path src = base.resolve("src");
+ − 287
tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
+ − 288
+ − 289
tb.new JavacTask(ToolBox.Mode.CMDLINE)
+ − 290
.options("-modulepath", module.toString(),
+ − 291
"-upgrademodulepath", upgrade.toString(),
+ − 292
"-Xmodule:m1")
+ − 293
.files(findJavaFiles(src))
+ − 294
.run()
+ − 295
.writeAll();
+ − 296
}
+ − 297
}