ohrstrom@1504: /* ohrstrom@1504: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. ohrstrom@1504: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohrstrom@1504: * ohrstrom@1504: * This code is free software; you can redistribute it and/or modify it ohrstrom@1504: * under the terms of the GNU General Public License version 2 only, as ohrstrom@1504: * published by the Free Software Foundation. Oracle designates this ohrstrom@1504: * particular file as subject to the "Classpath" exception as provided ohrstrom@1504: * by Oracle in the LICENSE file that accompanied this code. ohrstrom@1504: * ohrstrom@1504: * This code is distributed in the hope that it will be useful, but WITHOUT ohrstrom@1504: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohrstrom@1504: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohrstrom@1504: * version 2 for more details (a copy is included in the LICENSE file that ohrstrom@1504: * accompanied this code). ohrstrom@1504: * ohrstrom@1504: * You should have received a copy of the GNU General Public License version ohrstrom@1504: * 2 along with this work; if not, write to the Free Software Foundation, ohrstrom@1504: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohrstrom@1504: * ohrstrom@1504: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohrstrom@1504: * or visit www.oracle.com if you need additional information or have any ohrstrom@1504: * questions. ohrstrom@1504: */ ohrstrom@1504: ohrstrom@1504: package com.sun.tools.sjavac; ohrstrom@1504: ohrstrom@1504: import java.io.File; ohrstrom@1504: import java.net.URI; ohrstrom@1504: import java.util.HashMap; ohrstrom@1504: import java.util.List; ohrstrom@1504: import java.util.Map; ohrstrom@1504: import java.util.Set; ohrstrom@1504: ohrstrom@1504: /** ohrstrom@1504: * The module is the root of a set of packages/sources/artifacts. ohrstrom@1504: * At the moment there is only one module in use, the empty/no-name/default module. ohrstrom@1504: * ohrstrom@1504: *

This is NOT part of any supported API. ohrstrom@1504: * If you write code that depends on this, you do so at your own ohrstrom@1504: * risk. This code and its internal interfaces are subject to change ohrstrom@1504: * or deletion without notice.

ohrstrom@1504: */ ohrstrom@1504: public class Module implements Comparable { ohrstrom@1504: private String name; ohrstrom@1504: private String dirname; ohrstrom@1504: private Map packages = new HashMap(); ohrstrom@1504: private Map sources = new HashMap(); ohrstrom@1504: private Map artifacts = new HashMap(); ohrstrom@1504: ohrstrom@1504: public Module(String n, String dn) { ohrstrom@1504: name = n; ohrstrom@1504: dirname = n; ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public String name() { return name; } ohrstrom@1504: public String dirname() { return dirname; } ohrstrom@1504: public Map packages() { return packages; } ohrstrom@1504: public Map sources() { return sources; } ohrstrom@1504: public Map artifacts() { return artifacts; } ohrstrom@1504: ohrstrom@1504: @Override ohrstrom@1504: public boolean equals(Object o) { ohrstrom@1504: return (o instanceof Module) && name.equals(((Module)o).name); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: @Override ohrstrom@1504: public int hashCode() { ohrstrom@1504: return name.hashCode(); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: @Override ohrstrom@1504: public int compareTo(Module o) { ohrstrom@1504: return name.compareTo(o.name); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public void save(StringBuilder b) { ohrstrom@1504: b.append("M ").append(name).append(":").append("\n"); ohrstrom@1504: Package.savePackages(packages, b); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public static Module load(String l) { ohrstrom@1504: int cp = l.indexOf(':',2); ohrstrom@1504: if (cp == -1) return null; ohrstrom@1504: String name = l.substring(2,cp); ohrstrom@1504: return new Module(name, ""); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public static void saveModules(Map ms, StringBuilder b) ohrstrom@1504: { ohrstrom@1504: for (Module m : ms.values()) { ohrstrom@1504: m.save(b); ohrstrom@1504: } ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public void addPackage(Package p) { ohrstrom@1504: packages.put(p.name(), p); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public Package lookupPackage(String pkg) { ohrstrom@1504: Package p = packages.get(pkg); ohrstrom@1504: if (p == null) { ohrstrom@1504: p = new Package(this, pkg); ohrstrom@1504: packages.put(pkg, p); ohrstrom@1504: } ohrstrom@1504: return p; ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public void addSource(String pkg, Source src) { ohrstrom@1504: Package p = lookupPackage(pkg); ohrstrom@1504: src.setPackage(p); ohrstrom@1504: p.addSource(src); ohrstrom@1504: sources.put(src.file().getPath(), src); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public Source lookupSource(String path) { ohrstrom@1504: return sources.get(path); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public void addArtifacts(String pkg, Set as) { ohrstrom@1504: Package p = lookupPackage(pkg); ohrstrom@1504: for (URI u : as) { ohrstrom@1504: p.addArtifact(new File(u)); ohrstrom@1504: } ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public void setDependencies(String pkg, Set deps) { ohrstrom@1504: Package p = lookupPackage(pkg); ohrstrom@1504: p.setDependencies(deps); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public void setPubapi(String pkg, List ps) { ohrstrom@1504: Package p = lookupPackage(pkg); ohrstrom@1504: p.setPubapi(ps); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: public boolean hasPubapiChanged(String pkg, List ps) { ohrstrom@1504: Package p = lookupPackage(pkg); ohrstrom@1504: return p.hasPubapiChanged(ps); ohrstrom@1504: } ohrstrom@1504: }