Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/tools/sjavac/Module.java
38899 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.sjavac;2627import java.io.File;28import java.net.URI;29import java.util.HashMap;30import java.util.List;31import java.util.Map;32import java.util.Set;3334/**35* The module is the root of a set of packages/sources/artifacts.36* At the moment there is only one module in use, the empty/no-name/default module.37*38* <p><b>This is NOT part of any supported API.39* If you write code that depends on this, you do so at your own40* risk. This code and its internal interfaces are subject to change41* or deletion without notice.</b></p>42*/43public class Module implements Comparable<Module> {44private String name;45private String dirname;46private Map<String,Package> packages = new HashMap<String,Package>();47private Map<String,Source> sources = new HashMap<String,Source>();48private Map<String,File> artifacts = new HashMap<String,File>();4950public Module(String n, String dn) {51name = n;52dirname = n;53}5455public String name() { return name; }56public String dirname() { return dirname; }57public Map<String,Package> packages() { return packages; }58public Map<String,Source> sources() { return sources; }59public Map<String,File> artifacts() { return artifacts; }6061@Override62public boolean equals(Object o) {63return (o instanceof Module) && name.equals(((Module)o).name);64}6566@Override67public int hashCode() {68return name.hashCode();69}7071@Override72public int compareTo(Module o) {73return name.compareTo(o.name);74}7576public void save(StringBuilder b) {77b.append("M ").append(name).append(":").append("\n");78Package.savePackages(packages, b);79}8081public static Module load(String l) {82int cp = l.indexOf(':',2);83if (cp == -1) return null;84String name = l.substring(2,cp);85return new Module(name, "");86}8788public static void saveModules(Map<String,Module> ms, StringBuilder b)89{90for (Module m : ms.values()) {91m.save(b);92}93}9495public void addPackage(Package p) {96packages.put(p.name(), p);97}9899public Package lookupPackage(String pkg) {100Package p = packages.get(pkg);101if (p == null) {102p = new Package(this, pkg);103packages.put(pkg, p);104}105return p;106}107108public void addSource(String pkg, Source src) {109Package p = lookupPackage(pkg);110src.setPackage(p);111p.addSource(src);112sources.put(src.file().getPath(), src);113}114115public Source lookupSource(String path) {116return sources.get(path);117}118119public void addArtifacts(String pkg, Set<URI> as) {120Package p = lookupPackage(pkg);121for (URI u : as) {122p.addArtifact(new File(u));123}124}125126public void setDependencies(String pkg, Set<String> deps) {127Package p = lookupPackage(pkg);128p.setDependencies(deps);129}130131public void setPubapi(String pkg, List<String> ps) {132Package p = lookupPackage(pkg);133p.setPubapi(ps);134}135136public boolean hasPubapiChanged(String pkg, List<String> ps) {137Package p = lookupPackage(pkg);138return p.hasPubapiChanged(ps);139}140}141142143