1 /* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.*; 25 import java.net.URI; 26 import java.util.*; 27 import java.lang.module.*; 28 import java.security.CodeSigner; 29 import org.openjdk.jigsaw.*; 30 31 class MockLibrary 32 extends Library 33 { 34 35 private static JigsawModuleSystem jms = JigsawModuleSystem.instance(); 36 37 MockLibrary() { } 38 39 private Map<String,List<ModuleId>> idsForName 40 = new HashMap<String,List<ModuleId>>(); 41 42 private Map<ModuleId,ModuleInfo> infoForId 43 = new HashMap<ModuleId,ModuleInfo>(); 44 45 MockLibrary add(ModuleInfo mi) { 46 for (ModuleView mv : mi.views()) { 47 String name = mv.id().name(); 48 infoForId.put(mv.id(), mi); 49 List<ModuleId> ls = idsForName.get(name); 50 if (ls == null) { 51 ls = new ArrayList<ModuleId>(); 52 idsForName.put(name, ls); 53 } 54 ls.add(mv.id()); 55 } 56 return this; 57 } 58 59 MockLibrary add(ModuleInfoBuilder mib) { 60 return add(mib.build()); 61 } 62 63 MockLibrary add(ModuleInfoBuilder.ModuleViewBuilder mvb) { 64 return add(mvb.mib); 65 } 66 67 private Map<ModuleId,List<String>> publicClassesForId 68 = new HashMap<ModuleId,List<String>>(); 69 70 private Map<ModuleId,List<String>> otherClassesForId 71 = new HashMap<ModuleId,List<String>>(); 72 73 MockLibrary add(ModuleId id, String cn, 74 Map<ModuleId,List<String>> map) 75 { 76 List<String> ls = map.get(id); 77 if (ls == null) { 78 ls = new ArrayList<String>(); 79 map.put(id, ls); 80 } 81 ls.add(cn); 82 return this; 83 } 84 85 MockLibrary addPublic(String mids, String cn) { 86 return add(jms.parseModuleId(mids), cn, publicClassesForId); 87 } 88 89 MockLibrary addOther(String mids, String cn) { 90 return add(jms.parseModuleId(mids), cn, otherClassesForId); 91 } 92 93 public String name() { return "mock-library"; } 94 public int majorVersion() { return 0; } 95 public int minorVersion() { return 1; } 96 97 public URI location() { 98 throw new UnsupportedOperationException(); 99 } 100 101 public void installFromManifests(Collection<Manifest> mf) { 102 throw new UnsupportedOperationException(); 103 } 104 105 public void install(Collection<File> mf, boolean verifySignature) { 106 throw new UnsupportedOperationException(); 107 } 108 109 public Resolution resolve(Collection<ModuleIdQuery> midqs) { 110 throw new UnsupportedOperationException(); 111 } 112 113 public void install(Resolution res, boolean verifySignature) { 114 throw new UnsupportedOperationException(); 115 } 116 117 public Library parent() { 118 return null; 119 } 120 121 protected void gatherLocalModuleIds(String mn, Set<ModuleId> mids) { 122 if (idsForName.containsKey(mn)) { 123 mids.addAll(idsForName.get(mn)); 124 } 125 } 126 127 protected void gatherLocalDeclaringModuleIds(Set<ModuleId> set) { 128 set.addAll(infoForId.keySet()); 129 } 130 131 public List<ModuleId> findModuleIds(String moduleName) { 132 List<ModuleId> ls = idsForName.get(moduleName); 133 if (ls == null) 134 ls = Collections.emptyList(); 135 return ls; 136 } 137 138 public List<ModuleId> findModuleIds(ModuleIdQuery midq) { 139 throw new UnsupportedOperationException(); 140 } 141 142 public ModuleId findLatestModuleId(ModuleIdQuery midq) { 143 throw new UnsupportedOperationException(); 144 } 145 146 public ModuleInfo readLocalModuleInfo(ModuleId mid) { 147 return infoForId.get(mid); 148 } 149 150 public byte[] readLocalModuleInfoBytes(ModuleId mid) { 151 throw new UnsupportedOperationException(); 152 } 153 154 public CodeSigner[] readLocalCodeSigners(ModuleId mid) { 155 throw new UnsupportedOperationException(); 156 } 157 158 public byte[] readLocalClass(ModuleId mid, String className) { 159 throw new UnsupportedOperationException(); 160 } 161 162 public void remove(List<ModuleId> mids, boolean dry) { 163 throw new UnsupportedOperationException(); 164 } 165 166 public void removeForcibly(List<ModuleId> mids) { 167 throw new UnsupportedOperationException(); 168 } 169 170 public ModuleId findModuleForClass(String className, 171 ModuleId requestor) 172 throws ClassNotFoundException 173 { 174 throw new UnsupportedOperationException(); 175 } 176 177 public List<String> listLocalClasses(ModuleId mid, boolean all) { 178 List<String> rv = new ArrayList<String>(); 179 List<String> pcns = publicClassesForId.get(mid); 180 if (pcns != null) 181 rv.addAll(pcns); 182 if (all) { 183 List<String> ocns = otherClassesForId.get(mid); 184 if (ocns != null) 185 rv.addAll(ocns); 186 } 187 return rv; 188 } 189 190 public Configuration<Context> readConfiguration(ModuleId mid) { 191 throw new UnsupportedOperationException(); 192 } 193 194 public URI findLocalResource(ModuleId mid, String name) { 195 throw new UnsupportedOperationException(); 196 } 197 198 public File findLocalNativeLibrary(ModuleId mid, String name) { 199 throw new UnsupportedOperationException(); 200 } 201 202 public File classPath(ModuleId mid) { 203 throw new UnsupportedOperationException(); 204 } 205 206 public RemoteRepositoryList repositoryList() throws IOException { 207 return new RemoteRepositoryList() { 208 public List<RemoteRepository> repositories() { 209 return Collections.emptyList(); 210 } 211 212 public RemoteRepository firstRepository() { 213 return null; 214 } 215 216 public RemoteRepository add(URI uri, int position) { 217 throw new UnsupportedOperationException(); 218 } 219 220 public boolean remove(RemoteRepository rr) { 221 throw new UnsupportedOperationException(); 222 } 223 224 public boolean areCatalogsStale() { 225 throw new UnsupportedOperationException(); 226 } 227 228 public boolean updateCatalogs(boolean force) { 229 throw new UnsupportedOperationException(); 230 } 231 232 }; 233 } 234 } --- EOF ---