mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8175057: module-info on patch path should not produce an error
Allowing module-infos on patch paths during compilation. Reviewed-by: jjg, ksrini
This commit is contained in:
parent
4d045d7e88
commit
d60b98466f
13 changed files with 491 additions and 404 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -39,6 +39,7 @@ import javax.tools.JavaFileObject;
|
|||
import javax.tools.JavaFileObject.Kind;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
||||
import com.sun.tools.javac.code.Symbol.Completer;
|
||||
import com.sun.tools.javac.code.Symbol.CompletionFailure;
|
||||
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
|
||||
|
@ -90,7 +91,7 @@ public class ModuleFinder {
|
|||
|
||||
private ModuleNameReader moduleNameReader;
|
||||
|
||||
public ModuleInfoSourceFileCompleter sourceFileCompleter;
|
||||
public ModuleNameFromSourceReader moduleNameFromSourceReader;
|
||||
|
||||
/** Get the ModuleFinder instance for this invocation. */
|
||||
public static ModuleFinder instance(Context context) {
|
||||
|
@ -190,8 +191,6 @@ public class ModuleFinder {
|
|||
return list;
|
||||
}
|
||||
|
||||
private boolean inFindSingleModule;
|
||||
|
||||
public ModuleSymbol findSingleModule() {
|
||||
try {
|
||||
JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE);
|
||||
|
@ -204,49 +203,67 @@ public class ModuleFinder {
|
|||
if (fo == null) {
|
||||
msym = syms.unnamedModule;
|
||||
} else {
|
||||
msym = readModule(fo);
|
||||
}
|
||||
|
||||
if (msym.patchLocation == null) {
|
||||
msym.classLocation = StandardLocation.CLASS_OUTPUT;
|
||||
} else {
|
||||
msym.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
|
||||
}
|
||||
return msym;
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new Error(e); // FIXME
|
||||
}
|
||||
}
|
||||
|
||||
private ModuleSymbol readModule(JavaFileObject fo) throws IOException {
|
||||
Name name;
|
||||
switch (fo.getKind()) {
|
||||
case SOURCE:
|
||||
if (!inFindSingleModule) {
|
||||
try {
|
||||
inFindSingleModule = true;
|
||||
// Note: the following will trigger a re-entrant call to Modules.enter
|
||||
msym = sourceFileCompleter.complete(fo);
|
||||
msym.module_info.classfile = fo;
|
||||
} finally {
|
||||
inFindSingleModule = false;
|
||||
}
|
||||
} else {
|
||||
//the module-info.java does not contain a module declaration,
|
||||
//avoid infinite recursion:
|
||||
msym = syms.unnamedModule;
|
||||
name = moduleNameFromSourceReader.readModuleName(fo);
|
||||
if (name == null) {
|
||||
JCDiagnostic diag =
|
||||
diags.fragment("file.does.not.contain.module");
|
||||
ClassSymbol errModuleInfo = syms.defineClass(names.module_info, syms.errModule);
|
||||
throw new ClassFinder.BadClassFile(errModuleInfo, fo, diag, diags);
|
||||
}
|
||||
break;
|
||||
case CLASS:
|
||||
Name name;
|
||||
try {
|
||||
name = names.fromString(readModuleName(fo));
|
||||
} catch (BadClassFile | IOException ex) {
|
||||
//fillIn will report proper errors:
|
||||
name = names.error;
|
||||
}
|
||||
msym = syms.enterModule(name);
|
||||
msym.module_info.classfile = fo;
|
||||
msym.completer = Completer.NULL_COMPLETER;
|
||||
classFinder.fillIn(msym.module_info);
|
||||
break;
|
||||
default:
|
||||
Assert.error();
|
||||
msym = syms.unnamedModule;
|
||||
name = names.error;
|
||||
break;
|
||||
}
|
||||
|
||||
ModuleSymbol msym = syms.enterModule(name);
|
||||
msym.module_info.classfile = fo;
|
||||
if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && name != names.error) {
|
||||
msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, name.toString());
|
||||
|
||||
if (msym.patchLocation != null) {
|
||||
JavaFileObject patchFO = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
|
||||
patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), patchFO);
|
||||
patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), patchFO);
|
||||
|
||||
if (patchFO != null) {
|
||||
msym.module_info.classfile = patchFO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msym.classLocation = StandardLocation.CLASS_OUTPUT;
|
||||
msym.completer = Completer.NULL_COMPLETER;
|
||||
classFinder.fillIn(msym.module_info);
|
||||
|
||||
return msym;
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new Error(e); // FIXME
|
||||
}
|
||||
}
|
||||
|
||||
private String readModuleName(JavaFileObject jfo) throws IOException, ModuleNameReader.BadClassFile {
|
||||
|
@ -256,7 +273,7 @@ public class ModuleFinder {
|
|||
}
|
||||
|
||||
private JavaFileObject getModuleInfoFromLocation(Location location, Kind kind) throws IOException {
|
||||
if (!fileManager.hasLocation(location))
|
||||
if (location == null || !fileManager.hasLocation(location))
|
||||
return null;
|
||||
|
||||
return fileManager.getJavaFileForInput(location,
|
||||
|
@ -285,25 +302,21 @@ public class ModuleFinder {
|
|||
msym.patchLocation =
|
||||
fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
|
||||
msym.name.toString());
|
||||
checkModuleInfoOnLocation(msym.patchLocation, Kind.CLASS, Kind.SOURCE);
|
||||
if (msym.patchLocation != null &&
|
||||
multiModuleMode &&
|
||||
fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
|
||||
msym.patchOutputLocation =
|
||||
fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
|
||||
msym.name.toString());
|
||||
checkModuleInfoOnLocation(msym.patchOutputLocation, Kind.CLASS);
|
||||
}
|
||||
}
|
||||
if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
|
||||
if (msym.patchLocation == null) {
|
||||
msym.sourceLocation = l;
|
||||
if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
|
||||
msym.classLocation =
|
||||
fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
|
||||
msym.name.toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
msym.classLocation = l;
|
||||
}
|
||||
|
@ -332,34 +345,18 @@ public class ModuleFinder {
|
|||
return results.toList();
|
||||
}
|
||||
|
||||
private void checkModuleInfoOnLocation(Location location, Kind... kinds) throws IOException {
|
||||
if (location == null)
|
||||
return ;
|
||||
|
||||
for (Kind kind : kinds) {
|
||||
JavaFileObject file = fileManager.getJavaFileForInput(location,
|
||||
names.module_info.toString(),
|
||||
kind);
|
||||
if (file != null) {
|
||||
log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(file));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void findModuleInfo(ModuleSymbol msym) {
|
||||
try {
|
||||
JavaFileObject src_fo = (msym.sourceLocation == null) ? null
|
||||
: fileManager.getJavaFileForInput(msym.sourceLocation,
|
||||
names.module_info.toString(), Kind.SOURCE);
|
||||
JavaFileObject fo;
|
||||
|
||||
JavaFileObject class_fo = (msym.classLocation == null) ? null
|
||||
: fileManager.getJavaFileForInput(msym.classLocation,
|
||||
names.module_info.toString(), Kind.CLASS);
|
||||
fo = getModuleInfoFromLocation(msym.patchOutputLocation, Kind.CLASS);
|
||||
fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), fo);
|
||||
fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), fo);
|
||||
|
||||
JavaFileObject fo = (src_fo == null) ? class_fo :
|
||||
(class_fo == null) ? src_fo :
|
||||
classFinder.preferredFileObject(src_fo, class_fo);
|
||||
if (fo == null) {
|
||||
fo = getModuleInfoFromLocation(msym.classLocation, Kind.CLASS);
|
||||
fo = preferredFileObject(fo, getModuleInfoFromLocation(msym.sourceLocation, Kind.SOURCE));
|
||||
}
|
||||
|
||||
if (fo == null) {
|
||||
String moduleName = msym.sourceLocation == null && msym.classLocation != null ?
|
||||
|
@ -388,6 +385,12 @@ public class ModuleFinder {
|
|||
}
|
||||
}
|
||||
|
||||
private JavaFileObject preferredFileObject(JavaFileObject fo1, JavaFileObject fo2) {
|
||||
if (fo1 == null) return fo2;
|
||||
if (fo2 == null) return fo1;
|
||||
return classFinder.preferredFileObject(fo1, fo2);
|
||||
}
|
||||
|
||||
Fragment getDescription(StandardLocation l) {
|
||||
switch (l) {
|
||||
case MODULE_PATH: return Fragments.LocnModule_path;
|
||||
|
@ -399,8 +402,8 @@ public class ModuleFinder {
|
|||
}
|
||||
}
|
||||
|
||||
public interface ModuleInfoSourceFileCompleter {
|
||||
public ModuleSymbol complete(JavaFileObject file);
|
||||
public interface ModuleNameFromSourceReader {
|
||||
public Name readModuleName(JavaFileObject file);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -408,9 +408,18 @@ public class Modules extends JCTree.Visitor {
|
|||
}
|
||||
if (msym.sourceLocation == null) {
|
||||
msym.sourceLocation = msplocn;
|
||||
if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) {
|
||||
msym.patchLocation = fileManager.getLocationForModule(
|
||||
StandardLocation.PATCH_MODULE_PATH, msym.name.toString());
|
||||
}
|
||||
if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
|
||||
msym.classLocation = fileManager.getLocationForModule(
|
||||
Location outputLocn = fileManager.getLocationForModule(
|
||||
StandardLocation.CLASS_OUTPUT, msym.name.toString());
|
||||
if (msym.patchLocation == null) {
|
||||
msym.classLocation = outputLocn;
|
||||
} else {
|
||||
msym.patchOutputLocation = outputLocn;
|
||||
}
|
||||
}
|
||||
}
|
||||
tree.modle = msym;
|
||||
|
@ -460,7 +469,6 @@ public class Modules extends JCTree.Visitor {
|
|||
defaultModule.classLocation = StandardLocation.CLASS_PATH;
|
||||
}
|
||||
} else {
|
||||
checkSpecifiedModule(trees, moduleOverride, Errors.ModuleInfoWithPatchedModuleClassoutput);
|
||||
checkNoAllModulePath();
|
||||
defaultModule.complete();
|
||||
// Question: why not do completeModule here?
|
||||
|
@ -470,18 +478,30 @@ public class Modules extends JCTree.Visitor {
|
|||
rootModules.add(defaultModule);
|
||||
break;
|
||||
case 1:
|
||||
checkSpecifiedModule(trees, moduleOverride, Errors.ModuleInfoWithPatchedModuleSourcepath);
|
||||
checkNoAllModulePath();
|
||||
defaultModule = rootModules.iterator().next();
|
||||
defaultModule.sourceLocation = StandardLocation.SOURCE_PATH;
|
||||
if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) {
|
||||
try {
|
||||
defaultModule.patchLocation = fileManager.getLocationForModule(
|
||||
StandardLocation.PATCH_MODULE_PATH, defaultModule.name.toString());
|
||||
} catch (IOException ex) {
|
||||
throw new Error(ex);
|
||||
}
|
||||
}
|
||||
if (defaultModule.patchLocation == null) {
|
||||
defaultModule.classLocation = StandardLocation.CLASS_OUTPUT;
|
||||
} else {
|
||||
defaultModule.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Assert.error("too many modules");
|
||||
}
|
||||
} else if (rootModules.size() == 1 && defaultModule == rootModules.iterator().next()) {
|
||||
defaultModule.complete();
|
||||
defaultModule.completer = sym -> completeModule((ModuleSymbol) sym);
|
||||
} else if (rootModules.size() == 1) {
|
||||
module = rootModules.iterator().next();
|
||||
module.complete();
|
||||
module.completer = sym -> completeModule((ModuleSymbol) sym);
|
||||
} else {
|
||||
Assert.check(rootModules.isEmpty());
|
||||
String moduleOverride = singleModuleOverride(trees);
|
||||
|
@ -562,17 +582,6 @@ public class Modules extends JCTree.Visitor {
|
|||
return loc;
|
||||
}
|
||||
|
||||
private void checkSpecifiedModule(List<JCCompilationUnit> trees, String moduleOverride, JCDiagnostic.Error error) {
|
||||
if (moduleOverride != null) {
|
||||
JavaFileObject prev = log.useSource(trees.head.sourcefile);
|
||||
try {
|
||||
log.error(trees.head.pos(), error);
|
||||
} finally {
|
||||
log.useSource(prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNoAllModulePath() {
|
||||
if (addModsOpt != null && Arrays.asList(addModsOpt.split(",")).contains(ALL_MODULE_PATH)) {
|
||||
log.error(Errors.AddmodsAllModulePathInvalid);
|
||||
|
|
|
@ -69,12 +69,12 @@ import com.sun.tools.javac.tree.JCTree.JCExpression;
|
|||
import com.sun.tools.javac.tree.JCTree.JCLambda;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMemberReference;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.Tag;
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.DefinedBy.Api;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.Factory;
|
||||
import com.sun.tools.javac.util.Log.DiagnosticHandler;
|
||||
import com.sun.tools.javac.util.Log.DiscardDiagnosticHandler;
|
||||
import com.sun.tools.javac.util.Log.WriterKind;
|
||||
|
||||
import static com.sun.tools.javac.code.Kinds.Kind.*;
|
||||
|
@ -89,6 +89,8 @@ import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
|
|||
|
||||
import static javax.tools.StandardLocation.CLASS_OUTPUT;
|
||||
|
||||
import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
|
||||
|
||||
/** This class could be the main entry point for GJC when GJC is used as a
|
||||
* component in a larger software system. It provides operations to
|
||||
* construct a new compiler, and to run a new compiler on a set of source
|
||||
|
@ -340,13 +342,6 @@ public class JavaCompiler {
|
|||
protected final Symbol.Completer sourceCompleter =
|
||||
sym -> readSourceFile((ClassSymbol) sym);
|
||||
|
||||
protected final ModuleFinder.ModuleInfoSourceFileCompleter moduleInfoSourceFileCompleter =
|
||||
fo -> (ModuleSymbol) readSourceFile(parseImplicitFile(fo), null, tl -> {
|
||||
return tl.defs.nonEmpty() && tl.defs.head.hasTag(Tag.MODULEDEF) ?
|
||||
((JCModuleDecl) tl.defs.head).sym.module_info :
|
||||
syms.defineClass(names.module_info, syms.errModule);
|
||||
}).owner;
|
||||
|
||||
/**
|
||||
* Command line options.
|
||||
*/
|
||||
|
@ -417,7 +412,7 @@ public class JavaCompiler {
|
|||
diags = Factory.instance(context);
|
||||
|
||||
finder.sourceCompleter = sourceCompleter;
|
||||
moduleFinder.sourceFileCompleter = moduleInfoSourceFileCompleter;
|
||||
moduleFinder.moduleNameFromSourceReader = this::readModuleName;
|
||||
|
||||
options = Options.instance(context);
|
||||
|
||||
|
@ -787,19 +782,6 @@ public class JavaCompiler {
|
|||
readSourceFile(null, c);
|
||||
}
|
||||
|
||||
private JCTree.JCCompilationUnit parseImplicitFile(JavaFileObject filename) {
|
||||
JavaFileObject prev = log.useSource(filename);
|
||||
try {
|
||||
JCTree.JCCompilationUnit t = parse(filename, filename.getCharContent(false));
|
||||
return t;
|
||||
} catch (IOException e) {
|
||||
log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
|
||||
return make.TopLevel(List.nil());
|
||||
} finally {
|
||||
log.useSource(prev);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compile a ClassSymbol from source, optionally using the given compilation unit as
|
||||
* the source tree.
|
||||
* @param tree the compilation unit in which the given ClassSymbol resides,
|
||||
|
@ -810,20 +792,20 @@ public class JavaCompiler {
|
|||
if (completionFailureName == c.fullname) {
|
||||
throw new CompletionFailure(c, "user-selected completion failure by class name");
|
||||
}
|
||||
JavaFileObject filename = c.classfile;
|
||||
JavaFileObject prev = log.useSource(filename);
|
||||
|
||||
if (tree == null) {
|
||||
tree = parseImplicitFile(c.classfile);
|
||||
try {
|
||||
tree = parse(filename, filename.getCharContent(false));
|
||||
} catch (IOException e) {
|
||||
log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
|
||||
tree = make.TopLevel(List.<JCTree>nil());
|
||||
} finally {
|
||||
log.useSource(prev);
|
||||
}
|
||||
|
||||
readSourceFile(tree, c, cut -> c);
|
||||
}
|
||||
|
||||
private ClassSymbol readSourceFile(JCCompilationUnit tree,
|
||||
ClassSymbol expectedSymbol,
|
||||
Function<JCCompilationUnit, ClassSymbol> symbolGetter)
|
||||
throws CompletionFailure {
|
||||
Assert.checkNonNull(tree);
|
||||
|
||||
if (!taskListener.isEmpty()) {
|
||||
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
|
||||
taskListener.started(e);
|
||||
|
@ -835,20 +817,18 @@ public class JavaCompiler {
|
|||
// Note that if module resolution failed, we may not even
|
||||
// have enough modules available to access java.lang, and
|
||||
// so risk getting FatalError("no.java.lang") from MemberEnter.
|
||||
if (!modules.enter(List.of(tree), expectedSymbol)) {
|
||||
throw new CompletionFailure(symbolGetter.apply(tree),
|
||||
diags.fragment("cant.resolve.modules"));
|
||||
if (!modules.enter(List.of(tree), c)) {
|
||||
throw new CompletionFailure(c, diags.fragment("cant.resolve.modules"));
|
||||
}
|
||||
|
||||
enter.complete(List.of(tree), expectedSymbol);
|
||||
enter.complete(List.of(tree), c);
|
||||
|
||||
if (!taskListener.isEmpty()) {
|
||||
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
|
||||
taskListener.finished(e);
|
||||
}
|
||||
|
||||
ClassSymbol sym = symbolGetter.apply(tree);
|
||||
if (sym == null || enter.getEnv(sym) == null) {
|
||||
if (enter.getEnv(c) == null) {
|
||||
boolean isPkgInfo =
|
||||
tree.sourcefile.isNameCompatible("package-info",
|
||||
JavaFileObject.Kind.SOURCE);
|
||||
|
@ -859,26 +839,24 @@ public class JavaCompiler {
|
|||
if (enter.getEnv(tree.modle) == null) {
|
||||
JCDiagnostic diag =
|
||||
diagFactory.fragment("file.does.not.contain.module");
|
||||
throw new ClassFinder.BadClassFile(sym, tree.sourcefile, diag, diagFactory);
|
||||
throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
|
||||
}
|
||||
} else if (isPkgInfo) {
|
||||
if (enter.getEnv(tree.packge) == null) {
|
||||
JCDiagnostic diag =
|
||||
diagFactory.fragment("file.does.not.contain.package",
|
||||
sym.location());
|
||||
throw new ClassFinder.BadClassFile(sym, tree.sourcefile, diag, diagFactory);
|
||||
c.location());
|
||||
throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
|
||||
}
|
||||
} else {
|
||||
JCDiagnostic diag =
|
||||
diagFactory.fragment("file.doesnt.contain.class",
|
||||
sym.getQualifiedName());
|
||||
throw new ClassFinder.BadClassFile(sym, tree.sourcefile, diag, diagFactory);
|
||||
c.getQualifiedName());
|
||||
throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
|
||||
}
|
||||
}
|
||||
|
||||
implicitSourceFilesRead = true;
|
||||
|
||||
return sym;
|
||||
}
|
||||
|
||||
/** Track when the JavaCompiler has been used to compile something. */
|
||||
|
@ -1751,6 +1729,27 @@ public class JavaCompiler {
|
|||
return enterDone;
|
||||
}
|
||||
|
||||
private Name readModuleName(JavaFileObject fo) {
|
||||
return parseAndGetName(fo, t -> {
|
||||
JCModuleDecl md = t.getModuleDecl();
|
||||
|
||||
return md != null ? TreeInfo.fullName(md.getName()) : null;
|
||||
});
|
||||
}
|
||||
|
||||
private Name parseAndGetName(JavaFileObject fo,
|
||||
Function<JCTree.JCCompilationUnit, Name> tree2Name) {
|
||||
DiagnosticHandler dh = new DiscardDiagnosticHandler(log);
|
||||
try {
|
||||
JCTree.JCCompilationUnit t = parse(fo, fo.getCharContent(false));
|
||||
return tree2Name.apply(t);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
log.popDiagnosticHandler(dh);
|
||||
}
|
||||
}
|
||||
|
||||
/** Close the compiler, flushing the logs
|
||||
*/
|
||||
public void close() {
|
||||
|
|
|
@ -2961,12 +2961,6 @@ compiler.misc.module.non.zero.opens=\
|
|||
compiler.err.module.decl.sb.in.module-info.java=\
|
||||
module declarations should be in a file named module-info.java
|
||||
|
||||
compiler.err.module-info.with.patched.module.sourcepath=\
|
||||
compiling a module patch with module-info on sourcepath
|
||||
|
||||
compiler.err.module-info.with.patched.module.classoutput=\
|
||||
compiling a module patch with module-info on class output
|
||||
|
||||
# 0: set of string
|
||||
compiler.err.too.many.patched.modules=\
|
||||
too many patched modules ({0}), use --module-source-path
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.module-info.with.patched.module.classoutput
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
module mod {}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.lang.model.element;
|
||||
|
||||
public interface Extra {}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.module-info.with.patched.module.sourcepath
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.lang.model.element;
|
||||
|
||||
public interface Extra {}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
module java.compiler {}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -180,7 +180,9 @@ public class CompileModulePatchTest extends ModuleTestBase {
|
|||
|
||||
List<String> expectedOut = Arrays.asList(
|
||||
"Test.java:1:1: compiler.err.file.patched.and.msp: m1x, m2x",
|
||||
"1 error"
|
||||
"module-info.java:1:1: compiler.err.module.name.mismatch: m2x, m1x",
|
||||
"- compiler.err.cant.access: m1x.module-info, (compiler.misc.cant.resolve.modules)",
|
||||
"3 errors"
|
||||
);
|
||||
|
||||
if (!expectedOut.equals(log))
|
||||
|
@ -258,112 +260,6 @@ public class CompileModulePatchTest extends ModuleTestBase {
|
|||
throw new Exception("expected output not found: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoModuleInfoOnSourcePath(Path base) throws Exception {
|
||||
//note: avoiding use of java.base, as that gets special handling on some places:
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"module java.compiler {}",
|
||||
"package javax.lang.model.element; public interface Extra { }");
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
List<String> log;
|
||||
List<String> expected;
|
||||
|
||||
log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--patch-module", "java.compiler=" + src.toString())
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.patched.module.sourcepath",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found: " + log);
|
||||
|
||||
//multi-module mode:
|
||||
log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--patch-module", "java.compiler=" + src.toString(),
|
||||
"--module-source-path", "dummy")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
expected = Arrays.asList("- compiler.err.locn.module-info.not.allowed.on.patch.path: module-info.java",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoModuleInfoInClassOutput(Path base) throws Exception {
|
||||
//note: avoiding use of java.base, as that gets special handling on some places:
|
||||
Path srcMod = base.resolve("src-mod");
|
||||
tb.writeJavaFiles(srcMod,
|
||||
"module mod {}");
|
||||
Path classes = base.resolve("classes").resolve("java.compiler");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
String logMod = new JavacTask(tb)
|
||||
.options()
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(srcMod))
|
||||
.run()
|
||||
.writeAll()
|
||||
.getOutput(Task.OutputKind.DIRECT);
|
||||
|
||||
if (!logMod.isEmpty())
|
||||
throw new Exception("unexpected output found: " + logMod);
|
||||
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"package javax.lang.model.element; public interface Extra { }");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
List<String> log;
|
||||
List<String> expected;
|
||||
|
||||
log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--patch-module", "java.compiler=" + src.toString())
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.patched.module.classoutput",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found: " + log);
|
||||
|
||||
log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--patch-module", "java.compiler=" + src.toString(),
|
||||
"--module-source-path", "dummy")
|
||||
.outdir(classes.getParent())
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
expected = Arrays.asList("- compiler.err.locn.module-info.not.allowed.on.patch.path: module-info.class",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithModulePath(Path base) throws Exception {
|
||||
Path modSrc = base.resolve("modSrc");
|
||||
|
|
|
@ -269,13 +269,22 @@ public class EdgeCases extends ModuleTestBase {
|
|||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
new JavacTask(tb)
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("--source-path", src_m1.toString(),
|
||||
"-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src_m1.resolve("test")))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll();
|
||||
.writeAll()
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList(
|
||||
"- compiler.err.cant.access: module-info, (compiler.misc.bad.source.file.header: module-info.java, (compiler.misc.file.does.not.contain.module))",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log)) {
|
||||
throw new AssertionError("Unexpected output: " + log);
|
||||
}
|
||||
|
||||
tb.writeJavaFiles(src_m1,
|
||||
"module m1x {}");
|
||||
|
|
325
langtools/test/tools/javac/modules/ModuleInfoPatchPath.java
Normal file
325
langtools/test/tools/javac/modules/ModuleInfoPatchPath.java
Normal file
|
@ -0,0 +1,325 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8175057
|
||||
* @summary Verify that having module-info on patch path works correctly.
|
||||
* @library /tools/lib
|
||||
* @modules
|
||||
* jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.code
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
* jdk.compiler/com.sun.tools.javac.processing
|
||||
* jdk.compiler/com.sun.tools.javac.util
|
||||
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
|
||||
* @run main ModuleInfoPatchPath
|
||||
*/
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import toolbox.JavacTask;
|
||||
import toolbox.Task.OutputKind;
|
||||
|
||||
public class ModuleInfoPatchPath extends ModuleTestBase {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new ModuleInfoPatchPath().runTests();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModuleInfoToModulePath(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"module m { exports api; }",
|
||||
"package api; public class Api {}");
|
||||
Path patch = base.resolve("patch");
|
||||
tb.writeJavaFiles(patch,
|
||||
"module m { requires java.compiler; exports api; }",
|
||||
"package api; public class Api { public static javax.lang.model.element.Element element; }");
|
||||
Path classes = base.resolve("classes");
|
||||
Path mClasses = classes.resolve("m");
|
||||
tb.createDirectories(mClasses);
|
||||
|
||||
System.err.println("Building the vanilla module...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(src))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
Path test = base.resolve("test");
|
||||
tb.writeJavaFiles(test,
|
||||
"module test { requires m; }",
|
||||
"package test; public class Test { private void test() { api.Api.element = null; } }");
|
||||
|
||||
Path testClasses = classes.resolve("test");
|
||||
tb.createDirectories(testClasses);
|
||||
|
||||
System.err.println("Building patched module...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--module-path", mClasses.toString(),
|
||||
"--patch-module", "m=" + patch.toString())
|
||||
.outdir(testClasses)
|
||||
.files(findJavaFiles(test))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
Path patchClasses = classes.resolve("patch");
|
||||
tb.createDirectories(patchClasses);
|
||||
|
||||
System.err.println("Building patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.outdir(patchClasses)
|
||||
.files(findJavaFiles(patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
tb.cleanDirectory(testClasses);
|
||||
|
||||
Files.delete(patch.resolve("module-info.java"));
|
||||
Files.copy(patchClasses.resolve("module-info.class"), patch.resolve("module-info.class"));
|
||||
|
||||
System.err.println("Building patched module against binary patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--module-path", mClasses.toString(),
|
||||
"--patch-module", "m=" + patch.toString())
|
||||
.outdir(testClasses)
|
||||
.files(findJavaFiles(test))
|
||||
.run()
|
||||
.writeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModuleInfoToSourcePath(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"module m { exports api; }",
|
||||
"package api; public class Api {}",
|
||||
"package test; public class Test { private void test() { api.Api.element = null; } }");
|
||||
Path patch = base.resolve("patch");
|
||||
tb.writeJavaFiles(patch,
|
||||
"module m { requires java.compiler; exports api; }",
|
||||
"package api; public class Api { public static javax.lang.model.element.Element element; }");
|
||||
Path classes = base.resolve("classes");
|
||||
Path mClasses = classes.resolve("m");
|
||||
tb.createDirectories(mClasses);
|
||||
|
||||
System.err.println("Building patched module against source patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"-sourcepath", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(src.resolve("test")))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
//incremental compilation:
|
||||
List<String> log;
|
||||
|
||||
System.err.println("Incremental building of patched module against source patch, no module-info...");
|
||||
|
||||
log = new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"-sourcepath", src.toString(),
|
||||
"-verbose")
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(src.resolve("test")))
|
||||
.run()
|
||||
.writeAll()
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (log.stream().filter(line -> line.contains("[parsing started")).count() != 1) {
|
||||
throw new AssertionError("incorrect number of parsing events.");
|
||||
}
|
||||
|
||||
System.err.println("Incremental building of patched module against source patch, with module-info...");
|
||||
|
||||
log = new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"-sourcepath", src.toString(),
|
||||
"-verbose")
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(patch.resolve("module-info.java"), src.resolve("test")))
|
||||
.run()
|
||||
.writeAll()
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (log.stream().filter(line -> line.contains("[parsing started")).count() != 2) {
|
||||
throw new AssertionError("incorrect number of parsing events.");
|
||||
}
|
||||
|
||||
tb.cleanDirectory(mClasses);
|
||||
|
||||
System.err.println("Building patched module against source patch with source patch on patch path...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"-sourcepath", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(src.resolve("test"), patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
Path patchClasses = classes.resolve("patch");
|
||||
tb.createDirectories(patchClasses);
|
||||
|
||||
System.err.println("Building patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.outdir(patchClasses)
|
||||
.files(findJavaFiles(patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
tb.cleanDirectory(mClasses);
|
||||
|
||||
Files.delete(patch.resolve("module-info.java"));
|
||||
Files.copy(patchClasses.resolve("module-info.class"), patch.resolve("module-info.class"));
|
||||
|
||||
System.err.println("Building patched module against binary patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"-sourcepath", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(src.resolve("test")))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
tb.cleanDirectory(mClasses);
|
||||
|
||||
System.err.println("Building patched module against binary patch with source patch on patch path...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"-sourcepath", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(src.resolve("test"), patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModuleInfoToModuleSourcePath(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
Path m = src.resolve("m");
|
||||
tb.writeJavaFiles(m,
|
||||
"module m { exports api; }",
|
||||
"package api; public class Api {}",
|
||||
"package test; public class Test { private void test() { api.Api.element = null; } }");
|
||||
Path patch = base.resolve("patch");
|
||||
tb.writeJavaFiles(patch,
|
||||
"module m { requires java.compiler; exports api; }",
|
||||
"package api; public class Api { public static javax.lang.model.element.Element element; }");
|
||||
Path classes = base.resolve("classes");
|
||||
Path mClasses = classes.resolve("m");
|
||||
tb.createDirectories(mClasses);
|
||||
|
||||
System.err.println("Building patched module against source patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"--module-source-path", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(m.resolve("test")))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
//incremental compilation:
|
||||
|
||||
System.err.println("Incremental building of patched module against source patch...");
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"--module-source-path", src.toString(),
|
||||
"-verbose")
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(m.resolve("test")))
|
||||
.run()
|
||||
.writeAll()
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (log.stream().filter(line -> line.contains("[parsing started")).count() != 1) {
|
||||
throw new AssertionError("incorrect number of parsing events.");
|
||||
}
|
||||
|
||||
tb.cleanDirectory(mClasses);
|
||||
|
||||
System.err.println("Building patched module against source patch with source patch on patch path...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"--module-source-path", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(m.resolve("test"), patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
Path patchClasses = classes.resolve("patch");
|
||||
tb.createDirectories(patchClasses);
|
||||
|
||||
System.err.println("Building patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.outdir(patchClasses)
|
||||
.files(findJavaFiles(patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
tb.cleanDirectory(mClasses);
|
||||
|
||||
Files.delete(patch.resolve("module-info.java"));
|
||||
Files.copy(patchClasses.resolve("module-info.class"), patch.resolve("module-info.class"));
|
||||
|
||||
System.err.println("Building patched module against binary patch...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"--module-source-path", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(m.resolve("test")))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
tb.cleanDirectory(mClasses);
|
||||
|
||||
System.err.println("Building patched module against binary patch with source patch on patch path...");
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--patch-module", "m=" + patch.toString(),
|
||||
"--module-source-path", src.toString())
|
||||
.outdir(mClasses)
|
||||
.files(findJavaFiles(m.resolve("test"), patch))
|
||||
.run()
|
||||
.writeAll();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue