8147571: Information about written .h files is printed on the wrong logging level
authoralundblad
Mon, 29 Feb 2016 13:37:29 +0100
changeset 36162 e5c4e9ab3cdd
parent 36161 a025c0619f25
child 36163 3d0d0a06fe92
8147571: Information about written .h files is printed on the wrong logging level Summary: Changed how SmartWriter outputs log messages. Reviewed-by: jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/CompilationService.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileManager.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileObject.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartWriter.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/CompilationService.java	Mon Feb 29 13:24:01 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/CompilationService.java	Mon Feb 29 13:37:29 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, 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
@@ -95,11 +95,8 @@
             for (JavaFileObject jfo : fm.getJavaFileObjectsFromFiles(sourcesToCompileFiles))
                 explicitJFOs.append(SmartFileManager.locWrap(jfo, StandardLocation.SOURCE_PATH));
 
-            // Create a new logger
-            StringWriter stdoutLog = new StringWriter();
+            // Create a log to capture compiler output
             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;
             PublicApiCollector pubApiCollector = new PublicApiCollector(context, explicitJFOs);
             PathAndPackageVerifier papVerifier = new PathAndPackageVerifier();
@@ -108,11 +105,10 @@
                 if (explicitJFOs.size() > 0) {
                     sfm.setVisibleSources(visibleSources);
                     sfm.cleanArtifacts();
-                    sfm.setLog(stdout);
 
                     // Do the compilation!
                     JavacTaskImpl task =
-                            (JavacTaskImpl) compiler.getTask(stderr,
+                            (JavacTaskImpl) compiler.getTask(new PrintWriter(stderrLog),
                                                              sfm,
                                                              null,
                                                              Arrays.asList(args),
@@ -144,7 +140,6 @@
 
             compilationResult.packagePubapis = pubApiCollector.getPubApis(true);
             compilationResult.dependencyPubapis = pubApiCollector.getPubApis(false);
-            compilationResult.stdout = stdoutLog.toString();
             compilationResult.stderr = stderrLog.toString();
             compilationResult.returnCode = rc.exitCode;
 
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileManager.java	Mon Feb 29 13:24:01 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileManager.java	Mon Feb 29 13:37:29 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, 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
@@ -63,8 +63,6 @@
     Set<URI> visibleSources = new HashSet<>();
     // Map from modulename:packagename to artifacts.
     Map<String,Set<URI>> packageArtifacts = new HashMap<>();
-    // Where to print informational messages.
-    PrintWriter stdout;
 
     public SmartFileManager(JavaFileManager fileManager) {
         super(fileManager);
@@ -78,10 +76,6 @@
         packageArtifacts = new HashMap<>();
     }
 
-    public void setLog(PrintWriter pw) {
-        stdout = pw;
-    }
-
     /**
      * Set whether or not to use ct.sym as an alternate to rt.jar.
      */
@@ -188,7 +182,7 @@
         if (file == null) return file;
 
         if (location.equals(StandardLocation.NATIVE_HEADER_OUTPUT) && superFile instanceof JavaFileObject) {
-           file = new SmartFileObject((JavaFileObject) file, stdout);
+           file = new SmartFileObject((JavaFileObject) file);
            packageName = ":" + packageNameFromFileName(relativeName);
         }
         if (packageName.equals("")) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileObject.java	Mon Feb 29 13:24:01 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileObject.java	Mon Feb 29 13:37:29 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, 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
@@ -49,11 +49,9 @@
 public class SmartFileObject implements JavaFileObject {
 
     JavaFileObject file;
-    PrintWriter stdout;
 
-    public SmartFileObject(JavaFileObject r, PrintWriter pw) {
+    public SmartFileObject(JavaFileObject r) {
         file = r;
-        stdout = pw;
     }
 
     @Override
@@ -113,7 +111,7 @@
         } catch (FileNotFoundException | NoSuchFileException e) {
             // Perfectly ok.
         }
-        return new SmartWriter(file, s.toString(), file.getName(), stdout);
+        return new SmartWriter(file, s.toString(), file.getName());
     }
 
     @DefinedBy(Api.COMPILER)
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartWriter.java	Mon Feb 29 13:24:01 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartWriter.java	Mon Feb 29 13:37:29 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, 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
@@ -25,6 +25,8 @@
 
 package com.sun.tools.sjavac.comp;
 
+import com.sun.tools.sjavac.Log;
+
 import java.io.*;
 import javax.tools.JavaFileObject;
 
@@ -45,19 +47,17 @@
     JavaFileObject file;
     String oldContent;
     StringWriter newContent = new StringWriter();
-    PrintWriter stdout;
     boolean closed;
-    public SmartWriter(JavaFileObject f, String s, String n, PrintWriter pw) {
+
+    public SmartWriter(JavaFileObject f, String s, String n) {
         name = n;
         file = f;
         oldContent = s;
         newContent = new StringWriter();
-        stdout = pw;
         closed = false;
     }
 
-    public void write(char[] chars, int i, int i1)
-    {
+    public void write(char[] chars, int i, int i1) {
         newContent.write(chars, i, i1);
     }
 
@@ -70,7 +70,7 @@
             try (Writer writer = file.openWriter()) {
                 writer.write(s);
             }
-            stdout.println("Writing "+file.getName().substring(p+1));
+            Log.debug("Writing " + file.getName().substring(p + 1));
         }
     }