--- old/src/share/classes/com/sun/tools/sjavac/Package.java 2014-08-09 00:28:46.411895956 +0200 +++ new/src/share/classes/com/sun/tools/sjavac/Package.java 2014-08-09 00:28:46.263900252 +0200 @@ -74,12 +74,16 @@ private Set dependencies = new HashSet<>(); // This package has the following dependents, that depend on this package. private Set dependents = new HashSet<>(); - // This is the public api of this package. - private List pubapi = new ArrayList<>(); // Map from source file name to Source info object. private Map sources = new HashMap<>(); // This package generated these artifacts. private Map artifacts = new HashMap<>(); + // Pubapi for compiled sources + private List pubapi_for_compiled_sources = new ArrayList<>(); + // Pubapi for linked classes + private List pubapi_for_linked_classes = new ArrayList<>(); + // Archives that have the same timestamp as previous run, ie they are probably unchanged. + private Set unchanged_archives = new HashSet<>(); public Package(Module m, String n) { int c = n.indexOf(":"); @@ -99,7 +103,8 @@ public String dirname() { return dirname; } public Map sources() { return sources; } public Map artifacts() { return artifacts; } - public List pubapi() { return pubapi; } + public List pubapiForCompiledSources() { return pubapi_for_compiled_sources; } + public List pubapiForLinkedClasses() { return pubapi_for_linked_classes; } public Set dependencies() { return dependencies; } public Set dependents() { return dependents; } @@ -131,31 +136,17 @@ dependents.add(d); } - public void addPubapi(String p) { - pubapi.add(p); - } - /** * Check if we have knowledge in the javac state that * describe the results of compiling this package before. */ public boolean existsInJavacState() { - return artifacts.size() > 0 || pubapi.size() > 0; + return artifacts.size() > 0 || pubapi_for_compiled_sources.size() > 0; } - public static List pubapiToList(String ps) - { - String[] lines = ps.split("\n"); - List r = new ArrayList<>(); - for (String l : lines) { - r.add(l); - } - return r; - } - - public boolean hasPubapiChanged(List ps) { + public boolean hasPubapiForCompiledSourcesChanged(List ps) { Iterator i = ps.iterator(); - Iterator j = pubapi.iterator(); + Iterator j = pubapi_for_compiled_sources.iterator(); int line = 0; while (i.hasNext() && j.hasNext()) { String is = i.next(); @@ -181,8 +172,12 @@ return false; } - public void setPubapi(List ps) { - pubapi = ps; + public void setPubapiForCompiledSources(List ps) { + pubapi_for_compiled_sources = ps; + } + + public void setPubapiForLinkedClasses(List ps) { + pubapi_for_linked_classes = ps; } public void setDependencies(Set ds) { @@ -208,8 +203,14 @@ } public void loadPubapi(String l) { - String pi = l.substring(2); - addPubapi(pi); + char c = l.charAt(2); + String pi = l.substring(4); + switch (c) { + case 'C' : pubapi_for_compiled_sources.add(pi); + break; + case 'Z' : pubapi_for_linked_classes.add(pi); + break; + } } public void saveDependencies(StringBuilder b) { @@ -224,18 +225,40 @@ } public void savePubapi(StringBuilder b) { - for (String l : pubapi) { - b.append("I "+l+"\n"); + for (String l : pubapi_for_compiled_sources) { + b.append("I C "+l+"\n"); + } + for (String l : pubapi_for_linked_classes) { + b.append("I Z "+l+"\n"); } } public static void savePackages(Map packages, StringBuilder b) { - List sorted_packages = new ArrayList<>(); + List sorted_source_packages = new ArrayList<>(); + // First add all packages that have components from from our own sources. for (String key : packages.keySet() ) { - sorted_packages.add(key); + Package p = packages.get(key); + if (p.sources().size() > 0) { + sorted_source_packages.add(key); + } + } + Collections.sort(sorted_source_packages); + + List sorted_classpath_packages = new ArrayList<>(); + // Second add all packages found on the classpath only. + for (String key : packages.keySet() ) { + Package p = packages.get(key); + if (p.sources().size() == 0) { + sorted_classpath_packages.add(key); + } } - Collections.sort(sorted_packages); - for (String s : sorted_packages) { + Collections.sort(sorted_classpath_packages); + + for (String s : sorted_source_packages) { + Package p = packages.get(s); + p.save(b); + } + for (String s : sorted_classpath_packages) { Package p = packages.get(s); p.save(b); } @@ -304,4 +327,20 @@ a.delete(); } } + + /** + * Extract the classes stored in the pubapi. + */ + public Set getClassesFromClasspathPubapi() { + Set set = new HashSet(); + + for (String s : pubapi_for_linked_classes) { + if (s.startsWith(" TYPE ")) { + set.add(s.substring(6, s.indexOf(' ', 6))); + } + } + return set; + } + + }