changeset 3403:220bfc92607e

8046369: sjavac should not use javac internal API for starting javac Reviewed-by: jfranck, alundblad, ohrstrom
author jjg
date Mon, 16 Jun 2014 11:30:31 -0700
parents c2d589333410
children 33cb06e65de2
files src/share/classes/com/sun/tools/javac/api/JavacTool.java src/share/classes/com/sun/tools/javac/main/Main.java src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java test/tools/sjavac/SJavac.java
diffstat 5 files changed, 22 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/api/JavacTool.java	Thu Jun 12 14:29:09 2014 +0200
+++ b/src/share/classes/com/sun/tools/javac/api/JavacTool.java	Mon Jun 16 11:30:31 2014 -0700
@@ -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 static void processOptions(Context context,
+    private void processOptions(Context context,
                                        JavaFileManager fileManager,
                                        Iterable<String> options)
     {
--- a/src/share/classes/com/sun/tools/javac/main/Main.java	Thu Jun 12 14:29:09 2014 +0200
+++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Mon Jun 16 11:30:31 2014 -0700
@@ -384,7 +384,7 @@
     /** 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)
--- a/src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java	Thu Jun 12 14:29:09 2014 +0200
+++ b/src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java	Mon Jun 16 11:30:31 2014 -0700
@@ -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 @@
     private Dependencies(Context context) {
         context.put(dependenciesKey, this);
         log = Log.instance(context);
-    }
-
-    public void reset()
-    {
         deps = new HashMap<>();
         explicitPackages = new HashSet<>();
         publicApiPerClass = new HashMap<>();
--- a/src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java	Thu Jun 12 14:29:09 2014 +0200
+++ b/src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java	Mon Jun 16 11:30:31 2014 -0700
@@ -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.Arrays;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
-import java.util.Map;
 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.ResolveWithDeps;
 import com.sun.tools.sjavac.comp.SmartFileManager;
-import com.sun.tools.sjavac.comp.ResolveWithDeps;
 
 /**
  * The compiler thread maintains a JavaCompiler instance and
@@ -78,7 +81,6 @@
     // 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 @@
         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 @@
         inUse = false;
         compiler = null;
         fileManager = null;
-        fileManagerBase = null;
         smartFileManager = null;
         context = null;
         subTasks = null;
@@ -315,24 +314,13 @@
             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) { }
--- a/test/tools/sjavac/SJavac.java	Thu Jun 12 14:29:09 2014 +0200
+++ b/test/tools/sjavac/SJavac.java	Mon Jun 16 11:30:31 2014 -0700
@@ -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 @@
 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 @@
     }
 
     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 @@
         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