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