1 package com.kirkk.analyzer.textui; 2 3 4 import java.io.*; 5 import java.util.*; 6 import com.kirkk.analyzer.framework.*; 7 import com.kirkk.analyzer.*; 8 9 18 public class DOTSummary implements Summary { 19 private PrintWriter writer; 20 21 public static void main(String args[]) throws Exception { 22 new DOTSummary().instanceMain(args); 23 } 24 25 public void instanceMain(String args[]) throws Exception { 26 File scrDir = (args.length > 0) ? new File(args[0]) : null; 27 File destFile = (args.length > 1) ? new File(args[1]) : null; 28 if(scrDir == null) 29 { 30 System.out.print("Please enter input directory name: "); 31 scrDir = getFile(); 32 } 33 if(destFile == null) 34 { 35 System.out.print("Please enter output file name: "); 36 destFile = getFile(); 37 } 38 createSummary(scrDir, destFile); 39 } 40 41 public void createSummary(File srcDir, File destFile) throws Exception 42 { 43 Analyzer analyzer = new Analyzer(); 44 Jar jarBundle[] = analyzer.analyze(srcDir); 45 outputAll(jarBundle, destFile); 46 } 47 48 public void createSummary(File srcDir, File destFile, String packageFilter, String jarFilter) throws Exception { 49 Analyzer analyzer = new Analyzer(); 50 Configuration.initialize(packageFilter, jarFilter); 51 Jar jarBundle[] = analyzer.analyze(srcDir); 52 outputAll(jarBundle, destFile); 53 } 54 55 private File getFile() throws IOException { 56 try { 57 InputStreamReader streamReader = new InputStreamReader(System.in); 58 BufferedReader reader = new BufferedReader(streamReader); 59 String fileName = reader.readLine(); 60 File file = new File(fileName); 61 return file; 62 } catch (IOException e) { 63 throw e; 64 } 65 } 66 67 private void outputAll(Jar[] jarBundle, File file) { 68 try { 69 FileWriter fileWriter = new FileWriter(file); 70 writer = new PrintWriter(fileWriter); 71 } catch (IOException e) { 72 System.out.println("IOException - Redirecting to System.out"); 73 System.out.println(e); 74 OutputStreamWriter outputWriter = new OutputStreamWriter(System.out); 75 writer = new PrintWriter(outputWriter); 76 } 77 this.printHeader(); 78 this.output(jarBundle); 79 this.printFooter(); 80 writer.flush(); 81 writer.close(); 82 } 83 84 private void printHeader() { 85 writer.println("digraph G {"); 86 } 88 89 private void printFooter() { 90 writer.println("}"); 91 } 92 93 private void output(Jar[] jarBundles) { 94 for (int i = 0; i < jarBundles.length; i++) { 96 String jar = jarBundles[i].getJarFileName().substring(jarBundles[i].getJarFileName().lastIndexOf("\\") + 1, 97 jarBundles[i].getJarFileName().length()); 98 this.externalJars(jarBundles[i]); 103 } 107 } 109 110 117 private void externalJars(Jar jarBundle) { 118 Iterator jarDependencies = jarBundle.getOutgoingDependencies().iterator(); 120 while (jarDependencies.hasNext()) { 121 String jarName = jarBundle.getJarFileName().replaceAll("[-.]","_"); 122 writer.print(tab() + jarName.substring(0, jarName.length() - 4)); 123 Jar dependentBundle = (Jar) jarDependencies.next(); 124 String jar2= dependentBundle.getJarFileName().replaceAll("[-.]","_"); 127 writer.println(" -> " + jar2.substring(0, jar2.length() - 4) + ";"); 128 } 129 } 131 132 133 140 141 150 151 160 161 private String tab() { 162 return " "; 163 } 164 165 private String tab(int i) { 166 String tab = tab(); 167 for (int j = 0; j < i - 1; j++) { 168 tab = tab + tab(); 169 } 170 return tab; 171 } 172 173 } | Popular Tags |