88 CompilationResult compilationResult = new CompilationResult(0); 89 90 // First deal with explicit source files on cmdline and in at file. 91 ListBuffer<JavaFileObject> compilationUnits = new ListBuffer<>(); 92 for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(explicitSources)) { 93 compilationUnits.append(i); 94 } 95 // Now deal with sources supplied as source_to_compile. 96 ListBuffer<File> sourcesToCompileFiles = new ListBuffer<>(); 97 for (URI u : sourcesToCompile) { 98 sourcesToCompileFiles.append(new File(u)); 99 } 100 for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(sourcesToCompileFiles)) { 101 compilationUnits.append(i); 102 } 103 // Log the options to be used. 104 StringBuilder options = new StringBuilder(); 105 for (String s : args) { 106 options.append(">").append(s).append("< "); 107 } 108 javacServer.log(protocolId+" <"+invocationId+"> options "+options.toString()); 109 110 forcedExit.set(false); 111 // Create a new logger. 112 StringWriter stdoutLog = new StringWriter(); 113 StringWriter stderrLog = new StringWriter(); 114 PrintWriter stdout = new PrintWriter(stdoutLog); 115 PrintWriter stderr = new PrintWriter(stderrLog); 116 com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK; 117 try { 118 if (compilationUnits.size() > 0) { 119 smartFileManager.setVisibleSources(visibleSources); 120 smartFileManager.cleanArtifacts(); 121 smartFileManager.setLog(stdout); 122 123 124 // Do the compilation! 125 CompilationTask task = compiler.getTask(stderr, smartFileManager, null, Arrays.asList(args), null, compilationUnits, context); 126 rc = ((JavacTaskImpl) task).doCall(); 127 smartFileManager.flush(); 128 } 129 } catch (Exception e) { 130 stderr.println(e.getMessage()); 131 forcedExit.set(true); 132 } 133 134 compilationResult.packageArtifacts = smartFileManager.getPackageArtifacts(); 135 136 Dependencies deps = Dependencies.instance(context); 137 compilationResult.packageDependencies = deps.getDependencies(); 138 compilationResult.packagePubapis = deps.getPubapis(); 139 140 compilationResult.stdout = stdoutLog.toString(); 141 compilationResult.stderr = stderrLog.toString(); 142 compilationResult.returnCode = rc.exitCode == 0 && forcedExit.get() ? -1 : rc.exitCode; 143 144 return compilationResult; 145 } 146 147 @Override 148 public String serverSettings() { 149 return ""; 150 } 151 152 } | 88 CompilationResult compilationResult = new CompilationResult(0); 89 90 // First deal with explicit source files on cmdline and in at file. 91 ListBuffer<JavaFileObject> compilationUnits = new ListBuffer<>(); 92 for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(explicitSources)) { 93 compilationUnits.append(i); 94 } 95 // Now deal with sources supplied as source_to_compile. 96 ListBuffer<File> sourcesToCompileFiles = new ListBuffer<>(); 97 for (URI u : sourcesToCompile) { 98 sourcesToCompileFiles.append(new File(u)); 99 } 100 for (JavaFileObject i : fileManager.getJavaFileObjectsFromFiles(sourcesToCompileFiles)) { 101 compilationUnits.append(i); 102 } 103 // Log the options to be used. 104 StringBuilder options = new StringBuilder(); 105 for (String s : args) { 106 options.append(">").append(s).append("< "); 107 } 108 if (javacServer != null) { 109 javacServer.log(protocolId+" <"+invocationId+"> options "+options.toString()); 110 } 111 112 forcedExit.set(false); 113 // Create a new logger. 114 StringWriter stdoutLog = new StringWriter(); 115 StringWriter stderrLog = new StringWriter(); 116 PrintWriter stdout = new PrintWriter(stdoutLog); 117 PrintWriter stderr = new PrintWriter(stderrLog); 118 com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK; 119 try { 120 if (compilationUnits.size() > 0) { 121 smartFileManager.setVisibleSources(visibleSources); 122 smartFileManager.cleanArtifacts(); 123 smartFileManager.setLog(stdout); 124 125 // Do the compilation! 126 CompilationTask task = compiler.getTask(stderr, smartFileManager, null, Arrays.asList(args), null, compilationUnits, context); 127 rc = ((JavacTaskImpl) task).doCall(); 128 smartFileManager.flush(); 129 } 130 } catch (Exception e) { 131 stderr.println(e.getMessage()); 132 forcedExit.set(true); 133 } 134 135 compilationResult.packageArtifacts = smartFileManager.getPackageArtifacts(); 136 137 Dependencies deps = Dependencies.instance(context); 138 compilationResult.packageDependencies = deps.getSourcefileDependencies(); 139 compilationResult.classpathPackageDependencies = deps.getClasspathDependencies(); 140 compilationResult.packagePublicApis = deps.getPublicApis(); 141 142 compilationResult.stdout = stdoutLog.toString(); 143 compilationResult.stderr = stderrLog.toString(); 144 compilationResult.returnCode = rc.exitCode == 0 && forcedExit.get() ? -1 : rc.exitCode; 145 146 return compilationResult; 147 } 148 149 @Override 150 public String serverSettings() { 151 return ""; 152 } 153 154 } |