Path: blob/master/src/jdk.compiler/share/classes/com/sun/tools/sjavac/Module.java
41175 views
/*1* Copyright (c) 2012, 2021, 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.Map;31import java.util.Set;3233import com.sun.tools.sjavac.pubapi.PubApi;3435/**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 or42* deletion without notice.</b>43*/44public class Module implements Comparable<Module> {45private String name;46private String dirname;47private Map<String,Package> packages = new HashMap<>();48private Map<String,Source> sources = new HashMap<>();49private Map<String,File> artifacts = new HashMap<>();5051public Module(String n, String dn) {52name = n;53dirname = n;54}5556public String name() { return name; }57public String dirname() { return dirname; }58public Map<String,Package> packages() { return packages; }59public Map<String,Source> sources() { return sources; }60public Map<String,File> artifacts() { return artifacts; }6162@Override63public boolean equals(Object o) {64return (o instanceof Module module) && name.equals(module.name);65}6667@Override68public int hashCode() {69return name.hashCode();70}7172@Override73public int compareTo(Module o) {74return name.compareTo(o.name);75}7677public void save(StringBuilder b) {78b.append("M ").append(name).append(":").append("\n");79Package.savePackages(packages, b);80}8182public static Module load(String l) {83int cp = l.indexOf(':',2);84if (cp == -1) return null;85String name = l.substring(2,cp);86return new Module(name, "");87}8889public static void saveModules(Map<String,Module> ms, StringBuilder b) {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) {100// See JDK-8071904101Package p = packages.get(pkg);102if (p == null) {103p = new Package(this, pkg);104packages.put(pkg, p);105}106return p;107}108109public void addSource(String pkg, Source src) {110Package p = lookupPackage(pkg);111src.setPackage(p);112p.addSource(src);113sources.put(src.file().getPath(), src);114}115116public Source lookupSource(String path) {117return sources.get(path);118}119120public void addArtifacts(String pkg, Set<URI> as) {121Package p = lookupPackage(pkg);122for (URI u : as) {123p.addArtifact(new File(u));124}125}126127public void setDependencies(String pkg, Map<String, Set<String>> deps, boolean cp) {128lookupPackage(pkg).setDependencies(deps, cp);129}130131public void setPubapi(String pkg, PubApi ps) {132Package p = lookupPackage(pkg);133p.setPubapi(ps);134}135136public boolean hasPubapiChanged(String pkg, PubApi newPubApi) {137Package p = lookupPackage(pkg);138return p.hasPubApiChanged(newPubApi);139}140}141142143