8046369: sjavac should not use javac internal API for starting javac

Reviewed-by: jfranck, alundblad, ohrstrom
This commit is contained in:
Jonathan Gibbons 2014-06-16 11:30:31 -07:00
parent 77fa3101ec
commit 2613fffb87
5 changed files with 22 additions and 35 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 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
@ -161,7 +161,7 @@ public final class JavacTool implements JavaCompiler {
} }
} }
public static void processOptions(Context context, private void processOptions(Context context,
JavaFileManager fileManager, JavaFileManager fileManager,
Iterable<String> options) Iterable<String> options)
{ {

View file

@ -384,7 +384,7 @@ public class Main {
/** Programmatic interface for main function. /** Programmatic interface for main function.
* @param args The command line parameters. * @param args The command line parameters.
*/ */
public Result compile(String[] args, protected Result compile(String[] args,
Context context, Context context,
List<JavaFileObject> fileObjects, List<JavaFileObject> fileObjects,
Iterable<? extends Processor> processors) Iterable<? extends Processor> processors)

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 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
@ -72,10 +72,6 @@ public class Dependencies {
private Dependencies(Context context) { private Dependencies(Context context) {
context.put(dependenciesKey, this); context.put(dependenciesKey, this);
log = Log.instance(context); log = Log.instance(context);
}
public void reset()
{
deps = new HashMap<>(); deps = new HashMap<>();
explicitPackages = new HashSet<>(); explicitPackages = new HashSet<>();
publicApiPerClass = new HashMap<>(); publicApiPerClass = new HashMap<>();

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
@ -39,23 +39,26 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager; import javax.tools.StandardJavaFileManager;
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.StringUtils; import com.sun.tools.javac.util.StringUtils;
import com.sun.tools.sjavac.comp.AttrWithDeps; import com.sun.tools.sjavac.comp.AttrWithDeps;
import com.sun.tools.sjavac.comp.Dependencies; import com.sun.tools.sjavac.comp.Dependencies;
import com.sun.tools.sjavac.comp.JavaCompilerWithDeps; import com.sun.tools.sjavac.comp.JavaCompilerWithDeps;
import com.sun.tools.sjavac.comp.SmartFileManager;
import com.sun.tools.sjavac.comp.ResolveWithDeps; import com.sun.tools.sjavac.comp.ResolveWithDeps;
import com.sun.tools.sjavac.comp.SmartFileManager;
/** /**
* The compiler thread maintains a JavaCompiler instance and * The compiler thread maintains a JavaCompiler instance and
@ -78,7 +81,6 @@ public class CompilerThread implements Runnable {
// The necessary classes to do a compilation. // The necessary classes to do a compilation.
private com.sun.tools.javac.api.JavacTool compiler; private com.sun.tools.javac.api.JavacTool compiler;
private StandardJavaFileManager fileManager; private StandardJavaFileManager fileManager;
private BaseFileManager fileManagerBase;
private SmartFileManager smartFileManager; private SmartFileManager smartFileManager;
private Context context; private Context context;
@ -127,10 +129,8 @@ public class CompilerThread implements Runnable {
inUse = true; inUse = true;
compiler = com.sun.tools.javac.api.JavacTool.create(); compiler = com.sun.tools.javac.api.JavacTool.create();
fileManager = compiler.getStandardFileManager(null, null, null); fileManager = compiler.getStandardFileManager(null, null, null);
fileManagerBase = (BaseFileManager)fileManager;
smartFileManager = new SmartFileManager(fileManager); smartFileManager = new SmartFileManager(fileManager);
context = new Context(); context = new Context();
context.put(JavaFileManager.class, smartFileManager);
ResolveWithDeps.preRegister(context); ResolveWithDeps.preRegister(context);
AttrWithDeps.preRegister(context); AttrWithDeps.preRegister(context);
JavaCompilerWithDeps.preRegister(context, this); JavaCompilerWithDeps.preRegister(context, this);
@ -145,7 +145,6 @@ public class CompilerThread implements Runnable {
inUse = false; inUse = false;
compiler = null; compiler = null;
fileManager = null; fileManager = null;
fileManagerBase = null;
smartFileManager = null; smartFileManager = null;
context = null; context = null;
subTasks = null; subTasks = null;
@ -315,24 +314,13 @@ public class CompilerThread implements Runnable {
com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK; com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK;
try { try {
if (compilationUnits.size() > 0) { if (compilationUnits.size() > 0) {
// Bind the new logger to the existing context.
context.put(Log.outKey, stderr);
Log.instance(context).setWriter(Log.WriterKind.NOTICE, stdout);
Log.instance(context).setWriter(Log.WriterKind.WARNING, stderr);
Log.instance(context).setWriter(Log.WriterKind.ERROR, stderr);
// Process the options.
com.sun.tools.javac.api.JavacTool.processOptions(context, smartFileManager, the_options);
fileManagerBase.setContext(context);
smartFileManager.setVisibleSources(visibleSources); smartFileManager.setVisibleSources(visibleSources);
smartFileManager.cleanArtifacts(); smartFileManager.cleanArtifacts();
smartFileManager.setLog(stdout); smartFileManager.setLog(stdout);
Dependencies.instance(context).reset();
com.sun.tools.javac.main.Main ccompiler = new com.sun.tools.javac.main.Main("javacTask", stderr);
String[] aa = the_options.toArray(new String[0]);
// Do the compilation! // Do the compilation!
rc = ccompiler.compile(aa, context, compilationUnits.toList(), null); CompilationTask task = compiler.getTask(stderr, smartFileManager, null, the_options, null, compilationUnits, context);
rc = ((JavacTaskImpl) task).doCall();
while (numActiveSubTasks()>0) { while (numActiveSubTasks()>0) {
try { Thread.sleep(1000); } catch (InterruptedException e) { } try { Thread.sleep(1000); } catch (InterruptedException e) { }

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
@ -34,8 +34,12 @@ public
class SJavac { class SJavac {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
SJavac s = new SJavac(); try {
s.test(); SJavac s = new SJavac();
s.test();
} finally {
System.out.println("\ntest complete\n");
}
} }
FileSystem defaultfs = FileSystems.getDefault(); FileSystem defaultfs = FileSystems.getDefault();
@ -412,7 +416,7 @@ class SJavac {
} }
void incrementalCompileTestFullyQualifiedRef() throws Exception { void incrementalCompileTestFullyQualifiedRef() throws Exception {
System.out.println("Verify that \"alfa.omega.A a;\" does create a proper dependency."); System.out.println("\nVerify that \"alfa.omega.A a;\" does create a proper dependency.");
System.out.println("----------------------------------------------------------------"); System.out.println("----------------------------------------------------------------");
populate(gensrc, populate(gensrc,
@ -517,8 +521,7 @@ class SJavac {
if (rc == 0) throw new Exception("Expected error during compile! Did not fail!"); if (rc == 0) throw new Exception("Expected error during compile! Did not fail!");
} }
Map<String,Long> collectState(Path dir) throws IOException Map<String,Long> collectState(Path dir) throws IOException {
{
final Map<String,Long> files = new HashMap<>(); final Map<String,Long> files = new HashMap<>();
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override @Override