src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java

Print this page




 314             stderr = new PrintWriter(stderrLog);
 315             com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK;
 316             try {
 317                 if (compilationUnits.size() > 0) {
 318                     smartFileManager.setVisibleSources(visibleSources);
 319                     smartFileManager.cleanArtifacts();
 320                     smartFileManager.setLog(stdout);
 321 
 322                     // Do the compilation!
 323                     CompilationTask task = compiler.getTask(stderr, smartFileManager, null, the_options, null, compilationUnits, context);
 324                     smartFileManager.setSymbolFileEnabled(!Options.instance(context).isSet("ignore.symbol.file"));
 325                     rc = ((JavacTaskImpl) task).doCall();
 326 
 327                     while (numActiveSubTasks()>0) {
 328                         try { Thread.sleep(1000); } catch (InterruptedException e) { }
 329                     }
 330 
 331                     smartFileManager.flush();
 332                 }
 333             } catch (Exception e) {

 334                 stderr.println(e.getMessage());
 335                 forcedExitCode = -1;
 336             }
 337 
 338             // Send the response..
 339             out.println(JavacServer.PROTOCOL_STDOUT);
 340             out.print(stdoutLog);
 341             out.println(JavacServer.PROTOCOL_STDERR);
 342             out.print(stderrLog);
 343             // The compilation is complete! And errors will have already been printed on out!
 344             out.println(JavacServer.PROTOCOL_PACKAGE_ARTIFACTS);
 345             Map<String,Set<URI>> pa = smartFileManager.getPackageArtifacts();
 346             for (String aPkgName : pa.keySet()) {
 347                 out.println("+"+aPkgName);
 348                 Set<URI> as = pa.get(aPkgName);
 349                 for (URI a : as) {
 350                     out.println(" "+a.toString());
 351                 }
 352             }
 353             Dependencies deps = Dependencies.instance(context);
 354             out.println(JavacServer.PROTOCOL_PACKAGE_DEPENDENCIES);
 355             Map<String,Set<String>> pd = deps.getDependencies();


 356             for (String aPkgName : pd.keySet()) {
 357                 out.println("+"+aPkgName);
 358                 Set<String> ds = pd.get(aPkgName);
 359                     // Everything depends on java.lang
 360                     if (!ds.contains(":java.lang")) ds.add(":java.lang");
 361                 for (String d : ds) {
 362                     out.println(" "+d);
 363                 }
 364             }








 365             out.println(JavacServer.PROTOCOL_PACKAGE_PUBLIC_APIS);
 366             Map<String,String> pp = deps.getPubapis();
 367             for (String aPkgName : pp.keySet()) {
 368                 out.println("+"+aPkgName);
 369                 String ps = pp.get(aPkgName);
 370                 // getPubapis added a space to each line!
 371                 out.println(ps);


 372                 compiledPkgs.append(aPkgName+" ");
 373             }
 374             out.println(JavacServer.PROTOCOL_SYSINFO);
 375             out.println("num_cores=" + Runtime.getRuntime().availableProcessors());
 376             out.println("max_memory=" + Runtime.getRuntime().maxMemory());
 377             out.println(JavacServer.PROTOCOL_RETURN_CODE);
 378 
 379             // Errors from sjavac that affect compilation status!
 380             int rcv = rc.exitCode;
 381             if (rcv == 0 && forcedExitCode != 0) {
 382                 rcv = forcedExitCode;
 383             }
 384             out.println("" + rcv);
 385             out.println(JavacServer.PROTOCOL_END);
 386             out.flush();
 387         } catch (IOException e) {
 388             e.printStackTrace();
 389         } finally {
 390             try {
 391                 if (out != null) out.close();




 314             stderr = new PrintWriter(stderrLog);
 315             com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK;
 316             try {
 317                 if (compilationUnits.size() > 0) {
 318                     smartFileManager.setVisibleSources(visibleSources);
 319                     smartFileManager.cleanArtifacts();
 320                     smartFileManager.setLog(stdout);
 321 
 322                     // Do the compilation!
 323                     CompilationTask task = compiler.getTask(stderr, smartFileManager, null, the_options, null, compilationUnits, context);
 324                     smartFileManager.setSymbolFileEnabled(!Options.instance(context).isSet("ignore.symbol.file"));
 325                     rc = ((JavacTaskImpl) task).doCall();
 326 
 327                     while (numActiveSubTasks()>0) {
 328                         try { Thread.sleep(1000); } catch (InterruptedException e) { }
 329                     }
 330 
 331                     smartFileManager.flush();
 332                 }
 333             } catch (Exception e) {
 334                         e.printStackTrace(System.err);
 335                 stderr.println(e.getMessage());
 336                 forcedExitCode = -1;
 337             }
 338 
 339             // Send the response..
 340             out.println(JavacServer.PROTOCOL_STDOUT);
 341             out.print(stdoutLog);
 342             out.println(JavacServer.PROTOCOL_STDERR);
 343             out.print(stderrLog);
 344             // The compilation is complete! And errors will have already been printed on out!
 345             out.println(JavacServer.PROTOCOL_PACKAGE_ARTIFACTS);
 346             Map<String,Set<URI>> pa = smartFileManager.getPackageArtifacts();
 347             for (String aPkgName : pa.keySet()) {
 348                 out.println("+"+aPkgName);
 349                 Set<URI> as = pa.get(aPkgName);
 350                 for (URI a : as) {
 351                     out.println(" "+a.toString());
 352                 }
 353             }
 354             Dependencies deps = Dependencies.instance(context);
 355             out.println(JavacServer.PROTOCOL_PACKAGE_DEPENDENCIES);
 356             Map<String,Set<String>> pd = deps.getSourcefileDependencies();
 357             Map<String,Set<String>> cd = deps.getClasspathDependencies();
 358 
 359             for (String aPkgName : pd.keySet()) {
 360                 out.println("+"+aPkgName);
 361                 Set<String> ds = pd.get(aPkgName);
 362                     // Everything depends on java.lang
 363                     if (!ds.contains(":java.lang")) ds.add(":java.lang");
 364                 for (String d : ds) {
 365                     out.println(" "+d);
 366                 }
 367             }
 368 
 369             for (String aPkgName : cd.keySet()) {
 370                 Set<String> cs = cd.get(aPkgName);
 371                 for (String c : cs) {
 372                     out.println(" "+c);
 373                 }
 374             }
 375 
 376             out.println(JavacServer.PROTOCOL_PACKAGE_PUBLIC_APIS);
 377             Map<String,List<String>> pp = deps.getPublicApis();
 378             for (String aPkgName : pp.keySet()) {
 379                 out.println("+"+aPkgName);
 380                 List<String> ls = pp.get(aPkgName);
 381                 for (String s : ls) {
 382                     out.print(" ");
 383                     out.println(s);
 384                 }
 385                 compiledPkgs.append(aPkgName+" ");
 386             }
 387             out.println(JavacServer.PROTOCOL_SYSINFO);
 388             out.println("num_cores=" + Runtime.getRuntime().availableProcessors());
 389             out.println("max_memory=" + Runtime.getRuntime().maxMemory());
 390             out.println(JavacServer.PROTOCOL_RETURN_CODE);
 391 
 392             // Errors from sjavac that affect compilation status!
 393             int rcv = rc.exitCode;
 394             if (rcv == 0 && forcedExitCode != 0) {
 395                 rcv = forcedExitCode;
 396             }
 397             out.println("" + rcv);
 398             out.println(JavacServer.PROTOCOL_END);
 399             out.flush();
 400         } catch (IOException e) {
 401             e.printStackTrace();
 402         } finally {
 403             try {
 404                 if (out != null) out.close();