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

Print this page

        

*** 39,48 **** --- 39,49 ---- import java.net.SocketAddress; import java.net.URI; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; + import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import com.sun.tools.sjavac.Util;
*** 134,143 **** --- 135,169 ---- // Delegate to useServer, which delegates to compileHelper return useServer(args, sourcesToCompile, visibleSources, null); } /** + * Extract the package name and the class from the string. + * Deps will be a map from packag name to class name. + */ + static void addClasspathPackageDependency(Map<String, Set<String>> deps, String fullname) { + // Modules beware! + String pkg; + int p = fullname.lastIndexOf('.'); + if (p == -1) { + // Arghh, a source file without a package. + pkg = ":"; + } + else { + pkg = ":"+fullname.substring(0, p); + } + synchronized (deps) { + Set<String> set = deps.get(pkg); + if (set == null) { + set = new HashSet<String>(); + deps.put(pkg, set); + } + set.add(fullname); + } + } + + /** * Connect and compile using the javac server settings and the args. When using more advanced features, the sources_to_compile and visible_sources are * supplied to the server and meta data is returned in package_artifacts, package_dependencies and package_pubapis. */ public CompilationResult compileHelper(String id, String[] args,
*** 279,315 **** if (l.length() > 1 && l.charAt(0) == '+') { String pkg = l.substring(1); lastPackageSet = new HashSet<>(); rc.packageDependencies.put(pkg, lastPackageSet); } else if (l.length() > 1 && lastPackageSet != null) { lastPackageSet.add(l.substring(1)); } } // Load package pubapis ! Map<String, StringBuffer> tmp = new HashMap<>(); ! StringBuffer lastPublicApi = null; for (;;) { String l = in.readLine(); if (l == null) { return new CompilationResult(ERROR_FATAL); } if (l.equals(JavacServer.PROTOCOL_SYSINFO)) { break; } if (l.length() > 1 && l.charAt(0) == '+') { String pkg = l.substring(1); ! lastPublicApi = new StringBuffer(); ! tmp.put(pkg, lastPublicApi); } else if (l.length() > 1 && lastPublicApi != null) { ! lastPublicApi.append(l.substring(1)); ! lastPublicApi.append("\n"); ! } } - for (String p : tmp.keySet()) { - //assert (packagePublicApis.get(p) == null); - String api = tmp.get(p).toString(); - rc.packagePubapis.put(p, api); } // Now reading the max memory possible. for (;;) { String l = in.readLine(); if (l == null) { --- 305,340 ---- if (l.length() > 1 && l.charAt(0) == '+') { String pkg = l.substring(1); lastPackageSet = new HashSet<>(); rc.packageDependencies.put(pkg, lastPackageSet); } else if (l.length() > 1 && lastPackageSet != null) { + if (l.startsWith(" :. ")) { + // This is a classpath dependency. + addClasspathPackageDependency(rc.classpathPackageDependencies, l.substring(4)); + } else { + // Standard package dependency. lastPackageSet.add(l.substring(1)); } } + } // Load package pubapis ! List<String> lastPublicApi = new LinkedList<>(); for (;;) { String l = in.readLine(); if (l == null) { return new CompilationResult(ERROR_FATAL); } if (l.equals(JavacServer.PROTOCOL_SYSINFO)) { break; } if (l.length() > 1 && l.charAt(0) == '+') { String pkg = l.substring(1); ! lastPublicApi = new LinkedList<>(); ! rc.packagePublicApis.put(pkg, lastPublicApi); } else if (l.length() > 1 && lastPublicApi != null) { ! lastPublicApi.add(l.substring(1)); } } // Now reading the max memory possible. for (;;) { String l = in.readLine(); if (l == null) {
*** 332,341 **** --- 357,368 ---- return rc; } rc.setReturnCode(Integer.parseInt(l)); rc.stdout = stdout.toString(); rc.stderr = stderr.toString(); + System.out.print(rc.stdout); + System.err.print(rc.stderr); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); rc.stderr = sw.toString(); }