This commit is contained in:
Lana Steuck 2014-11-06 15:13:39 -08:00
commit 6b9913f667
47 changed files with 970 additions and 515 deletions

View file

@ -191,7 +191,7 @@ public class BasicJavacTask extends JavacTask {
} }
} }
for (List<String> p: pluginsToCall) { for (List<String> p: pluginsToCall) {
Log.instance(context).error("msg.plugin.not.found", p.head); Log.instance(context).error("plugin.not.found", p.head);
} }
} }

View file

@ -25,6 +25,7 @@
package com.sun.tools.javac.api; package com.sun.tools.javac.api;
import java.io.IOException;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.util.*; import java.util.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -67,6 +68,7 @@ import com.sun.tools.javac.util.Log.WriterKind;
public class JavacTaskImpl extends BasicJavacTask { public class JavacTaskImpl extends BasicJavacTask {
private final Arguments args; private final Arguments args;
private JavaCompiler compiler; private JavaCompiler compiler;
private JavaFileManager fileManager;
private Locale locale; private Locale locale;
private Map<JavaFileObject, JCCompilationUnit> notYetEntered; private Map<JavaFileObject, JCCompilationUnit> notYetEntered;
private ListBuffer<Env<AttrContext>> genList; private ListBuffer<Env<AttrContext>> genList;
@ -76,6 +78,7 @@ public class JavacTaskImpl extends BasicJavacTask {
JavacTaskImpl(Context context) { JavacTaskImpl(Context context) {
super(context, true); super(context, true);
args = Arguments.instance(context); args = Arguments.instance(context);
fileManager = context.get(JavaFileManager.class);
} }
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
@ -202,6 +205,12 @@ public class JavacTaskImpl extends BasicJavacTask {
void cleanup() { void cleanup() {
if (compiler != null) if (compiler != null)
compiler.close(); compiler.close();
if (fileManager instanceof BaseFileManager && ((BaseFileManager) fileManager).autoClose) {
try {
fileManager.close();
} catch (IOException ignore) {
}
}
compiler = null; compiler = null;
context = null; context = null;
notYetEntered = null; notYetEntered = null;

View file

@ -43,6 +43,7 @@ import com.sun.source.util.JavacTask;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.Arguments; import com.sun.tools.javac.main.Arguments;
import com.sun.tools.javac.main.Option; import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.ClientCodeException;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy;
@ -151,8 +152,12 @@ public final class JavacTool implements JavaCompiler {
else else
context.put(Log.outKey, new PrintWriter(out, true)); context.put(Log.outKey, new PrintWriter(out, true));
if (fileManager == null) if (fileManager == null) {
fileManager = getStandardFileManager(diagnosticListener, null, null); fileManager = getStandardFileManager(diagnosticListener, null, null);
if (fileManager instanceof BaseFileManager) {
((BaseFileManager) fileManager).autoClose = true;
}
}
fileManager = ccw.wrap(fileManager); fileManager = ccw.wrap(fileManager);
context.put(JavaFileManager.class, fileManager); context.put(JavaFileManager.class, fileManager);

View file

@ -2677,10 +2677,19 @@ public class Types {
while (t.hasTag(TYPEVAR)) while (t.hasTag(TYPEVAR))
t = t.getUpperBound(); t = t.getUpperBound();
TypeSymbol c = t.tsym; TypeSymbol c = t.tsym;
Symbol bestSoFar = null;
for (Symbol sym : c.members().getSymbolsByName(ms.name, implFilter)) { for (Symbol sym : c.members().getSymbolsByName(ms.name, implFilter)) {
if (sym != null && if (sym != null && sym.overrides(ms, origin, Types.this, checkResult)) {
sym.overrides(ms, origin, Types.this, checkResult)) bestSoFar = sym;
return (MethodSymbol)sym; if ((sym.flags() & ABSTRACT) == 0) {
//if concrete impl is found, exit immediately
break;
}
}
}
if (bestSoFar != null) {
//return either the (only) concrete implementation or the first abstract one
return (MethodSymbol)bestSoFar;
} }
} }
return null; return null;

View file

@ -676,13 +676,19 @@ public class Infer {
ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>(); ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>();
for (Type sup : supertypesToCheck) { for (Type sup : supertypesToCheck) {
if (sup.isParameterized()) { if (sup.isParameterized()) {
Type asSuperOfT = types.asSuper(t, sup.tsym); Type asSuperOfT = asSuper(t, sup);
Type asSuperOfS = types.asSuper(s, sup.tsym); Type asSuperOfS = asSuper(s, sup);
commonSupertypes.add(new Pair<>(asSuperOfT, asSuperOfS)); commonSupertypes.add(new Pair<>(asSuperOfT, asSuperOfS));
} }
} }
return commonSupertypes.toList(); return commonSupertypes.toList();
} }
//where
private Type asSuper(Type t, Type sup) {
return (sup.hasTag(ARRAY)) ?
new ArrayType(asSuper(types.elemtype(t), types.elemtype(sup)), syms.arrayClass) :
types.asSuper(t, sup.tsym);
}
/** /**
* This enumeration defines an entry point for doing inference variable * This enumeration defines an entry point for doing inference variable

View file

@ -2033,11 +2033,12 @@ public class Resolve {
// Return the type variable if we have it, and have no // Return the type variable if we have it, and have no
// immediate member, OR the type variable is for a method. // immediate member, OR the type variable is for a method.
if (tyvar != typeNotFound) { if (tyvar != typeNotFound) {
if (sym == typeNotFound || if (env.baseClause || sym == typeNotFound ||
(tyvar.kind == TYP && tyvar.exists() && (tyvar.kind == TYP && tyvar.exists() &&
tyvar.owner.kind == MTH)) tyvar.owner.kind == MTH)) {
return tyvar; return tyvar;
} }
}
// If the environment is a class def, finish up, // If the environment is a class def, finish up,
// otherwise, do the entire findMemberType // otherwise, do the entire findMemberType

View file

@ -130,8 +130,6 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
if (register) if (register)
context.put(JavaFileManager.class, this); context.put(JavaFileManager.class, this);
setContext(context); setContext(context);
if (System.getProperty("show.fm.open.close") != null)
System.err.println("JavacFileManager.open " + this.hashCode());
} }
/** /**
@ -573,8 +571,6 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
*/ */
@DefinedBy(Api.COMPILER) @DefinedBy(Api.COMPILER)
public void close() { public void close() {
if (System.getProperty("show.fm.open.close") != null)
System.err.println("JavacFileManager.close " + this.hashCode());
for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) { for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) {
Archive a = i.next(); Archive a = i.next();
i.remove(); i.remove();

View file

@ -1133,6 +1133,10 @@ compiler.err.error=\
compiler.err.cant.read.file=\ compiler.err.cant.read.file=\
cannot read: {0} cannot read: {0}
# 0: string
compiler.err.plugin.not.found=\
plug-in not found: {0}
##### #####
# Fatal Errors # Fatal Errors

View file

@ -289,8 +289,7 @@ javac.err.file.not.directory=\
not a directory: {0} not a directory: {0}
javac.err.file.not.file=\ javac.err.file.not.file=\
not a file: {0} not a file: {0}
javac.msg.plugin.not.found=\
plug-in not found: {0}
## messages ## messages
javac.msg.usage.header=\ javac.msg.usage.header=\

View file

@ -104,6 +104,12 @@ public abstract class BaseFileManager implements JavaFileManager {
protected Locations locations; protected Locations locations;
/**
* A flag for clients to use to indicate that this file manager should
* be closed when it is no longer required.
*/
public boolean autoClose;
protected Source getSource() { protected Source getSource() {
String sourceName = options.get(Option.SOURCE); String sourceName = options.get(Option.SOURCE);
Source source = null; Source source = null;

View file

@ -412,6 +412,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
EXIT_ABNORMAL = 4; // Compiler terminated abnormally EXIT_ABNORMAL = 4; // Compiler terminated abnormally
int run(String[] args) { int run(String[] args) {
try {
try { try {
handleOptions(args); handleOptions(args);
@ -423,7 +424,6 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
return EXIT_CMDERR; return EXIT_CMDERR;
} }
try {
return run(); return run();
} finally { } finally {
if (defaultFileManager != null) { if (defaultFileManager != null) {

View file

@ -91,7 +91,7 @@ public class CompileJavaPackages implements Transformer {
// Get maximum heap size from the server! // Get maximum heap size from the server!
SysInfo sysinfo = sjavac.getSysInfo(); SysInfo sysinfo = sjavac.getSysInfo();
if (sysinfo.numCores == -1) { if (sysinfo == null) {
Log.error("Could not query server for sysinfo!"); Log.error("Could not query server for sysinfo!");
return false; return false;
} }

View file

@ -25,31 +25,33 @@
package com.sun.tools.sjavac.client; package com.sun.tools.sjavac.client;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Scanner;
import java.util.Set; import java.util.Set;
import com.sun.tools.sjavac.Log; import com.sun.tools.sjavac.Log;
import com.sun.tools.sjavac.ProblemException;
import com.sun.tools.sjavac.Util; import com.sun.tools.sjavac.Util;
import com.sun.tools.sjavac.options.OptionHelper;
import com.sun.tools.sjavac.options.Options;
import com.sun.tools.sjavac.server.CompilationResult; import com.sun.tools.sjavac.server.CompilationResult;
import com.sun.tools.sjavac.server.PortFile; import com.sun.tools.sjavac.server.PortFile;
import com.sun.tools.sjavac.server.Sjavac; import com.sun.tools.sjavac.server.Sjavac;
import com.sun.tools.sjavac.server.SjavacServer; import com.sun.tools.sjavac.server.SjavacServer;
import com.sun.tools.sjavac.server.SysInfo; import com.sun.tools.sjavac.server.SysInfo;
import com.sun.tools.sjavac.options.Options;
/** /**
* Sjavac implementation that delegates requests to a SjavacServer. * Sjavac implementation that delegates requests to a SjavacServer.
@ -64,10 +66,9 @@ public class SjavacClient implements Sjavac {
// The id can perhaps be used in the future by the javac server to reuse the // The id can perhaps be used in the future by the javac server to reuse the
// JavaCompiler instance for several compiles using the same id. // JavaCompiler instance for several compiles using the same id.
private final String id; private final String id;
private final String portfileName; private final PortFile portFile;
private final String logfile; private final String logfile;
private final String stdouterrfile; private final String stdouterrfile;
private final boolean background;
// Default keepalive for server is 120 seconds. // Default keepalive for server is 120 seconds.
// I.e. it will accept 120 seconds of inactivity before quitting. // I.e. it will accept 120 seconds of inactivity before quitting.
@ -88,16 +89,27 @@ public class SjavacClient implements Sjavac {
// Store the server conf settings here. // Store the server conf settings here.
private final String settings; private final String settings;
public SjavacClient(Options options) { // This constructor should not throw FileNotFoundException (to be resolved
// in JDK-8060030)
public SjavacClient(Options options) throws FileNotFoundException {
String tmpServerConf = options.getServerConf(); String tmpServerConf = options.getServerConf();
String serverConf = (tmpServerConf!=null)? tmpServerConf : ""; String serverConf = (tmpServerConf!=null)? tmpServerConf : "";
String tmpId = Util.extractStringOption("id", serverConf); String tmpId = Util.extractStringOption("id", serverConf);
id = (tmpId!=null) ? tmpId : "id"+(((new java.util.Random()).nextLong())&Long.MAX_VALUE); id = (tmpId!=null) ? tmpId : "id"+(((new java.util.Random()).nextLong())&Long.MAX_VALUE);
String p = Util.extractStringOption("portfile", serverConf); String defaultPortfile = options.getStateDir()
portfileName = (p!=null) ? p : options.getStateDir().toFile().getAbsolutePath()+File.separatorChar+"javac_server"; .resolve("javac_server")
.toAbsolutePath()
.toString();
String portfileName = Util.extractStringOption("portfile", serverConf, defaultPortfile);
try {
portFile = SjavacServer.getPortFile(portfileName);
} catch (FileNotFoundException e) {
// Reached for instance if directory of port file does not exist
Log.error("Port file inaccessable: " + e);
throw e;
}
logfile = Util.extractStringOption("logfile", serverConf, portfileName + ".javaclog"); logfile = Util.extractStringOption("logfile", serverConf, portfileName + ".javaclog");
stdouterrfile = Util.extractStringOption("stdouterrfile", serverConf, portfileName + ".stdouterr"); stdouterrfile = Util.extractStringOption("stdouterrfile", serverConf, portfileName + ".stdouterr");
background = Util.extractBooleanOption("background", serverConf, true);
sjavacForkCmd = Util.extractStringOption("sjavac", serverConf, "sjavac"); sjavacForkCmd = Util.extractStringOption("sjavac", serverConf, "sjavac");
int poolsize = Util.extractIntOption("poolsize", serverConf); int poolsize = Util.extractIntOption("poolsize", serverConf);
keepalive = Util.extractIntOption("keepalive", serverConf, 120); keepalive = Util.extractIntOption("keepalive", serverConf, 120);
@ -138,8 +150,11 @@ public class SjavacClient implements Sjavac {
return (SysInfo) ois.readObject(); return (SysInfo) ois.readObject();
} catch (IOException | ClassNotFoundException ex) { } catch (IOException | ClassNotFoundException ex) {
Log.error("[CLIENT] Exception caught: " + ex); Log.error("[CLIENT] Exception caught: " + ex);
StringWriter sw = new StringWriter(); Log.debug(Util.getStackTrace(ex));
ex.printStackTrace(new PrintWriter(sw)); } catch (InterruptedException ie) {
Thread.currentThread().interrupt(); // Restore interrupt
Log.error("[CLIENT] getSysInfo interrupted.");
Log.debug(Util.getStackTrace(ie));
} }
return null; return null;
} }
@ -170,106 +185,127 @@ public class SjavacClient implements Sjavac {
oos.flush(); oos.flush();
result = (CompilationResult) ois.readObject(); result = (CompilationResult) ois.readObject();
} catch (IOException | ClassNotFoundException ex) { } catch (IOException | ClassNotFoundException ex) {
Log.error("Exception caught: " + ex); Log.error("[CLIENT] Exception caught: " + ex);
result = new CompilationResult(CompilationResult.ERROR_FATAL); result = new CompilationResult(CompilationResult.ERROR_FATAL);
result.stderr = Util.getStackTrace(ex); result.stderr = Util.getStackTrace(ex);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt(); // Restore interrupt
Log.error("[CLIENT] compile interrupted.");
result = new CompilationResult(CompilationResult.ERROR_FATAL);
result.stderr = Util.getStackTrace(ie);
} }
return result; return result;
} }
private Socket tryConnect() throws IOException { /*
* Makes MAX_CONNECT_ATTEMPTS attepmts to connect to server.
PortFile portFile; */
private Socket tryConnect() throws IOException, InterruptedException {
makeSureServerIsRunning(portFile);
int attempt = 0;
while (true) {
Log.info("Trying to connect. Attempt " + (++attempt) + " of " + MAX_CONNECT_ATTEMPTS);
try { try {
// This should be taken care of at a higher level (JDK-8048451) return makeConnectionAttempt();
portFile = SjavacServer.getPortFile(portfileName); } catch (IOException ex) {
} catch (FileNotFoundException e) { Log.error("Connection attempt failed: " + ex.getMessage());
// Reached for instance if directory of port file does not exist if (attempt >= MAX_CONNECT_ATTEMPTS) {
Log.error("Port file inaccessable: " + e); Log.error("Giving up");
throw new RuntimeException(e); throw new IOException("Could not connect to server", ex);
} }
for (int i = 0; i < MAX_CONNECT_ATTEMPTS; i++) { }
Log.info(String.format("Trying to connect (attempt %d of %d)", Thread.sleep(WAIT_BETWEEN_CONNECT_ATTEMPTS);
i+1, MAX_CONNECT_ATTEMPTS)); }
try { }
if (!makeSureServerIsRunning(portFile))
continue; private Socket makeConnectionAttempt() throws IOException {
Socket socket = new Socket(); Socket socket = new Socket();
InetAddress localhost = InetAddress.getByName(null); InetAddress localhost = InetAddress.getByName(null);
socket.connect(new InetSocketAddress(localhost, portFile.getPort()), InetSocketAddress address = new InetSocketAddress(localhost, portFile.getPort());
CONNECTION_TIMEOUT); socket.connect(address, CONNECTION_TIMEOUT);
Log.info("Connected");
return socket; return socket;
} catch (ProblemException | IOException ex) {
Log.error("Caught exception during tryConnect: " + ex);
} }
try { /*
Thread.sleep(WAIT_BETWEEN_CONNECT_ATTEMPTS); * Will return immediately if a server already seems to be running,
} catch (InterruptedException e) { * otherwise fork a new server and block until it seems to be running.
Thread.currentThread().interrupt(); */
} private void makeSureServerIsRunning(PortFile portFile)
} throws IOException, InterruptedException {
throw new IOException("Could not connect to server");
}
private boolean makeSureServerIsRunning(PortFile portFile)
throws IOException, ProblemException, FileNotFoundException {
synchronized (portFile) {
portFile.lock(); portFile.lock();
portFile.getValues(); portFile.getValues();
portFile.unlock(); portFile.unlock();
if (portFile.containsPortInfo()) {
// Server seems to already be running
return;
} }
if (!portFile.containsPortInfo()) { // Fork a new server and wait for it to start
String forkCmd = SjavacServer.fork(sjavacForkCmd, SjavacClient.fork(sjavacForkCmd,
portFile.getFilename(), portFile,
logfile, logfile,
poolsize, poolsize,
keepalive, keepalive,
System.err, System.err,
stdouterrfile, stdouterrfile);
background);
if (!portFile.waitForValidValues()) {
// This can be simplified once JDK-8048457 has been addressed
// since we won't have an SjavacClient if background = false
if (background) {
// There seems be some problem with spawning the external
// process (for instance no fork command provided and no
// sjavac on path)
StringWriter sw = new StringWriter();
SjavacClient.printFailedAttempt(forkCmd,
stdouterrfile,
new PrintWriter(sw));
Log.error(sw.toString());
}
}
}
return portFile.containsPortInfo();
}
public static void printFailedAttempt(String cmd, String f, PrintWriter err) {
err.println("---- Failed to start javac server with this command -----");
err.println(cmd);
try {
BufferedReader in = new BufferedReader(new FileReader(f));
err.println("---- stdout/stderr output from attempt to start javac server -----");
for (;;) {
String l = in.readLine();
if (l == null) {
break;
}
err.println(l);
}
err.println("------------------------------------------------------------------");
} catch (Exception e) {
err.println("The stdout/stderr output in file " + f + " does not exist and the server did not start.");
}
} }
@Override @Override
public void shutdown() { public void shutdown() {
// Nothing to clean up // Nothing to clean up
} }
/*
* Fork a server process process and wait for server to come around
*/
public static void fork(String sjavacCmd,
PortFile portFile,
String logfile,
int poolsize,
int keepalive,
final PrintStream err,
String stdouterrfile)
throws IOException, InterruptedException {
List<String> cmd = new ArrayList<>();
cmd.addAll(Arrays.asList(OptionHelper.unescapeCmdArg(sjavacCmd).split(" ")));
cmd.add("--startserver:"
+ "portfile=" + portFile.getFilename()
+ ",logfile=" + logfile
+ ",stdouterrfile=" + stdouterrfile
+ ",poolsize=" + poolsize
+ ",keepalive="+ keepalive);
Process p = null;
Log.info("Starting server. Command: " + String.join(" ", cmd));
try {
// If the cmd for some reason can't be executed (file not found, or
// is not executable) this will throw an IOException with a decent
// error message.
p = new ProcessBuilder(cmd)
.redirectErrorStream(true)
.redirectOutput(new File(stdouterrfile))
.start();
// Throws an IOException if no valid values materialize
portFile.waitForValidValues();
} catch (IOException ex) {
// Log and rethrow exception
Log.error("Faild to launch server.");
Log.error(" Message: " + ex.getMessage());
String rc = p == null || p.isAlive() ? "n/a" : "" + p.exitValue();
Log.error(" Server process exit code: " + rc);
Log.error("Server log:");
Log.error("------- Server log start -------");
try (Scanner s = new Scanner(new File(stdouterrfile))) {
while (s.hasNextLine())
Log.error(s.nextLine());
}
Log.error("------- Server log end ---------");
throw ex;
}
}
} }

View file

@ -25,6 +25,7 @@
package com.sun.tools.sjavac.comp; package com.sun.tools.sjavac.comp;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URI; import java.net.URI;
@ -76,7 +77,7 @@ public class SjavacImpl implements Sjavac {
Set<URI> sourcesToCompile, Set<URI> sourcesToCompile,
Set<URI> visibleSources) { Set<URI> visibleSources) {
JavacTool compiler = JavacTool.create(); JavacTool compiler = JavacTool.create();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
SmartFileManager smartFileManager = new SmartFileManager(fileManager); SmartFileManager smartFileManager = new SmartFileManager(fileManager);
Context context = new Context(); Context context = new Context();
@ -160,6 +161,9 @@ public class SjavacImpl implements Sjavac {
compilationResult.returnCode = rc.exitCode; compilationResult.returnCode = rc.exitCode;
return compilationResult; return compilationResult;
} catch (IOException e) {
throw new Error(e);
}
} }
@Override @Override

View file

@ -25,7 +25,6 @@
package com.sun.tools.sjavac.options; package com.sun.tools.sjavac.options;
import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
@ -159,4 +158,9 @@ public abstract class OptionHelper {
} }
} }
} }
public static String unescapeCmdArg(String arg) {
return arg.replaceAll("%20", " ")
.replaceAll("%2C", ",");
}
} }

View file

@ -33,6 +33,8 @@ import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.channels.FileLockInterruptionException; import java.nio.channels.FileLockInterruptionException;
import java.util.concurrent.Semaphore;
import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Assert;
import com.sun.tools.sjavac.Log; import com.sun.tools.sjavac.Log;
@ -61,7 +63,12 @@ public class PortFile {
private File stopFile; private File stopFile;
private RandomAccessFile rwfile; private RandomAccessFile rwfile;
private FileChannel channel; private FileChannel channel;
// FileLock used to solve inter JVM synchronization, lockSem used to avoid
// JVM internal OverlappingFileLockExceptions.
// Class invariant: lock.isValid() <-> lockSem.availablePermits() == 0
private FileLock lock; private FileLock lock;
private Semaphore lockSem = new Semaphore(1);
private boolean containsPortInfo; private boolean containsPortInfo;
private int serverPort; private int serverPort;
@ -88,7 +95,8 @@ public class PortFile {
/** /**
* Lock the port file. * Lock the port file.
*/ */
public void lock() throws IOException { public void lock() throws IOException, InterruptedException {
lockSem.acquire();
lock = channel.lock(); lock = channel.lock();
} }
@ -195,34 +203,37 @@ public class PortFile {
Assert.check(lock != null); Assert.check(lock != null);
lock.release(); lock.release();
lock = null; lock = null;
lockSem.release();
} }
/** /**
* Wait for the port file to contain values that look valid. * Wait for the port file to contain values that look valid.
* Return true, if a-ok, false if the valid values did not materialize within 5 seconds.
*/ */
public synchronized boolean waitForValidValues() throws IOException, FileNotFoundException { public void waitForValidValues() throws IOException, InterruptedException {
for (int tries = 0; tries < 50; tries++) { final int MAX_ATTEMPTS = 10;
final int MS_BETWEEN_ATTEMPTS = 500;
long startTime = System.currentTimeMillis();
for (int attempt = 0; ; attempt++) {
Log.debug("Looking for valid port file values...");
lock(); lock();
getValues(); getValues();
unlock(); unlock();
if (containsPortInfo) { if (containsPortInfo) {
Log.debug("Found valid values in port file after waiting "+(tries*100)+"ms"); Log.debug("Valid port file values found after " + (System.currentTimeMillis() - startTime) + " ms");
return true; return;
} }
try { if (attempt >= MAX_ATTEMPTS) {
Thread.sleep(100); throw new IOException("No port file values materialized. Giving up after " +
} catch (InterruptedException e) (System.currentTimeMillis() - startTime) + " ms");
{} }
Thread.sleep(MS_BETWEEN_ATTEMPTS);
} }
Log.debug("Gave up waiting for valid values in port file");
return false;
} }
/** /**
* Check if the portfile still contains my values, assuming that I am the server. * Check if the portfile still contains my values, assuming that I am the server.
*/ */
public synchronized boolean stillMyValues() throws IOException, FileNotFoundException { public boolean stillMyValues() throws IOException, FileNotFoundException, InterruptedException {
for (;;) { for (;;) {
try { try {
lock(); lock();

View file

@ -75,6 +75,10 @@ public class PortFileMonitor {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(server.theLog); e.printStackTrace(server.theLog);
server.flushLog(); server.flushLog();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace(server.theLog);
server.flushLog();
} }
} }
}; };

View file

@ -46,8 +46,8 @@ public class ServerMain {
try { try {
SjavacServer server = new SjavacServer(args[0], System.err); SjavacServer server = new SjavacServer(args[0], System.err);
exitCode = server.startServer(); exitCode = server.startServer();
} catch (IOException ioex) { } catch (IOException | InterruptedException ex) {
ioex.printStackTrace(); ex.printStackTrace();
exitCode = -1; exitCode = -1;
} }

View file

@ -24,7 +24,6 @@
*/ */
package com.sun.tools.sjavac.server; package com.sun.tools.sjavac.server;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
@ -34,16 +33,14 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.tools.sjavac.ProblemException;
import com.sun.tools.sjavac.Util; import com.sun.tools.sjavac.Util;
import com.sun.tools.sjavac.comp.SjavacImpl;
import com.sun.tools.sjavac.comp.PooledSjavac; import com.sun.tools.sjavac.comp.PooledSjavac;
import com.sun.tools.sjavac.comp.SjavacImpl;
/** /**
* The JavacServer class contains methods both to setup a server that responds to requests and methods to connect to this server. * The JavacServer class contains methods both to setup a server that responds to requests and methods to connect to this server.
@ -95,13 +92,26 @@ public class SjavacServer implements Terminable {
private static Map<String, Long> maxServerMemory; private static Map<String, Long> maxServerMemory;
public SjavacServer(String settings, PrintStream err) throws FileNotFoundException { public SjavacServer(String settings, PrintStream err) throws FileNotFoundException {
// Extract options. TODO: Change to proper constructor args this(Util.extractStringOption("portfile", settings),
portfilename = Util.extractStringOption("portfile", settings); Util.extractStringOption("logfile", settings),
logfile = Util.extractStringOption("logfile", settings); Util.extractStringOption("stdouterrfile", settings),
stdouterrfile = Util.extractStringOption("stdouterrfile", settings); Util.extractIntOption("poolsize", settings, Runtime.getRuntime().availableProcessors()),
keepalive = Util.extractIntOption("keepalive", settings, 120); Util.extractIntOption("keepalive", settings, 120),
poolsize = Util.extractIntOption("poolsize", settings, err);
Runtime.getRuntime().availableProcessors()); }
public SjavacServer(String portfilename,
String logfile,
String stdouterrfile,
int poolsize,
int keepalive,
PrintStream err)
throws FileNotFoundException {
this.portfilename = portfilename;
this.logfile = logfile;
this.stdouterrfile = stdouterrfile;
this.poolsize = poolsize;
this.keepalive = keepalive;
this.err = err; this.err = err;
myCookie = new Random().nextLong(); myCookie = new Random().nextLong();
@ -180,7 +190,7 @@ public class SjavacServer implements Terminable {
* Start a server using a settings string. Typically: "--startserver:portfile=/tmp/myserver,poolsize=3" and the string "portfile=/tmp/myserver,poolsize=3" * Start a server using a settings string. Typically: "--startserver:portfile=/tmp/myserver,poolsize=3" and the string "portfile=/tmp/myserver,poolsize=3"
* is sent as the settings parameter. Returns 0 on success, -1 on failure. * is sent as the settings parameter. Returns 0 on success, -1 on failure.
*/ */
public int startServer() throws IOException { public int startServer() throws IOException, InterruptedException {
long serverStart = System.currentTimeMillis(); long serverStart = System.currentTimeMillis();
// The port file is locked and the server port and cookie is written into it. // The port file is locked and the server port and cookie is written into it.
@ -250,64 +260,6 @@ public class SjavacServer implements Terminable {
return 0; return 0;
} }
/**
* Fork a background process. Returns the command line used that can be printed if something failed.
*/
public static String fork(String sjavac, String portfile, String logfile, int poolsize, int keepalive,
final PrintStream err, String stdouterrfile, boolean background)
throws IOException, ProblemException {
if (stdouterrfile != null && stdouterrfile.trim().equals("")) {
stdouterrfile = null;
}
final String startserver = "--startserver:portfile=" + portfile + ",logfile=" + logfile + ",stdouterrfile=" + stdouterrfile + ",poolsize=" + poolsize + ",keepalive="+ keepalive;
if (background) {
sjavac += "%20" + startserver;
sjavac = sjavac.replaceAll("%20", " ");
sjavac = sjavac.replaceAll("%2C", ",");
// If the java/sh/cmd launcher fails the failure will be captured by stdouterr because of the redirection here.
String[] cmd = {"/bin/sh", "-c", sjavac + " >> " + stdouterrfile + " 2>&1"};
if (!(new File("/bin/sh")).canExecute()) {
ArrayList<String> wincmd = new ArrayList<>();
wincmd.add("cmd");
wincmd.add("/c");
wincmd.add("start");
wincmd.add("cmd");
wincmd.add("/c");
wincmd.add(sjavac + " >> " + stdouterrfile + " 2>&1");
cmd = wincmd.toArray(new String[wincmd.size()]);
}
Process pp = null;
try {
pp = Runtime.getRuntime().exec(cmd);
} catch (Exception e) {
e.printStackTrace(err);
e.printStackTrace(new PrintWriter(stdouterrfile));
}
StringBuilder rs = new StringBuilder();
for (String s : cmd) {
rs.append(s + " ");
}
return rs.toString();
}
// Do not spawn a background server, instead run it within the same JVM.
Thread t = new Thread() {
@Override
public void run() {
try {
SjavacServer server = new SjavacServer(startserver, err);
server.startServer();
} catch (Throwable t) {
t.printStackTrace(err);
}
}
};
t.setDaemon(true);
t.start();
return "";
}
@Override @Override
public void shutdown(String quitMsg) { public void shutdown(String quitMsg) {
if (!keepAcceptingRequests.compareAndSet(true, false)) { if (!keepAcceptingRequests.compareAndSet(true, false)) {

View file

@ -656,6 +656,9 @@ public class VisibleMemberMap {
// properties aren't named setA* or getA* // properties aren't named setA* or getA*
private final Pattern pattern = Pattern.compile("[sg]et\\p{Upper}.*"); private final Pattern pattern = Pattern.compile("[sg]et\\p{Upper}.*");
private boolean isPropertyMethod(MethodDoc method) { private boolean isPropertyMethod(MethodDoc method) {
if (!configuration.javafx) {
return false;
}
if (!method.name().endsWith("Property")) { if (!method.name().endsWith("Property")) {
return false; return false;
} }
@ -667,7 +670,9 @@ public class VisibleMemberMap {
if (pattern.matcher(method.name()).matches()) { if (pattern.matcher(method.name()).matches()) {
return false; return false;
} }
if (method.typeParameters().length > 0) {
return false;
}
return 0 == method.parameters().length return 0 == method.parameters().length
&& !"void".equals(method.returnType().simpleTypeName()); && !"void".equals(method.returnType().simpleTypeName());
} }

View file

@ -89,7 +89,6 @@ public class Start extends ToolOption.Helper {
private boolean apiMode; private boolean apiMode;
private JavaFileManager fileManager; private JavaFileManager fileManager;
private boolean closeFileManagerOnExit;
Start(String programName, Start(String programName,
PrintWriter errWriter, PrintWriter errWriter,
@ -242,7 +241,9 @@ public class Start extends ToolOption.Helper {
messager.error(Messager.NOPOS, "main.fatal.exception"); messager.error(Messager.NOPOS, "main.fatal.exception");
failed = true; failed = true;
} finally { } finally {
if (fileManager != null && closeFileManagerOnExit) { if (fileManager != null
&& fileManager instanceof BaseFileManager
&& ((BaseFileManager) fileManager).autoClose) {
try { try {
fileManager.close(); fileManager.close();
} catch (IOException ignore) { } catch (IOException ignore) {
@ -343,7 +344,9 @@ public class Start extends ToolOption.Helper {
if (fileManager == null) { if (fileManager == null) {
JavacFileManager.preRegister(context); JavacFileManager.preRegister(context);
fileManager = context.get(JavaFileManager.class); fileManager = context.get(JavaFileManager.class);
closeFileManagerOnExit = true; if (fileManager instanceof BaseFileManager) {
((BaseFileManager) fileManager).autoClose = true;
}
} }
if (fileManager instanceof BaseFileManager) { if (fileManager instanceof BaseFileManager) {
((BaseFileManager) fileManager).handleOptions(fileManagerOpts); ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,6 +45,7 @@ import javax.tools.StandardJavaFileManager;
import com.sun.tools.javac.api.ClientCodeWrapper; import com.sun.tools.javac.api.ClientCodeWrapper;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.ClientCodeException;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy;
@ -111,8 +112,12 @@ public class JavadocTool implements DocumentationTool {
else else
context.put(Log.outKey, new PrintWriter(out, true)); context.put(Log.outKey, new PrintWriter(out, true));
if (fileManager == null) if (fileManager == null) {
fileManager = getStandardFileManager(diagnosticListener, null, null); fileManager = getStandardFileManager(diagnosticListener, null, null);
if (fileManager instanceof BaseFileManager) {
((BaseFileManager) fileManager).autoClose = true;
}
}
fileManager = ccw.wrap(fileManager); fileManager = ccw.wrap(fileManager);
context.put(JavaFileManager.class, fileManager); context.put(JavaFileManager.class, fileManager);

View file

@ -186,6 +186,10 @@ ifdef JTREG_TIMEOUT_FACTOR
JTREG_OPTIONS += -timeoutFactor:$(JTREG_TIMEOUT_FACTOR) JTREG_OPTIONS += -timeoutFactor:$(JTREG_TIMEOUT_FACTOR)
endif endif
ifdef JCK_TIMEOUT_FACTOR
JCK_OPTIONS += -timeout:$(JCK_TIMEOUT_FACTOR)
endif
# Default verbosity setting for jtreg # Default verbosity setting for jtreg
JTREG_VERBOSE = fail,error,nopass JTREG_VERBOSE = fail,error,nopass
@ -298,7 +302,7 @@ ifdef JTREG_REFERENCE
endif endif
jtreg-summary: FRC jtreg-summary: FRC
if [ -r $(JTREG_OUTPUT_DIR)/status.txt ]; then \ @if [ -r $(JTREG_OUTPUT_DIR)/status.txt ]; then \
echo ; echo "Summary of jtreg test failures" ; \ echo ; echo "Summary of jtreg test failures" ; \
cat $(JTREG_OUTPUT_DIR)/JTreport/text/summary.txt | \ cat $(JTREG_OUTPUT_DIR)/JTreport/text/summary.txt | \
grep -v 'Not run' | grep -v 'Passed' ; \ grep -v 'Not run' | grep -v 'Passed' ; \
@ -336,8 +340,8 @@ jck-compiler-tests: check-jck FRC
$(JCK_COMPILER_OUTPUT_DIR)/diff.html $(JCK_COMPILER_OUTPUT_DIR)/status.txt $(JCK_COMPILER_OUTPUT_DIR)/diff.html $(JCK_COMPILER_OUTPUT_DIR)/status.txt
@mkdir -p $(JCK_COMPILER_OUTPUT_DIR) @mkdir -p $(JCK_COMPILER_OUTPUT_DIR)
$(JT_JAVA)/bin/java -Xmx512m \ $(JT_JAVA)/bin/java -Xmx512m \
-jar $(JCK_HOME)/JCK-compiler-8/lib/jtjck.jar \ -jar $(JCK_HOME)/JCK-compiler-9/lib/jtjck.jar \
$(if $(JCK_VERBOSE),-v:$(JCK_VERBOSE)) \ $(if $(JCK_VERBOSE),$(if $(filter $(JCK_VERBOSE),summary),-v,-v:$(JCK_VERBOSE))) \
-r:$(JCK_COMPILER_OUTPUT_DIR)/report \ -r:$(JCK_COMPILER_OUTPUT_DIR)/report \
-w:$(JCK_COMPILER_OUTPUT_DIR)/work \ -w:$(JCK_COMPILER_OUTPUT_DIR)/work \
-jdk:$(TESTJAVA) \ -jdk:$(TESTJAVA) \
@ -353,7 +357,7 @@ ifdef JCK_COMPILER_REFERENCE
endif endif
jck-compiler-summary: FRC jck-compiler-summary: FRC
if [ -r $(JCK_COMPILER_OUTPUT_DIR)/status.txt ]; then \ @if [ -r $(JCK_COMPILER_OUTPUT_DIR)/status.txt ]; then \
echo ; echo "Summary of JCK-compiler test failures" ; \ echo ; echo "Summary of JCK-compiler test failures" ; \
cat $(JCK_COMPILER_OUTPUT_DIR)/report/text/summary.txt | \ cat $(JCK_COMPILER_OUTPUT_DIR)/report/text/summary.txt | \
grep -v 'Not run' | grep -v 'Passed' ; \ grep -v 'Not run' | grep -v 'Passed' ; \
@ -387,8 +391,8 @@ jck-runtime-tests: check-jck FRC
$(JCK_RUNTIME_OUTPUT_DIR)/diff.html $(JCK_RUNTIME_OUTPUT_DIR)/status.txt $(JCK_RUNTIME_OUTPUT_DIR)/diff.html $(JCK_RUNTIME_OUTPUT_DIR)/status.txt
@mkdir -p $(JCK_RUNTIME_OUTPUT_DIR) @mkdir -p $(JCK_RUNTIME_OUTPUT_DIR)
$(JT_JAVA)/bin/java -Xmx512m \ $(JT_JAVA)/bin/java -Xmx512m \
-jar $(JCK_HOME)/JCK-runtime-8/lib/jtjck.jar \ -jar $(JCK_HOME)/JCK-runtime-9/lib/jtjck.jar \
$(if $(JCK_VERBOSE),-v:$(JCK_VERBOSE)) \ $(if $(JCK_VERBOSE),$(if $(filter $(JCK_VERBOSE),summary),-v,-v:$(JCK_VERBOSE))) \
-r:$(JCK_RUNTIME_OUTPUT_DIR)/report \ -r:$(JCK_RUNTIME_OUTPUT_DIR)/report \
-w:$(JCK_RUNTIME_OUTPUT_DIR)/work \ -w:$(JCK_RUNTIME_OUTPUT_DIR)/work \
-jdk:$(TESTJAVA) \ -jdk:$(TESTJAVA) \
@ -405,7 +409,7 @@ ifdef JCK_RUNTIME_REFERENCE
endif endif
jck-runtime-summary: FRC jck-runtime-summary: FRC
if [ -r $(JCK_RUNTIME_OUTPUT_DIR)/status.txt ]; then \ @if [ -r $(JCK_RUNTIME_OUTPUT_DIR)/status.txt ]; then \
echo ; echo "Summary of JCK-runtime test failures" ; \ echo ; echo "Summary of JCK-runtime test failures" ; \
cat $(JCK_RUNTIME_OUTPUT_DIR)/report/text/summary.txt | \ cat $(JCK_RUNTIME_OUTPUT_DIR)/report/text/summary.txt | \
grep -v 'Not run' | grep -v 'Passed' ; \ grep -v 'Not run' | grep -v 'Passed' ; \
@ -417,7 +421,7 @@ jck-runtime-summary: FRC
check-jck: $(JCK_HOME) $(PRODUCT_HOME) check-jck: $(JCK_HOME) $(PRODUCT_HOME)
all-summary: FRC all-summary: FRC
if [ -n "`find $(TEST_OUTPUT_DIR) -name status.txt`" ]; then @if [ -n "`find $(TEST_OUTPUT_DIR) -name status.txt`" ]; then
echo ; echo "Summary of test failures" ; \ echo ; echo "Summary of test failures" ; \
cat `find $(TEST_OUTPUT_DIR) -name summary.txt` | \ cat `find $(TEST_OUTPUT_DIR) -name summary.txt` | \
grep -v 'Not run' | grep -v 'Passed' ; \ grep -v 'Not run' | grep -v 'Passed' ; \

View file

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 7112427 8012295 8025633 8026567 * @bug 7112427 8012295 8025633 8026567 8061305
* @summary Test of the JavaFX doclet features. * @summary Test of the JavaFX doclet features.
* @author jvalenta * @author jvalenta
* @library ../lib * @library ../lib
@ -39,17 +39,19 @@ public class TestJavaFX extends JavadocTester {
} }
@Test @Test
void test() { void test1() {
javadoc("-d", "out", javadoc("-d", "out1",
"-sourcepath", testSrc, "-sourcepath", testSrc,
"-javafx", "-javafx",
testSrc("C.java"), testSrc("D.java")); "-package",
checkExit(Exit.FAILED); // should be EXIT_OK -- need to fix C.java "pkg1");
checkExit(Exit.OK);
checkOutput("C.html", true, checkOutput("pkg1/C.html", true,
"<dt><span class=\"seeLabel\">See Also:</span></dt>\n" "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
+ "<dd><a href=\"C.html#getRate--\"><code>getRate()</code></a>, \n" + "<dd><a href=\"../pkg1/C.html#getRate--\"><code>getRate()</code></a>, \n"
+ "<a href=\"C.html#setRate-double-\"><code>setRate(double)</code></a></dd>", + "<a href=\"../pkg1/C.html#setRate-double-\">"
+ "<code>setRate(double)</code></a></dd>",
"<pre>public final&nbsp;void&nbsp;setRate(double&nbsp;value)</pre>\n" "<pre>public final&nbsp;void&nbsp;setRate(double&nbsp;value)</pre>\n"
+ "<div class=\"block\">Sets the value of the property rate.</div>\n" + "<div class=\"block\">Sets the value of the property rate.</div>\n"
+ "<dl>\n" + "<dl>\n"
@ -58,25 +60,122 @@ public class TestJavaFX extends JavadocTester {
+ "<div class=\"block\">Gets the value of the property rate.</div>\n" + "<div class=\"block\">Gets the value of the property rate.</div>\n"
+ "<dl>\n" + "<dl>\n"
+ "<dt><span class=\"simpleTagLabel\">Property description:</span></dt>", + "<dt><span class=\"simpleTagLabel\">Property description:</span></dt>",
"<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"C.html#rateProperty\">rate</a></span></code>\n" "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+ "<div class=\"block\">Defines the direction/speed at which the <code>Timeline</code> is expected to", + "<a href=\"../pkg1/C.html#rateProperty\">rate</a></span></code>\n"
+ "<div class=\"block\">Defines the direction/speed at which the "
+ "<code>Timeline</code> is expected to",
"<span class=\"simpleTagLabel\">Default value:</span>", "<span class=\"simpleTagLabel\">Default value:</span>",
"<span class=\"simpleTagLabel\">Since:</span></dt>\n" "<span class=\"simpleTagLabel\">Since:</span></dt>\n"
+ "<dd>JavaFX 8.0</dd>", + "<dd>JavaFX 8.0</dd>",
"<p>Sets the value of the property <code>Property</code>", "<p>Sets the value of the property <code>Property</code>",
"<p>Gets the value of the property <code>Property</code>", "<p>Gets the value of the property <code>Property</code>",
"<span class=\"simpleTagLabel\">Property description:</span>", "<span class=\"simpleTagLabel\">Property description:</span>",
"<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"C.html#setTestMethodProperty--\">setTestMethodProperty</a></span>()</code>&nbsp;</td>", "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+ "<a href=\"../pkg1/C.html#setTestMethodProperty--\">"
+ "setTestMethodProperty</a></span>()</code>&nbsp;</td>",
"<h4>isPaused</h4>\n" "<h4>isPaused</h4>\n"
+ "<pre>public final&nbsp;double&nbsp;isPaused()</pre>\n" + "<pre>public final&nbsp;double&nbsp;isPaused()</pre>\n"
+ "<div class=\"block\">Gets the value of the property paused.</div>"); + "<div class=\"block\">Gets the value of the property paused.</div>");
checkOutput("C.html", false, checkOutput("pkg1/C.html", false,
"A()"); "A()");
checkOutput("D.html", true, checkOutput("pkg1/D.html", true,
"<h3>Properties inherited from class&nbsp;<a href=\"C.html\" title=\"class in &lt;Unnamed&gt;\">C</a></h3>\n" "<h3>Properties inherited from class&nbsp;pkg1."
+ "<code><a href=\"C.html#pausedProperty\">paused</a>, <a href=\"C.html#rateProperty\">rate</a></code></li>"); + "<a href=\"../pkg1/C.html\" title=\"class in pkg1\">C</a></h3>\n"
+ "<code><a href=\"../pkg1/C.html#pausedProperty\">"
+ "paused</a>, <a href=\"../pkg1/C.html#rateProperty\">rate</a></code></li>");
}
/*
* Test with -javafx option enabled, to ensure property getters and setters
* are treated correctly.
*/
@Test
void test2() {
javadoc("-d", "out2a",
"-sourcepath", testSrc,
"-javafx",
"-package",
"pkg2");
checkExit(Exit.OK);
checkOutput("pkg2/Test.html", true,
"<li class=\"blockList\"><a name=\"property.detail\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<h3>Property Detail</h3>\n"
+ "<a name=\"betaProperty\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
+ "<h4>beta</h4>\n"
+ "<pre>public&nbsp;java.lang.Object betaProperty</pre>\n"
+ "</li>\n"
+ "</ul>\n"
+ "<a name=\"gammaProperty\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
+ "<h4>gamma</h4>\n"
+ "<pre>public final&nbsp;java.util.List&lt;"
+ "java.lang.String&gt; gammaProperty</pre>\n"
+ "</li>\n"
+ "</ul>\n"
+ "<a name=\"deltaProperty\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<ul class=\"blockListLast\">\n"
+ "<li class=\"blockList\">\n"
+ "<h4>delta</h4>\n"
+ "<pre>public final&nbsp;java.util.List&lt;"
+ "java.util.Set&lt;? super java.lang.Object&gt;&gt; deltaProperty</pre>\n"
+ "</li>\n"
+ "</ul>\n"
+ "</li>");
}
/*
* Test without -javafx option, to ensure property getters and setters
* are treated just like any other java method.
*/
@Test
void test3() {
javadoc("-d", "out2b",
"-sourcepath", testSrc,
"-package",
"pkg2");
checkExit(Exit.OK);
checkOutput("pkg2/Test.html", false, "<h3>Property Summary</h3>");
checkOutput("pkg2/Test.html", true,
"<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
+ "<th class=\"colLast\" scope=\"col\">Method and Description</th>\n"
+ "</tr>\n"
+ "<tr id=\"i0\" class=\"altColor\">\n"
+ "<td class=\"colFirst\"><code>&lt;T&gt;&nbsp;java.lang.Object</code></td>\n"
+ "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+ "<a href=\"../pkg2/Test.html#alphaProperty-java.util.List-\">"
+ "alphaProperty</a></span>(java.util.List&lt;T&gt;&nbsp;foo)</code>&nbsp;</td>\n"
+ "</tr>\n"
+ "<tr id=\"i1\" class=\"rowColor\">\n"
+ "<td class=\"colFirst\"><code>java.lang.Object</code></td>\n"
+ "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+ "<a href=\"../pkg2/Test.html#betaProperty--\">betaProperty</a></span>()</code>"
+ "&nbsp;</td>\n"
+ "</tr>\n"
+ "<tr id=\"i2\" class=\"altColor\">\n"
+ "<td class=\"colFirst\"><code>"
+ "java.util.List&lt;java.util.Set&lt;? super java.lang.Object&gt;&gt;"
+ "</code></td>\n"
+ "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+ "<a href=\"../pkg2/Test.html#deltaProperty--\">"
+ "deltaProperty</a></span>()</code>&nbsp;</td>\n"
+ "</tr>\n"
+ "<tr id=\"i3\" class=\"rowColor\">\n"
+ "<td class=\"colFirst\"><code>java.util.List&lt;java.lang.String&gt;"
+ "</code></td>\n"
+ "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+ "<a href=\"../pkg2/Test.html#gammaProperty--\">gammaProperty</a>"
+ "</span>()</code>&nbsp;</td>"
);
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -20,10 +20,7 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package pkg1;
/**
* @expert Expert tag text
*/
public class C { public class C {
@ -35,7 +32,6 @@ public class C {
/** /**
* @propertyGetter Property * @propertyGetter Property
* @expert Expert tag text
* *
*/ */
public void B() {} public void B() {}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -20,9 +20,6 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package pkg1;
/**
* @expert Expert tag text
*/
public class D extends C {} public class D extends C {}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2012, 2014, 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 pkg2;
import java.util.List;
import java.util.Set;
public class Test {
public <T> Object alphaProperty(List<T> foo) { return null; }
public Object betaProperty() { return null; }
public final List<String> gammaProperty() {return null;}
public final List<Set<? super Object>> deltaProperty() {return null;}
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -245,7 +245,7 @@ public abstract class JavacTemplateTestBase {
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException { private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null); try (StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null)) {
if (classpaths.size() > 0) if (classpaths.size() > 0)
fm.setLocation(StandardLocation.CLASS_PATH, classpaths); fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files); JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
@ -262,6 +262,7 @@ public abstract class JavacTemplateTestBase {
return nullDir; return nullDir;
} }
} }
}
/** Load the given class using the provided list of class paths */ /** Load the given class using the provided list of class paths */
protected Class<?> loadClass(String className, File... destDirs) { protected Class<?> loadClass(String className, File... destDirs) {

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014, 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
* @summary Incorrect shadowing of classes vs type parameters
* @bug 8035259
* @run compile TypeVarShadow.java
*/
public class TypeVarShadow {
class T<E> {}
abstract class One<E> {
abstract E foo();
}
abstract class Two<T> extends One<T> {
abstract T foo();
}
}

View file

@ -44,6 +44,7 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.tools.Diagnostic; import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener; import javax.tools.DiagnosticListener;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
@ -52,7 +53,8 @@ public class VerifyErroneousAnnotationsAttributed {
new VerifyErroneousAnnotationsAttributed().run(); new VerifyErroneousAnnotationsAttributed().run();
} }
void run() { void run() throws IOException {
try {
int failCount = 0; int failCount = 0;
for (String ann : generateAnnotations()) { for (String ann : generateAnnotations()) {
String code = PATTERN.replace("PLACEHOLDER", ann); String code = PATTERN.replace("PLACEHOLDER", ann);
@ -69,6 +71,9 @@ public class VerifyErroneousAnnotationsAttributed {
if (failCount > 0) { if (failCount > 0) {
throw new IllegalStateException("failed sub-tests: " + failCount); throw new IllegalStateException("failed sub-tests: " + failCount);
} }
} finally {
fm.close();
}
} }
List<String> generateAnnotations() { List<String> generateAnnotations() {
@ -221,13 +226,14 @@ public class VerifyErroneousAnnotationsAttributed {
} }
final JavacTool tool = JavacTool.create(); final JavacTool tool = JavacTool.create();
final JavaFileManager fm = tool.getStandardFileManager(null, null, null);
final DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() { final DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() {
@Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) {} @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) {}
}; };
void validate(String code) throws IOException, URISyntaxException { void validate(String code) throws IOException, URISyntaxException {
JavacTask task = tool.getTask(null, JavacTask task = tool.getTask(null,
null, fm,
devNull, devNull,
Arrays.asList("-XDshouldStopPolicy=FLOW"), Arrays.asList("-XDshouldStopPolicy=FLOW"),
null, null,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,19 +34,20 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.DeclaredType; import javax.lang.model.type.DeclaredType;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
import com.sun.source.util.JavacTask; import com.sun.source.util.JavacTask;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
public class TestContainTypes { public class TestContainTypes {
@ -127,7 +128,11 @@ public class TestContainTypes {
} }
} }
static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
static final JavaFileManager fm = tool.getStandardFileManager(null, null, null);
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
try {
for (ClassType ctA : ClassType.values()) { for (ClassType ctA : ClassType.values()) {
for (ParameterType ptA : ParameterType.values()) { for (ParameterType ptA : ParameterType.values()) {
for (ClassType ctB : ClassType.values()) { for (ClassType ctB : ClassType.values()) {
@ -137,12 +142,14 @@ public class TestContainTypes {
} }
} }
} }
} finally {
fm.close();
}
} }
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception { static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception {
JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB)); JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB));
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTask ct = (JavacTask)tool.getTask(null, fm, null,
JavacTask ct = (JavacTask)tool.getTask(null, null, null,
null, null, Arrays.asList(source)); null, null, Arrays.asList(source));
ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source))); ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source)));
System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA)); System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA));

View file

@ -100,6 +100,7 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
JavacTool tool = JavacTool.create(); JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
try {
if (fmOpts != null) if (fmOpts != null)
fm = new FileManager(fm, fmOpts); fm = new FileManager(fm, fmOpts);
@ -108,6 +109,9 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
Context c = initContext(); Context c = initContext();
JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c); JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c);
return t.call(); return t.call();
} finally {
close(fm);
}
} }
} }
@ -136,9 +140,14 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
Main main = new Main("javac", out); Main main = new Main("javac", out);
Context c = initContext(); Context c = initContext();
JavacFileManager.preRegister(c); // can't create it until Log has been set up JavacFileManager.preRegister(c); // can't create it until Log has been set up
try {
Main.Result result = main.compile(args.toArray(new String[args.size()]), c); Main.Result result = main.compile(args.toArray(new String[args.size()]), c);
return result.isOK(); return result.isOK();
} finally {
close(c.get(JavaFileManager.class));
}
} }
} }
@ -160,10 +169,15 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
Context c = initContext(); Context c = initContext();
JavacFileManager.preRegister(c); // can't create it until Log has been set up JavacFileManager.preRegister(c); // can't create it until Log has been set up
try {
Main m = new Main("javac", out); Main m = new Main("javac", out);
Main.Result result = m.compile(args.toArray(new String[args.size()]), c); Main.Result result = m.compile(args.toArray(new String[args.size()]), c);
return result.isOK(); return result.isOK();
} finally {
close(c.get(JavaFileManager.class));
}
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@ import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask; import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager; import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
@ -351,6 +352,14 @@ class Example implements Comparable<Example> {
loader = cl; loader = cl;
} }
protected void close(JavaFileManager fm) {
try {
fm.close();
} catch (IOException e) {
throw new Error(e);
}
}
protected ClassLoader loader; protected ClassLoader loader;
protected boolean verbose; protected boolean verbose;
} }
@ -399,6 +408,7 @@ class Example implements Comparable<Example> {
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(dc, null, null); StandardJavaFileManager fm = c.getStandardFileManager(dc, null, null);
try {
if (fmOpts != null) if (fmOpts != null)
fm = new FileManager(fm, fmOpts); fm = new FileManager(fm, fmOpts);
@ -414,6 +424,9 @@ class Example implements Comparable<Example> {
} }
return ok; return ok;
} finally {
close(fm);
}
} }
/** /**
@ -526,6 +539,8 @@ class Example implements Comparable<Example> {
Context c = new Context(); Context c = new Context();
JavacFileManager.preRegister(c); // can't create it until Log has been set up JavacFileManager.preRegister(c); // can't create it until Log has been set up
MessageTracker.preRegister(c, keys); MessageTracker.preRegister(c, keys);
try {
Main m = new Main("javac", pw); Main m = new Main("javac", pw);
Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); Main.Result rc = m.compile(args.toArray(new String[args.size()]), c);
@ -534,6 +549,9 @@ class Example implements Comparable<Example> {
} }
return rc.isOK(); return rc.isOK();
} finally {
close(c.get(JavaFileManager.class));
}
} }
static class MessageTracker extends JavacMessages { static class MessageTracker extends JavacMessages {

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014, 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.plugin.not.found
// options: -Xplugin:MissingPlugin
class PluginNotFound { }

View file

@ -0,0 +1,29 @@
/*
* @test /nodynamiccopyright/
* @bug 6987475
*
* @summary Order of declarations affects whether abstract method considered overridden
* @compile/fail/ref=T6987475neg.out -XDrawDiagnostics T6987475neg.java
*/
class T6987475neg {
static abstract class Base<A> {
public void go(String s) { }
public abstract void go(A a);
}
static abstract class BaseReverse<A> {
public abstract void go(A a);
public void go(String s) { }
}
static abstract class Sub<A> extends Base<A> {
public abstract void go(A a);
}
static abstract class SubReverse<A> extends BaseReverse<A> {
public abstract void go(A a);
}
static class Impl1 extends Sub<String> { }
static class Impl2 extends SubReverse<String> { }
}

View file

@ -0,0 +1,3 @@
T6987475neg.java:27:12: compiler.err.does.not.override.abstract: T6987475neg.Impl1, go(java.lang.String), T6987475neg.Sub
T6987475neg.java:28:12: compiler.err.does.not.override.abstract: T6987475neg.Impl2, go(java.lang.String), T6987475neg.SubReverse
2 errors

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2014, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 6987475
*
* @summary Order of declarations affects whether abstract method considered overridden
* @compile T6987475pos.java
*/
class T6987475pos {
static abstract class Base<A> {
public void go(String s) { }
public abstract void go(A a);
}
static abstract class BaseReverse<A> {
public abstract void go(A a);
public void go(String s) { }
}
static class Impl1 extends Base<String> { }
static class Impl2 extends BaseReverse<String> { }
}

View file

@ -0,0 +1,29 @@
/*
* @test /nodynamiccopyright/
* @bug 8062977
* @summary Inference: NullPointerException during bound incorporation
*
* @compile/fail/ref=T8062977.out -XDrawDiagnostics T8062977.java
*/
import java.util.List;
class T8062977 {
<T extends B, B> T m(Class<B> cb) { return null; }
void test1(Class<Iterable<?>> cb) {
List<Integer>[] r1 = m(cb); //fail
List<Integer> r2 = m(cb); //ok
}
void test2(Class<Iterable<?>[]> cb) {
List<Integer>[] r1 = m(cb); //ok
List<Integer> r2 = m(cb); //fail
}
void test3(Class<Iterable<?>[][]> cb) {
List<Integer>[][] r1 = m(cb); //ok
List<Integer>[] r2 = m(cb); //fail
List<Integer> r3 = m(cb); //fail
}
}

View file

@ -0,0 +1,5 @@
T8062977.java:15:31: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.util.List<java.lang.Integer>[]&java.lang.Iterable<?>, java.util.List<java.lang.Integer>[],java.lang.Iterable<?>,java.lang.Object)
T8062977.java:21:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Iterable<?>[]&java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>,java.lang.Iterable<?>[],java.lang.Object)
T8062977.java:26:31: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.util.List<java.lang.Integer>[], java.util.List<java.lang.Integer>[],java.lang.Iterable<?>[][],java.lang.Object)
T8062977.java:27:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Iterable<?>[][]&java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>,java.lang.Iterable<?>[][],java.lang.Object)
4 errors

View file

@ -35,6 +35,7 @@ import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import javax.tools.Diagnostic; import javax.tools.Diagnostic;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
@ -206,9 +207,8 @@ public class SamConversionComboTest {
String clientFileStr = clientSourceFile.toString(); String clientFileStr = clientSourceFile.toString();
System.out.println(clientFileStr.substring(0, clientFileStr.indexOf("\n\n"))); System.out.println(clientFileStr.substring(0, clientFileStr.indexOf("\n\n")));
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
DiagnosticChecker dc = new DiagnosticChecker(); DiagnosticChecker dc = new DiagnosticChecker();
JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile)); JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile));
try { try {
ct.analyze(); ct.analyze();
} catch (Exception e) { } catch (Exception e) {
@ -255,6 +255,9 @@ public class SamConversionComboTest {
ReturnValue returnValue; ReturnValue returnValue;
static int count = 0; static int count = 0;
static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
static JavaFileManager fm = comp.getStandardFileManager(null, null, null);
SamConversionComboTest(FInterface f, Context c, LambdaBody lb, LambdaKind lk, ReturnValue rv) { SamConversionComboTest(FInterface f, Context c, LambdaBody lb, LambdaKind lk, ReturnValue rv) {
fInterface = f; fInterface = f;
context = c; context = c;
@ -264,6 +267,7 @@ public class SamConversionComboTest {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
try {
for(Context ct : Context.values()) { for(Context ct : Context.values()) {
for (FInterface fi : FInterface.values()) { for (FInterface fi : FInterface.values()) {
for (LambdaKind lk: LambdaKind.values()) { for (LambdaKind lk: LambdaKind.values()) {
@ -276,5 +280,8 @@ public class SamConversionComboTest {
} }
} }
System.out.println("total tests: " + count); System.out.println("total tests: " + count);
} finally {
fm.close();
}
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -67,17 +67,23 @@ import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticCollector;
import javax.tools.DiagnosticListener; import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
public class JavacParserTest extends TestCase { public class JavacParserTest extends TestCase {
static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
static final JavaFileManager fm = tool.getStandardFileManager(null, null, null);
private JavacParserTest(){} private JavacParserTest(){}
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
try {
new JavacParserTest().run(args); new JavacParserTest().run(args);
} finally {
fm.close();
}
} }
class MyFileObject extends SimpleJavaFileObject { class MyFileObject extends SimpleJavaFileObject {
@ -103,7 +109,7 @@ public class JavacParserTest extends TestCase {
CompilationUnitTree getCompilationUnitTree(String code) throws IOException { CompilationUnitTree getCompilationUnitTree(String code) throws IOException {
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
return cut; return cut;
@ -129,7 +135,7 @@ public class JavacParserTest extends TestCase {
String code = "package test; public class Test {public Test() {super();}}"; String code = "package test; public class Test {public Test() {super();}}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
SourcePositions pos = Trees.instance(ct).getSourcePositions(); SourcePositions pos = Trees.instance(ct).getSourcePositions();
@ -168,7 +174,7 @@ public class JavacParserTest extends TestCase {
final String theString = "public"; final String theString = "public";
String code = "package test; " + theString + " enum Test {A;}"; String code = "package test; " + theString + " enum Test {A;}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
SourcePositions pos = Trees.instance(ct).getSourcePositions(); SourcePositions pos = Trees.instance(ct).getSourcePositions();
@ -191,7 +197,7 @@ public class JavacParserTest extends TestCase {
"class d {} private void method() { " + "class d {} private void method() { " +
"Object o = " + theString + "; } }"; "Object o = " + theString + "; } }";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
SourcePositions pos = Trees.instance(ct).getSourcePositions(); SourcePositions pos = Trees.instance(ct).getSourcePositions();
@ -238,7 +244,7 @@ public class JavacParserTest extends TestCase {
final List<Diagnostic<? extends JavaFileObject>> errors = final List<Diagnostic<? extends JavaFileObject>> errors =
new LinkedList<Diagnostic<? extends JavaFileObject>>(); new LinkedList<Diagnostic<? extends JavaFileObject>>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm,
new DiagnosticListener<JavaFileObject>() { new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
errors.add(diagnostic); errors.add(diagnostic);
@ -261,7 +267,7 @@ public class JavacParserTest extends TestCase {
String code = "\n@interface Test {}"; String code = "\n@interface Test {}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
@ -300,7 +306,7 @@ public class JavacParserTest extends TestCase {
final List<Diagnostic<? extends JavaFileObject>> errors = final List<Diagnostic<? extends JavaFileObject>> errors =
new LinkedList<Diagnostic<? extends JavaFileObject>>(); new LinkedList<Diagnostic<? extends JavaFileObject>>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm,
new DiagnosticListener<JavaFileObject>() { new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
@ -443,7 +449,7 @@ public class JavacParserTest extends TestCase {
final List<Diagnostic<? extends JavaFileObject>> errors = final List<Diagnostic<? extends JavaFileObject>> errors =
new LinkedList<Diagnostic<? extends JavaFileObject>>(); new LinkedList<Diagnostic<? extends JavaFileObject>>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm,
new DiagnosticListener<JavaFileObject>() { new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
errors.add(diagnostic); errors.add(diagnostic);
@ -482,7 +488,7 @@ public class JavacParserTest extends TestCase {
String code = "package t; class Test { <T> void t() {} }"; String code = "package t; class Test { <T> void t() {} }";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
@ -505,7 +511,7 @@ public class JavacParserTest extends TestCase {
DiagnosticCollector<JavaFileObject> coll = DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>(); new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
ct.parse(); ct.parse();
@ -529,7 +535,7 @@ public class JavacParserTest extends TestCase {
"if (name != null) class X {} } }"; "if (name != null) class X {} } }";
DiagnosticCollector<JavaFileObject> coll = DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>(); new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
ct.parse(); ct.parse();
@ -552,7 +558,7 @@ public class JavacParserTest extends TestCase {
"if (true) abstract class F {} }}"; "if (true) abstract class F {} }}";
DiagnosticCollector<JavaFileObject> coll = DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>(); new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
ct.parse(); ct.parse();
@ -575,7 +581,7 @@ public class JavacParserTest extends TestCase {
"if (name != null) interface X {} } }"; "if (name != null) interface X {} } }";
DiagnosticCollector<JavaFileObject> coll = DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>(); new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
ct.parse(); ct.parse();
@ -598,7 +604,7 @@ public class JavacParserTest extends TestCase {
"if (true) } }"; "if (true) } }";
DiagnosticCollector<JavaFileObject> coll = DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>(); new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
ct.parse(); ct.parse();
@ -620,7 +626,7 @@ public class JavacParserTest extends TestCase {
String code = "\nclass Test { { System.err.println(0e); } }"; String code = "\nclass Test { { System.err.println(0e); } }";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
assertNotNull(ct.parse().iterator().next()); assertNotNull(ct.parse().iterator().next());
@ -820,7 +826,7 @@ public class JavacParserTest extends TestCase {
+ " };\n" + " };\n"
+ " }\n" + " }\n"
+ "}"; + "}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
null, null, Arrays.asList(new MyFileObject(code))); null, null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
@ -861,7 +867,7 @@ public class JavacParserTest extends TestCase {
+ " }\n" + " }\n"
+ "}"; + "}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
null, null, Arrays.asList(new MyFileObject(code))); null, null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
@ -886,7 +892,7 @@ public class JavacParserTest extends TestCase {
String code = "package t; enum Test { AAA; }"; String code = "package t; enum Test { AAA; }";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
@ -905,7 +911,7 @@ public class JavacParserTest extends TestCase {
"}"; "}";
DiagnosticCollector<JavaFileObject> coll = DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<>(); new DiagnosticCollector<>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null,
null, Arrays.asList(new MyFileObject(code))); null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next(); CompilationUnitTree cut = ct.parse().iterator().next();

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2014, 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 8063039
* @summary incorrect message reference or broken message file
* @compile/fail/ref=PluginNotFound.out -Xplugin:MissingPlugin PluginNotFound.java
*/
class PluginNotFound { }

View file

@ -0,0 +1,2 @@
error: plug-in not found: MissingPlugin
1 error

View file

@ -24,6 +24,9 @@
/** /**
* @test * @test
* @bug 8001098 8004961 8004082 * @bug 8001098 8004961 8004082
* @library /tools/lib
* @build ToolBox
* @run main Test
* @summary Provide a simple light-weight "plug-in" mechanism for javac * @summary Provide a simple light-weight "plug-in" mechanism for javac
*/ */
@ -58,14 +61,16 @@ public class Test {
final List<String> ref2; final List<String> ref2;
final JavaCompiler compiler; final JavaCompiler compiler;
final StandardJavaFileManager fm; final StandardJavaFileManager fm;
ToolBox tb = new ToolBox();
Test() throws Exception { Test() throws Exception {
testSrc = new File(System.getProperty("test.src")); testSrc = new File(tb.testSrc);
pluginSrc = new File(testSrc, "ShowTypePlugin.java"); pluginSrc = new File(testSrc, "ShowTypePlugin.java");
pluginClasses = new File("plugin"); pluginClasses = new File("plugin");
tb.createDirectories(pluginClasses.toPath());
pluginJar = new File("plugin.jar"); pluginJar = new File("plugin.jar");
ref1 = readFile(testSrc, "Identifiers.out"); ref1 = tb.readAllLines((new File(testSrc,"Identifiers.out")).toPath());
ref2 = readFile(testSrc, "Identifiers_PI.out"); ref2 = tb.readAllLines((new File(testSrc,"Identifiers_PI.out")).toPath());
compiler = ToolProvider.getSystemJavaCompiler(); compiler = ToolProvider.getSystemJavaCompiler();
fm = compiler.getStandardFileManager(null, null, null); fm = compiler.getStandardFileManager(null, null, null);
} }
@ -74,11 +79,15 @@ public class Test {
try { try {
// compile the plugin explicitly, to a non-standard directory // compile the plugin explicitly, to a non-standard directory
// so that we don't find it on the wrong path by accident // so that we don't find it on the wrong path by accident
pluginClasses.mkdirs(); tb.new JavacTask()
compile("-d", pluginClasses.getPath(), pluginSrc.getPath()); .options("-d", pluginClasses.getPath())
writeFile(new File(pluginClasses, "META-INF/services/com.sun.source.util.Plugin"), .files(pluginSrc.getPath())
"ShowTypePlugin\n"); .run();
jar("cf", pluginJar.getPath(), "-C", pluginClasses.getPath(), ".");
File plugin = new File(pluginClasses.getPath(), "META-INF/services/com.sun.source.util.Plugin");
tb.writeFile(plugin.getPath(), "ShowTypePlugin\n");
tb.new JarTask()
.run("cf", pluginJar.getPath(), "-C", pluginClasses.getPath(), ".");
testCommandLine("-Xplugin:showtype", ref1); testCommandLine("-Xplugin:showtype", ref1);
testCommandLine("-Xplugin:showtype PI", ref2); testCommandLine("-Xplugin:showtype PI", ref2);
@ -100,14 +109,13 @@ public class Test {
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(identifiers); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(identifiers);
System.err.println("test api: " + options + " " + files); System.err.println("test api: " + options + " " + files);
ToolBox.Result result = tb.new JavacTask(ToolBox.Mode.API)
StringWriter sw = new StringWriter(); .fileManager(fm)
PrintWriter pw = new PrintWriter(sw); .options(opt)
boolean ok = compiler.getTask(pw, fm, null, options, null, files).call(); .files(identifiers.toPath())
String out = sw.toString(); .run(ToolBox.Expect.SUCCESS)
System.err.println(out); .writeAll();
if (!ok) String out = result.getOutput(ToolBox.OutputKind.DIRECT);
error("testCommandLine: compilation failed");
checkOutput(out, ref); checkOutput(out, ref);
} }
@ -120,14 +128,11 @@ public class Test {
identifiers.getPath() }; identifiers.getPath() };
System.err.println("test command line: " + Arrays.asList(args)); System.err.println("test command line: " + Arrays.asList(args));
ToolBox.Result result = tb.new JavacTask(ToolBox.Mode.CMDLINE)
StringWriter sw = new StringWriter(); .options(args)
PrintWriter pw = new PrintWriter(sw); .run(ToolBox.Expect.SUCCESS)
int rc = com.sun.tools.javac.Main.compile(args, pw); .writeAll();
String out = sw.toString(); String out = result.getOutput(ToolBox.OutputKind.DIRECT);
System.err.println(out);
if (rc != 0)
error("testCommandLine: compilation failed");
checkOutput(out, ref); checkOutput(out, ref);
} }
@ -140,31 +145,6 @@ public class Test {
} }
} }
private void compile(String... args) throws Exception {
System.err.println("compile: " + Arrays.asList(args));
int rc = com.sun.tools.javac.Main.compile(args);
if (rc != 0)
throw new Exception("compiled failed, rc=" + rc);
}
private void jar(String... args) throws Exception {
System.err.println("jar: " + Arrays.asList(args));
boolean ok = new sun.tools.jar.Main(System.out, System.err, "jar").run(args);
if (!ok)
throw new Exception("jar failed");
}
private List<String> readFile(File dir, String name) throws IOException {
return Files.readAllLines(new File(dir, name).toPath(), Charset.defaultCharset());
}
private void writeFile(File f, String body) throws IOException {
f.getParentFile().mkdirs();
try (FileWriter out = new FileWriter(f)) {
out.write(body);
}
}
private void error(String msg) { private void error(String msg) {
System.err.println(msg); System.err.println(msg);
errors++; errors++;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,6 +40,7 @@ import java.util.List;
import java.util.LinkedList; import java.util.LinkedList;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
@ -114,7 +115,8 @@ public class TypeAnnotationsPretty {
code + "; }" + code + "; }" +
postfix; postfix;
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, try (JavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(src))); null, Arrays.asList(new MyFileObject(src)));
for (CompilationUnitTree cut : ct.parse()) { for (CompilationUnitTree cut : ct.parse()) {
@ -123,13 +125,15 @@ public class TypeAnnotationsPretty {
checkMatch(code, var); checkMatch(code, var);
} }
} }
}
private void runMethod(String code) throws IOException { private void runMethod(String code) throws IOException {
String src = prefix + String src = prefix +
code + "}" + code + "}" +
postfix; postfix;
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, try (JavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(src))); null, Arrays.asList(new MyFileObject(src)));
@ -139,6 +143,7 @@ public class TypeAnnotationsPretty {
checkMatch(code, meth); checkMatch(code, meth);
} }
} }
}
void checkMatch(String code, JCTree tree) { void checkMatch(String code, JCTree tree) {
String expect = code.replace("\n", NL); String expect = code.replace("\n", NL);

View file

@ -1475,7 +1475,11 @@ public class ToolBox {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try { try {
JarEntry e = new JarEntry(base.relativize(file).toString()); String p = base.relativize(file)
.normalize()
.toString()
.replace(File.separatorChar, '/');
JarEntry e = new JarEntry(p);
jos.putNextEntry(e); jos.putNextEntry(e);
jos.write(Files.readAllBytes(file)); jos.write(Files.readAllBytes(file));
jos.closeEntry(); jos.closeEntry();

View file

@ -32,6 +32,7 @@
* @run main Wrapper DependencyCollection * @run main Wrapper DependencyCollection
*/ */
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -55,7 +56,7 @@ import com.sun.tools.sjavac.comp.dependencies.DependencyCollector;
public class DependencyCollection { public class DependencyCollection {
public static void main(String[] args) { public static void main(String[] args) throws IOException {
Path src = Paths.get(ToolBox.testSrc, "test-input", "src"); Path src = Paths.get(ToolBox.testSrc, "test-input", "src");
JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); JavaCompiler javac = ToolProvider.getSystemJavaCompiler();