@Test public void allStreamsAreClosedInCaseOfFailure() throws Exception { final MockPath impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer"); impl1.toThrow = new IOException(); final MockPath impl2 = new MockPath("META-INF/services/java.lang.Number", "nobody.knows.such.Class"); Clazzes clazzes = createClazzes(impl1, impl2); Clazz interfaceClazz = clazzes.load("java/lang/Number"); Set<Clazz> compiled = new HashSet<>(); Set<Clazz> queue = new LinkedHashSet<>(); try { AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue); fail("Should throw an exception"); } catch (IOException ex) { assertSame("Our exception is thrown", impl1.toThrow, ex); } assertTrue("First stream is closed", impl1.closed); assertTrue("Second stream is closed", impl2.closed); }
static void addMetaInfImplementations(Clazzes clazzes, Clazz clazz, Set<Clazz> compiled, Set<Clazz> compileQueue) throws IOException { String metaInfName = "META-INF/services/" + clazz.getClassName(); IOException throwLater = null; for (InputStream is : clazzes.loadResources(metaInfName)) { try (BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8"))) { for (;;) { String line = r.readLine(); if (line == null) { break; } if (line.startsWith("#")) { continue; } String implClazzName = line.replace('.', '/'); Clazz implClazz = clazzes.load(implClazzName); if (implClazz != null && !compiled.contains(implClazz)) { compileQueue.add(implClazz); } } } catch (IOException ex) { throwLater = ex; } } if (throwLater != null) { throw throwLater; } }
AppCompiler { static void addMetaInfImplementations(Clazzes clazzes, Clazz clazz, Set<Clazz> compiled, Set<Clazz> compileQueue) throws IOException { String metaInfName = "META-INF/services/" + clazz.getClassName(); IOException throwLater = null; for (InputStream is : clazzes.loadResources(metaInfName)) { try (BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8"))) { for (;;) { String line = r.readLine(); if (line == null) { break; } if (line.startsWith("#")) { continue; } String implClazzName = line.replace('.', '/'); Clazz implClazz = clazzes.load(implClazzName); if (implClazz != null && !compiled.contains(implClazz)) { compileQueue.add(implClazz); } } } catch (IOException ex) { throwLater = ex; } } if (throwLater != null) { throw throwLater; } } }
AppCompiler { static void addMetaInfImplementations(Clazzes clazzes, Clazz clazz, Set<Clazz> compiled, Set<Clazz> compileQueue) throws IOException { String metaInfName = "META-INF/services/" + clazz.getClassName(); IOException throwLater = null; for (InputStream is : clazzes.loadResources(metaInfName)) { try (BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8"))) { for (;;) { String line = r.readLine(); if (line == null) { break; } if (line.startsWith("#")) { continue; } String implClazzName = line.replace('.', '/'); Clazz implClazz = clazzes.load(implClazzName); if (implClazz != null && !compiled.contains(implClazz)) { compileQueue.add(implClazz); } } } catch (IOException ex) { throwLater = ex; } } if (throwLater != null) { throw throwLater; } } AppCompiler(Config config); }
AppCompiler { static void addMetaInfImplementations(Clazzes clazzes, Clazz clazz, Set<Clazz> compiled, Set<Clazz> compileQueue) throws IOException { String metaInfName = "META-INF/services/" + clazz.getClassName(); IOException throwLater = null; for (InputStream is : clazzes.loadResources(metaInfName)) { try (BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8"))) { for (;;) { String line = r.readLine(); if (line == null) { break; } if (line.startsWith("#")) { continue; } String implClazzName = line.replace('.', '/'); Clazz implClazz = clazzes.load(implClazzName); if (implClazz != null && !compiled.contains(implClazz)) { compileQueue.add(implClazz); } } } catch (IOException ex) { throwLater = ex; } } if (throwLater != null) { throw throwLater; } } AppCompiler(Config config); Config getConfig(); Set<Clazz> compile(Set<Clazz> rootClasses, boolean compileDependencies,
            final ClassCompilerListener listener); static void main(String[] args); void build(); void archive(); void install(); int launch(LaunchParameters launchParameters); int launch(LaunchParameters launchParameters, InputStream inputStream); Process launchAsync(LaunchParameters launchParameters); Process launchAsync(LaunchParameters launchParameters, InputStream inputStream); void launchAsyncCleanup(); }
AppCompiler { static void addMetaInfImplementations(Clazzes clazzes, Clazz clazz, Set<Clazz> compiled, Set<Clazz> compileQueue) throws IOException { String metaInfName = "META-INF/services/" + clazz.getClassName(); IOException throwLater = null; for (InputStream is : clazzes.loadResources(metaInfName)) { try (BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8"))) { for (;;) { String line = r.readLine(); if (line == null) { break; } if (line.startsWith("#")) { continue; } String implClazzName = line.replace('.', '/'); Clazz implClazz = clazzes.load(implClazzName); if (implClazz != null && !compiled.contains(implClazz)) { compileQueue.add(implClazz); } } } catch (IOException ex) { throwLater = ex; } } if (throwLater != null) { throw throwLater; } } AppCompiler(Config config); Config getConfig(); Set<Clazz> compile(Set<Clazz> rootClasses, boolean compileDependencies,
            final ClassCompilerListener listener); static void main(String[] args); void build(); void archive(); void install(); int launch(LaunchParameters launchParameters); int launch(LaunchParameters launchParameters, InputStream inputStream); Process launchAsync(LaunchParameters launchParameters); Process launchAsync(LaunchParameters launchParameters, InputStream inputStream); void launchAsyncCleanup();  }