/** check a candidate plugin for jar hell before installing it */ private void jarHellCheck(Path candidate, boolean isolated) throws IOException { // create list of current jars in classpath final List<URL> jars = new ArrayList<>(Arrays.asList(JarHell.parseClassPath())); // read existing bundles. this does some checks on the installation too. List<Bundle> bundles = PluginsService.getPluginBundles(environment.pluginsFile()); // if we aren't isolated, we need to jarhellcheck against any other non-isolated plugins // thats always the first bundle if (isolated == false) { jars.addAll(bundles.get(0).urls); } // add plugin jars to the list Path pluginJars[] = FileSystemUtils.files(candidate, "*.jar"); for (Path jar : pluginJars) { jars.add(jar.toUri().toURL()); } // check combined (current classpath + new jars to-be-added) try { JarHell.checkJarHell(jars.toArray(new URL[jars.size()])); } catch (Exception ex) { throw new RuntimeException(ex); } }
static void testCopyInputStreamToFile(int size) throws IOException { Path tmpdir = createTempDirectory("blah"); Path source = tmpdir.resolve("source"); Path target = tmpdir.resolve("target"); try { boolean testReplaceExisting = rand.nextBoolean(); // create source file byte[] b = new byte[size]; rand.nextBytes(b); write(source, b); // target file might already exist if (testReplaceExisting && rand.nextBoolean()) { write(target, new byte[rand.nextInt(512)]); } // copy from stream to file InputStream in = new FileInputStream(source.toFile()); try { long n; if (testReplaceExisting) { n = copy(in, target, StandardCopyOption.REPLACE_EXISTING); } else { n = copy(in, target); } assertTrue(in.read() == -1); // EOF assertTrue(n == size); assertTrue(size(target) == size); } finally { in.close(); } // check file byte[] read = readAllBytes(target); assertTrue(Arrays.equals(read, b)); } finally { deleteIfExists(source); deleteIfExists(target); delete(tmpdir); } }
static void testCopyFileToOuputStream(int size) throws IOException { Path source = createTempFile("blah", null); try { byte[] b = new byte[size]; rand.nextBytes(b); write(source, b); ByteArrayOutputStream out = new ByteArrayOutputStream(); long n = copy(source, out); assertTrue(n == size); assertTrue(out.size() == size); byte[] read = out.toByteArray(); assertTrue(Arrays.equals(read, b)); // check output stream is open out.write(0); assertTrue(out.size() == size + 1); } finally { delete(source); } }