1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/sjavac/Module.java Mon Feb 04 18:08:53 2013 -0500 1.3 @@ -0,0 +1,141 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.sjavac; 1.30 + 1.31 +import java.io.File; 1.32 +import java.net.URI; 1.33 +import java.util.HashMap; 1.34 +import java.util.List; 1.35 +import java.util.Map; 1.36 +import java.util.Set; 1.37 + 1.38 +/** 1.39 + * The module is the root of a set of packages/sources/artifacts. 1.40 + * At the moment there is only one module in use, the empty/no-name/default module. 1.41 + * 1.42 + * <p><b>This is NOT part of any supported API. 1.43 + * If you write code that depends on this, you do so at your own 1.44 + * risk. This code and its internal interfaces are subject to change 1.45 + * or deletion without notice.</b></p> 1.46 + */ 1.47 +public class Module implements Comparable<Module> { 1.48 + private String name; 1.49 + private String dirname; 1.50 + private Map<String,Package> packages = new HashMap<String,Package>(); 1.51 + private Map<String,Source> sources = new HashMap<String,Source>(); 1.52 + private Map<String,File> artifacts = new HashMap<String,File>(); 1.53 + 1.54 + public Module(String n, String dn) { 1.55 + name = n; 1.56 + dirname = n; 1.57 + } 1.58 + 1.59 + public String name() { return name; } 1.60 + public String dirname() { return dirname; } 1.61 + public Map<String,Package> packages() { return packages; } 1.62 + public Map<String,Source> sources() { return sources; } 1.63 + public Map<String,File> artifacts() { return artifacts; } 1.64 + 1.65 + @Override 1.66 + public boolean equals(Object o) { 1.67 + return (o instanceof Module) && name.equals(((Module)o).name); 1.68 + } 1.69 + 1.70 + @Override 1.71 + public int hashCode() { 1.72 + return name.hashCode(); 1.73 + } 1.74 + 1.75 + @Override 1.76 + public int compareTo(Module o) { 1.77 + return name.compareTo(o.name); 1.78 + } 1.79 + 1.80 + public void save(StringBuilder b) { 1.81 + b.append("M ").append(name).append(":").append("\n"); 1.82 + Package.savePackages(packages, b); 1.83 + } 1.84 + 1.85 + public static Module load(String l) { 1.86 + int cp = l.indexOf(':',2); 1.87 + if (cp == -1) return null; 1.88 + String name = l.substring(2,cp); 1.89 + return new Module(name, ""); 1.90 + } 1.91 + 1.92 + public static void saveModules(Map<String,Module> ms, StringBuilder b) 1.93 + { 1.94 + for (Module m : ms.values()) { 1.95 + m.save(b); 1.96 + } 1.97 + } 1.98 + 1.99 + public void addPackage(Package p) { 1.100 + packages.put(p.name(), p); 1.101 + } 1.102 + 1.103 + public Package lookupPackage(String pkg) { 1.104 + Package p = packages.get(pkg); 1.105 + if (p == null) { 1.106 + p = new Package(this, pkg); 1.107 + packages.put(pkg, p); 1.108 + } 1.109 + return p; 1.110 + } 1.111 + 1.112 + public void addSource(String pkg, Source src) { 1.113 + Package p = lookupPackage(pkg); 1.114 + src.setPackage(p); 1.115 + p.addSource(src); 1.116 + sources.put(src.file().getPath(), src); 1.117 + } 1.118 + 1.119 + public Source lookupSource(String path) { 1.120 + return sources.get(path); 1.121 + } 1.122 + 1.123 + public void addArtifacts(String pkg, Set<URI> as) { 1.124 + Package p = lookupPackage(pkg); 1.125 + for (URI u : as) { 1.126 + p.addArtifact(new File(u)); 1.127 + } 1.128 + } 1.129 + 1.130 + public void setDependencies(String pkg, Set<String> deps) { 1.131 + Package p = lookupPackage(pkg); 1.132 + p.setDependencies(deps); 1.133 + } 1.134 + 1.135 + public void setPubapi(String pkg, List<String> ps) { 1.136 + Package p = lookupPackage(pkg); 1.137 + p.setPubapi(ps); 1.138 + } 1.139 + 1.140 + public boolean hasPubapiChanged(String pkg, List<String> ps) { 1.141 + Package p = lookupPackage(pkg); 1.142 + return p.hasPubapiChanged(ps); 1.143 + } 1.144 +}