src/share/classes/com/sun/tools/sjavac/Package.java

Print this page

        

@@ -72,16 +72,20 @@
     private String dirname;
     // This package depends on these packages.
     private Set<String> dependencies = new HashSet<>();
     // This package has the following dependents, that depend on this package.
     private Set<String> dependents = new HashSet<>();
-    // This is the public api of this package.
-    private List<String> pubapi = new ArrayList<>();
     // Map from source file name to Source info object.
     private Map<String,Source> sources = new HashMap<>();
     // This package generated these artifacts.
     private Map<String,File> artifacts = new HashMap<>();
+    // Pubapi for compiled sources
+    private List<String> pubapi_for_compiled_sources = new ArrayList<>();
+    // Pubapi for linked classes
+    private List<String> pubapi_for_linked_classes = new ArrayList<>();
+    // Archives that have the same timestamp as previous run, ie they are probably unchanged.
+    private Set<String> unchanged_archives = new HashSet<>();
 
     public Package(Module m, String n) {
         int c = n.indexOf(":");
         assert(c != -1);
         String mn = n.substring(0,c);

@@ -97,11 +101,12 @@
     public Module mod() { return mod; }
     public String name() { return name; }
     public String dirname() { return dirname; }
     public Map<String,Source> sources() { return sources; }
     public Map<String,File> artifacts() { return artifacts; }
-    public List<String> pubapi() { return pubapi; }
+    public List<String> pubapiForCompiledSources() { return pubapi_for_compiled_sources; }
+    public List<String> pubapiForLinkedClasses() { return pubapi_for_linked_classes; }
 
     public Set<String> dependencies() { return dependencies; }
     public Set<String> dependents() { return dependents; }
 
     @Override

@@ -129,35 +134,21 @@
 
     public void addDependent(String d) {
         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<String> pubapiToList(String ps)
-    {
-        String[] lines = ps.split("\n");
-        List<String> r = new ArrayList<>();
-        for (String l : lines) {
-            r.add(l);
-        }
-        return r;
-    }
-
-    public boolean hasPubapiChanged(List<String> ps) {
+    public boolean hasPubapiForCompiledSourcesChanged(List<String> ps) {
         Iterator<String> i = ps.iterator();
-        Iterator<String> j = pubapi.iterator();
+        Iterator<String> j = pubapi_for_compiled_sources.iterator();
         int line = 0;
         while (i.hasNext() && j.hasNext()) {
             String is = i.next();
             String js = j.next();
             if (!is.equals(js)) {

@@ -179,12 +170,16 @@
             return true;
         }
         return false;
     }
 
-    public void setPubapi(List<String> ps) {
-        pubapi = ps;
+    public void setPubapiForCompiledSources(List<String> ps) {
+        pubapi_for_compiled_sources = ps;
+    }
+
+    public void setPubapiForLinkedClasses(List<String> ps) {
+        pubapi_for_linked_classes = ps;
     }
 
     public void setDependencies(Set<String> ds) {
         dependencies = ds;
     }

@@ -206,12 +201,18 @@
         String n = l.substring(2);
         addDependency(n);
     }
 
     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) {
         List<String> sorted_dependencies = new ArrayList<>();
         for (String key : dependencies) {

@@ -222,22 +223,44 @@
             b.append("D "+a+"\n");
         }
     }
 
     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<String,Package> packages, StringBuilder b) {
-        List<String> sorted_packages = new ArrayList<>();
+        List<String> 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<String> 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);
         }
     }
 

@@ -302,6 +325,22 @@
     public void deleteArtifacts() {
         for (File a : artifacts.values()) {
             a.delete();
         }
     }
+
+    /**
+     * Extract the classes stored in the pubapi.
+     */
+    public Set<String> getClassesFromClasspathPubapi() {
+        Set<String> set = new HashSet<String>();
+
+        for (String s : pubapi_for_linked_classes) {
+            if (s.startsWith(" TYPE ")) {
+                set.add(s.substring(6, s.indexOf(' ', 6)));
+            }
+        }
+        return set;
+    }
+
+
 }