--- a/make/langtools/tools/propertiesparser/parser/MessageType.java Wed Apr 18 13:37:39 2018 -0400
+++ b/make/langtools/tools/propertiesparser/parser/MessageType.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, 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
@@ -86,13 +86,17 @@
NAME("name", "Name", "com.sun.tools.javac.util"),
NUMBER("number", "int", null),
OPTION_NAME("option name", "Option", "com.sun.tools.javac.main"),
+ PROFILE("profile", "Profile", "com.sun.tools.javac.jvm"),
+ SOURCE("source", "Source", "com.sun.tools.javac.code"),
SOURCE_VERSION("source version", "SourceVersion", "javax.lang.model"),
STRING("string", "String", null),
SYMBOL("symbol", "Symbol", "com.sun.tools.javac.code"),
SYMBOL_KIND("symbol kind", "Kind", "com.sun.tools.javac.code.Kinds"),
KIND_NAME("kind name", "KindName", "com.sun.tools.javac.code.Kinds"),
+ TARGET("target", "Target", "com.sun.tools.javac.jvm"),
TOKEN("token", "TokenKind", "com.sun.tools.javac.parser.Tokens"),
TYPE("type", "Type", "com.sun.tools.javac.code"),
+ URL("url", "URL", "java.net"),
SET("set", "Set", "java.util"),
LIST("list", "List", "java.util"),
OBJECT("object", "Object", null),
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, 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
@@ -172,7 +172,7 @@
if (compiler == null || compiler.errorCount() == 0
|| Options.instance(context).isSet("dev")) {
Log log = Log.instance(context);
- log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version());
+ log.printLines("msg.bug", JavaCompiler.version());
ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
return abnormalErrorResult;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java Wed Apr 18 16:02:53 2018 -0400
@@ -54,7 +54,6 @@
import com.sun.tools.doclint.DocLint;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.file.BaseFileManager;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.jvm.Profile;
@@ -66,6 +65,7 @@
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JCDiagnostic;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log;
@@ -295,7 +295,7 @@
String platformString = options.get(Option.RELEASE);
checkOptionAllowed(platformString == null,
- option -> error("err.release.bootclasspath.conflict", option.getPrimaryName()),
+ option -> reportDiag(Errors.ReleaseBootclasspathConflict(option)),
Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
Option.XBOOTCLASSPATH_PREPEND,
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
@@ -308,7 +308,7 @@
PlatformUtils.lookupPlatformDescription(platformString);
if (platformDescription == null) {
- error("err.unsupported.release.version", platformString);
+ reportDiag(Errors.UnsupportedReleaseVersion(platformString));
return false;
}
@@ -363,7 +363,7 @@
while (argIter.hasNext()) {
String arg = argIter.next();
if (arg.isEmpty()) {
- error("err.invalid.flag", arg);
+ reportDiag(Errors.InvalidFlag(arg));
return false;
}
@@ -392,7 +392,7 @@
}
// none of the above
- error("err.invalid.flag", arg);
+ reportDiag(Errors.InvalidFlag(arg));
return false;
}
@@ -457,9 +457,9 @@
if (!emptyAllowed) {
if (!errors) {
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
- error("err.no.source.files.classes");
+ reportDiag(Errors.NoSourceFilesClasses);
} else {
- error("err.no.source.files");
+ reportDiag(Errors.NoSourceFiles);
}
}
return false;
@@ -520,13 +520,9 @@
if (target.compareTo(source.requiredTarget()) < 0) {
if (targetString != null) {
if (sourceString == null) {
- error("warn.target.default.source.conflict",
- targetString,
- source.requiredTarget().name);
+ reportDiag(Warnings.TargetDefaultSourceConflict(targetString, source.requiredTarget()));
} else {
- error("warn.source.target.conflict",
- sourceString,
- source.requiredTarget().name);
+ reportDiag(Warnings.SourceTargetConflict(sourceString, source.requiredTarget()));
}
return false;
} else {
@@ -539,13 +535,11 @@
if (options.isSet(Option.PREVIEW)) {
if (sourceString == null) {
//enable-preview must be used with explicit -source or --release
- error("err.preview.without.source.or.release");
+ report(Errors.PreviewWithoutSourceOrRelease);
return false;
} else if (source != Source.DEFAULT) {
//enable-preview must be used with latest source version
- error("err.preview.not.latest",
- sourceString,
- Source.DEFAULT.name);
+ report(Errors.PreviewNotLatest(sourceString, Source.DEFAULT));
return false;
}
}
@@ -554,18 +548,18 @@
if (profileString != null) {
Profile profile = Profile.lookup(profileString);
if (!profile.isValid(target)) {
- error("warn.profile.target.conflict", profileString, target.name);
+ reportDiag(Warnings.ProfileTargetConflict(profile, target));
}
// This check is only effective in command line mode,
// where the file manager options are added to options
if (options.get(Option.BOOT_CLASS_PATH) != null) {
- error("err.profile.bootclasspath.conflict");
+ reportDiag(Errors.ProfileBootclasspathConflict);
}
}
if (options.isSet(Option.SOURCE_PATH) && options.isSet(Option.MODULE_SOURCE_PATH)) {
- error("err.sourcepath.modulesourcepath.conflict");
+ reportDiag(Errors.SourcepathModulesourcepathConflict);
}
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
@@ -586,15 +580,15 @@
}
if (target.compareTo(Target.MIN) < 0) {
- log.error(Errors.OptionRemovedTarget(target.name, Target.MIN.name));
+ log.error(Errors.OptionRemovedTarget(target, Target.MIN));
} else if (target == Target.MIN && lintOptions) {
- log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target.name));
+ log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target));
obsoleteOptionFound = true;
}
final Target t = target;
checkOptionAllowed(t.compareTo(Target.JDK1_8) <= 0,
- option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name),
+ option -> reportDiag(Errors.OptionNotAllowedWithTarget(option, t)),
Option.BOOT_CLASS_PATH,
Option.XBOOTCLASSPATH_PREPEND, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
@@ -602,7 +596,7 @@
Option.PROFILE);
checkOptionAllowed(t.compareTo(Target.JDK1_9) >= 0,
- option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name),
+ option -> reportDiag(Errors.OptionNotAllowedWithTarget(option, t)),
Option.MODULE_SOURCE_PATH, Option.UPGRADE_MODULE_PATH,
Option.SYSTEM, Option.MODULE_PATH, Option.ADD_MODULES,
Option.ADD_EXPORTS, Option.ADD_OPENS, Option.ADD_READS,
@@ -610,7 +604,7 @@
Option.PATCH_MODULE);
if (lintOptions && options.isSet(Option.PARAMETERS) && !target.hasMethodParameters()) {
- log.warning(Warnings.OptionParametersUnsupported(target.name, Target.JDK1_8.name));
+ log.warning(Warnings.OptionParametersUnsupported(target, Target.JDK1_8));
}
if (fm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
@@ -871,7 +865,7 @@
}
Path file = Paths.get(value);
if (Files.exists(file) && !Files.isDirectory(file)) {
- error("err.file.not.directory", value);
+ reportDiag(Errors.FileNotDirectory(value));
return false;
}
return true;
@@ -889,35 +883,19 @@
}
}
- void error(JCDiagnostic.Error error) {
+ void reportDiag(DiagnosticInfo diag) {
errors = true;
switch (errorMode) {
case ILLEGAL_ARGUMENT: {
- String msg = log.localize(error);
+ String msg = log.localize(diag);
throw new PropagatedException(new IllegalArgumentException(msg));
}
case ILLEGAL_STATE: {
- String msg = log.localize(error);
+ String msg = log.localize(diag);
throw new PropagatedException(new IllegalStateException(msg));
}
case LOG:
- report(error);
- }
- }
-
- void error(String key, Object... args) {
- errors = true;
- switch (errorMode) {
- case ILLEGAL_ARGUMENT: {
- String msg = log.localize(PrefixKind.JAVAC, key, args);
- throw new PropagatedException(new IllegalArgumentException(msg));
- }
- case ILLEGAL_STATE: {
- String msg = log.localize(PrefixKind.JAVAC, key, args);
- throw new PropagatedException(new IllegalStateException(msg));
- }
- case LOG:
- report(key, args);
+ report(diag);
}
}
@@ -932,22 +910,17 @@
throw new PropagatedException(new IllegalStateException(msg, f.getCause()));
}
case LOG:
- log.printRawLines(ownName + ": " + msg);
+ log.printRawLines(msg);
}
}
- void warning(String key, Object... args) {
- report(key, args);
- }
-
- private void report(String key, Object... args) {
+ private void report(DiagnosticInfo diag) {
// Would be good to have support for -XDrawDiagnostics here
- log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
- }
-
- private void report(JCDiagnostic.Error error) {
- // Would be good to have support for -XDrawDiagnostics here
- log.printRawLines(ownName + ": " + log.localize(error));
+ if (diag instanceof JCDiagnostic.Error) {
+ log.error((JCDiagnostic.Error)diag);
+ } else if (diag instanceof JCDiagnostic.Warning){
+ log.warning((JCDiagnostic.Warning)diag);
+ }
}
private JavaFileManager getFileManager() {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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
@@ -49,7 +49,9 @@
import com.sun.tools.javac.main.CommandLine.UnmatchedQuote;
import com.sun.tools.javac.platform.PlatformDescription;
import com.sun.tools.javac.processing.AnnotationProcessingError;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.util.*;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo;
import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.util.Log.WriterKind;
@@ -138,19 +140,22 @@
/** Report a usage error.
*/
- void error(String key, Object... args) {
+ void reportDiag(DiagnosticInfo diag) {
if (apiMode) {
- String msg = log.localize(PrefixKind.JAVAC, key, args);
+ String msg = log.localize(diag);
throw new PropagatedException(new IllegalStateException(msg));
}
- warning(key, args);
+ reportHelper(diag);
log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
- /** Report a warning.
+ /** Report helper.
*/
- void warning(String key, Object... args) {
- log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
+ void reportHelper(DiagnosticInfo diag) {
+ String msg = log.localize(diag);
+ String errorPrefix = log.localize(Errors.Error);
+ msg = msg.startsWith(errorPrefix) ? msg : errorPrefix + msg;
+ log.printRawLines(msg);
}
@@ -209,10 +214,10 @@
try {
argv = CommandLine.parse(ENV_OPT_NAME, argv);
} catch (UnmatchedQuote ex) {
- error("err.unmatched.quote", ex.variableName);
+ reportDiag(Errors.UnmatchedQuote(ex.variableName));
return Result.CMDERR;
} catch (FileNotFoundException | NoSuchFileException e) {
- warning("err.file.not.found", e.getMessage());
+ reportHelper(Errors.FileNotFound(e.getMessage()));
return Result.SYSERR;
} catch (IOException ex) {
log.printLines(PrefixKind.JAVAC, "msg.io");
@@ -366,11 +371,10 @@
CodeSource otherClassCodeSource = otherClass.getProtectionDomain().getCodeSource();
CodeSource javacCodeSource = this.getClass().getProtectionDomain().getCodeSource();
if (otherClassCodeSource != null && javacCodeSource != null) {
- log.printLines(PrefixKind.JAVAC, "err.two.class.loaders.2",
- otherClassCodeSource.getLocation(),
- javacCodeSource.getLocation());
+ log.printLines(Errors.TwoClassLoaders2(otherClassCodeSource.getLocation(),
+ javacCodeSource.getLocation()));
} else {
- log.printLines(PrefixKind.JAVAC, "err.two.class.loaders.1");
+ log.printLines(Errors.TwoClassLoaders1);
}
return true;
}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java Wed Apr 18 16:02:53 2018 -0400
@@ -59,6 +59,7 @@
import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.platform.PlatformProvider;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.PrefixKind;
@@ -197,7 +198,7 @@
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else if (getPattern().matcher(arg).matches()) {
String prev = helper.get(PATCH_MODULE);
if (prev == null) {
@@ -209,13 +210,13 @@
.collect(Collectors.toSet())
.contains(argModulePackage);
if (isRepeated) {
- throw helper.newInvalidValueException("err.repeated.value.for.patch.module", argModulePackage);
+ throw helper.newInvalidValueException(Errors.RepeatedValueForPatchModule(argModulePackage));
} else {
super.process(helper, option, prev + '\0' + arg);
}
}
} else {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
@@ -290,7 +291,7 @@
public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
Source source = Source.lookup(operand);
if (source == null) {
- throw helper.newInvalidValueException("err.invalid.source", operand);
+ throw helper.newInvalidValueException(Errors.InvalidSource(operand));
}
super.process(helper, option, operand);
}
@@ -301,7 +302,7 @@
public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
Target target = Target.lookup(operand);
if (target == null) {
- throw helper.newInvalidValueException("err.invalid.target", operand);
+ throw helper.newInvalidValueException(Errors.InvalidTarget(operand));
}
super.process(helper, option, operand);
}
@@ -337,7 +338,7 @@
public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
Profile profile = Profile.lookup(operand);
if (profile == null) {
- throw helper.newInvalidValueException("err.invalid.profile", operand);
+ throw helper.newInvalidValueException(Errors.InvalidProfile(operand));
}
super.process(helper, option, operand);
}
@@ -392,12 +393,12 @@
public void process(OptionHelper helper, String option) throws InvalidValueException {
int argLength = option.length();
if (argLength == 2) {
- throw helper.newInvalidValueException("err.empty.A.argument");
+ throw helper.newInvalidValueException(Errors.EmptyAArgument);
}
int sepIndex = option.indexOf('=');
String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
if (!JavacProcessingEnvironment.isValidOptionName(key)) {
- throw helper.newInvalidValueException("err.invalid.A.key", option);
+ throw helper.newInvalidValueException(Errors.InvalidAKey(option));
}
helper.put(option, option);
}
@@ -410,14 +411,13 @@
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
String prev = helper.get(DEFAULT_MODULE_FOR_CREATED_FILES);
if (prev != null) {
- throw helper.newInvalidValueException("err.option.too.many",
- DEFAULT_MODULE_FOR_CREATED_FILES.primaryName);
+ throw helper.newInvalidValueException(Errors.OptionTooMany(DEFAULT_MODULE_FOR_CREATED_FILES.primaryName));
} else if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else if (getPattern().matcher(arg).matches()) {
helper.put(DEFAULT_MODULE_FOR_CREATED_FILES.primaryName, arg);
} else {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
@@ -487,7 +487,7 @@
Log log = helper.getLog();
log.setWriters(new PrintWriter(new FileWriter(arg), true));
} catch (java.io.IOException e) {
- throw helper.newInvalidValueException("err.error.writing.file", arg, e);
+ throw helper.newInvalidValueException(Errors.ErrorWritingFile(arg, e.getMessage()));
}
super.process(helper, option, arg);
}
@@ -570,12 +570,12 @@
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else if (getPattern().matcher(arg).matches()) {
String prev = helper.get(ADD_EXPORTS);
helper.put(ADD_EXPORTS.primaryName, (prev == null) ? arg : prev + '\0' + arg);
} else {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
@@ -591,12 +591,12 @@
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else if (getPattern().matcher(arg).matches()) {
String prev = helper.get(ADD_READS);
helper.put(ADD_READS.primaryName, (prev == null) ? arg : prev + '\0' + arg);
} else {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
@@ -612,14 +612,14 @@
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else if (getPattern().matcher(arg).matches()) {
String prev = helper.get(ADD_MODULES);
// since the individual values are simple names, we can simply join the
// values of multiple --add-modules options with ','
helper.put(ADD_MODULES.primaryName, (prev == null) ? arg : prev + ',' + arg);
} else {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
@@ -633,11 +633,11 @@
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else if (getPattern().matcher(arg).matches()) {
helper.put(LIMIT_MODULES.primaryName, arg); // last one wins
} else {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
@@ -651,13 +651,13 @@
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
- throw helper.newInvalidValueException("err.no.value.for.option", option);
+ throw helper.newInvalidValueException(Errors.NoValueForOption(option));
} else {
// use official parser if available
try {
ModuleDescriptor.Version.parse(arg);
} catch (IllegalArgumentException e) {
- throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+ throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
}
}
super.process(helper, option, arg);
@@ -692,10 +692,10 @@
if (option.endsWith(".java") ) {
Path p = Paths.get(option);
if (!Files.exists(p)) {
- throw helper.newInvalidValueException("err.file.not.found", p);
+ throw helper.newInvalidValueException(Errors.FileNotFound(p.toString()));
}
if (!Files.isRegularFile(p)) {
- throw helper.newInvalidValueException("err.file.not.file", p);
+ throw helper.newInvalidValueException(Errors.FileNotFile(p));
}
helper.addFile(p);
} else {
@@ -1078,7 +1078,7 @@
operand = arg.substring(sep + 1);
} else {
if (!rest.hasNext()) {
- throw helper.newInvalidValueException("err.req.arg", arg);
+ throw helper.newInvalidValueException(Errors.ReqArg(this.primaryName));
}
option = arg;
operand = rest.next();
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2018, 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
@@ -27,7 +27,9 @@
import java.nio.file.Path;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.util.JCDiagnostic;
+import com.sun.tools.javac.util.JCDiagnostic.Error;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.PrefixKind;
@@ -89,8 +91,8 @@
* @param args the arguments, if any, for the resource string
* @return the InvalidValueException
*/
- Option.InvalidValueException newInvalidValueException(String key, Object... args) {
- return new Option.InvalidValueException(getLog().localize(PrefixKind.JAVAC, key, args));
+ Option.InvalidValueException newInvalidValueException(Error error) {
+ return new Option.InvalidValueException(getLog().localize(error));
}
/** Record a file to be compiled. */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Apr 18 16:02:53 2018 -0400
@@ -39,13 +39,18 @@
# name a name, typically a Java identifier
# number an integer
# option name the name of a command line option
-# source version a source version number, such as 1.5, 1.6, 1.7
+# path a path
+# profile a profile name
+# source a source version number, such as 1.5, 1.6, 1.7, taken from a com.sun.tools.javac.code.Source
+# source version a source version number, such as 1.5, 1.6, 1.7, taken from a javax.lang.model.SourceVersion
# string a general string
# symbol the name of a declared type
# symbol kind the kind of a symbol (i.e. method, variable)
# kind name an informative description of the kind of a declaration; see compiler.misc.kindname.*
+# target a target version number, such as 1.5, 1.6, 1.7, taken from a com.sun.tools.javac.jvm.Target
# token the name of a non-terminal in source code; see compiler.misc.token.*
# type a Java type; e.g. int, X, X<T>
+# url a URL
# object a Java object (unspecified)
# unused the value is not used in this message
#
@@ -1779,7 +1784,7 @@
compiler.warn.option.obsolete.source=\
source value {0} is obsolete and will be removed in a future release
-# 0: string
+# 0: target
compiler.warn.option.obsolete.target=\
target value {0} is obsolete and will be removed in a future release
@@ -1787,12 +1792,12 @@
compiler.err.option.removed.source=\
Source option {0} is no longer supported. Use {1} or later.
-# 0: string, 1: string
+# 0: target, 1: target
compiler.err.option.removed.target=\
Target option {0} is no longer supported. Use {1} or later.
-# 0: string, 1: string
+# 0: target, 1: target
compiler.warn.option.parameters.unsupported=\
-parameters is not supported for target value {0}. Use {1} or later.
@@ -3257,3 +3262,123 @@
# 0: string, 1: string
compiler.err.illegal.argument.for.option=\
illegal argument for {0}: {1}
+
+
+############################################
+# messages previouly at javac.properties
+
+compiler.err.empty.A.argument=\
+ -A requires an argument; use ''-Akey'' or ''-Akey=value''
+
+# 0: string
+compiler.err.invalid.A.key=\
+ key in annotation processor option ''{0}'' is not a dot-separated sequence of identifiers
+
+# 0: string
+compiler.err.invalid.flag=\
+ invalid flag: {0}
+
+compiler.err.profile.bootclasspath.conflict=\
+ profile and bootclasspath options cannot be used together
+
+# 0: string
+compiler.err.invalid.profile=\
+ invalid profile: {0}
+
+# 0: string
+compiler.err.invalid.target=\
+ invalid target release: {0}
+
+# 0: option name, 1: target
+compiler.err.option.not.allowed.with.target=\
+ option {0} not allowed with target {1}
+
+# 0: string
+compiler.err.option.too.many=\
+ option {0} can only be specified once
+
+compiler.err.no.source.files=\
+ no source files
+
+compiler.err.no.source.files.classes=\
+ no source files or class names
+
+# 0: string
+compiler.err.req.arg=\
+ {0} requires an argument
+
+# 0: string
+compiler.err.invalid.source=\
+ invalid source release: {0}
+
+# 0: string, 1: string
+compiler.err.error.writing.file=\
+ error writing {0}; {1}
+
+compiler.err.sourcepath.modulesourcepath.conflict=\
+ cannot specify both --source-path and --module-source-path
+
+# 0: string, 1: target
+compiler.warn.source.target.conflict=\
+ source release {0} requires target release {1}
+
+# 0: string, 1: target
+compiler.warn.target.default.source.conflict=\
+ target release {0} conflicts with default source release {1}
+
+# 0: profile, 1: target
+compiler.warn.profile.target.conflict=\
+ profile {0} is not valid for target release {1}
+
+# 0: string
+compiler.err.file.not.directory=\
+ not a directory: {0}
+
+# 0: object
+compiler.err.file.not.file=\
+ not a file: {0}
+
+compiler.err.two.class.loaders.1=\
+ javac is split between multiple class loaders: check your configuration
+
+# 0: url, 1: url
+compiler.err.two.class.loaders.2=\
+ javac is split between multiple class loaders:\n\
+ one class comes from file: {0}\n\
+ while javac comes from {1}
+
+# 0: string, 1: string
+compiler.err.bad.value.for.option=\
+ bad value for {0} option: ''{1}''
+
+# 0: string
+compiler.err.no.value.for.option=\
+ no value for {0} option
+
+# 0: string
+compiler.err.repeated.value.for.patch.module=\
+ --patch-module specified more than once for {0}
+
+# 0: string
+compiler.err.unmatched.quote=\
+ unmatched quote in environment variable {0}
+
+# 0: option name
+compiler.err.release.bootclasspath.conflict=\
+ option {0} cannot be used together with --release
+
+# 0: string
+compiler.err.unsupported.release.version=\
+ release version {0} not supported
+
+# 0: string
+compiler.err.file.not.found=\
+ file not found: {0}
+
+# 0: string, 1: source
+compiler.err.preview.not.latest=\
+ invalid source release {0} with --enable-preview\n\
+ (preview language features are only supported for release {1})
+
+compiler.err.preview.without.source.or.release=\
+ --enable-preview must be used with either -source or --release
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties Wed Apr 18 16:02:53 2018 -0400
@@ -335,71 +335,6 @@
javac.opt.default.module.for.created.files=\
Fallback target module for files created by annotation processors, if none specified or inferred.
-## errors
-
-javac.err.empty.A.argument=\
- -A requires an argument; use ''-Akey'' or ''-Akey=value''
-javac.err.invalid.arg=\
- invalid argument: {0}
-javac.err.invalid.A.key=\
- key in annotation processor option ''{0}'' is not a dot-separated sequence of identifiers
-javac.err.invalid.flag=\
- invalid flag: {0}
-javac.err.profile.bootclasspath.conflict=\
- profile and bootclasspath options cannot be used together
-javac.err.invalid.profile=\
- invalid profile: {0}
-javac.err.invalid.target=\
- invalid target release: {0}
-javac.err.option.not.allowed.with.target=\
- option {0} not allowed with target {1}
-javac.err.option.too.many=\
- option {0} can only be specified once
-javac.err.no.source.files=\
- no source files
-javac.err.no.source.files.classes=\
- no source files or class names
-javac.err.req.arg=\
- {0} requires an argument
-javac.err.invalid.source=\
- invalid source release: {0}
-javac.err.error.writing.file=\
- error writing {0}; {1}
-javac.err.sourcepath.modulesourcepath.conflict=\
- cannot specify both --source-path and --module-source-path
-javac.warn.source.target.conflict=\
- source release {0} requires target release {1}
-javac.warn.target.default.source.conflict=\
- target release {0} conflicts with default source release {1}
-javac.warn.profile.target.conflict=\
- profile {0} is not valid for target release {1}
-javac.err.preview.not.latest=\
- invalid source release {0} with --enable-preview\n\
- (preview language features are only supported for release {1})
-javac.err.preview.without.source.or.release=\
- --enable-preview must be used with either -source or --release
-javac.err.file.not.found=\
- file not found: {0}
-javac.err.file.not.directory=\
- not a directory: {0}
-javac.err.file.not.file=\
- not a file: {0}
-javac.err.two.class.loaders.1=\
- javac is split between multiple class loaders: check your configuration
-javac.err.two.class.loaders.2=\
- javac is split between multiple class loaders:\n\
- one class comes from file: {0}\n\
- while javac comes from {1}
-javac.err.bad.value.for.option=\
- bad value for {0} option: ''{1}''
-javac.err.no.value.for.option=\
- no value for {0} option
-javac.err.repeated.value.for.patch.module=\
- --patch-module specified more than once for {0}
-
-javac.err.unmatched.quote=\
- unmatched quote in environment variable %s
-
## messages
javac.msg.usage.header=\
@@ -437,9 +372,3 @@
javac.version={0} {1}
javac.fullVersion={0} full version "{1}"
-
-javac.err.release.bootclasspath.conflict=\
- option {0} cannot be used together with --release
-
-javac.err.unsupported.release.version=\
- release version {0} not supported
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, 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
@@ -43,11 +43,13 @@
import com.sun.tools.javac.api.Formattable;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Printer;
+import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.CapturedType;
import com.sun.tools.javac.file.PathFileObject;
import com.sun.tools.javac.jvm.Profile;
+import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.Pretty;
@@ -211,6 +213,12 @@
else if (arg instanceof Formattable) {
return ((Formattable)arg).toString(l, messages);
}
+ else if (arg instanceof Target) {
+ return ((Target)arg).name;
+ }
+ else if (arg instanceof Source) {
+ return ((Source)arg).name;
+ }
else {
return String.valueOf(arg);
}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, 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
@@ -26,6 +26,7 @@
package com.sun.tools.javac.util;
import com.sun.tools.javac.api.Messages;
+
import java.lang.ref.SoftReference;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
@@ -34,6 +35,10 @@
import java.util.Locale;
import java.util.Map;
+import com.sun.tools.javac.api.DiagnosticFormatter;
+import com.sun.tools.javac.util.JCDiagnostic.Factory;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
+
/**
* Support for formatted localized messages.
*
@@ -61,6 +66,9 @@
private Locale currentLocale;
private List<ResourceBundle> currentBundles;
+ private DiagnosticFormatter<JCDiagnostic> diagFormatter;
+ private JCDiagnostic.Factory diagFactory;
+
public Locale getCurrentLocale() {
return currentLocale;
}
@@ -73,11 +81,18 @@
this.currentLocale = locale;
}
+ Context context;
+
/** Creates a JavacMessages object.
*/
public JavacMessages(Context context) {
this(defaultBundleName, context.get(Locale.class));
+ this.context = context;
context.put(messagesKey, this);
+ Options options = Options.instance(context);
+ boolean rawDiagnostics = options.isSet("rawDiagnostics");
+ this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(options) :
+ new BasicDiagnosticFormatter(options, this);
}
/** Creates a JavacMessages object.
@@ -140,6 +155,10 @@
return getLocalizedString(currentLocale, key, args);
}
+ public String getLocalizedString(JCDiagnostic.DiagnosticInfo diagInfo) {
+ return getLocalizedString(currentLocale, diagInfo);
+ }
+
@Override
public String getLocalizedString(Locale l, String key, Object... args) {
if (l == null)
@@ -147,6 +166,12 @@
return getLocalizedString(getBundles(l), key, args);
}
+ public String getLocalizedString(Locale l, JCDiagnostic.DiagnosticInfo diagInfo) {
+ if (l == null)
+ l = getCurrentLocale();
+ return getLocalizedString(getBundles(l), diagInfo);
+ }
+
/* Static access:
* javac has a firmly entrenched notion of a default message bundle
* which it can access from any static context. This is used to get
@@ -185,7 +210,7 @@
}
}
- private static String getLocalizedString(List<ResourceBundle> bundles,
+ static private String getLocalizedString(List<ResourceBundle> bundles,
String key,
Object... args) {
String msg = null;
@@ -205,6 +230,36 @@
return MessageFormat.format(msg, args);
}
+ private String getLocalizedString(List<ResourceBundle> bundles, JCDiagnostic.DiagnosticInfo diagInfo) {
+ String msg = null;
+ for (List<ResourceBundle> l = bundles; l.nonEmpty() && msg == null; l = l.tail) {
+ ResourceBundle rb = l.head;
+ try {
+ msg = rb.getString(diagInfo.key());
+ }
+ catch (MissingResourceException e) {
+ // ignore, try other bundles in list
+ }
+ }
+ if (msg == null) {
+ msg = "compiler message file broken: key=" + diagInfo.key() +
+ " arguments={0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}";
+ }
+ if (diagInfo == Errors.Error) {
+ return MessageFormat.format(msg, new Object[0]);
+ } else {
+ return diagFormatter.format(getDiagFactory().create(DiagnosticSource.NO_SOURCE, null, diagInfo),
+ getCurrentLocale());
+ }
+ }
+
+ JCDiagnostic.Factory getDiagFactory() {
+ if (diagFactory == null) {
+ this.diagFactory = JCDiagnostic.Factory.instance(context);
+ }
+ return diagFactory;
+ }
+
/**
* This provides a way for the JavacMessager to retrieve a
* ResourceBundle from another module such as jdk.javadoc.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java Wed Apr 18 13:37:39 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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
@@ -42,6 +42,7 @@
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
@@ -597,6 +598,11 @@
printRawLines(noticeWriter, localize(key, args));
}
+ public void printLines(DiagnosticInfo diag) {
+ PrintWriter noticeWriter = writers.get(WriterKind.NOTICE);
+ printRawLines(noticeWriter, localize(diag));
+ }
+
public void printLines(PrefixKind pk, String key, Object... args) {
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE);
printRawLines(noticeWriter, localize(pk, key, args));
@@ -789,7 +795,7 @@
if (useRawMessages) {
return diagInfo.key();
} else {
- return messages.getLocalizedString(diagInfo.key(), diagInfo.args);
+ return messages.getLocalizedString(diagInfo);
}
}
--- a/test/langtools/jdk/javadoc/tool/BadOptionsTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/jdk/javadoc/tool/BadOptionsTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -79,7 +79,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: error - no value for --add-modules option");
+ "javadoc: error - error: no value for --add-modules option");
checkNotFound(result, "Exception", "at jdk.javadoc/");
}
@@ -104,7 +104,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: error - no value for --add-exports option");
+ "javadoc: error - error: no value for --add-exports option");
checkNotFound(result, "Exception", "at jdk.javadoc/");
}
@@ -116,7 +116,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: error - bad value for --add-exports option");
+ "javadoc: error - error: bad value for --add-exports option: 'm/p'");
checkNotFound(result, "Exception", "at jdk.javadoc/");
}
@@ -146,7 +146,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: cannot specify both --source-path and --module-source-path");
+ "error: cannot specify both --source-path and --module-source-path");
checkFound(result.getOutput(Task.OutputKind.DIRECT),
"1 error");
}
--- a/test/langtools/tools/javac/6410653/T6410653.java Wed Apr 18 13:37:39 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2006, 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.
- */
-
-/**
- * @test
- * @bug 6410653 6401277
- * @summary REGRESSION: javac crashes if -d or -s argument is a file
- * @author Peter von der Ah\u00e9
- * @modules java.compiler
- * jdk.compiler/com.sun.tools.javac.util:open
- */
-
-import java.lang.reflect.Field;
-import java.io.File;
-import java.io.ByteArrayOutputStream;
-import javax.tools.*;
-
-public class T6410653 {
- public static void main(String... args) throws Exception {
- File testSrc = new File(System.getProperty("test.src"));
- String source = new File(testSrc, "T6410653.java").getPath();
- Tool compiler = ToolProvider.getSystemJavaCompiler();
- Module compilerModule = compiler.getClass().getModule();
- Class<?> log = Class.forName(compilerModule, "com.sun.tools.javac.util.Log");
- Field useRawMessages = log.getDeclaredField("useRawMessages");
- useRawMessages.setAccessible(true);
- useRawMessages.setBoolean(null, true);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- compiler.run(null, null, out, "-d", source, source);
- System.err.println(">>>" + out + "<<<");
- useRawMessages.setBoolean(null, false);
- if (!out.toString().equals(String.format("%s%n",
- "javac: javac.err.file.not.directory"))) {
- throw new AssertionError(out);
- }
- System.out.println("Test PASSED. Running javac again to see localized output:");
- compiler.run(null, null, System.out, "-d", source, source);
- }
-}
--- a/test/langtools/tools/javac/T8009640/CheckRejectProfileBCPOptionsIfUsedTogetherTest.java Wed Apr 18 13:37:39 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2013, 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.
- */
-
-/*
- * @test
- * @bug 8009640
- * @summary -profile <compact> does not work when -bootclasspath specified
- * @library /tools/lib
- * @modules jdk.compiler/com.sun.tools.javac.api
- * jdk.compiler/com.sun.tools.javac.main
- * jdk.compiler/com.sun.tools.javac.util
- * jdk.jdeps/com.sun.tools.javap
- * @build toolbox.ToolBox toolbox.JavacTask
- * @run main CheckRejectProfileBCPOptionsIfUsedTogetherTest
- */
-
-import java.nio.file.Paths;
-
-import com.sun.tools.javac.util.Assert;
-
-import toolbox.JavacTask;
-import toolbox.Task;
-import toolbox.ToolBox;
-
-public class CheckRejectProfileBCPOptionsIfUsedTogetherTest {
-
- private static final String TestSrc =
- "public class Test {\n" +
- " javax.swing.JButton b;\n" +
- "}";
-
- public static void main(String args[]) throws Exception {
- ToolBox tb = new ToolBox();
- tb.writeFile("Test.java", TestSrc);
-
- Task.Result result = new JavacTask(tb, Task.Mode.CMDLINE)
- .options("-profile", "compact1",
- "-bootclasspath", Paths.get(ToolBox.testJDK, "jre/lib/rt.jar").toString())
- .files("Test.java")
- .run(Task.Expect.FAIL)
- .writeAll();
-
- String out = result.getOutput(Task.OutputKind.DIRECT);
- Assert.check(out.startsWith(
- "javac: profile and bootclasspath options cannot be used together"),
- "Incorrect javac error output");
- }
-
-}
--- a/test/langtools/tools/javac/diags/CheckResourceKeys.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/diags/CheckResourceKeys.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, 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
@@ -233,7 +233,6 @@
"compiler.misc.non.denotable.type", // UNUSED
"compiler.misc.unnamed.package", // should be required, CR 6964147
"compiler.warn.proc.type.already.exists", // TODO in JavacFiler
- "javac.err.invalid.arg", // UNUSED ??
"javac.opt.arg.class", // UNUSED ??
"javac.opt.arg.pathname", // UNUSED ??
"javac.opt.moreinfo", // option commented out
--- a/test/langtools/tools/javac/diags/examples.not-yet.txt Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/diags/examples.not-yet.txt Wed Apr 18 16:02:53 2018 -0400
@@ -157,3 +157,35 @@
compiler.err.locn.module-info.not.allowed.on.patch.path
compiler.misc.cant.resolve.modules
compiler.misc.file.does.not.contain.module
+
+# these keys were in javac.properties and examples are hard to be produced for them
+# basically because in most cases the compilation ends with an exception
+compiler.err.bad.value.for.option
+compiler.err.empty.A.argument
+compiler.err.error.writing.file
+compiler.err.file.not.directory
+compiler.err.file.not.file
+compiler.err.file.not.found
+compiler.err.invalid.A.key
+compiler.err.invalid.flag
+compiler.err.invalid.profile
+compiler.err.invalid.source
+compiler.err.invalid.target
+compiler.err.no.source.files.classes
+compiler.err.no.value.for.option
+compiler.err.option.not.allowed.with.target
+compiler.err.option.too.many
+compiler.err.profile.bootclasspath.conflict
+compiler.err.release.bootclasspath.conflict
+compiler.err.repeated.value.for.patch.module
+compiler.err.req.arg
+compiler.err.sourcepath.modulesourcepath.conflict
+compiler.err.two.class.loaders.1
+compiler.err.two.class.loaders.2
+compiler.err.unmatched.quote
+compiler.err.unsupported.release.version
+compiler.warn.profile.target.conflict
+compiler.warn.source.target.conflict
+compiler.warn.target.default.source.conflict
+compiler.err.preview.not.latest
+compiler.err.preview.without.source.or.release
\ No newline at end of file
--- a/test/langtools/tools/javac/diags/examples/DirPathElementNotDirectory/DirPathElementNotDirectory.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/diags/examples/DirPathElementNotDirectory/DirPathElementNotDirectory.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -22,5 +22,6 @@
*/
// key: compiler.warn.dir.path.element.not.directory
+// key: compiler.err.no.source.files
// options: -Xlint:path
// run: simple
--- a/test/langtools/tools/javac/doclint/DocLintTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/doclint/DocLintTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, 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
@@ -84,7 +84,7 @@
DL_ERR9(ERROR, "Test.java:9:14: compiler.err.proc.messager: reference not found"),
DL_WRN12(WARNING, "Test.java:12:9: compiler.warn.proc.messager: no description for @return"),
- OPT_BADARG(ERROR, "invalid flag: -Xdoclint:badarg");
+ OPT_BADARG(ERROR, "error: invalid flag: -Xdoclint:badarg");
final Diagnostic.Kind kind;
final String text;
--- a/test/langtools/tools/javac/doclint/IncludePackagesTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/doclint/IncludePackagesTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -96,7 +96,7 @@
p1sp1sp2T(ERROR, "p1sp1sp2T.java:2:12: compiler.err.proc.messager: malformed HTML"),
p2T(ERROR, "p2T.java:2:12: compiler.err.proc.messager: malformed HTML"),
Default(ERROR, "Default.java:1:12: compiler.err.proc.messager: malformed HTML"),
- INVALID_PACKAGE_ERROR(ERROR, "invalid flag: -Xdoclint/package:wrong+package");
+ INVALID_PACKAGE_ERROR(ERROR, "error: invalid flag: -Xdoclint/package:wrong+package");
final Diagnostic.Kind kind;
final String text;
--- a/test/langtools/tools/javac/modules/AddExportsTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/AddExportsTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -62,7 +62,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: no value for --add-exports option");
+ "error: no value for --add-exports option");
}
@Test
@@ -123,7 +123,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: bad value for --add-exports option: '" + option + "'");
+ "error: bad value for --add-exports option: '" + option + "'");
}
@Test
@@ -158,7 +158,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: bad value for --add-exports option: '" + option + "'");
+ "error: bad value for --add-exports option: '" + option + "'");
}
@Test
--- a/test/langtools/tools/javac/modules/AddLimitMods.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/AddLimitMods.java Wed Apr 18 16:02:53 2018 -0400
@@ -264,7 +264,7 @@
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
- if (!actual.contains("javac: option --add-modules not allowed with target 1.8")) {
+ if (!actual.contains("- compiler.err.option.not.allowed.with.target: --add-modules, 1.8")) {
throw new IllegalStateException("incorrect errors; actual=" + actual);
}
--- a/test/langtools/tools/javac/modules/AddModulesTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/AddModulesTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -73,7 +73,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: no value for --add-modules option");
+ "error: no value for --add-modules option");
}
@Test
@@ -120,7 +120,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: bad value for --add-modules option");
+ "error: bad value for --add-modules option");
}
@Test
--- a/test/langtools/tools/javac/modules/AddReadsTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/AddReadsTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -352,7 +352,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: no value for --add-reads option");
+ "error: no value for --add-reads option");
}
@Test
@@ -421,7 +421,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: bad value for --add-reads option: '" + option + "'");
+ "error: bad value for --add-reads option: '" + option + "'");
}
@Test
@@ -572,7 +572,7 @@
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
- "javac: bad value for --add-reads option: 'm1x:m2x'");
+ "error: bad value for --add-reads option: 'm1x:m2x'");
}
@Test
--- a/test/langtools/tools/javac/modules/LimitModulesTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/LimitModulesTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -58,7 +58,7 @@
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
- if (!log.contains("javac: no value for --limit-modules option"))
+ if (!log.contains("error: no value for --limit-modules option"))
throw new Exception("expected output not found");
log = new JavacTask(tb, Task.Mode.CMDLINE)
@@ -70,7 +70,7 @@
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
- if (!log.contains("javac: no value for --limit-modules option"))
+ if (!log.contains("error: no value for --limit-modules option"))
throw new Exception("expected output not found");
}
@@ -127,7 +127,7 @@
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
- if (!log.contains("javac: bad value for --limit-modules option"))
+ if (!log.contains("error: bad value for --limit-modules option"))
throw new Exception("expected output not found");
}
--- a/test/langtools/tools/javac/modules/ModuleSourcePathTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/ModuleSourcePathTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -76,7 +76,7 @@
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
- if (!log.contains("cannot specify both --source-path and --module-source-path"))
+ if (!log.contains("compiler.err.sourcepath.modulesourcepath.conflict"))
throw new Exception("expected diagnostic not found");
}
--- a/test/langtools/tools/javac/modules/PatchModulesTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/modules/PatchModulesTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -98,19 +98,19 @@
@Test
public void testDuplicates(Path base) throws Exception {
test(asList("java.base=a", "java.compiler=b", "java.base=c"),
- false, "--patch-module specified more than once for java.base");
+ false, "error: --patch-module specified more than once for java.base");
}
@Test
public void testEmpty(Path base) throws Exception {
test(asList(""),
- false, "no value for --patch-module option");
+ false, "error: no value for --patch-module option");
}
@Test
public void testInvalid(Path base) throws Exception {
test(asList("java.base/java.lang=."),
- false, "bad value for --patch-module option: 'java.base/java.lang=.'");
+ false, "error: bad value for --patch-module option: 'java.base/java.lang=.'");
}
void test(List<String> patches, String expect) throws Exception {
--- a/test/langtools/tools/javac/options/release/ReleaseOptionClashes.java Wed Apr 18 13:37:39 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- */
-
-/**
- * @test
- * @bug 8072480
- * @summary Verify option clash between --release and -source is reported correctly.
- * @modules jdk.compiler/com.sun.tools.javac.util:open
- */
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.tools.Tool;
-import javax.tools.ToolProvider;
-
-public class ReleaseOptionClashes {
- public static void main(String... args) throws Exception {
- new ReleaseOptionClashes().run();
- }
-
- void run() throws Exception {
- doRunTest("7", "-bootclasspath", "any");
- doRunTest("7", "-Xbootclasspath:any");
- doRunTest("7", "-Xbootclasspath/a:any");
- doRunTest("7", "-Xbootclasspath/p:any");
- doRunTest("7", "-endorseddirs", "any");
- doRunTest("7", "-extdirs", "any");
- doRunTest("7", "-source", "8");
- doRunTest("7", "-target", "8");
- doRunTest("9", "--system", "none");
- doRunTest("9", "--upgrade-module-path", "any");
- }
-
- void doRunTest(String release, String... args) throws Exception {
- System.out.println("Testing clashes for arguments: " + Arrays.asList(args));
- Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl);
- Field useRawMessages = log.getDeclaredField("useRawMessages");
- useRawMessages.setAccessible(true);
- useRawMessages.setBoolean(null, true);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- List<String> options = new ArrayList<>();
- options.addAll(Arrays.asList("--release", release));
- options.addAll(Arrays.asList(args));
- options.add(System.getProperty("test.src") + File.separator + "ReleaseOptionClashes.java");
- compiler.run(null, null, out, options.toArray(new String[0]));
- useRawMessages.setBoolean(null, false);
- if (!out.toString().equals(String.format("%s%n%s%n",
- "javac: javac.err.release.bootclasspath.conflict",
- "javac.msg.usage")) &&
- //-Xbootclasspath:any produces two warnings: one for -bootclasspath and one for -Xbootclasspath:
- !out.toString().equals(String.format("%s%n%s%n%s%n%s%n",
- "javac: javac.err.release.bootclasspath.conflict",
- "javac.msg.usage",
- "javac: javac.err.release.bootclasspath.conflict",
- "javac.msg.usage"))) {
- throw new AssertionError(out);
- }
- System.out.println("Test PASSED. Running javac again to see localized output:");
- compiler.run(null, null, System.out, options.toArray(new String[0]));
- }
-
- Tool compiler = ToolProvider.getSystemJavaCompiler();
- ClassLoader cl = compiler.getClass().getClassLoader();
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/options/smokeTests/OptionSmokeTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2018, 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 8196433
+ * @summary use the new error diagnostic approach at javac.Main
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ * jdk.compiler/com.sun.tools.javac.main
+ * jdk.compiler/com.sun.tools.javac.util
+ * jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner
+ * @run main OptionSmokeTest
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import com.sun.tools.javac.util.Assert;
+
+import toolbox.TestRunner;
+import toolbox.ToolBox;
+import toolbox.JavacTask;
+import toolbox.Task;
+
+public class OptionSmokeTest extends TestRunner {
+ ToolBox tb = new ToolBox();
+
+ public OptionSmokeTest() {
+ super(System.err);
+ }
+
+ protected void runTests() throws Exception {
+ runTests(m -> new Object[] { Paths.get(m.getName()) });
+ }
+
+ Path[] findJavaFiles(Path... paths) throws Exception {
+ return tb.findJavaFiles(paths);
+ }
+
+ public static void main(String... args) throws Exception {
+ new OptionSmokeTest().runTests();
+ }
+
+ @Test
+ public void optionA1(Path base) throws Exception {
+ doTest(base,
+ "error: -A requires an argument; use '-Akey' or '-Akey=value'",
+ "-A");
+ }
+
+ @Test
+ public void optionA2(Path base) throws Exception {
+ doTest(base,
+ "error: key in annotation processor option '-A1e=2' is not a dot-separated sequence of identifiers",
+ "-A1e=2");
+ }
+
+ @Test
+ public void noFlag(Path base) throws Exception {
+ doTest(base, "error: invalid flag: -noFlag", "-noFlag");
+ }
+
+ @Test
+ public void profileAndBSP(Path base) throws Exception {
+ doTest(base, "error: profile and bootclasspath options cannot be used together",
+ "-profile compact1 -bootclasspath . -target 8 -source 8");
+ }
+
+ @Test
+ public void invalidProfile(Path base) throws Exception {
+ doTest(base, "error: invalid profile: noProfile",
+ "-profile noProfile");
+ }
+
+ @Test
+ public void invalidTarget(Path base) throws Exception {
+ doTest(base, "error: invalid target release: 999999",
+ "-target 999999");
+ }
+
+ @Test
+ public void optionNotAvailableWithTarget(Path base) throws Exception {
+ doTest(base, "error: option -profile not allowed with target 11",
+ "-profile compact1 -target 11");
+ }
+
+ @Test
+ public void optionTooMany(Path base) throws Exception {
+ doTest(base, "error: option --default-module-for-created-files can only be specified once",
+ "--default-module-for-created-files=m1x --default-module-for-created-files=m1x");
+ }
+
+ @Test
+ public void noSrcFiles(Path base) throws Exception {
+ doTestNoSource(base, "error: no source files", "-target 11");
+ }
+
+ @Test
+ public void requiresArg(Path base) throws Exception {
+ doTestNoSource(base, "error: -target requires an argument", "-target");
+ }
+
+ @Test
+ public void invalidSource(Path base) throws Exception {
+ doTestNoSource(base, "error: invalid source release: 999999", "-source 999999");
+ }
+
+ @Test
+ public void sourceAndModuleSourceCantBeTogether(Path base) throws Exception {
+ doTest(base, "error: cannot specify both --source-path and --module-source-path",
+ "--source-path . --module-source-path .");
+ }
+
+ @Test
+ public void sourceAndTargetMismatch(Path base) throws Exception {
+ doTest(base, "warning: source release 11 requires target release 11",
+ "-source 11 -target 10");
+ }
+
+ @Test
+ public void targetConflictsWithDefaultSource(Path base) throws Exception {
+ doTest(base, "warning: target release 10 conflicts with default source release 11",
+ "-target 10");
+ }
+
+ @Test
+ public void profileNotValidForTarget(Path base) throws Exception {
+ doTest(base, "warning: profile compact2 is not valid for target release 1.7",
+ "-profile compact2 -target 7 -source 7");
+ }
+
+ @Test
+ public void fileNotFound(Path base) throws Exception {
+ String log = new JavacTask(tb, Task.Mode.CMDLINE)
+ .files("notExistent/T.java")
+ .run(Task.Expect.FAIL)
+ .writeAll()
+ .getOutput(Task.OutputKind.DIRECT);
+ Assert.check(log.startsWith("error: file not found: notExistent" + fileSeparator + "T.java"),
+ "real value of log:" + log);
+ }
+
+ static final String fileSeparator = System.getProperty("file.separator");
+
+ @Test
+ public void notADirectory(Path base) throws Exception {
+ doTest(base, "error: not a directory: notADirectory" + fileSeparator + "src" + fileSeparator + "Dummy.java",
+ "-d notADirectory" + fileSeparator + "src" + fileSeparator + "Dummy.java");
+ }
+
+ @Test
+ public void notAFile(Path base) throws Exception {
+ // looks like a java file, it is a directory
+ Path dir = base.resolve("dir.java");
+ tb.createDirectories(dir);
+ String log = new JavacTask(tb, Task.Mode.CMDLINE)
+ .spaceSeparatedOptions("-XDsourcefile " + dir)
+ .run(Task.Expect.FAIL)
+ .writeAll()
+ .getOutput(Task.OutputKind.DIRECT);
+ Assert.check(log.startsWith("error: not a file: notAFile" + fileSeparator + "dir.java"));
+ }
+
+ @Test
+ public void badValueForOption(Path base) throws Exception {
+ doTestNoSource(base, "error: bad value for --patch-module option: \'notExistent\'",
+ "--patch-module notExistent");
+ }
+
+ @Test
+ public void patchModuleMoreThanOnce(Path base) throws Exception {
+ doTestNoSource(base, "error: --patch-module specified more than once for m",
+ "--patch-module m=. --patch-module m=.");
+ }
+
+ @Test
+ public void unmatchedQuoteInEnvVar(Path base) throws Exception {
+ Path src = base.resolve("src");
+ tb.writeJavaFiles(src, "class Dummy {}");
+ String log = new JavacTask(tb, Task.Mode.EXEC)
+ .envVar("JDK_JAVAC_OPTIONS", "--add-exports jdk.compiler" + fileSeparator + "com.sun.tools.javac.jvm=\"ALL-UNNAMED")
+ .files(findJavaFiles(src))
+ .run(Task.Expect.FAIL)
+ .writeAll()
+ .getOutput(Task.OutputKind.STDERR);
+ Assert.check(log.startsWith("error: unmatched quote in environment variable JDK_JAVAC_OPTIONS"));
+ }
+
+ @Test
+ public void optionCantBeUsedWithRelease(Path base) throws Exception {
+ doTestNoSource(base, "error: option -source cannot be used together with --release",
+ "--release 7 -source 7");
+ }
+
+ @Test
+ public void releaseVersionNotSupported(Path base) throws Exception {
+ doTestNoSource(base, "error: release version 99999999 not supported",
+ "--release 99999999");
+ }
+
+ // taken from former test: tools/javac/options/release/ReleaseOptionClashes
+ @Test
+ public void releaseAndBootclasspath(Path base) throws Exception {
+ doTestNoSource(base, "error: option --boot-class-path cannot be used together with --release",
+ "--release 7 -bootclasspath any");
+ doTestNoSource(base, "error: option -Xbootclasspath: cannot be used together with --release",
+ "--release 7 -Xbootclasspath:any");
+ doTestNoSource(base, "error: option -Xbootclasspath/p: cannot be used together with --release",
+ "--release 7 -Xbootclasspath/p:any");
+ doTestNoSource(base, "error: option -endorseddirs cannot be used together with --release",
+ "--release 7 -endorseddirs any");
+ doTestNoSource(base, "error: option -extdirs cannot be used together with --release",
+ "--release 7 -extdirs any");
+ doTestNoSource(base, "error: option -source cannot be used together with --release",
+ "--release 7 -source 8");
+ doTestNoSource(base, "error: option -target cannot be used together with --release",
+ "--release 7 -target 8");
+ doTestNoSource(base, "error: option --system cannot be used together with --release",
+ "--release 9 --system none");
+ doTestNoSource(base, "error: option --upgrade-module-path cannot be used together with --release",
+ "--release 9 --upgrade-module-path any");
+ }
+
+ void doTest(Path base, String output, String options) throws Exception {
+ Path src = base.resolve("src");
+ tb.writeJavaFiles(src, "class Dummy { }");
+ String log = new JavacTask(tb, Task.Mode.CMDLINE)
+ .spaceSeparatedOptions(options)
+ .files(findJavaFiles(src))
+ .run(Task.Expect.FAIL)
+ .writeAll()
+ .getOutput(Task.OutputKind.DIRECT);
+ Assert.check(log.startsWith(output), "expected:\n" + output + '\n' + "found:\n" + log);
+ }
+
+ void doTestNoSource(Path base, String output, String options) throws Exception {
+ String log = new JavacTask(tb, Task.Mode.CMDLINE)
+ .spaceSeparatedOptions(options)
+ .run(Task.Expect.FAIL)
+ .writeAll()
+ .getOutput(Task.OutputKind.DIRECT);
+ Assert.check(log.startsWith(output), "expected:\n" + output + '\n' + "found:\n" + log);
+ }
+}
--- a/test/langtools/tools/javac/platform/PlatformProviderTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javac/platform/PlatformProviderTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -141,7 +141,7 @@
List<String> expectedOutput =
Arrays.asList("getSupportedPlatformNames",
"getPlatform(fail, )",
- "javac: javac.err.unsupported.release.version",
+ "error: release version fail not supported",
"javac.msg.usage");
List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
result.writeAll();
--- a/test/langtools/tools/javadoc/BadOptionsTest.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/javadoc/BadOptionsTest.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -96,7 +96,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: error - no value for --add-modules option");
+ "javadoc: error - error: no value for --add-modules option");
checkNotFound(result, "Exception", "at jdk.javadoc/");
}
@@ -122,7 +122,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: error - no value for --add-exports option");
+ "javadoc: error - error: no value for --add-exports option");
checkNotFound(result, "Exception", "at jdk.javadoc/");
}
@@ -135,7 +135,7 @@
.run(Task.Expect.FAIL)
.writeAll();
checkFound(result.getOutput(Task.OutputKind.DIRECT),
- "javadoc: error - bad value for --add-exports option");
+ "javadoc: error - error: bad value for --add-exports option: 'm/p'");
checkNotFound(result, "Exception", "at jdk.javadoc/");
}
--- a/test/langtools/tools/lib/toolbox/JavacTask.java Wed Apr 18 13:37:39 2018 -0400
+++ b/test/langtools/tools/lib/toolbox/JavacTask.java Wed Apr 18 16:02:53 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -179,6 +179,16 @@
/**
* Sets the options.
+ * @param spaceSeparatedOption the space separated options
+ * @return this task object
+ */
+ public JavacTask spaceSeparatedOptions(String spaceSeparatedOption) {
+ this.options = Arrays.asList(spaceSeparatedOption.split("\\s+"));
+ return this;
+ }
+
+ /**
+ * Sets the options.
* @param options the options
* @return this task object
*/