mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8062676: Tests which leak lots of file managers should be fixed (group 2)
Reviewed-by: darcy
This commit is contained in:
parent
b96daffd2e
commit
a75d2dbd39
10 changed files with 286 additions and 218 deletions
|
@ -413,17 +413,17 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
|
|||
|
||||
int run(String[] args) {
|
||||
try {
|
||||
handleOptions(args);
|
||||
|
||||
// the following gives consistent behavior with javac
|
||||
if (classes == null || classes.size() == 0) {
|
||||
if (options.help || options.version || options.fullVersion)
|
||||
return EXIT_OK;
|
||||
else
|
||||
return EXIT_CMDERR;
|
||||
}
|
||||
|
||||
try {
|
||||
handleOptions(args);
|
||||
|
||||
// the following gives consistent behavior with javac
|
||||
if (classes == null || classes.size() == 0) {
|
||||
if (options.help || options.version || options.fullVersion)
|
||||
return EXIT_OK;
|
||||
else
|
||||
return EXIT_CMDERR;
|
||||
}
|
||||
|
||||
return run();
|
||||
} finally {
|
||||
if (defaultFileManager != null) {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package com.sun.tools.sjavac.comp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
|
@ -76,90 +77,93 @@ public class SjavacImpl implements Sjavac {
|
|||
Set<URI> sourcesToCompile,
|
||||
Set<URI> visibleSources) {
|
||||
JavacTool compiler = JavacTool.create();
|
||||
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
|
||||
SmartFileManager smartFileManager = new SmartFileManager(fileManager);
|
||||
Context context = new Context();
|
||||
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
|
||||
SmartFileManager smartFileManager = new SmartFileManager(fileManager);
|
||||
Context context = new Context();
|
||||
|
||||
// Now setup the actual compilation....
|
||||
CompilationResult compilationResult = new CompilationResult(0);
|
||||
// Now setup the actual compilation....
|
||||
CompilationResult compilationResult = new CompilationResult(0);
|
||||
|
||||
// First deal with explicit source files on cmdline and in at file.
|
||||
ListBuffer<JavaFileObject> compilationUnits = new ListBuffer<>();
|
||||
for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(explicitSources)) {
|
||||
compilationUnits.append(i);
|
||||
}
|
||||
// Now deal with sources supplied as source_to_compile.
|
||||
ListBuffer<File> sourcesToCompileFiles = new ListBuffer<>();
|
||||
for (URI u : sourcesToCompile) {
|
||||
sourcesToCompileFiles.append(new File(u));
|
||||
}
|
||||
for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(sourcesToCompileFiles)) {
|
||||
compilationUnits.append(i);
|
||||
}
|
||||
|
||||
// Create a new logger.
|
||||
StringWriter stdoutLog = new StringWriter();
|
||||
StringWriter stderrLog = new StringWriter();
|
||||
PrintWriter stdout = new PrintWriter(stdoutLog);
|
||||
PrintWriter stderr = new PrintWriter(stderrLog);
|
||||
com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK;
|
||||
DependencyCollector depsCollector = new DependencyCollector();
|
||||
PublicApiCollector pubApiCollector = new PublicApiCollector();
|
||||
PathAndPackageVerifier papVerifier = new PathAndPackageVerifier();
|
||||
try {
|
||||
if (compilationUnits.size() > 0) {
|
||||
smartFileManager.setVisibleSources(visibleSources);
|
||||
smartFileManager.cleanArtifacts();
|
||||
smartFileManager.setLog(stdout);
|
||||
|
||||
// Do the compilation!
|
||||
JavacTaskImpl task =
|
||||
(JavacTaskImpl) compiler.getTask(stderr,
|
||||
smartFileManager,
|
||||
null,
|
||||
Arrays.asList(args),
|
||||
null,
|
||||
compilationUnits,
|
||||
context);
|
||||
smartFileManager.setSymbolFileEnabled(!Options.instance(context).isSet("ignore.symbol.file"));
|
||||
task.addTaskListener(depsCollector);
|
||||
task.addTaskListener(pubApiCollector);
|
||||
task.addTaskListener(papVerifier);
|
||||
rc = task.doCall();
|
||||
smartFileManager.flush();
|
||||
// First deal with explicit source files on cmdline and in at file.
|
||||
ListBuffer<JavaFileObject> compilationUnits = new ListBuffer<>();
|
||||
for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(explicitSources)) {
|
||||
compilationUnits.append(i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stderrLog.append(Util.getStackTrace(e));
|
||||
rc = com.sun.tools.javac.main.Main.Result.ERROR;
|
||||
}
|
||||
|
||||
compilationResult.packageArtifacts = smartFileManager.getPackageArtifacts();
|
||||
|
||||
Dependencies deps = Dependencies.instance(context);
|
||||
for (PackageSymbol from : depsCollector.getSourcePackages()) {
|
||||
for (PackageSymbol to : depsCollector.getDependenciesForPkg(from))
|
||||
deps.collect(from.fullname, to.fullname);
|
||||
}
|
||||
|
||||
for (ClassSymbol cs : pubApiCollector.getClassSymbols())
|
||||
deps.visitPubapi(cs);
|
||||
|
||||
if (papVerifier.getMisplacedCompilationUnits().size() > 0) {
|
||||
for (CompilationUnitTree cu : papVerifier.getMisplacedCompilationUnits()) {
|
||||
System.err.println("Misplaced compilation unit.");
|
||||
System.err.println(" Directory: " + Paths.get(cu.getSourceFile().toUri()).getParent());
|
||||
System.err.println(" Package: " + cu.getPackageName());
|
||||
// Now deal with sources supplied as source_to_compile.
|
||||
ListBuffer<File> sourcesToCompileFiles = new ListBuffer<>();
|
||||
for (URI u : sourcesToCompile) {
|
||||
sourcesToCompileFiles.append(new File(u));
|
||||
}
|
||||
rc = com.sun.tools.javac.main.Main.Result.ERROR;
|
||||
for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(sourcesToCompileFiles)) {
|
||||
compilationUnits.append(i);
|
||||
}
|
||||
|
||||
// Create a new logger.
|
||||
StringWriter stdoutLog = new StringWriter();
|
||||
StringWriter stderrLog = new StringWriter();
|
||||
PrintWriter stdout = new PrintWriter(stdoutLog);
|
||||
PrintWriter stderr = new PrintWriter(stderrLog);
|
||||
com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK;
|
||||
DependencyCollector depsCollector = new DependencyCollector();
|
||||
PublicApiCollector pubApiCollector = new PublicApiCollector();
|
||||
PathAndPackageVerifier papVerifier = new PathAndPackageVerifier();
|
||||
try {
|
||||
if (compilationUnits.size() > 0) {
|
||||
smartFileManager.setVisibleSources(visibleSources);
|
||||
smartFileManager.cleanArtifacts();
|
||||
smartFileManager.setLog(stdout);
|
||||
|
||||
// Do the compilation!
|
||||
JavacTaskImpl task =
|
||||
(JavacTaskImpl) compiler.getTask(stderr,
|
||||
smartFileManager,
|
||||
null,
|
||||
Arrays.asList(args),
|
||||
null,
|
||||
compilationUnits,
|
||||
context);
|
||||
smartFileManager.setSymbolFileEnabled(!Options.instance(context).isSet("ignore.symbol.file"));
|
||||
task.addTaskListener(depsCollector);
|
||||
task.addTaskListener(pubApiCollector);
|
||||
task.addTaskListener(papVerifier);
|
||||
rc = task.doCall();
|
||||
smartFileManager.flush();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stderrLog.append(Util.getStackTrace(e));
|
||||
rc = com.sun.tools.javac.main.Main.Result.ERROR;
|
||||
}
|
||||
|
||||
compilationResult.packageArtifacts = smartFileManager.getPackageArtifacts();
|
||||
|
||||
Dependencies deps = Dependencies.instance(context);
|
||||
for (PackageSymbol from : depsCollector.getSourcePackages()) {
|
||||
for (PackageSymbol to : depsCollector.getDependenciesForPkg(from))
|
||||
deps.collect(from.fullname, to.fullname);
|
||||
}
|
||||
|
||||
for (ClassSymbol cs : pubApiCollector.getClassSymbols())
|
||||
deps.visitPubapi(cs);
|
||||
|
||||
if (papVerifier.getMisplacedCompilationUnits().size() > 0) {
|
||||
for (CompilationUnitTree cu : papVerifier.getMisplacedCompilationUnits()) {
|
||||
System.err.println("Misplaced compilation unit.");
|
||||
System.err.println(" Directory: " + Paths.get(cu.getSourceFile().toUri()).getParent());
|
||||
System.err.println(" Package: " + cu.getPackageName());
|
||||
}
|
||||
rc = com.sun.tools.javac.main.Main.Result.ERROR;
|
||||
}
|
||||
|
||||
compilationResult.packageDependencies = deps.getDependencies();
|
||||
compilationResult.packagePubapis = deps.getPubapis();
|
||||
compilationResult.stdout = stdoutLog.toString();
|
||||
compilationResult.stderr = stderrLog.toString();
|
||||
compilationResult.returnCode = rc.exitCode;
|
||||
|
||||
return compilationResult;
|
||||
} catch (IOException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
||||
compilationResult.packageDependencies = deps.getDependencies();
|
||||
compilationResult.packagePubapis = deps.getPubapis();
|
||||
compilationResult.stdout = stdoutLog.toString();
|
||||
compilationResult.stderr = stderrLog.toString();
|
||||
compilationResult.returnCode = rc.exitCode;
|
||||
|
||||
return compilationResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -245,21 +245,22 @@ public abstract class JavacTemplateTestBase {
|
|||
|
||||
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
|
||||
JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||
StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null);
|
||||
if (classpaths.size() > 0)
|
||||
fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
|
||||
JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
|
||||
if (generate) {
|
||||
File destDir = new File(root, Integer.toString(counter.incrementAndGet()));
|
||||
// @@@ Assert that this directory didn't exist, or start counter at max+1
|
||||
destDir.mkdirs();
|
||||
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
|
||||
ct.generate();
|
||||
return destDir;
|
||||
}
|
||||
else {
|
||||
ct.analyze();
|
||||
return nullDir;
|
||||
try (StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null)) {
|
||||
if (classpaths.size() > 0)
|
||||
fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
|
||||
JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
|
||||
if (generate) {
|
||||
File destDir = new File(root, Integer.toString(counter.incrementAndGet()));
|
||||
// @@@ Assert that this directory didn't exist, or start counter at max+1
|
||||
destDir.mkdirs();
|
||||
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
|
||||
ct.generate();
|
||||
return destDir;
|
||||
}
|
||||
else {
|
||||
ct.analyze();
|
||||
return nullDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import javax.lang.model.element.ElementKind;
|
|||
import javax.lang.model.type.TypeKind;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.DiagnosticListener;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
|
||||
|
@ -52,22 +53,26 @@ public class VerifyErroneousAnnotationsAttributed {
|
|||
new VerifyErroneousAnnotationsAttributed().run();
|
||||
}
|
||||
|
||||
void run() {
|
||||
int failCount = 0;
|
||||
for (String ann : generateAnnotations()) {
|
||||
String code = PATTERN.replace("PLACEHOLDER", ann);
|
||||
try {
|
||||
validate(code);
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed for: ");
|
||||
System.out.println(code);
|
||||
t.printStackTrace(System.out);
|
||||
failCount++;
|
||||
void run() throws IOException {
|
||||
try {
|
||||
int failCount = 0;
|
||||
for (String ann : generateAnnotations()) {
|
||||
String code = PATTERN.replace("PLACEHOLDER", ann);
|
||||
try {
|
||||
validate(code);
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed for: ");
|
||||
System.out.println(code);
|
||||
t.printStackTrace(System.out);
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failCount > 0) {
|
||||
throw new IllegalStateException("failed sub-tests: " + failCount);
|
||||
if (failCount > 0) {
|
||||
throw new IllegalStateException("failed sub-tests: " + failCount);
|
||||
}
|
||||
} finally {
|
||||
fm.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,13 +226,14 @@ public class VerifyErroneousAnnotationsAttributed {
|
|||
}
|
||||
|
||||
final JavacTool tool = JavacTool.create();
|
||||
final JavaFileManager fm = tool.getStandardFileManager(null, null, null);
|
||||
final DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() {
|
||||
@Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) {}
|
||||
};
|
||||
|
||||
void validate(String code) throws IOException, URISyntaxException {
|
||||
JavacTask task = tool.getTask(null,
|
||||
null,
|
||||
fm,
|
||||
devNull,
|
||||
Arrays.asList("-XDshouldStopPolicy=FLOW"),
|
||||
null,
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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 javax.annotation.processing.AbstractProcessor;
|
||||
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.TypeElement;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import com.sun.source.util.JavacTask;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
public class TestContainTypes {
|
||||
|
||||
|
@ -127,22 +128,28 @@ 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 {
|
||||
for (ClassType ctA : ClassType.values()) {
|
||||
for (ParameterType ptA : ParameterType.values()) {
|
||||
for (ClassType ctB : ClassType.values()) {
|
||||
for (ParameterType ptB : ParameterType.values()) {
|
||||
compileAndCheck(ptA, ctA, ptB, ctB);
|
||||
try {
|
||||
for (ClassType ctA : ClassType.values()) {
|
||||
for (ParameterType ptA : ParameterType.values()) {
|
||||
for (ClassType ctB : ClassType.values()) {
|
||||
for (ParameterType ptB : ParameterType.values()) {
|
||||
compileAndCheck(ptA, ctA, ptB, ctB);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fm.close();
|
||||
}
|
||||
}
|
||||
|
||||
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception {
|
||||
JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB));
|
||||
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
|
||||
JavacTask ct = (JavacTask)tool.getTask(null, null, null,
|
||||
JavacTask ct = (JavacTask)tool.getTask(null, fm, null,
|
||||
null, null, Arrays.asList(source));
|
||||
ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source)));
|
||||
System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA));
|
||||
|
|
|
@ -100,14 +100,18 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
|
|||
JavacTool tool = JavacTool.create();
|
||||
|
||||
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
|
||||
if (fmOpts != null)
|
||||
fm = new FileManager(fm, fmOpts);
|
||||
try {
|
||||
if (fmOpts != null)
|
||||
fm = new FileManager(fm, fmOpts);
|
||||
|
||||
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
|
||||
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
|
||||
|
||||
Context c = initContext();
|
||||
JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c);
|
||||
return t.call();
|
||||
Context c = initContext();
|
||||
JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c);
|
||||
return t.call();
|
||||
} finally {
|
||||
close(fm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,9 +140,14 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
|
|||
Main main = new Main("javac", out);
|
||||
Context c = initContext();
|
||||
JavacFileManager.preRegister(c); // can't create it until Log has been set up
|
||||
Main.Result result = main.compile(args.toArray(new String[args.size()]), c);
|
||||
|
||||
return result.isOK();
|
||||
try {
|
||||
Main.Result result = main.compile(args.toArray(new String[args.size()]), c);
|
||||
|
||||
return result.isOK();
|
||||
} finally {
|
||||
close(c.get(JavaFileManager.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,10 +169,15 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
|
|||
|
||||
Context c = initContext();
|
||||
JavacFileManager.preRegister(c); // can't create it until Log has been set up
|
||||
Main m = new Main("javac", out);
|
||||
Main.Result result = m.compile(args.toArray(new String[args.size()]), c);
|
||||
|
||||
return result.isOK();
|
||||
try {
|
||||
Main m = new Main("javac", out);
|
||||
Main.Result result = m.compile(args.toArray(new String[args.size()]), c);
|
||||
|
||||
return result.isOK();
|
||||
} finally {
|
||||
close(c.get(JavaFileManager.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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.JavaCompiler;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
|
@ -311,24 +312,24 @@ class Example implements Comparable<Example> {
|
|||
|
||||
static class DefaultFactory implements Factory {
|
||||
public Compiler getCompiler(List<String> opts, boolean verbose) {
|
||||
String first;
|
||||
String[] rest;
|
||||
if (opts == null || opts.isEmpty()) {
|
||||
first = null;
|
||||
rest = new String[0];
|
||||
} else {
|
||||
first = opts.get(0);
|
||||
rest = opts.subList(1, opts.size()).toArray(new String[opts.size() - 1]);
|
||||
}
|
||||
if (first == null || first.equals("jsr199"))
|
||||
return new Jsr199Compiler(verbose, rest);
|
||||
else if (first.equals("simple"))
|
||||
return new SimpleCompiler(verbose);
|
||||
else if (first.equals("backdoor"))
|
||||
return new BackdoorCompiler(verbose);
|
||||
else
|
||||
throw new IllegalArgumentException(first);
|
||||
String first;
|
||||
String[] rest;
|
||||
if (opts == null || opts.isEmpty()) {
|
||||
first = null;
|
||||
rest = new String[0];
|
||||
} else {
|
||||
first = opts.get(0);
|
||||
rest = opts.subList(1, opts.size()).toArray(new String[opts.size() - 1]);
|
||||
}
|
||||
if (first == null || first.equals("jsr199"))
|
||||
return new Jsr199Compiler(verbose, rest);
|
||||
else if (first.equals("simple"))
|
||||
return new SimpleCompiler(verbose);
|
||||
else if (first.equals("backdoor"))
|
||||
return new BackdoorCompiler(verbose);
|
||||
else
|
||||
throw new IllegalArgumentException(first);
|
||||
}
|
||||
}
|
||||
|
||||
static Factory factory;
|
||||
|
@ -351,6 +352,14 @@ class Example implements Comparable<Example> {
|
|||
loader = cl;
|
||||
}
|
||||
|
||||
protected void close(JavaFileManager fm) {
|
||||
try {
|
||||
fm.close();
|
||||
} catch (IOException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected ClassLoader loader;
|
||||
protected boolean verbose;
|
||||
}
|
||||
|
@ -399,21 +408,25 @@ class Example implements Comparable<Example> {
|
|||
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
|
||||
|
||||
StandardJavaFileManager fm = c.getStandardFileManager(dc, null, null);
|
||||
if (fmOpts != null)
|
||||
fm = new FileManager(fm, fmOpts);
|
||||
try {
|
||||
if (fmOpts != null)
|
||||
fm = new FileManager(fm, fmOpts);
|
||||
|
||||
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
|
||||
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
|
||||
|
||||
CompilationTask t = c.getTask(out, fm, dc, opts, null, fos);
|
||||
Boolean ok = t.call();
|
||||
CompilationTask t = c.getTask(out, fm, dc, opts, null, fos);
|
||||
Boolean ok = t.call();
|
||||
|
||||
if (keys != null) {
|
||||
for (Diagnostic<? extends JavaFileObject> d: dc.getDiagnostics()) {
|
||||
scanForKeys(unwrap(d), keys);
|
||||
if (keys != null) {
|
||||
for (Diagnostic<? extends JavaFileObject> d: dc.getDiagnostics()) {
|
||||
scanForKeys(unwrap(d), keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
return ok;
|
||||
} finally {
|
||||
close(fm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -526,14 +539,19 @@ class Example implements Comparable<Example> {
|
|||
Context c = new Context();
|
||||
JavacFileManager.preRegister(c); // can't create it until Log has been set up
|
||||
MessageTracker.preRegister(c, keys);
|
||||
Main m = new Main("javac", pw);
|
||||
Main.Result rc = m.compile(args.toArray(new String[args.size()]), c);
|
||||
|
||||
if (keys != null) {
|
||||
pw.close();
|
||||
try {
|
||||
Main m = new Main("javac", pw);
|
||||
Main.Result rc = m.compile(args.toArray(new String[args.size()]), c);
|
||||
|
||||
if (keys != null) {
|
||||
pw.close();
|
||||
}
|
||||
|
||||
return rc.isOK();
|
||||
} finally {
|
||||
close(c.get(JavaFileManager.class));
|
||||
}
|
||||
|
||||
return rc.isOK();
|
||||
}
|
||||
|
||||
static class MessageTracker extends JavacMessages {
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.net.URI;
|
|||
import java.util.Arrays;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import javax.tools.ToolProvider;
|
||||
|
@ -206,9 +207,8 @@ public class SamConversionComboTest {
|
|||
String clientFileStr = clientSourceFile.toString();
|
||||
System.out.println(clientFileStr.substring(0, clientFileStr.indexOf("\n\n")));
|
||||
|
||||
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
|
||||
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 {
|
||||
ct.analyze();
|
||||
} catch (Exception e) {
|
||||
|
@ -255,6 +255,9 @@ public class SamConversionComboTest {
|
|||
ReturnValue returnValue;
|
||||
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) {
|
||||
fInterface = f;
|
||||
context = c;
|
||||
|
@ -264,17 +267,21 @@ public class SamConversionComboTest {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for(Context ct : Context.values()) {
|
||||
for (FInterface fi : FInterface.values()) {
|
||||
for (LambdaKind lk: LambdaKind.values()) {
|
||||
for (LambdaBody lb : LambdaBody.values()) {
|
||||
for(ReturnValue rv : ReturnValue.values()) {
|
||||
new SamConversionComboTest(fi, ct, lb, lk, rv).test();
|
||||
try {
|
||||
for(Context ct : Context.values()) {
|
||||
for (FInterface fi : FInterface.values()) {
|
||||
for (LambdaKind lk: LambdaKind.values()) {
|
||||
for (LambdaBody lb : LambdaBody.values()) {
|
||||
for(ReturnValue rv : ReturnValue.values()) {
|
||||
new SamConversionComboTest(fi, ct, lb, lk, rv).test();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("total tests: " + count);
|
||||
} finally {
|
||||
fm.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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.DiagnosticListener;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
public class JavacParserTest extends TestCase {
|
||||
static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
|
||||
static final JavaFileManager fm = tool.getStandardFileManager(null, null, null);
|
||||
|
||||
private JavacParserTest(){}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new JavacParserTest().run(args);
|
||||
try {
|
||||
new JavacParserTest().run(args);
|
||||
} finally {
|
||||
fm.close();
|
||||
}
|
||||
}
|
||||
|
||||
class MyFileObject extends SimpleJavaFileObject {
|
||||
|
@ -103,7 +109,7 @@ public class JavacParserTest extends TestCase {
|
|||
|
||||
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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
return cut;
|
||||
|
@ -129,7 +135,7 @@ public class JavacParserTest extends TestCase {
|
|||
|
||||
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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
SourcePositions pos = Trees.instance(ct).getSourcePositions();
|
||||
|
@ -168,7 +174,7 @@ public class JavacParserTest extends TestCase {
|
|||
final String theString = "public";
|
||||
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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
SourcePositions pos = Trees.instance(ct).getSourcePositions();
|
||||
|
@ -191,7 +197,7 @@ public class JavacParserTest extends TestCase {
|
|||
"class d {} private void method() { " +
|
||||
"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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
SourcePositions pos = Trees.instance(ct).getSourcePositions();
|
||||
|
@ -238,7 +244,7 @@ public class JavacParserTest extends TestCase {
|
|||
final List<Diagnostic<? extends JavaFileObject>> errors =
|
||||
new LinkedList<Diagnostic<? extends JavaFileObject>>();
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null,
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm,
|
||||
new DiagnosticListener<JavaFileObject>() {
|
||||
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||
errors.add(diagnostic);
|
||||
|
@ -261,7 +267,7 @@ public class JavacParserTest extends TestCase {
|
|||
|
||||
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)));
|
||||
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
|
@ -300,7 +306,7 @@ public class JavacParserTest extends TestCase {
|
|||
final List<Diagnostic<? extends JavaFileObject>> errors =
|
||||
new LinkedList<Diagnostic<? extends JavaFileObject>>();
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null,
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm,
|
||||
new DiagnosticListener<JavaFileObject>() {
|
||||
|
||||
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||
|
@ -443,7 +449,7 @@ public class JavacParserTest extends TestCase {
|
|||
final List<Diagnostic<? extends JavaFileObject>> errors =
|
||||
new LinkedList<Diagnostic<? extends JavaFileObject>>();
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null,
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm,
|
||||
new DiagnosticListener<JavaFileObject>() {
|
||||
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||
errors.add(diagnostic);
|
||||
|
@ -482,7 +488,7 @@ public class JavacParserTest extends TestCase {
|
|||
|
||||
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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
|
||||
|
@ -505,7 +511,7 @@ public class JavacParserTest extends TestCase {
|
|||
DiagnosticCollector<JavaFileObject> coll =
|
||||
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)));
|
||||
|
||||
ct.parse();
|
||||
|
@ -529,7 +535,7 @@ public class JavacParserTest extends TestCase {
|
|||
"if (name != null) class X {} } }";
|
||||
DiagnosticCollector<JavaFileObject> coll =
|
||||
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)));
|
||||
|
||||
ct.parse();
|
||||
|
@ -552,7 +558,7 @@ public class JavacParserTest extends TestCase {
|
|||
"if (true) abstract class F {} }}";
|
||||
DiagnosticCollector<JavaFileObject> coll =
|
||||
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)));
|
||||
|
||||
ct.parse();
|
||||
|
@ -575,7 +581,7 @@ public class JavacParserTest extends TestCase {
|
|||
"if (name != null) interface X {} } }";
|
||||
DiagnosticCollector<JavaFileObject> coll =
|
||||
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)));
|
||||
|
||||
ct.parse();
|
||||
|
@ -598,7 +604,7 @@ public class JavacParserTest extends TestCase {
|
|||
"if (true) } }";
|
||||
DiagnosticCollector<JavaFileObject> coll =
|
||||
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)));
|
||||
|
||||
ct.parse();
|
||||
|
@ -620,7 +626,7 @@ public class JavacParserTest extends TestCase {
|
|||
|
||||
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)));
|
||||
|
||||
assertNotNull(ct.parse().iterator().next());
|
||||
|
@ -820,7 +826,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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
|
||||
|
@ -861,7 +867,7 @@ public class JavacParserTest extends TestCase {
|
|||
+ " }\n"
|
||||
+ "}";
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null,
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
|
||||
null, null, Arrays.asList(new MyFileObject(code)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
|
||||
|
@ -886,7 +892,7 @@ public class JavacParserTest extends TestCase {
|
|||
|
||||
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)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
|
||||
|
@ -905,7 +911,7 @@ public class JavacParserTest extends TestCase {
|
|||
"}";
|
||||
DiagnosticCollector<JavaFileObject> coll =
|
||||
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)));
|
||||
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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 javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import javax.tools.ToolProvider;
|
||||
|
@ -114,13 +115,15 @@ public class TypeAnnotationsPretty {
|
|||
code + "; }" +
|
||||
postfix;
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null,
|
||||
null, Arrays.asList(new MyFileObject(src)));
|
||||
try (JavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
|
||||
null, Arrays.asList(new MyFileObject(src)));
|
||||
|
||||
for (CompilationUnitTree cut : ct.parse()) {
|
||||
JCTree.JCVariableDecl var =
|
||||
(JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
|
||||
checkMatch(code, var);
|
||||
for (CompilationUnitTree cut : ct.parse()) {
|
||||
JCTree.JCVariableDecl var =
|
||||
(JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
|
||||
checkMatch(code, var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,14 +132,16 @@ public class TypeAnnotationsPretty {
|
|||
code + "}" +
|
||||
postfix;
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null,
|
||||
null, Arrays.asList(new MyFileObject(src)));
|
||||
try (JavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
|
||||
null, Arrays.asList(new MyFileObject(src)));
|
||||
|
||||
|
||||
for (CompilationUnitTree cut : ct.parse()) {
|
||||
JCTree.JCMethodDecl meth =
|
||||
(JCTree.JCMethodDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
|
||||
checkMatch(code, meth);
|
||||
for (CompilationUnitTree cut : ct.parse()) {
|
||||
JCTree.JCMethodDecl meth =
|
||||
(JCTree.JCMethodDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
|
||||
checkMatch(code, meth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue