11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.sjavac;
27
28 import java.io.File;
29 import java.net.URI;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34
35 /**
36 * The module is the root of a set of packages/sources/artifacts.
37 * At the moment there is only one module in use, the empty/no-name/default module.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 */
44 public class Module implements Comparable<Module> {
45 private String name;
46 private String dirname;
47 private Map<String,Package> packages = new HashMap<>();
48 private Map<String,Source> sources = new HashMap<>();
49 private Map<String,File> artifacts = new HashMap<>();
50
51 public Module(String n, String dn) {
52 name = n;
53 dirname = n;
54 }
69 return name.hashCode();
70 }
71
72 @Override
73 public int compareTo(Module o) {
74 return name.compareTo(o.name);
75 }
76
77 public void save(StringBuilder b) {
78 b.append("M ").append(name).append(":").append("\n");
79 Package.savePackages(packages, b);
80 }
81
82 public static Module load(String l) {
83 int cp = l.indexOf(':',2);
84 if (cp == -1) return null;
85 String name = l.substring(2,cp);
86 return new Module(name, "");
87 }
88
89 public static void saveModules(Map<String,Module> ms, StringBuilder b)
90 {
91 for (Module m : ms.values()) {
92 m.save(b);
93 }
94 }
95
96 public void addPackage(Package p) {
97 packages.put(p.name(), p);
98 }
99
100 public Package lookupPackage(String pkg) {
101 Package p = packages.get(pkg);
102 if (p == null) {
103 p = new Package(this, pkg);
104 packages.put(pkg, p);
105 }
106 return p;
107 }
108
109 public void addSource(String pkg, Source src) {
110 Package p = lookupPackage(pkg);
111 src.setPackage(p);
112 p.addSource(src);
113 sources.put(src.file().getPath(), src);
114 }
115
116 public Source lookupSource(String path) {
117 return sources.get(path);
118 }
119
120 public void addArtifacts(String pkg, Set<URI> as) {
121 Package p = lookupPackage(pkg);
122 for (URI u : as) {
123 p.addArtifact(new File(u));
124 }
125 }
126
127 public void setDependencies(String pkg, Set<String> deps) {
128 Package p = lookupPackage(pkg);
129 p.setDependencies(deps);
130 }
131
132 public void setPubapi(String pkg, List<String> ps) {
133 Package p = lookupPackage(pkg);
134 p.setPubapi(ps);
135 }
136
137 public boolean hasPubapiChanged(String pkg, List<String> ps) {
138 Package p = lookupPackage(pkg);
139 return p.hasPubapiChanged(ps);
140 }
141 }
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.sjavac;
27
28 import java.io.File;
29 import java.net.URI;
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.Set;
33
34 import com.sun.tools.sjavac.pubapi.PubApi;
35
36 /**
37 * The module is the root of a set of packages/sources/artifacts.
38 * At the moment there is only one module in use, the empty/no-name/default module.
39 *
40 * <p><b>This is NOT part of any supported API.
41 * If you write code that depends on this, you do so at your own risk.
42 * This code and its internal interfaces are subject to change or
43 * deletion without notice.</b>
44 */
45 public class Module implements Comparable<Module> {
46 private String name;
47 private String dirname;
48 private Map<String,Package> packages = new HashMap<>();
49 private Map<String,Source> sources = new HashMap<>();
50 private Map<String,File> artifacts = new HashMap<>();
51
52 public Module(String n, String dn) {
53 name = n;
54 dirname = n;
55 }
70 return name.hashCode();
71 }
72
73 @Override
74 public int compareTo(Module o) {
75 return name.compareTo(o.name);
76 }
77
78 public void save(StringBuilder b) {
79 b.append("M ").append(name).append(":").append("\n");
80 Package.savePackages(packages, b);
81 }
82
83 public static Module load(String l) {
84 int cp = l.indexOf(':',2);
85 if (cp == -1) return null;
86 String name = l.substring(2,cp);
87 return new Module(name, "");
88 }
89
90 public static void saveModules(Map<String,Module> ms, StringBuilder b) {
91 for (Module m : ms.values()) {
92 m.save(b);
93 }
94 }
95
96 public void addPackage(Package p) {
97 packages.put(p.name(), p);
98 }
99
100 public Package lookupPackage(String pkg) {
101 // See JDK-8071904
102 Package p = packages.get(pkg);
103 if (p == null) {
104 p = new Package(this, pkg);
105 packages.put(pkg, p);
106 }
107 return p;
108 }
109
110 public void addSource(String pkg, Source src) {
111 Package p = lookupPackage(pkg);
112 src.setPackage(p);
113 p.addSource(src);
114 sources.put(src.file().getPath(), src);
115 }
116
117 public Source lookupSource(String path) {
118 return sources.get(path);
119 }
120
121 public void addArtifacts(String pkg, Set<URI> as) {
122 Package p = lookupPackage(pkg);
123 for (URI u : as) {
124 p.addArtifact(new File(u));
125 }
126 }
127
128 public void setDependencies(String pkg, Map<String, Set<String>> deps, boolean cp) {
129 lookupPackage(pkg).setDependencies(deps, cp);
130 }
131
132 public void setPubapi(String pkg, PubApi ps) {
133 Package p = lookupPackage(pkg);
134 p.setPubapi(ps);
135 }
136
137 public boolean hasPubapiChanged(String pkg, PubApi newPubApi) {
138 Package p = lookupPackage(pkg);
139 return p.hasPubApiChanged(newPubApi);
140 }
141 }
|