# HG changeset patch # User jlahoda # Date 1486490368 -3600 # Tue Feb 07 18:59:28 2017 +0100 # Node ID 8d517ebc414a7fd97ecc3b1cac18fcb12e36d3d4 # Parent 31f3cfd70930e3ed8f7a2e4baf980377873b06c1 imported patch xmodule-to-patch-module diff --git a/src/java.compiler/share/classes/javax/tools/StandardLocation.java b/src/java.compiler/share/classes/javax/tools/StandardLocation.java --- a/src/java.compiler/share/classes/javax/tools/StandardLocation.java +++ b/src/java.compiler/share/classes/javax/tools/StandardLocation.java @@ -102,7 +102,14 @@ * Location to search for precompiled user modules. * @since 9 */ - MODULE_PATH; + MODULE_PATH, + + /** + * Location to search for module patches. + * @since 9 + * @spec JPMS + */ + PATCH_MODULE_PATH; /** * Returns a location object with the given name. The following @@ -158,6 +165,7 @@ case UPGRADE_MODULE_PATH: case SYSTEM_MODULES: case MODULE_PATH: + case PATCH_MODULE_PATH: return true; default: return false; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java @@ -361,7 +361,7 @@ @Override @DefinedBy(Api.COMPILER) public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException { try { - return clientJavaFileManager.getLocationForModule(location, fo, pkgName); + return clientJavaFileManager.getLocationForModule(location, unwrap(fo), pkgName); } catch (ClientCodeException e) { throw e; } catch (RuntimeException | Error e) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java @@ -553,20 +553,39 @@ Location classLocn = msym.classLocation; Location sourceLocn = msym.sourceLocation; + Location patchLocn = msym.patchLocation; - if (wantClassFiles && (classLocn != null)) { - fillIn(p, classLocn, - list(classLocn, - p, - packageName, - classKinds)); - } - if (wantSourceFiles && (sourceLocn != null)) { - fillIn(p, sourceLocn, - list(sourceLocn, - p, - packageName, - sourceKinds)); + boolean prevPreferCurrent = preferCurrent; + + try { + preferCurrent = false; + if ((wantClassFiles || wantSourceFiles) && (patchLocn != null)) { + Set combined = EnumSet.noneOf(JavaFileObject.Kind.class); + combined.addAll(classKinds); + combined.addAll(sourceKinds); + fillIn(p, patchLocn, + list(patchLocn, + p, + packageName, + combined)); + } + preferCurrent = true; + if (wantClassFiles && (classLocn != null)) { + fillIn(p, classLocn, + list(classLocn, + p, + packageName, + classKinds)); + } + if (wantSourceFiles && (sourceLocn != null)) { + fillIn(p, sourceLocn, + list(sourceLocn, + p, + packageName, + sourceKinds)); + } + } finally { + preferCurrent = prevPreferCurrent; } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java @@ -287,6 +287,9 @@ } else { msym.classLocation = l; } + if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) { + msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, msym.name.toString()); + } if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES || moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) { msym.flags_field |= Flags.SYSTEM_MODULE; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java @@ -907,6 +907,7 @@ public Name version; public JavaFileManager.Location sourceLocation; + public JavaFileManager.Location patchLocation; public JavaFileManager.Location classLocation; /** All directives, in natural order. */ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java @@ -145,7 +145,7 @@ public final boolean multiModuleMode; - private final String moduleOverride; + private final String legacyModuleOverride; private final Name java_se; private final Name java_; @@ -192,7 +192,7 @@ lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option); - moduleOverride = options.get(Option.XMODULE); + legacyModuleOverride = options.get(Option.XMODULE); multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH); ClassWriter classWriter = ClassWriter.instance(context); @@ -366,9 +366,17 @@ JavaFileObject prev = log.useSource(tree.sourcefile); try { - Location locn = getModuleLocation(tree); - if (locn != null) { - Name name = names.fromString(fileManager.inferModuleName(locn)); + Location msplocn = getModuleLocation(tree); + Location plocn = fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) ? + fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, + tree.sourcefile, getPackageName(tree)) : + null; + + if (msplocn != null) { + if (plocn != null) { + log.error(tree.pos(), Errors.FilePatchedAndMsp); + } + Name name = names.fromString(fileManager.inferModuleName(msplocn)); ModuleSymbol msym; JCModuleDecl decl = tree.getModuleDecl(); if (decl != null) { @@ -383,7 +391,7 @@ msym = syms.enterModule(name); } if (msym.sourceLocation == null) { - msym.sourceLocation = locn; + msym.sourceLocation = msplocn; if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { msym.classLocation = fileManager.getLocationForModule( StandardLocation.CLASS_OUTPUT, msym.name.toString()); @@ -391,6 +399,11 @@ } tree.modle = msym; rootModules.add(msym); + } else if (plocn != null) { + Name name = names.fromString(fileManager.inferModuleName(plocn)); + ModuleSymbol msym = moduleFinder.findModule(name); + tree.modle = msym; + rootModules.add(msym); } else if (c != null && c.packge().modle == syms.unnamedModule) { tree.modle = syms.unnamedModule; } else { @@ -414,7 +427,9 @@ } defaultModule = syms.unnamedModule; } else { + ModuleSymbol module = null; if (defaultModule == null) { + String moduleOverride = singleModuleOverride(trees); switch (rootModules.size()) { case 0: defaultModule = moduleFinder.findSingleModule(); @@ -422,38 +437,48 @@ if (moduleOverride != null) { checkNoAllModulePath(); defaultModule = moduleFinder.findModule(names.fromString(moduleOverride)); - defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; + if (legacyModuleOverride != null) { + defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; + } } else { // Question: why not do findAllModules and initVisiblePackages here? // i.e. body of unnamedModuleCompleter defaultModule.completer = getUnnamedModuleCompleter(); + defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; defaultModule.classLocation = StandardLocation.CLASS_PATH; } } else { - checkSpecifiedModule(trees, Errors.ModuleInfoWithXmoduleClasspath); + checkSpecifiedModule(trees, moduleOverride, Errors.ModuleInfoWithPatchedModuleClasspath); checkNoAllModulePath(); defaultModule.complete(); // Question: why not do completeModule here? defaultModule.completer = sym -> completeModule((ModuleSymbol) sym); + defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; } rootModules.add(defaultModule); break; case 1: - checkSpecifiedModule(trees, Errors.ModuleInfoWithXmoduleSourcepath); + checkSpecifiedModule(trees, moduleOverride, Errors.ModuleInfoWithPatchedModuleSourcepath); checkNoAllModulePath(); defaultModule = rootModules.iterator().next(); + defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; defaultModule.classLocation = StandardLocation.CLASS_OUTPUT; break; default: Assert.error("too many modules"); } - defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; } else if (rootModules.size() == 1 && defaultModule == rootModules.iterator().next()) { defaultModule.complete(); defaultModule.completer = sym -> completeModule((ModuleSymbol) sym); } else { Assert.check(rootModules.isEmpty()); - rootModules.add(defaultModule); + String moduleOverride = singleModuleOverride(trees); + if (moduleOverride != null) { + module = moduleFinder.findModule(names.fromString(moduleOverride)); + } else { + module = defaultModule; + } + rootModules.add(module); } if (defaultModule != syms.unnamedModule) { @@ -461,12 +486,60 @@ syms.unnamedModule.classLocation = StandardLocation.CLASS_PATH; } + if (module == null) { + module = defaultModule; + } + for (JCCompilationUnit tree: trees) { - tree.modle = defaultModule; + tree.modle = module; } } } + private String singleModuleOverride(List trees) { + if (!fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) { + return legacyModuleOverride; + } + + Set override = new LinkedHashSet<>(); + for (JCCompilationUnit tree : trees) { + JavaFileObject fo = tree.sourcefile; + + try { + Location loc = + fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, + fo, getPackageName(tree)); + + if (loc != null) { + try { + override.add(fileManager.inferModuleName(loc)); + } catch (IOException ex) { + throw new Error(ex); + } + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + switch (override.size()) { + case 0: return legacyModuleOverride; + case 1: return override.iterator().next(); + default: + log.error(Errors.TooManyPatchedModules(override)); + return null; + } + } + + private String getPackageName(JCCompilationUnit tree) { + if (tree.getModuleDecl() != null) { + return null; + } else { + JCPackageDecl pkg = tree.getPackage(); + return (pkg == null) ? "" : TreeInfo.fullName(pkg.pid).toString(); + } + } + /** * Determine the location for the module on the module source path * or source output directory which contains a given CompilationUnit. @@ -478,32 +551,23 @@ * @throws IOException if there is a problem while searching for the module. */ private Location getModuleLocation(JCCompilationUnit tree) throws IOException { - Name pkgName; - if (tree.getModuleDecl() != null) { - pkgName = null; - } else { - JCPackageDecl pkg = tree.getPackage(); - pkgName = (pkg == null) ? names.empty : TreeInfo.fullName(pkg.pid); - } - + String pkgName = getPackageName(tree); JavaFileObject fo = tree.sourcefile; - // For now, just check module source path. - // We may want to check source path as well. Location loc = fileManager.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, - fo, (pkgName == null) ? null : pkgName.toString()); + fo, (pkgName == null) ? null : pkgName); if (loc == null) { Location sourceOutput = fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT) ? StandardLocation.SOURCE_OUTPUT : StandardLocation.CLASS_OUTPUT; loc = fileManager.getLocationForModule(sourceOutput, - fo, (pkgName == null) ? null : pkgName.toString()); + fo, (pkgName == null) ? null : pkgName); } return loc; } - private void checkSpecifiedModule(List trees, JCDiagnostic.Error error) { + private void checkSpecifiedModule(List trees, String moduleOverride, JCDiagnostic.Error error) { if (moduleOverride != null) { JavaFileObject prev = log.useSource(trees.head.sourcefile); try { @@ -1600,8 +1664,8 @@ } public void newRound() { + allModules = null; rootModules = null; - allModules = null; warnedMissing.clear(); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java @@ -980,7 +980,7 @@ public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException { checkModuleOrientedOrOutputLocation(location); if (!(fo instanceof PathFileObject)) - throw new IllegalArgumentException(fo.getName()); + return null; int depth = 1; // allow 1 for filename if (pkgName != null && !pkgName.isEmpty()) { depth += 1; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java @@ -432,7 +432,7 @@ /** * @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String) */ - Location getLocationForModule(Path dir) { + Location getLocationForModule(Path dir) throws IOException { return null; } @@ -545,7 +545,7 @@ l = new ModuleLocationHandler(location.getName() + "[" + name + "]", name, Collections.singleton(out), - true, false); + true); moduleLocations.put(name, l); pathLocations.put(out.toAbsolutePath(), l); } @@ -864,29 +864,14 @@ protected final String name; protected final String moduleName; protected final Collection searchPath; - protected final Collection searchPathWithOverrides; protected final boolean output; ModuleLocationHandler(String name, String moduleName, Collection searchPath, - boolean output, boolean allowOverrides) { + boolean output) { this.name = name; this.moduleName = moduleName; this.searchPath = searchPath; this.output = output; - - if (allowOverrides && patchMap != null) { - SearchPath mPatch = patchMap.get(moduleName); - if (mPatch != null) { - SearchPath sp = new SearchPath(); - sp.addAll(mPatch); - sp.addAll(searchPath); - searchPathWithOverrides = sp; - } else { - searchPathWithOverrides = searchPath; - } - } else { - searchPathWithOverrides = searchPath; - } } @Override @DefinedBy(Api.COMPILER) @@ -909,7 +894,7 @@ // For now, we always return searchPathWithOverrides. This may differ from the // JVM behavior if there is a module-info.class to be found in the overriding // classes. - return searchPathWithOverrides; + return searchPath; } @Override // defined by LocationHandler @@ -1063,7 +1048,7 @@ String name = location.getName() + "[" + pathIndex + ":" + moduleName + "]"; ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName, - Collections.singleton(path), false, true); + Collections.singleton(path), false); return Collections.singleton(l); } catch (ModuleNameReader.BadClassFile e) { log.error(Errors.LocnBadModuleInfo(path)); @@ -1088,7 +1073,7 @@ String name = location.getName() + "[" + pathIndex + "." + (index++) + ":" + moduleName + "]"; ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName, - Collections.singleton(modulePath), false, true); + Collections.singleton(modulePath), false); result.add(l); } return result; @@ -1105,7 +1090,7 @@ String name = location.getName() + "[" + pathIndex + ":" + moduleName + "]"; ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName, - Collections.singleton(modulePath), false, true); + Collections.singleton(modulePath), false); return Collections.singleton(l); } @@ -1272,7 +1257,7 @@ pathLocations = new LinkedHashMap<>(); map.forEach((k, v) -> { String name = location.getName() + "[" + k + "]"; - ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false, false); + ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false); moduleLocations.put(k, h); v.forEach(p -> pathLocations.put(normalize(p), h)); }); @@ -1412,6 +1397,7 @@ private Path systemJavaHome; private Path modules; private Map systemModules; + private Map pathLocations; SystemModulesLocationHandler() { super(StandardLocation.SYSTEM_MODULES, Option.SYSTEM); @@ -1486,6 +1472,12 @@ } @Override + Location getLocationForModule(Path dir) throws IOException { + initSystemModules(); + return (pathLocations == null) ? null : pathLocations.get(dir); + } + + @Override Iterable> listLocationsForModules() throws IOException { initSystemModules(); Set locns = new LinkedHashSet<>(); @@ -1539,18 +1531,106 @@ } systemModules = new LinkedHashMap<>(); + pathLocations = new LinkedHashMap<>(); try (DirectoryStream stream = Files.newDirectoryStream(modules, Files::isDirectory)) { for (Path entry : stream) { String moduleName = entry.getFileName().toString(); String name = location.getName() + "[" + moduleName + "]"; ModuleLocationHandler h = new ModuleLocationHandler(name, moduleName, - Collections.singleton(entry), false, true); + Collections.singleton(entry), false); systemModules.put(moduleName, h); + pathLocations.put(normalize(entry), h); } } } } + private class PatchModulesLocationHandler extends BasicLocationHandler { + private final Map moduleLocations = new HashMap<>(); + private final Map pathLocations = new HashMap<>(); + + PatchModulesLocationHandler() { + super(StandardLocation.PATCH_MODULE_PATH, Option.PATCH_MODULE); + } + + @Override + boolean handleOption(Option option, String value) { + if (!options.contains(option)) { + return false; + } + + // Allow an extended syntax for --patch-module consisting of a series + // of values separated by NULL characters. This is to facilitate + // supporting deferred file manager options on the command line. + // See Option.PATCH_MODULE for the code that composes these multiple + // values. + for (String v : value.split("\0")) { + int eq = v.indexOf('='); + if (eq > 0) { + String moduleName = v.substring(0, eq); + SearchPath mPatchPath = new SearchPath() + .addFiles(v.substring(eq + 1)); + boolean ok = true; + for (Path p : mPatchPath) { + Path mi = p.resolve("module-info.class"); + if (Files.exists(mi)) { + log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi)); + ok = false; + } + } + if (ok) { + String name = location.getName() + "[" + moduleName + "]"; + ModuleLocationHandler h = new ModuleLocationHandler(name, moduleName, mPatchPath, false); + moduleLocations.put(moduleName, h); + for (Path r : mPatchPath) { + pathLocations.put(normalize(r), h); + } + } + } else { + // Should not be able to get here; + // this should be caught and handled in Option.PATCH_MODULE + log.error(Errors.LocnInvalidArgForXpatch(value)); + } + } + + return true; + } + + @Override + boolean isSet() { + return !moduleLocations.isEmpty(); + } + + @Override + Collection getPaths() { + throw new UnsupportedOperationException(); + } + + @Override + void setPaths(Iterable files) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + Location getLocationForModule(String name) throws IOException { + return moduleLocations.get(name); + } + + @Override + Location getLocationForModule(Path dir) throws IOException { + return (pathLocations == null) ? null : pathLocations.get(dir); + } + + @Override + Iterable> listLocationsForModules() throws IOException { + Set locns = new LinkedHashSet<>(); + for (Location l: moduleLocations.values()) + locns.add(l); + return Collections.singleton(locns); + } + + } + Map handlersForLocation; Map handlersForOption; @@ -1568,6 +1648,7 @@ new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S), new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H), new ModuleSourcePathLocationHandler(), + new PatchModulesLocationHandler(), // TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES? new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH), new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH), @@ -1582,51 +1663,9 @@ } } - private Map patchMap; - boolean handleOption(Option option, String value) { - switch (option) { - case PATCH_MODULE: - if (value == null) { - patchMap = null; - } else { - // Allow an extended syntax for --patch-module consisting of a series - // of values separated by NULL characters. This is to facilitate - // supporting deferred file manager options on the command line. - // See Option.PATCH_MODULE for the code that composes these multiple - // values. - for (String v : value.split("\0")) { - int eq = v.indexOf('='); - if (eq > 0) { - String mName = v.substring(0, eq); - SearchPath mPatchPath = new SearchPath() - .addFiles(v.substring(eq + 1)); - boolean ok = true; - for (Path p : mPatchPath) { - Path mi = p.resolve("module-info.class"); - if (Files.exists(mi)) { - log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi)); - ok = false; - } - } - if (ok) { - if (patchMap == null) { - patchMap = new LinkedHashMap<>(); - } - patchMap.put(mName, mPatchPath); - } - } else { - // Should not be able to get here; - // this should be caught and handled in Option.PATCH_MODULE - log.error(Errors.LocnInvalidArgForXpatch(value)); - } - } - } - return true; - default: - LocationHandler h = handlersForOption.get(option); - return (h == null ? false : h.handleOption(option, value)); - } + LocationHandler h = handlersForOption.get(option); + return (h == null ? false : h.handleOption(option, value)); } boolean hasLocation(Location location) { @@ -1665,7 +1704,7 @@ return (h == null ? null : h.getLocationForModule(name)); } - Location getLocationForModule(Location location, Path dir) { + Location getLocationForModule(Location location, Path dir) throws IOException { LocationHandler h = getHandler(location); return (h == null ? null : h.getLocationForModule(dir)); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java @@ -598,9 +598,6 @@ && !fm.hasLocation(StandardLocation.CLASS_OUTPUT)) { log.error(Errors.NoOutputDir); } - if (options.isSet(Option.XMODULE)) { - log.error(Errors.XmoduleNoModuleSourcepath); - } } if (fm.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH) && diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -1448,6 +1448,11 @@ return; } + if (!modules.multiModuleMode && env.toplevel.modle != modules.getDefaultModule()) { + //can only generate classfiles for a single module: + return; + } + if (compileStates.isDone(env, CompileState.LOWER)) { results.addAll(desugaredEnvs.get(env)); return; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java @@ -579,7 +579,7 @@ } }, - XMODULE("-Xmodule:", "opt.arg.module", "opt.module", EXTENDED, BASIC) { + XMODULE("-Xmodule:", "opt.arg.module", "opt.module", HIDDEN, BASIC) { @Override public void process(OptionHelper helper, String option, String arg) throws InvalidValueException { String prev = helper.get(XMODULE); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -2950,14 +2950,18 @@ 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.xmodule.sourcepath=\ - illegal combination of -Xmodule and module-info on sourcepath - -compiler.err.module-info.with.xmodule.classpath=\ - illegal combination of -Xmodule and module-info on classpath - -compiler.err.xmodule.no.module.sourcepath=\ - illegal combination of -Xmodule and --module-source-path +compiler.err.module-info.with.patched.module.sourcepath=\ + compiling a patch module with module-info on sourcepath + +compiler.err.module-info.with.patched.module.classpath=\ + compiling a patch module with module-info on classpath + +# 0: set of string +compiler.err.too.many.patched.modules=\ + too many patched modules ({0}), use --module-source-path + +compiler.err.file.patched.and.msp=\ + file accessible from both --module-source-path and --patch-module compiler.err.processorpath.no.processormodulepath=\ illegal combination of -processorpath and --processor-module-path diff --git a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java --- a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java +++ b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java @@ -204,13 +204,6 @@ } }, - XMODULE("-Xmodule:", false) { - @Override - public void process(Helper helper, String arg) throws InvalidValueException { - Option.XMODULE.process(helper.getOptionHelper(), arg); - } - }, - PATCH_MODULE("--patch-module", true) { @Override public void process(Helper helper, String arg) throws InvalidValueException { diff --git a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties --- a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties +++ b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties @@ -82,7 +82,6 @@ \ Specify additional modules to be considered as required by a\n\ \ given module. may be ALL-UNNAMED to require\n\ \ the unnamed module.\n\ -\ -Xmodule: Specify a module to which the classes being compiled belong.\n\ \ --patch-module =(:)*\n\ \ Override or augment a module with classes and resources\n\ \ in JAR files or directories\n diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java @@ -181,13 +181,6 @@ } }, - XMODULE("-Xmodule:", EXTENDED, false) { - @Override - public void process(Helper helper, String arg) throws InvalidValueException { - Option.XMODULE.process(helper.getOptionHelper(), arg); - } - }, - PATCH_MODULE("--patch-module", EXTENDED, true) { @Override public void process(Helper helper, String arg) throws InvalidValueException { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties @@ -238,11 +238,6 @@ given module. may be ALL-UNNAMED to require\n\ the unnamed module. -main.opt.Xmodule.arg=\ - -main.opt.Xmodule.desc=\ - Specify a module to which the classes being compiled belong - main.opt.patch.module.arg=\ =(:)* main.opt.patch.module.desc=\ diff --git a/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java b/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java --- a/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java @@ -30,8 +30,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.URI; import java.nio.file.FileSystems; import java.nio.file.Files; @@ -71,10 +69,6 @@ private final JShell proc; - // Upcoming Jigsaw - private Method inferModuleNameMethod = null; - private Method listLocationsForModulesMethod = null; - Iterable getLocationAsPaths(Location loc) { return this.stdFileManager.getLocationAsPaths(loc); } @@ -184,43 +178,6 @@ return new SourceMemoryJavaFileObject(origin, name, code); } - // Make compatible with Jigsaw - public String inferModuleName(Location location) { - try { - if (inferModuleNameMethod == null) { - inferModuleNameMethod = JavaFileManager.class.getDeclaredMethod("inferModuleName", Location.class); - } - @SuppressWarnings("unchecked") - String result = (String) inferModuleNameMethod.invoke(stdFileManager, location); - return result; - } catch (NoSuchMethodException | SecurityException ex) { - throw new InternalError("Cannot lookup JavaFileManager method", ex); - } catch (IllegalAccessException | - IllegalArgumentException | - InvocationTargetException ex) { - throw new InternalError("Cannot invoke JavaFileManager method", ex); - } - } - - // Make compatible with Jigsaw - public Iterable> listLocationsForModules(Location location) throws IOException { - try { - if (listLocationsForModulesMethod == null) { - listLocationsForModulesMethod = JavaFileManager.class.getDeclaredMethod("listLocationsForModules", Location.class); - } - @SuppressWarnings("unchecked") - Iterable> result = (Iterable>) listLocationsForModulesMethod.invoke(stdFileManager, location); - return result; - } catch (NoSuchMethodException | SecurityException ex) { - throw new InternalError("Cannot lookup JavaFileManager method", ex); - } catch (IllegalAccessException | - IllegalArgumentException | - InvocationTargetException ex) { - throw new InternalError("Cannot invoke JavaFileManager method", ex); - } - } - - /** * Returns a class loader for loading plug-ins from the given location. For * example, to load annotation processors, a compiler will request a class @@ -580,6 +537,26 @@ ", sibling: " + sibling); } + @Override + public Location getLocationForModule(Location location, String moduleName) throws IOException { + return stdFileManager.getLocationForModule(location, moduleName); + } + + @Override + public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException { + return stdFileManager.getLocationForModule(location, fo, pkgName); + } + + @Override + public String inferModuleName(Location location) throws IOException { + return stdFileManager.inferModuleName(location); + } + + @Override + public Iterable> listLocationsForModules(Location location) throws IOException { + return stdFileManager.listLocationsForModules(location); + } + /** * Flushes any resources opened for output by this file manager * directly or indirectly. Flushing a closed file manager has no diff --git a/test/tools/javac/6627362/T6627362.java b/test/tools/javac/6627362/T6627362.java --- a/test/tools/javac/6627362/T6627362.java +++ b/test/tools/javac/6627362/T6627362.java @@ -68,9 +68,9 @@ // compile and disassemble E.java, using modified Object.java, // check for reference to System.arraycopy File x = new File(testSrc, "x"); - String[] jcArgs = { "-d", ".", "-Xmodule:java.base", + String[] jcArgs = { "-d", ".", "--patch-module", "java.base=" + x.getAbsolutePath(), new File(x, "E.java").getPath(), - new File(x, "Object.java").getPath()}; + new File(new File(new File(x, "java"), "lang"), "Object.java").getPath()}; compile(jcArgs); String[] jpArgs = { "-classpath", ".", "-c", "E" }; diff --git a/test/tools/javac/6627362/x/Object.java b/test/tools/javac/6627362/x/java/lang/Object.java rename from test/tools/javac/6627362/x/Object.java rename to test/tools/javac/6627362/x/java/lang/Object.java diff --git a/test/tools/javac/diags/Example.java b/test/tools/javac/diags/Example.java --- a/test/tools/javac/diags/Example.java +++ b/test/tools/javac/diags/Example.java @@ -63,6 +63,7 @@ procFiles = new ArrayList(); srcPathFiles = new ArrayList(); moduleSourcePathFiles = new ArrayList(); + patchModulePathFiles = new ArrayList(); modulePathFiles = new ArrayList(); classPathFiles = new ArrayList(); additionalFiles = new ArrayList(); @@ -88,6 +89,9 @@ } else if (files == srcFiles && c.getName().equals("modulesourcepath")) { moduleSourcePathDir = c; findFiles(c, moduleSourcePathFiles); + } else if (files == srcFiles && c.getName().equals("patchmodule")) { + patchModulePathDir = c; + findFiles(c, patchModulePathFiles); } else if (files == srcFiles && c.getName().equals("additional")) { additionalFilesDir = c; findFiles(c, additionalFiles); @@ -272,6 +276,16 @@ files.addAll(nonEmptySrcFiles); // srcFiles containing declarations } + if (patchModulePathDir != null) { + for (File mod : patchModulePathDir.listFiles()) { + opts.add("--patch-module"); + opts.add(mod.getName() + "=" + mod.getPath()); + } + files = new ArrayList<>(); + files.addAll(patchModulePathFiles); + files.addAll(nonEmptySrcFiles); // srcFiles containing declarations + } + if (additionalFiles.size() > 0) { List sOpts = Arrays.asList("-d", classesDir.getPath()); new Jsr199Compiler(verbose).run(null, null, false, sOpts, additionalFiles); @@ -343,9 +357,11 @@ List procFiles; File srcPathDir; File moduleSourcePathDir; + File patchModulePathDir; File additionalFilesDir; List srcPathFiles; List moduleSourcePathFiles; + List patchModulePathFiles; List modulePathFiles; List classPathFiles; List additionalFiles; diff --git a/test/tools/javac/diags/examples.not-yet.txt b/test/tools/javac/diags/examples.not-yet.txt --- a/test/tools/javac/diags/examples.not-yet.txt +++ b/test/tools/javac/diags/examples.not-yet.txt @@ -5,6 +5,7 @@ compiler.err.cant.read.file # (apt.JavaCompiler?) compiler.err.cant.select.static.class.from.param.type compiler.err.dc.unterminated.string # cannot happen +compiler.err.file.patched.and.msp # needs the same dir on --module-source-path and --patch-module compiler.err.illegal.char.for.encoding compiler.err.invalid.repeatable.annotation # should not happen compiler.err.invalid.repeatable.annotation.invalid.value # "can't" happen diff --git a/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/ModuleInfoWithXmoduleClasspath.java b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/ModuleInfoWithXmoduleClasspath.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/ModuleInfoWithXmoduleClasspath.java @@ -0,0 +1,24 @@ +/* + * 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.classpath diff --git a/test/tools/javac/diags/examples/ModuleInfoWithXmoduleClasspath/additional/module-info.java b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/additional/module-info.java rename from test/tools/javac/diags/examples/ModuleInfoWithXmoduleClasspath/additional/module-info.java rename to test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/additional/module-info.java diff --git a/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/patchmodule/java.compiler/javax/lang/model/element/Extra.java b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/patchmodule/java.compiler/javax/lang/model/element/Extra.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleClasspath/patchmodule/java.compiler/javax/lang/model/element/Extra.java @@ -0,0 +1,26 @@ +/* + * 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 {} diff --git a/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/ModuleInfoWithPatchedModuleSourcePath.java b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/ModuleInfoWithPatchedModuleSourcePath.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/ModuleInfoWithPatchedModuleSourcePath.java @@ -0,0 +1,24 @@ +/* + * 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 diff --git a/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/patchmodule/java.compiler/javax/lang/model/element/Extra.java b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/patchmodule/java.compiler/javax/lang/model/element/Extra.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/patchmodule/java.compiler/javax/lang/model/element/Extra.java @@ -0,0 +1,26 @@ +/* + * 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 {} diff --git a/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/patchmodule/java.compiler/module-info.java b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/patchmodule/java.compiler/module-info.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/ModuleInfoWithPatchedModuleSourcePath/patchmodule/java.compiler/module-info.java @@ -0,0 +1,24 @@ +/* + * 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 {} diff --git a/test/tools/javac/diags/examples/ModuleInfoWithXModuleSourcePath/Extra.java b/test/tools/javac/diags/examples/ModuleInfoWithXModuleSourcePath/Extra.java deleted file mode 100644 --- a/test/tools/javac/diags/examples/ModuleInfoWithXModuleSourcePath/Extra.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2016, 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.xmodule.sourcepath -// options: -Xmodule:java.compiler - -package javax.lang.model.element; - -public interface Extra {} diff --git a/test/tools/javac/diags/examples/ModuleInfoWithXModuleSourcePath/module-info.java b/test/tools/javac/diags/examples/ModuleInfoWithXModuleSourcePath/module-info.java deleted file mode 100644 --- a/test/tools/javac/diags/examples/ModuleInfoWithXModuleSourcePath/module-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2016, 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 {} diff --git a/test/tools/javac/diags/examples/ModuleInfoWithXmoduleClasspath/ModuleInfoWithXmoduleClasspath.java b/test/tools/javac/diags/examples/ModuleInfoWithXmoduleClasspath/ModuleInfoWithXmoduleClasspath.java deleted file mode 100644 --- a/test/tools/javac/diags/examples/ModuleInfoWithXmoduleClasspath/ModuleInfoWithXmoduleClasspath.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2016, 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.xmodule.classpath -// options: -Xmodule:java.compiler - -package javax.lang.model.element; - -public interface ModuleInfoWithXModuleClasspath {} diff --git a/test/tools/javac/diags/examples/NoSuperclass.java b/test/tools/javac/diags/examples/NoSuperclass.java deleted file mode 100644 --- a/test/tools/javac/diags/examples/NoSuperclass.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2010, 2016, 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.no.superclass -// options: -Xmodule:java.base - -package java.lang; - -class Object { - public Object() { - super(); - } -} diff --git a/test/tools/javac/diags/examples/NoSuperclass/NoSuperclass.java b/test/tools/javac/diags/examples/NoSuperclass/NoSuperclass.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/NoSuperclass/NoSuperclass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 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.no.superclass diff --git a/test/tools/javac/diags/examples/NoSuperclass/patchmodule/java.base/java/lang/Object.java b/test/tools/javac/diags/examples/NoSuperclass/patchmodule/java.base/java/lang/Object.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/NoSuperclass/patchmodule/java.base/java/lang/Object.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 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 java.lang; + +class Object { + public Object() { + super(); + } +} diff --git a/test/tools/javac/diags/examples/TooManyPatchedModules/TooManyPatchedModules.java b/test/tools/javac/diags/examples/TooManyPatchedModules/TooManyPatchedModules.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/TooManyPatchedModules/TooManyPatchedModules.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +// key: compiler.err.too.many.patched.modules diff --git a/test/tools/javac/diags/examples/TooManyPatchedModules/patchmodule/java.compiler/p/C.java b/test/tools/javac/diags/examples/TooManyPatchedModules/patchmodule/java.compiler/p/C.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/TooManyPatchedModules/patchmodule/java.compiler/p/C.java @@ -0,0 +1,25 @@ +/* + * 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. + */ +package p; + +class C {} diff --git a/test/tools/javac/diags/examples/TooManyPatchedModules/patchmodule/jdk.compiler/p/C.java b/test/tools/javac/diags/examples/TooManyPatchedModules/patchmodule/jdk.compiler/p/C.java new file mode 100644 --- /dev/null +++ b/test/tools/javac/diags/examples/TooManyPatchedModules/patchmodule/jdk.compiler/p/C.java @@ -0,0 +1,25 @@ +/* + * 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. + */ +package p; + +class C {} diff --git a/test/tools/javac/diags/examples/XModuleWithModulePath/XModuleWithModulePath.java b/test/tools/javac/diags/examples/XModuleWithModulePath/XModuleWithModulePath.java deleted file mode 100644 --- a/test/tools/javac/diags/examples/XModuleWithModulePath/XModuleWithModulePath.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2016, 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.xmodule.no.module.sourcepath -// options: -Xmodule:java.compiler --module-source-path src - -class XModuleWithModulePath {} diff --git a/test/tools/javac/meth/BadPolySig.java b/test/tools/javac/meth/BadPolySig/BadPolySig.java rename from test/tools/javac/meth/BadPolySig.java rename to test/tools/javac/meth/BadPolySig/BadPolySig.java --- a/test/tools/javac/meth/BadPolySig.java +++ b/test/tools/javac/meth/BadPolySig/BadPolySig.java @@ -1,12 +1,30 @@ +/* + * 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. + */ + /* * @test * @bug 8168774 * @summary Polymorhic signature method check crashes javac - * @compile -Xmodule:java.base BadPolySig.java + * @modules jdk.compiler + * @compile/module=java.base java/lang/invoke/MethodHandle.java */ - -package java.lang.invoke; - -class MethodHandle { - native Object m(); -} diff --git a/test/tools/javac/meth/BadPolySig.java b/test/tools/javac/meth/BadPolySig/java.base/java/lang/invoke/MethodHandle.java copy from test/tools/javac/meth/BadPolySig.java copy to test/tools/javac/meth/BadPolySig/java.base/java/lang/invoke/MethodHandle.java --- a/test/tools/javac/meth/BadPolySig.java +++ b/test/tools/javac/meth/BadPolySig/java.base/java/lang/invoke/MethodHandle.java @@ -1,8 +1,24 @@ /* - * @test - * @bug 8168774 - * @summary Polymorhic signature method check crashes javac - * @compile -Xmodule:java.base BadPolySig.java + * 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 java.lang.invoke; diff --git a/test/tools/javac/modules/AddLimitMods.java b/test/tools/javac/modules/AddLimitMods.java --- a/test/tools/javac/modules/AddLimitMods.java +++ b/test/tools/javac/modules/AddLimitMods.java @@ -293,7 +293,7 @@ } actual = new JavacTask(tb) - .options("-Xmodule:java.base", + .options("--patch-module", "java.base=" + cpSrc.toString(), "-XDrawDiagnostics", "--add-modules", "ALL-MODULE-PATH") .outdir(cpOut) diff --git a/test/tools/javac/modules/AddReadsTest.java b/test/tools/javac/modules/AddReadsTest.java --- a/test/tools/javac/modules/AddReadsTest.java +++ b/test/tools/javac/modules/AddReadsTest.java @@ -217,7 +217,7 @@ new JavacTask(tb) .options("--class-path", jar.toString(), "--add-reads", "java.base=ALL-UNNAMED", - "-Xmodule:java.base") + "--patch-module", "java.base=" + src.toString()) .outdir(classes) .files(src.resolve("impl").resolve("Impl.java")) .run() @@ -237,7 +237,7 @@ new JavacTask(tb) .options("--add-modules", "java.desktop", "--add-reads", "java.base=java.desktop", - "-Xmodule:java.base") + "--patch-module", "java.base=" + src) .outdir(classes) .files(findJavaFiles(src)) .run() @@ -304,7 +304,7 @@ new JavacTask(tb) .options("--add-reads", "m1x=ALL-UNNAMED", - "-Xmodule:m1x", + "--patch-module", "m1x=" + unnamedSrc.toString(), "--module-path", classes.toString()) .outdir(unnamedClasses) .files(findJavaFiles(unnamedSrc)) diff --git a/test/tools/javac/modules/InheritRuntimeEnvironmentTest.java b/test/tools/javac/modules/InheritRuntimeEnvironmentTest.java --- a/test/tools/javac/modules/InheritRuntimeEnvironmentTest.java +++ b/test/tools/javac/modules/InheritRuntimeEnvironmentTest.java @@ -177,7 +177,7 @@ Files.createDirectories(patch); new JavacTask(tb) - .options("-Xmodule:java.base") + .options("--patch-module", "java.base=" + patchSrc.toString()) .outdir(patch) .sourcepath(patchSrc) .files(findJavaFiles(patchSrc)) diff --git a/test/tools/javac/modules/PatchModulesTest.java b/test/tools/javac/modules/PatchModulesTest.java --- a/test/tools/javac/modules/PatchModulesTest.java +++ b/test/tools/javac/modules/PatchModulesTest.java @@ -28,7 +28,7 @@ * @library /tools/lib * @modules * jdk.compiler/com.sun.tools.javac.api - * jdk.compiler/com.sun.tools.javac.file:+open + * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.main * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase * @run main PatchModulesTest @@ -38,21 +38,26 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.lang.reflect.Field; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.AbstractMap.SimpleEntry; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; +import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileObject; import javax.tools.ToolProvider; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; import com.sun.source.util.JavacTask; import com.sun.tools.javac.api.JavacTool; -import com.sun.tools.javac.file.BaseFileManager; import com.sun.tools.javac.file.JavacFileManager; -import com.sun.tools.javac.file.Locations; import static java.util.Arrays.asList; @@ -115,21 +120,29 @@ void test(List patches, boolean expectOK, String expect) throws Exception { JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); StringWriter sw = new StringWriter(); - try (PrintWriter pw = new PrintWriter(sw)) { - JavacFileManager fm = tool.getStandardFileManager(null, null, null); + try (PrintWriter pw = new PrintWriter(sw); + JavacFileManager fm = tool.getStandardFileManager(null, null, null)) { List opts = patches.stream() .map(p -> "--patch-module=" + p.replace(":", PS)) .collect(Collectors.toList()); Iterable files = fm.getJavaFileObjects("C.java"); JavacTask task = tool.getTask(pw, fm, null, opts, null, files); - Field locationsField = BaseFileManager.class.getDeclaredField("locations"); - locationsField.setAccessible(true); - Object locations = locationsField.get(fm); + Map> mod2Location = + StreamSupport.stream(fm.listLocationsForModules(StandardLocation.PATCH_MODULE_PATH) + .spliterator(), + false) + .flatMap(sl -> sl.stream()) + .collect(Collectors.groupingBy(l -> fm.inferModuleName(l))); - Field patchMapField = Locations.class.getDeclaredField("patchMap"); - patchMapField.setAccessible(true); - Map patchMap = (Map) patchMapField.get(locations); + Map> patchMap = mod2Location.entrySet() + .stream() + .map(e -> new SimpleEntry<>(e.getKey(), e.getValue().get(0))) + .map(e -> new SimpleEntry<>(e.getKey(), locationPaths(fm, e.getValue()))) + .collect(Collectors.toMap(Entry :: getKey, + Entry :: getValue, + (v1, v2) -> {throw new IllegalStateException();}, + TreeMap::new)); String found = patchMap.toString(); if (!found.equals(expect)) { @@ -150,5 +163,34 @@ } } } + + static List locationPaths(StandardJavaFileManager fm, Location loc) { + return StreamSupport.stream(fm.getLocationAsPaths(loc).spliterator(), false) + .map(p -> p.toString()) + .collect(Collectors.toList()); + } + + @Test + public void testPatchWithSource(Path base) throws Exception { + Path patch = base.resolve("patch"); + tb.writeJavaFiles(patch, "package javax.lang.model.element; public interface Extra { }"); + Path src = base.resolve("src"); + tb.writeJavaFiles(src, + "module m { requires java.compiler; }", + "package test; public interface Test extends javax.lang.model.element.Extra { }"); + Path classes = base.resolve("classes"); + tb.createDirectories(classes); + + new toolbox.JavacTask(tb) + .options("--patch-module", "java.compiler=" + patch.toString()) + .outdir(classes) + .files(findJavaFiles(src)) + .run() + .writeAll(); + + if (Files.exists(classes.resolve("javax"))) { + throw new AssertionError(); + } + } } diff --git a/test/tools/javac/modules/XModuleTest.java b/test/tools/javac/modules/XModuleTest.java --- a/test/tools/javac/modules/XModuleTest.java +++ b/test/tools/javac/modules/XModuleTest.java @@ -23,6 +23,7 @@ /* * @test + * @bug 8173777 * @summary tests for multi-module mode compilation * @library /tools/lib * @modules @@ -34,6 +35,7 @@ * @run main XModuleTest */ +import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.List; @@ -69,7 +71,7 @@ tb.createDirectories(classes); String log = new JavacTask(tb) - .options("-Xmodule:java.compiler") + .options("--patch-module", "java.compiler=" + src.toString()) .outdir(classes) .files(findJavaFiles(src)) .run() @@ -81,23 +83,140 @@ } @Test - public void testSourcePath(Path base) throws Exception { + public void testCorrectXModuleMultiModule(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, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }"); + Path m1 = src.resolve("m1"); + tb.writeJavaFiles(m1, "package javax.lang.model.element; public interface Extra extends Element { }"); + Path m2 = src.resolve("m2"); + tb.writeJavaFiles(m2, "package com.sun.source.tree; public interface Extra extends Tree { }"); Path classes = base.resolve("classes"); tb.createDirectories(classes); String log = new JavacTask(tb) - .options("-Xmodule:java.compiler", "-sourcepath", src.toString()) + .options("--patch-module", "java.compiler=" + m1.toString(), + "--patch-module", "jdk.compiler=" + m2.toString(), + "--module-source-path", "dummy") .outdir(classes) - .files(src.resolve("javax/lang/model/element/Extra.java")) + .files(findJavaFiles(src)) .run() .writeAll() .getOutput(Task.OutputKind.DIRECT); if (!log.isEmpty()) throw new Exception("expected output not found: " + log); + + checkFileExists(classes, "java.compiler/javax/lang/model/element/Extra.class"); + checkFileExists(classes, "jdk.compiler/com/sun/source/tree/Extra.class"); + } + + @Test + public void testCorrectXModuleMultiModule2(Path base) throws Exception { + //note: avoiding use of java.base, as that gets special handling on some places: + Path src = base.resolve("src"); + Path m1 = src.resolve("m1"); + tb.writeJavaFiles(m1, + "package javax.lang.model.element; public interface Extra extends Element { }"); + Path m2 = src.resolve("m2"); + tb.writeJavaFiles(m2, + "package com.sun.source.tree; public interface Extra extends Tree { }"); + Path msp = base.resolve("msp"); + Path m3 = msp.resolve("m3x"); + tb.writeJavaFiles(m3, + "module m3x { }", + "package m3; public class Test { }"); + Path m4 = msp.resolve("m4x"); + tb.writeJavaFiles(m4, + "module m4x { }", + "package m4; public class Test { }"); + Path classes = base.resolve("classes"); + tb.createDirectories(classes); + + String log = new JavacTask(tb) + .options("--patch-module", "java.compiler=" + m1.toString(), + "--patch-module", "jdk.compiler=" + m2.toString(), + "--module-source-path", msp.toString()) + .outdir(classes) + .files(findJavaFiles(src, msp)) + .run() + .writeAll() + .getOutput(Task.OutputKind.DIRECT); + + if (!log.isEmpty()) + throw new Exception("expected output not found: " + log); + + checkFileExists(classes, "java.compiler/javax/lang/model/element/Extra.class"); + checkFileExists(classes, "jdk.compiler/com/sun/source/tree/Extra.class"); + checkFileExists(classes, "m3x/m3/Test.class"); + checkFileExists(classes, "m4x/m4/Test.class"); + } + + @Test + public void testPatchModuleModuleSourcePathConflict(Path base) throws Exception { + //note: avoiding use of java.base, as that gets special handling on some places: + Path src = base.resolve("src"); + Path m1 = src.resolve("m1x"); + tb.writeJavaFiles(m1, + "module m1x { }", + "package m1; public class Test { }"); + Path m2 = src.resolve("m2x"); + tb.writeJavaFiles(m2, + "module m2x { }", + "package m2; public class Test { }"); + Path classes = base.resolve("classes"); + tb.createDirectories(classes); + + List log = new JavacTask(tb) + .options("--patch-module", "m1x=" + m1.toString(), + "--patch-module", "m2x=" + m2.toString(), + "--module-source-path", src.toString(), + "-XDrawDiagnostics") + .outdir(classes) + .files(findJavaFiles(src.resolve("m1x").resolve("m1"), + src.resolve("m2x").resolve("m2"))) + .run(Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + List expectedOut = Arrays.asList( + "Test.java:1:1: compiler.err.file.patched.and.msp", + "Test.java:1:1: compiler.err.file.patched.and.msp", + "module-info.java:1:1: compiler.err.file.patched.and.msp", + "- compiler.err.cant.access: m2x.module-info, (compiler.misc.cant.resolve.modules)", + "4 errors" + ); + + if (!expectedOut.equals(log)) + throw new Exception("expected output not found: " + log); + } + + @Test + public void testSourcePath(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, "package javax.lang.model.element; public interface Extra extends Element, Other { }"); + Path srcPath = base.resolve("src-path"); + tb.writeJavaFiles(srcPath, "package javax.lang.model.element; interface Other { }"); + Path classes = base.resolve("classes"); + tb.createDirectories(classes); + + List log = new JavacTask(tb) + .options("--patch-module", "java.compiler=" + src.toString(), + "-sourcepath", srcPath.toString(), + "-XDrawDiagnostics") + .outdir(classes) + .files(src.resolve("javax/lang/model/element/Extra.java")) + .run(Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + List expectedOut = Arrays.asList( + "Extra.java:1:75: compiler.err.cant.resolve: kindname.class, Other, , ", + "1 error" + ); + + if (!expectedOut.equals(log)) + throw new Exception("expected output not found: " + log); } @Test @@ -124,7 +243,7 @@ tb.createDirectories(classes); List log = new JavacTask(tb) - .options("-Xmodule:java.compiler", + .options("--patch-module", "java.compiler=" + src.toString(), "--class-path", cpClasses.toString(), "-XDrawDiagnostics") .outdir(classes) @@ -147,20 +266,23 @@ //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 srcPath = base.resolve("src-path"); + tb.writeJavaFiles(src, + "module java.compiler {}"); Path classes = base.resolve("classes"); tb.createDirectories(classes); List log = new JavacTask(tb) - .options("-XDrawDiagnostics", "-Xmodule:java.compiler") + .options("-XDrawDiagnostics", + "--patch-module", "java.compiler=" + src.toString()) .outdir(classes) .files(findJavaFiles(src)) .run(Task.Expect.FAIL) .writeAll() .getOutputLines(Task.OutputKind.DIRECT); - List expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.sourcepath", + List expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.patched.module.sourcepath", "1 error"); if (!expected.equals(log)) @@ -193,14 +315,15 @@ tb.createDirectories(classes); List log = new JavacTask(tb) - .options("-XDrawDiagnostics", "-Xmodule:java.compiler") + .options("-XDrawDiagnostics", + "--patch-module", "java.compiler=" + src.toString()) .outdir(classes) .files(findJavaFiles(src)) .run(Task.Expect.FAIL) .writeAll() .getOutputLines(Task.OutputKind.DIRECT); - List expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath", + List expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.patched.module.classpath", "1 error"); if (!expected.equals(log)) @@ -208,52 +331,6 @@ } @Test - public void testModuleSourcePathXModule(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, "package javax.lang.model.element; public interface Extra extends Element { }"); - Path classes = base.resolve("classes"); - tb.createDirectories(classes); - - List log = new JavacTask(tb) - .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "--module-source-path", src.toString()) - .outdir(classes) - .files(findJavaFiles(src)) - .run(Task.Expect.FAIL) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - List expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath"); - - if (!expected.equals(log)) - throw new Exception("expected output not found: " + log); - } - - @Test - public void testXModuleTooMany(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, "package javax.lang.model.element; public interface Extra extends Element { }"); - Path classes = base.resolve("classes"); - tb.createDirectories(classes); - - List log = new JavacTask(tb, Task.Mode.CMDLINE) - .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler") - .outdir(classes) - .files(findJavaFiles(src)) - .run(Task.Expect.FAIL) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - List expected = Arrays.asList("javac: option -Xmodule: can only be specified once", - "Usage: javac ", - "use --help for a list of possible options"); - - 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"); Path modules = base.resolve("modules"); @@ -266,7 +343,7 @@ new JavacTask(tb, Task.Mode.CMDLINE) .options("--module-path", modules.toString(), - "-Xmodule:m1") + "--patch-module", "m1=" + src.toString()) .files(findJavaFiles(src)) .run() .writeAll(); @@ -282,7 +359,7 @@ List log = new JavacTask(tb, Task.Mode.CMDLINE) .options("-XDrawDiagnostics", "--module-path", modules.toString(), - "-Xmodule:m1") + "--patch-module", "m1=" + src2.toString()) .files(findJavaFiles(src2)) .run(Task.Expect.FAIL) .writeAll() @@ -315,7 +392,7 @@ new JavacTask(tb, Task.Mode.CMDLINE) .options("--module-path", modules.toString(), "--upgrade-module-path", upgrade.toString(), - "-Xmodule:m1") + "--patch-module", "m1=" + src.toString()) .files(findJavaFiles(src)) .run() .writeAll(); @@ -365,7 +442,7 @@ tb.createDirectories(classes); String log = new JavacTask(tb) - .options("-Xmodule:m", + .options("--patch-module", "m=" + sourcePath.toString(), "--class-path", classPath.toString(), "--source-path", sourcePath.toString(), "--module-path", modulePath.toString(), @@ -419,4 +496,11 @@ } } + private void checkFileExists(Path dir, String path) { + Path toCheck = dir.resolve(path.replace("/", dir.getFileSystem().getSeparator())); + + if (!Files.exists(toCheck)) { + throw new AssertionError(toCheck.toString() + " does not exist!"); + } + } } diff --git a/test/tools/javac/synthesize/Main.java b/test/tools/javac/synthesize/Main.java --- a/test/tools/javac/synthesize/Main.java +++ b/test/tools/javac/synthesize/Main.java @@ -92,12 +92,17 @@ File empty = new File("empty"); empty.mkdirs(); + // files to compile are in a separate directory from test to avoid + // confusing jtreg + File src = new File(testSrc, "src"); + List args = new ArrayList(); args.add("-classpath"); args.add("empty"); if (stdBootClassPath) { - args.add("-Xmodule:java.base"); + args.add("--patch-module"); + args.add("java.base=" + testSrc.getAbsolutePath()); } else { args.add("--system"); args.add("none"); @@ -108,9 +113,6 @@ args.add("-d"); args.add("."); - // files to compile are in a separate directory from test to avoid - // confusing jtreg - File src = new File(testSrc, "src"); for (String f: files) args.add(new File(src, f).getPath()); diff --git a/test/tools/jdeps/jdkinternals/RemovedJDKInternals.java b/test/tools/jdeps/jdkinternals/RemovedJDKInternals.java --- a/test/tools/jdeps/jdkinternals/RemovedJDKInternals.java +++ b/test/tools/jdeps/jdkinternals/RemovedJDKInternals.java @@ -63,7 +63,7 @@ Path sunMiscSrc = Paths.get(TEST_SRC, "patches", JDK_UNSUPPORTED); Path patchDir = PATCHES_DIR.resolve(JDK_UNSUPPORTED); assertTrue(CompilerUtils.compile(sunMiscSrc, patchDir, - "-Xmodule:" + JDK_UNSUPPORTED)); + "--patch-module", JDK_UNSUPPORTED + "=" + sunMiscSrc.toString())); // compile com.sun.image.codec.jpeg types Path codecSrc = Paths.get(TEST_SRC, "patches", "java.desktop");