Fri, 18 Jan 2013 00:16:21 +0100
8004658: Add internal smart javac wrapper to solve JEP 139
Reviewed-by: jjg
ohrstrom@1504 | 1 | /* |
ohrstrom@1504 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
ohrstrom@1504 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohrstrom@1504 | 4 | * |
ohrstrom@1504 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohrstrom@1504 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohrstrom@1504 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohrstrom@1504 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohrstrom@1504 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohrstrom@1504 | 10 | * |
ohrstrom@1504 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohrstrom@1504 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohrstrom@1504 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohrstrom@1504 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohrstrom@1504 | 15 | * accompanied this code). |
ohrstrom@1504 | 16 | * |
ohrstrom@1504 | 17 | * You should have received a copy of the GNU General Public License version |
ohrstrom@1504 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohrstrom@1504 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohrstrom@1504 | 20 | * |
ohrstrom@1504 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohrstrom@1504 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohrstrom@1504 | 23 | * questions. |
ohrstrom@1504 | 24 | */ |
ohrstrom@1504 | 25 | |
ohrstrom@1504 | 26 | package com.sun.tools.sjavac.server; |
ohrstrom@1504 | 27 | |
ohrstrom@1504 | 28 | import java.io.BufferedReader; |
ohrstrom@1504 | 29 | import java.io.File; |
ohrstrom@1504 | 30 | import java.io.IOException; |
ohrstrom@1504 | 31 | import java.io.InputStreamReader; |
ohrstrom@1504 | 32 | import java.io.OutputStreamWriter; |
ohrstrom@1504 | 33 | import java.io.PrintWriter; |
ohrstrom@1504 | 34 | import java.io.StringWriter; |
ohrstrom@1504 | 35 | import java.net.Socket; |
ohrstrom@1504 | 36 | import java.net.URI; |
ohrstrom@1504 | 37 | import java.net.URISyntaxException; |
ohrstrom@1504 | 38 | import java.util.ArrayList; |
ohrstrom@1504 | 39 | import java.util.Arrays; |
ohrstrom@1504 | 40 | import java.util.HashSet; |
ohrstrom@1504 | 41 | import java.util.List; |
ohrstrom@1504 | 42 | import java.util.Set; |
ohrstrom@1504 | 43 | import java.util.Map; |
ohrstrom@1504 | 44 | import java.util.concurrent.Future; |
ohrstrom@1504 | 45 | import javax.tools.JavaFileManager; |
ohrstrom@1504 | 46 | import javax.tools.JavaFileObject; |
ohrstrom@1504 | 47 | import javax.tools.StandardJavaFileManager; |
ohrstrom@1504 | 48 | |
ohrstrom@1504 | 49 | import com.sun.tools.javac.util.Context; |
ohrstrom@1504 | 50 | import com.sun.tools.javac.util.Log; |
ohrstrom@1504 | 51 | import com.sun.tools.javac.util.BaseFileManager; |
ohrstrom@1504 | 52 | import com.sun.tools.sjavac.comp.Dependencies; |
ohrstrom@1504 | 53 | import com.sun.tools.sjavac.comp.JavaCompilerWithDeps; |
ohrstrom@1504 | 54 | import com.sun.tools.sjavac.comp.SmartFileManager; |
ohrstrom@1504 | 55 | import com.sun.tools.sjavac.comp.ResolveWithDeps; |
ohrstrom@1504 | 56 | |
ohrstrom@1504 | 57 | /** |
ohrstrom@1504 | 58 | * The compiler thread maintains a JavaCompiler instance and |
ohrstrom@1504 | 59 | * can receive a request from the client, perform the compilation |
ohrstrom@1504 | 60 | * requested and report back the results. |
ohrstrom@1504 | 61 | * |
ohrstrom@1504 | 62 | * * <p><b>This is NOT part of any supported API. |
ohrstrom@1504 | 63 | * If you write code that depends on this, you do so at your own |
ohrstrom@1504 | 64 | * risk. This code and its internal interfaces are subject to change |
ohrstrom@1504 | 65 | * or deletion without notice.</b></p> |
ohrstrom@1504 | 66 | */ |
ohrstrom@1504 | 67 | public class CompilerThread implements Runnable { |
ohrstrom@1504 | 68 | private JavacServer javacServer; |
ohrstrom@1504 | 69 | private CompilerPool compilerPool; |
ohrstrom@1504 | 70 | private List<Future<?>> subTasks; |
ohrstrom@1504 | 71 | |
ohrstrom@1504 | 72 | // Communicating over this socket. |
ohrstrom@1504 | 73 | private Socket socket; |
ohrstrom@1504 | 74 | |
ohrstrom@1504 | 75 | // The necessary classes to do a compilation. |
ohrstrom@1504 | 76 | private com.sun.tools.javac.api.JavacTool compiler; |
ohrstrom@1504 | 77 | private StandardJavaFileManager fileManager; |
ohrstrom@1504 | 78 | private BaseFileManager fileManagerBase; |
ohrstrom@1504 | 79 | private SmartFileManager smartFileManager; |
ohrstrom@1504 | 80 | private Context context; |
ohrstrom@1504 | 81 | |
ohrstrom@1504 | 82 | // If true, then this thread is serving a request. |
ohrstrom@1504 | 83 | private boolean inUse = false; |
ohrstrom@1504 | 84 | |
ohrstrom@1504 | 85 | CompilerThread(CompilerPool cp) { |
ohrstrom@1504 | 86 | compilerPool = cp; |
ohrstrom@1504 | 87 | javacServer = cp.getJavacServer(); |
ohrstrom@1504 | 88 | } |
ohrstrom@1504 | 89 | |
ohrstrom@1504 | 90 | /** |
ohrstrom@1504 | 91 | * Execute a minor task, for example generating bytecodes and writing them to disk, |
ohrstrom@1504 | 92 | * that belong to a major compiler thread task. |
ohrstrom@1504 | 93 | */ |
ohrstrom@1504 | 94 | public synchronized void executeSubtask(Runnable r) { |
ohrstrom@1504 | 95 | subTasks.add(compilerPool.executeSubtask(this, r)); |
ohrstrom@1504 | 96 | } |
ohrstrom@1504 | 97 | |
ohrstrom@1504 | 98 | /** |
ohrstrom@1504 | 99 | * Count the number of active sub tasks. |
ohrstrom@1504 | 100 | */ |
ohrstrom@1504 | 101 | public synchronized int numActiveSubTasks() { |
ohrstrom@1504 | 102 | int c = 0; |
ohrstrom@1504 | 103 | for (Future<?> f : subTasks) { |
ohrstrom@1504 | 104 | if (!f.isDone() && !f.isCancelled()) { |
ohrstrom@1504 | 105 | c++; |
ohrstrom@1504 | 106 | } |
ohrstrom@1504 | 107 | } |
ohrstrom@1504 | 108 | return c; |
ohrstrom@1504 | 109 | } |
ohrstrom@1504 | 110 | |
ohrstrom@1504 | 111 | /** |
ohrstrom@1504 | 112 | * Use this socket for the upcoming request. |
ohrstrom@1504 | 113 | */ |
ohrstrom@1504 | 114 | public void setSocket(Socket s) { |
ohrstrom@1504 | 115 | socket = s; |
ohrstrom@1504 | 116 | } |
ohrstrom@1504 | 117 | |
ohrstrom@1504 | 118 | /** |
ohrstrom@1504 | 119 | * Prepare the compiler thread for use. It is not yet started. |
ohrstrom@1504 | 120 | * It will be started by the executor service. |
ohrstrom@1504 | 121 | */ |
ohrstrom@1504 | 122 | public synchronized void use() { |
ohrstrom@1504 | 123 | assert(!inUse); |
ohrstrom@1504 | 124 | inUse = true; |
ohrstrom@1504 | 125 | compiler = com.sun.tools.javac.api.JavacTool.create(); |
ohrstrom@1504 | 126 | fileManager = compiler.getStandardFileManager(null, null, null); |
ohrstrom@1504 | 127 | fileManagerBase = (BaseFileManager)fileManager; |
ohrstrom@1504 | 128 | smartFileManager = new SmartFileManager(fileManager); |
ohrstrom@1504 | 129 | context = new Context(); |
ohrstrom@1504 | 130 | context.put(JavaFileManager.class, smartFileManager); |
ohrstrom@1504 | 131 | ResolveWithDeps.preRegister(context); |
ohrstrom@1504 | 132 | JavaCompilerWithDeps.preRegister(context, this); |
ohrstrom@1504 | 133 | subTasks = new ArrayList<Future<?>>(); |
ohrstrom@1504 | 134 | } |
ohrstrom@1504 | 135 | |
ohrstrom@1504 | 136 | /** |
ohrstrom@1504 | 137 | * Prepare the compiler thread for idleness. |
ohrstrom@1504 | 138 | */ |
ohrstrom@1504 | 139 | public synchronized void unuse() { |
ohrstrom@1504 | 140 | assert(inUse); |
ohrstrom@1504 | 141 | inUse = false; |
ohrstrom@1504 | 142 | compiler = null; |
ohrstrom@1504 | 143 | fileManager = null; |
ohrstrom@1504 | 144 | fileManagerBase = null; |
ohrstrom@1504 | 145 | smartFileManager = null; |
ohrstrom@1504 | 146 | context = null; |
ohrstrom@1504 | 147 | subTasks = null; |
ohrstrom@1504 | 148 | } |
ohrstrom@1504 | 149 | |
ohrstrom@1504 | 150 | /** |
ohrstrom@1504 | 151 | * Expect this key on the next line read from the reader. |
ohrstrom@1504 | 152 | */ |
ohrstrom@1504 | 153 | private static boolean expect(BufferedReader in, String key) throws IOException { |
ohrstrom@1504 | 154 | String s = in.readLine(); |
ohrstrom@1504 | 155 | if (s != null && s.equals(key)) { |
ohrstrom@1504 | 156 | return true; |
ohrstrom@1504 | 157 | } |
ohrstrom@1504 | 158 | return false; |
ohrstrom@1504 | 159 | } |
ohrstrom@1504 | 160 | |
ohrstrom@1504 | 161 | // The request identifier, for example GENERATE_NEWBYTECODE |
ohrstrom@1504 | 162 | String id = ""; |
ohrstrom@1504 | 163 | |
ohrstrom@1504 | 164 | public String currentRequestId() { |
ohrstrom@1504 | 165 | return id; |
ohrstrom@1504 | 166 | } |
ohrstrom@1504 | 167 | |
ohrstrom@1504 | 168 | PrintWriter stdout; |
ohrstrom@1504 | 169 | PrintWriter stderr; |
ohrstrom@1504 | 170 | int forcedExitCode = 0; |
ohrstrom@1504 | 171 | |
ohrstrom@1504 | 172 | public void logError(String msg) { |
ohrstrom@1504 | 173 | stderr.println(msg); |
ohrstrom@1504 | 174 | forcedExitCode = -1; |
ohrstrom@1504 | 175 | } |
ohrstrom@1504 | 176 | |
ohrstrom@1504 | 177 | /** |
ohrstrom@1504 | 178 | * Invoked by the executor service. |
ohrstrom@1504 | 179 | */ |
ohrstrom@1504 | 180 | public void run() { |
ohrstrom@1504 | 181 | // Unique nr that identifies this request. |
ohrstrom@1504 | 182 | int thisRequest = compilerPool.startRequest(); |
ohrstrom@1504 | 183 | long start = System.currentTimeMillis(); |
ohrstrom@1504 | 184 | int numClasses = 0; |
ohrstrom@1504 | 185 | StringBuilder compiledPkgs = new StringBuilder(); |
ohrstrom@1504 | 186 | use(); |
ohrstrom@1504 | 187 | |
ohrstrom@1504 | 188 | PrintWriter out = null; |
ohrstrom@1504 | 189 | try { |
ohrstrom@1504 | 190 | javacServer.log("<"+thisRequest+"> Connect from "+socket.getRemoteSocketAddress()+" activethreads="+compilerPool.numActiveRequests()); |
ohrstrom@1504 | 191 | BufferedReader in = new BufferedReader(new InputStreamReader( |
ohrstrom@1504 | 192 | socket.getInputStream())); |
ohrstrom@1504 | 193 | out = new PrintWriter(new OutputStreamWriter( |
ohrstrom@1504 | 194 | socket.getOutputStream())); |
ohrstrom@1504 | 195 | if (!expect(in, JavacServer.PROTOCOL_COOKIE_VERSION)) { |
ohrstrom@1504 | 196 | javacServer.log("<"+thisRequest+"> Bad protocol from ip "+socket.getRemoteSocketAddress()); |
ohrstrom@1504 | 197 | return; |
ohrstrom@1504 | 198 | } |
ohrstrom@1504 | 199 | |
ohrstrom@1504 | 200 | String cookie = in.readLine(); |
ohrstrom@1504 | 201 | if (cookie == null || !cookie.equals(""+javacServer.getCookie())) { |
ohrstrom@1504 | 202 | javacServer.log("<"+thisRequest+"> Bad cookie from ip "+socket.getRemoteSocketAddress()); |
ohrstrom@1504 | 203 | return; |
ohrstrom@1504 | 204 | } |
ohrstrom@1504 | 205 | if (!expect(in, JavacServer.PROTOCOL_CWD)) { |
ohrstrom@1504 | 206 | return; |
ohrstrom@1504 | 207 | } |
ohrstrom@1504 | 208 | String cwd = in.readLine(); |
ohrstrom@1504 | 209 | if (cwd == null) |
ohrstrom@1504 | 210 | return; |
ohrstrom@1504 | 211 | if (!expect(in, JavacServer.PROTOCOL_ID)) { |
ohrstrom@1504 | 212 | return; |
ohrstrom@1504 | 213 | } |
ohrstrom@1504 | 214 | id = in.readLine(); |
ohrstrom@1504 | 215 | if (id == null) |
ohrstrom@1504 | 216 | return; |
ohrstrom@1504 | 217 | if (!expect(in, JavacServer.PROTOCOL_ARGS)) { |
ohrstrom@1504 | 218 | return; |
ohrstrom@1504 | 219 | } |
ohrstrom@1504 | 220 | ArrayList<String> the_options = new ArrayList<String>(); |
ohrstrom@1504 | 221 | ArrayList<File> the_classes = new ArrayList<File>(); |
ohrstrom@1504 | 222 | Iterable<File> path = Arrays.<File> asList(new File(cwd)); |
ohrstrom@1504 | 223 | |
ohrstrom@1504 | 224 | for (;;) { |
ohrstrom@1504 | 225 | String l = in.readLine(); |
ohrstrom@1504 | 226 | if (l == null) |
ohrstrom@1504 | 227 | return; |
ohrstrom@1504 | 228 | if (l.equals(JavacServer.PROTOCOL_SOURCES_TO_COMPILE)) |
ohrstrom@1504 | 229 | break; |
ohrstrom@1504 | 230 | if (l.startsWith("--server:")) |
ohrstrom@1504 | 231 | continue; |
ohrstrom@1504 | 232 | if (!l.startsWith("-") && l.endsWith(".java")) { |
ohrstrom@1504 | 233 | the_classes.add(new File(l)); |
ohrstrom@1504 | 234 | numClasses++; |
ohrstrom@1504 | 235 | } else { |
ohrstrom@1504 | 236 | the_options.add(l); |
ohrstrom@1504 | 237 | } |
ohrstrom@1504 | 238 | continue; |
ohrstrom@1504 | 239 | } |
ohrstrom@1504 | 240 | |
ohrstrom@1504 | 241 | // Load sources to compile |
ohrstrom@1504 | 242 | Set<URI> sourcesToCompile = new HashSet<URI>(); |
ohrstrom@1504 | 243 | for (;;) { |
ohrstrom@1504 | 244 | String l = in.readLine(); |
ohrstrom@1504 | 245 | if (l == null) |
ohrstrom@1504 | 246 | return; |
ohrstrom@1504 | 247 | if (l.equals(JavacServer.PROTOCOL_VISIBLE_SOURCES)) |
ohrstrom@1504 | 248 | break; |
ohrstrom@1504 | 249 | try { |
ohrstrom@1504 | 250 | sourcesToCompile.add(new URI(l)); |
ohrstrom@1504 | 251 | numClasses++; |
ohrstrom@1504 | 252 | } catch (URISyntaxException e) { |
ohrstrom@1504 | 253 | return; |
ohrstrom@1504 | 254 | } |
ohrstrom@1504 | 255 | } |
ohrstrom@1504 | 256 | // Load visible sources |
ohrstrom@1504 | 257 | Set<URI> visibleSources = new HashSet<URI>(); |
ohrstrom@1504 | 258 | boolean fix_drive_letter_case = System.getProperty("os.name").toLowerCase().equals("windows"); |
ohrstrom@1504 | 259 | for (;;) { |
ohrstrom@1504 | 260 | String l = in.readLine(); |
ohrstrom@1504 | 261 | if (l == null) |
ohrstrom@1504 | 262 | return; |
ohrstrom@1504 | 263 | if (l.equals(JavacServer.PROTOCOL_END)) |
ohrstrom@1504 | 264 | break; |
ohrstrom@1504 | 265 | try { |
ohrstrom@1504 | 266 | URI u = new URI(l); |
ohrstrom@1504 | 267 | if (fix_drive_letter_case) { |
ohrstrom@1504 | 268 | // Make sure the driver letter is lower case. |
ohrstrom@1504 | 269 | String s = u.toString(); |
ohrstrom@1504 | 270 | if (s.startsWith("file:/") && |
ohrstrom@1504 | 271 | Character.isUpperCase(s.charAt(6))) { |
ohrstrom@1504 | 272 | u = new URI("file:/"+Character.toLowerCase(s.charAt(6))+s.substring(7)); |
ohrstrom@1504 | 273 | } |
ohrstrom@1504 | 274 | } |
ohrstrom@1504 | 275 | visibleSources.add(u); |
ohrstrom@1504 | 276 | } catch (URISyntaxException e) { |
ohrstrom@1504 | 277 | return; |
ohrstrom@1504 | 278 | } |
ohrstrom@1504 | 279 | } |
ohrstrom@1504 | 280 | |
ohrstrom@1504 | 281 | // A completed request has been received. |
ohrstrom@1504 | 282 | |
ohrstrom@1504 | 283 | // Now setup the actual compilation.... |
ohrstrom@1504 | 284 | // First deal with explicit source files on cmdline and in at file. |
ohrstrom@1504 | 285 | com.sun.tools.javac.util.ListBuffer<JavaFileObject> compilationUnits = |
ohrstrom@1504 | 286 | new com.sun.tools.javac.util.ListBuffer<JavaFileObject>(); |
ohrstrom@1504 | 287 | for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(the_classes)) { |
ohrstrom@1504 | 288 | compilationUnits.append(i); |
ohrstrom@1504 | 289 | } |
ohrstrom@1504 | 290 | // Now deal with sources supplied as source_to_compile. |
ohrstrom@1504 | 291 | com.sun.tools.javac.util.ListBuffer<File> sourcesToCompileFiles = |
ohrstrom@1504 | 292 | new com.sun.tools.javac.util.ListBuffer<File>(); |
ohrstrom@1504 | 293 | for (URI u : sourcesToCompile) { |
ohrstrom@1504 | 294 | sourcesToCompileFiles.append(new File(u)); |
ohrstrom@1504 | 295 | } |
ohrstrom@1504 | 296 | for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(sourcesToCompileFiles)) { |
ohrstrom@1504 | 297 | compilationUnits.append(i); |
ohrstrom@1504 | 298 | } |
ohrstrom@1504 | 299 | // Log the options to be used. |
ohrstrom@1504 | 300 | StringBuilder options = new StringBuilder(); |
ohrstrom@1504 | 301 | for (String s : the_options) { |
ohrstrom@1504 | 302 | options.append(">").append(s).append("< "); |
ohrstrom@1504 | 303 | } |
ohrstrom@1504 | 304 | javacServer.log(id+" <"+thisRequest+"> options "+options.toString()); |
ohrstrom@1504 | 305 | |
ohrstrom@1504 | 306 | forcedExitCode = 0; |
ohrstrom@1504 | 307 | // Create a new logger. |
ohrstrom@1504 | 308 | StringWriter stdoutLog = new StringWriter(); |
ohrstrom@1504 | 309 | StringWriter stderrLog = new StringWriter(); |
ohrstrom@1504 | 310 | stdout = new PrintWriter(stdoutLog); |
ohrstrom@1504 | 311 | stderr = new PrintWriter(stderrLog); |
ohrstrom@1504 | 312 | com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK; |
ohrstrom@1504 | 313 | try { |
ohrstrom@1504 | 314 | if (compilationUnits.size() > 0) { |
ohrstrom@1504 | 315 | // Bind the new logger to the existing context. |
ohrstrom@1504 | 316 | context.put(Log.outKey, stderr); |
ohrstrom@1504 | 317 | Log.instance(context).setWriter(Log.WriterKind.NOTICE, stdout); |
ohrstrom@1504 | 318 | Log.instance(context).setWriter(Log.WriterKind.WARNING, stderr); |
ohrstrom@1504 | 319 | Log.instance(context).setWriter(Log.WriterKind.ERROR, stderr); |
ohrstrom@1504 | 320 | // Process the options. |
ohrstrom@1504 | 321 | com.sun.tools.javac.api.JavacTool.processOptions(context, smartFileManager, the_options); |
ohrstrom@1504 | 322 | fileManagerBase.setContext(context); |
ohrstrom@1504 | 323 | smartFileManager.setVisibleSources(visibleSources); |
ohrstrom@1504 | 324 | smartFileManager.cleanArtifacts(); |
ohrstrom@1504 | 325 | smartFileManager.setLog(stdout); |
ohrstrom@1504 | 326 | Dependencies.instance(context).reset(); |
ohrstrom@1504 | 327 | |
ohrstrom@1504 | 328 | com.sun.tools.javac.main.Main ccompiler = new com.sun.tools.javac.main.Main("javacTask", stderr); |
ohrstrom@1504 | 329 | String[] aa = the_options.toArray(new String[0]); |
ohrstrom@1504 | 330 | |
ohrstrom@1504 | 331 | // Do the compilation! |
ohrstrom@1504 | 332 | rc = ccompiler.compile(aa, context, compilationUnits.toList(), null); |
ohrstrom@1504 | 333 | |
ohrstrom@1504 | 334 | while (numActiveSubTasks()>0) { |
ohrstrom@1504 | 335 | try { Thread.sleep(1000); } catch (InterruptedException e) { } |
ohrstrom@1504 | 336 | } |
ohrstrom@1504 | 337 | |
ohrstrom@1504 | 338 | smartFileManager.flush(); |
ohrstrom@1504 | 339 | } |
ohrstrom@1504 | 340 | } catch (Exception e) { |
ohrstrom@1504 | 341 | stderr.println(e.getMessage()); |
ohrstrom@1504 | 342 | forcedExitCode = -1; |
ohrstrom@1504 | 343 | } |
ohrstrom@1504 | 344 | |
ohrstrom@1504 | 345 | // Send the response.. |
ohrstrom@1504 | 346 | out.println(JavacServer.PROTOCOL_STDOUT); |
ohrstrom@1504 | 347 | out.print(stdoutLog); |
ohrstrom@1504 | 348 | out.println(JavacServer.PROTOCOL_STDERR); |
ohrstrom@1504 | 349 | out.print(stderrLog); |
ohrstrom@1504 | 350 | // The compilation is complete! And errors will have already been printed on out! |
ohrstrom@1504 | 351 | out.println(JavacServer.PROTOCOL_PACKAGE_ARTIFACTS); |
ohrstrom@1504 | 352 | Map<String,Set<URI>> pa = smartFileManager.getPackageArtifacts(); |
ohrstrom@1504 | 353 | for (String aPkgName : pa.keySet()) { |
ohrstrom@1504 | 354 | out.println("+"+aPkgName); |
ohrstrom@1504 | 355 | Set<URI> as = pa.get(aPkgName); |
ohrstrom@1504 | 356 | for (URI a : as) { |
ohrstrom@1504 | 357 | out.println(" "+a.toString()); |
ohrstrom@1504 | 358 | } |
ohrstrom@1504 | 359 | } |
ohrstrom@1504 | 360 | Dependencies deps = Dependencies.instance(context); |
ohrstrom@1504 | 361 | out.println(JavacServer.PROTOCOL_PACKAGE_DEPENDENCIES); |
ohrstrom@1504 | 362 | Map<String,Set<String>> pd = deps.getDependencies(); |
ohrstrom@1504 | 363 | for (String aPkgName : pd.keySet()) { |
ohrstrom@1504 | 364 | out.println("+"+aPkgName); |
ohrstrom@1504 | 365 | Set<String> ds = pd.get(aPkgName); |
ohrstrom@1504 | 366 | // Everything depends on java.lang |
ohrstrom@1504 | 367 | if (!ds.contains(":java.lang")) ds.add(":java.lang"); |
ohrstrom@1504 | 368 | for (String d : ds) { |
ohrstrom@1504 | 369 | out.println(" "+d); |
ohrstrom@1504 | 370 | } |
ohrstrom@1504 | 371 | } |
ohrstrom@1504 | 372 | out.println(JavacServer.PROTOCOL_PACKAGE_PUBLIC_APIS); |
ohrstrom@1504 | 373 | Map<String,String> pp = deps.getPubapis(); |
ohrstrom@1504 | 374 | for (String aPkgName : pp.keySet()) { |
ohrstrom@1504 | 375 | out.println("+"+aPkgName); |
ohrstrom@1504 | 376 | String ps = pp.get(aPkgName); |
ohrstrom@1504 | 377 | // getPubapis added a space to each line! |
ohrstrom@1504 | 378 | out.println(ps); |
ohrstrom@1504 | 379 | compiledPkgs.append(aPkgName+" "); |
ohrstrom@1504 | 380 | } |
ohrstrom@1504 | 381 | out.println(JavacServer.PROTOCOL_SYSINFO); |
ohrstrom@1504 | 382 | out.println("num_cores=" + Runtime.getRuntime().availableProcessors()); |
ohrstrom@1504 | 383 | out.println("max_memory=" + Runtime.getRuntime().maxMemory()); |
ohrstrom@1504 | 384 | out.println(JavacServer.PROTOCOL_RETURN_CODE); |
ohrstrom@1504 | 385 | |
ohrstrom@1504 | 386 | // Errors from sjavac that affect compilation status! |
ohrstrom@1504 | 387 | int rcv = rc.exitCode; |
ohrstrom@1504 | 388 | if (rcv == 0 && forcedExitCode != 0) { |
ohrstrom@1504 | 389 | rcv = forcedExitCode; |
ohrstrom@1504 | 390 | } |
ohrstrom@1504 | 391 | out.println("" + rcv); |
ohrstrom@1504 | 392 | out.println(JavacServer.PROTOCOL_END); |
ohrstrom@1504 | 393 | out.flush(); |
ohrstrom@1504 | 394 | } catch (IOException e) { |
ohrstrom@1504 | 395 | e.printStackTrace(); |
ohrstrom@1504 | 396 | } finally { |
ohrstrom@1504 | 397 | try { |
ohrstrom@1504 | 398 | if (out != null) out.close(); |
ohrstrom@1504 | 399 | if (!socket.isClosed()) { |
ohrstrom@1504 | 400 | socket.close(); |
ohrstrom@1504 | 401 | } |
ohrstrom@1504 | 402 | socket = null; |
ohrstrom@1504 | 403 | } catch (Exception e) { |
ohrstrom@1504 | 404 | javacServer.log("ERROR "+e); |
ohrstrom@1504 | 405 | e.printStackTrace(); |
ohrstrom@1504 | 406 | } |
ohrstrom@1504 | 407 | compilerPool.stopRequest(); |
ohrstrom@1504 | 408 | long duration = System.currentTimeMillis()-start; |
ohrstrom@1504 | 409 | javacServer.addBuildTime(duration); |
ohrstrom@1504 | 410 | float classpersec = ((float)numClasses)*(((float)1000.0)/((float)duration)); |
ohrstrom@1504 | 411 | javacServer.log(id+" <"+thisRequest+"> "+compiledPkgs+" duration " + duration+ " ms num_classes="+numClasses+ |
ohrstrom@1504 | 412 | " classpersec="+classpersec+" subtasks="+subTasks.size()); |
ohrstrom@1504 | 413 | javacServer.flushLog(); |
ohrstrom@1504 | 414 | unuse(); |
ohrstrom@1504 | 415 | compilerPool.returnCompilerThread(this); |
ohrstrom@1504 | 416 | } |
ohrstrom@1504 | 417 | } |
ohrstrom@1504 | 418 | } |
ohrstrom@1504 | 419 |