mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
8046369: sjavac should not use javac internal API for starting javac
Reviewed-by: jfranck, alundblad, ohrstrom
This commit is contained in:
parent
77fa3101ec
commit
2613fffb87
5 changed files with 22 additions and 35 deletions
|
@ -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.
|
||||
*
|
||||
* 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,
|
||||
Iterable<String> options)
|
||||
{
|
||||
|
|
|
@ -384,7 +384,7 @@ public class Main {
|
|||
/** Programmatic interface for main function.
|
||||
* @param args The command line parameters.
|
||||
*/
|
||||
public Result compile(String[] args,
|
||||
protected Result compile(String[] args,
|
||||
Context context,
|
||||
List<JavaFileObject> fileObjects,
|
||||
Iterable<? extends Processor> processors)
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -72,10 +72,6 @@ public class Dependencies {
|
|||
private Dependencies(Context context) {
|
||||
context.put(dependenciesKey, this);
|
||||
log = Log.instance(context);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
deps = new HashMap<>();
|
||||
explicitPackages = new HashSet<>();
|
||||
publicApiPerClass = new HashMap<>();
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
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.ListBuffer;
|
||||
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.sjavac.comp.AttrWithDeps;
|
||||
import com.sun.tools.sjavac.comp.Dependencies;
|
||||
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.SmartFileManager;
|
||||
|
||||
/**
|
||||
* The compiler thread maintains a JavaCompiler instance and
|
||||
|
@ -78,7 +81,6 @@ public class CompilerThread implements Runnable {
|
|||
// The necessary classes to do a compilation.
|
||||
private com.sun.tools.javac.api.JavacTool compiler;
|
||||
private StandardJavaFileManager fileManager;
|
||||
private BaseFileManager fileManagerBase;
|
||||
private SmartFileManager smartFileManager;
|
||||
private Context context;
|
||||
|
||||
|
@ -127,10 +129,8 @@ public class CompilerThread implements Runnable {
|
|||
inUse = true;
|
||||
compiler = com.sun.tools.javac.api.JavacTool.create();
|
||||
fileManager = compiler.getStandardFileManager(null, null, null);
|
||||
fileManagerBase = (BaseFileManager)fileManager;
|
||||
smartFileManager = new SmartFileManager(fileManager);
|
||||
context = new Context();
|
||||
context.put(JavaFileManager.class, smartFileManager);
|
||||
ResolveWithDeps.preRegister(context);
|
||||
AttrWithDeps.preRegister(context);
|
||||
JavaCompilerWithDeps.preRegister(context, this);
|
||||
|
@ -145,7 +145,6 @@ public class CompilerThread implements Runnable {
|
|||
inUse = false;
|
||||
compiler = null;
|
||||
fileManager = null;
|
||||
fileManagerBase = null;
|
||||
smartFileManager = null;
|
||||
context = 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;
|
||||
try {
|
||||
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.cleanArtifacts();
|
||||
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!
|
||||
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) {
|
||||
try { Thread.sleep(1000); } catch (InterruptedException e) { }
|
||||
|
|
|
@ -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
|
||||
|
@ -34,8 +34,12 @@ public
|
|||
class SJavac {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
SJavac s = new SJavac();
|
||||
s.test();
|
||||
try {
|
||||
SJavac s = new SJavac();
|
||||
s.test();
|
||||
} finally {
|
||||
System.out.println("\ntest complete\n");
|
||||
}
|
||||
}
|
||||
|
||||
FileSystem defaultfs = FileSystems.getDefault();
|
||||
|
@ -412,7 +416,7 @@ class SJavac {
|
|||
}
|
||||
|
||||
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("----------------------------------------------------------------");
|
||||
|
||||
populate(gensrc,
|
||||
|
@ -517,8 +521,7 @@ class SJavac {
|
|||
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<>();
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue