private String fixupGraph(String s) { s = fixGrapherBug(s); s = hideClassPaths(s); return s; }
@Override public void call(Injector injector) { Grapher grapher = injector.getInstance(Grapher.class); try { text = grapher.graph(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Writes the "Dot" graph to a new temp file. * * @return the name of the newly created file */ public String toFile() throws Exception { File file = File.createTempFile("GuiceDependencies_", ".dot"); toFile(file); return file.getCanonicalPath(); }
/** * Returns a String containing the "Dot" graph definition. * * @return the "Dot" graph definition */ public String graph() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter out = new PrintWriter(baos); Injector localInjector = Guice.createInjector(new GraphvizModule()); GraphvizGrapher renderer = localInjector.getInstance(GraphvizGrapher.class); renderer.setOut(out); renderer.setRankdir("TB"); if (!roots.isEmpty()) { renderer.graph(injector, roots); } renderer.graph(injector); return fixupGraph(baos.toString("UTF-8")); }
/** * Writes the "Dot" graph to a given file. * * @param file file to write to */ public void toFile(File file) throws Exception { PrintWriter out = new PrintWriter(file, "UTF-8"); try { out.write(graph()); } finally { Closeables.close(out, true); } }