138 } 139 } 140 try { 141 checkVM("minimal", CLIENT, JVM_CFG_CLIENT, MINIMAL, JVM_CFG_MINIMAL); 142 failed = true; 143 throw new Exception("Should have failed"); 144 } catch (Exception ex) { 145 if (failed) { 146 throw ex; 147 } 148 } 149 150 } 151 152 public void checkVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception { 153 154 for (String arch : ARCHITECTURES) { 155 String[] winput = new String[input.length]; 156 String[] woutput = new String[expectedOutput.length]; 157 for (int i = 0; i < input.length; i++) { 158 winput[i] = "/java.base/native" + arch + input[i]; 159 } 160 for (int i = 0; i < expectedOutput.length; i++) { 161 woutput[i] = "/java.base/native" + arch + expectedOutput[i]; 162 } 163 doCheckVM(vm, winput, jvmcfg, woutput, expectdJvmCfg); 164 } 165 } 166 167 private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception { 168 // Create a pool with jvm.cfg and the input paths. 169 byte[] jvmcfgContent = jvmcfg.getBytes(); 170 ResourcePoolManager poolMgr = new ResourcePoolManager(); 171 poolMgr.add( 172 ResourcePoolEntry.create("/java.base/native/jvm.cfg", 173 ResourcePoolEntry.Type.NATIVE_LIB, jvmcfgContent)); 174 175 // java.base/module-info.class is used by exclude vm plugin 176 // to get current osName(). We read it from jrt-fs and add a 177 // ResourcePoolEntry 178 poolMgr.add( 179 ResourcePoolEntry.create("/java.base/module-info.class", 180 ResourcePoolEntry.Type.CLASS_OR_RESOURCE, getJavaBaseModuleInfo())); 181 for (String in : input) { 182 poolMgr.add(ResourcePoolEntry.create(in, 183 ResourcePoolEntry.Type.NATIVE_LIB, new byte[0])); 184 } 185 ResourcePoolManager outMgr = new ResourcePoolManager(); 186 187 Plugin p = new ExcludeVMPlugin(); 188 Map<String, String> config = new HashMap<>(); 189 if (vm != null) { 190 config.put(ExcludeVMPlugin.NAME, vm); 191 } 192 p.configure(config); 193 ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder()); 194 195 String newContent = new String(out.findEntry("/java.base/native/jvm.cfg").get().contentBytes()); 196 197 if (!expectdJvmCfg.equals(newContent)) { 198 throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg); 199 } 200 201 // Apart from native resources, we should find jvm.cfg and 202 // java.base/module-info.class. So, we add 2 here to the 203 // expected count! 204 if (out.entryCount() != (expectedOutput.length + 2)) { 205 out.entries().forEach(m -> { 206 System.err.println(m.path()); 207 }); 208 throw new Exception("Invalid output size " + out.entryCount() + " expected " + (expectedOutput.length + 2)); 209 } 210 211 out.entries().forEach(md -> { 212 if (md.path().equals("/java.base/native/jvm.cfg") || 213 md.path().equals("/java.base/module-info.class")) { 214 return; 215 } 216 boolean contained = false; 217 for (String o : expectedOutput) { 218 if (md.path().equals(o)) { 219 contained = true; 220 break; 221 } 222 } 223 if (!contained) { 224 throw new RuntimeException(md.path() + " not expected"); 225 } 226 }); 227 } 228 229 // read java.base/module-info.class from jrt-fs 230 private static Path getJavaBaseModuleInfo() { 231 return Paths.get(URI.create("jrt:/modules/java.base/module-info.class")); 232 } | 138 } 139 } 140 try { 141 checkVM("minimal", CLIENT, JVM_CFG_CLIENT, MINIMAL, JVM_CFG_MINIMAL); 142 failed = true; 143 throw new Exception("Should have failed"); 144 } catch (Exception ex) { 145 if (failed) { 146 throw ex; 147 } 148 } 149 150 } 151 152 public void checkVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception { 153 154 for (String arch : ARCHITECTURES) { 155 String[] winput = new String[input.length]; 156 String[] woutput = new String[expectedOutput.length]; 157 for (int i = 0; i < input.length; i++) { 158 winput[i] = "/java.base/lib" + arch + input[i]; 159 } 160 for (int i = 0; i < expectedOutput.length; i++) { 161 woutput[i] = "/java.base/lib" + arch + expectedOutput[i]; 162 } 163 doCheckVM(vm, winput, jvmcfg, woutput, expectdJvmCfg); 164 } 165 } 166 167 private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception { 168 // Create a pool with jvm.cfg and the input paths. 169 byte[] jvmcfgContent = jvmcfg.getBytes(); 170 ResourcePoolManager poolMgr = new ResourcePoolManager(); 171 poolMgr.add( 172 ResourcePoolEntry.create("/java.base/lib/jvm.cfg", 173 ResourcePoolEntry.Type.NATIVE_LIB, jvmcfgContent)); 174 175 // java.base/module-info.class is used by exclude vm plugin 176 // to get current osName(). We read it from jrt-fs and add a 177 // ResourcePoolEntry 178 poolMgr.add( 179 ResourcePoolEntry.create("/java.base/module-info.class", 180 ResourcePoolEntry.Type.CLASS_OR_RESOURCE, getJavaBaseModuleInfo())); 181 for (String in : input) { 182 poolMgr.add(ResourcePoolEntry.create(in, 183 ResourcePoolEntry.Type.NATIVE_LIB, new byte[0])); 184 } 185 ResourcePoolManager outMgr = new ResourcePoolManager(); 186 187 Plugin p = new ExcludeVMPlugin(); 188 Map<String, String> config = new HashMap<>(); 189 if (vm != null) { 190 config.put(ExcludeVMPlugin.NAME, vm); 191 } 192 p.configure(config); 193 ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder()); 194 195 String newContent = new String(out.findEntry("/java.base/lib/jvm.cfg").get().contentBytes()); 196 197 if (!expectdJvmCfg.equals(newContent)) { 198 throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg); 199 } 200 201 // Apart from native resources, we should find jvm.cfg and 202 // java.base/module-info.class. So, we add 2 here to the 203 // expected count! 204 if (out.entryCount() != (expectedOutput.length + 2)) { 205 out.entries().forEach(m -> { 206 System.err.println(m.path()); 207 }); 208 throw new Exception("Invalid output size " + out.entryCount() + " expected " + (expectedOutput.length + 2)); 209 } 210 211 out.entries().forEach(md -> { 212 if (md.path().equals("/java.base/lib/jvm.cfg") || 213 md.path().equals("/java.base/module-info.class")) { 214 return; 215 } 216 boolean contained = false; 217 for (String o : expectedOutput) { 218 if (md.path().equals(o)) { 219 contained = true; 220 break; 221 } 222 } 223 if (!contained) { 224 throw new RuntimeException(md.path() + " not expected"); 225 } 226 }); 227 } 228 229 // read java.base/module-info.class from jrt-fs 230 private static Path getJavaBaseModuleInfo() { 231 return Paths.get(URI.create("jrt:/modules/java.base/module-info.class")); 232 } |