001 package jp.osdl.jbento2.report; 002 003 import java.io.File; 004 import java.io.InputStream; 005 import java.util.Iterator; 006 import java.util.Properties; 007 008 import jp.osdl.jbento2.PathUtils; 009 import jp.osdl.jbento2.RegexNameFileFilter; 010 011 import org.apache.commons.io.FileUtils; 012 import org.apache.commons.io.IOUtils; 013 import org.apache.commons.io.filefilter.FileFilterUtils; 014 import org.apache.velocity.app.Velocity; 015 016 public class Report { 017 018 public static void main(String[] args) throws Exception { 019 Report report = new Report(); 020 report.generate(); 021 } 022 023 private File sourceDir = null; 024 025 private File destDir = null; 026 027 private Properties props = null; 028 029 public void generate() throws Exception { 030 initProperties(); 031 initVelocity(); 032 033 if (destDir == null) { 034 destDir = sourceDir; 035 } 036 037 if (!destDir.exists()) { 038 destDir.mkdirs(); 039 } 040 041 StaticFileBuilder sfb = new StaticFileBuilder(destDir); 042 sfb.execute(); 043 044 Iterator ite = FileUtils.iterateFiles(sourceDir, 045 new RegexNameFileFilter("throughput\\.csv"), FileFilterUtils 046 .trueFileFilter()); 047 while (ite.hasNext()) { 048 File dataDir = ((File) ite.next()).getParentFile(); 049 if (dataDir.isDirectory()) { 050 File dataDestDir = makeRelativeDirToTargetDir(sourceDir, 051 dataDir, destDir); 052 SummaryBuilder builder = new SummaryBuilder(dataDir, 053 dataDestDir, destDir); 054 builder.execute(); 055 } 056 } 057 058 ite = FileUtils.iterateFiles(sourceDir, new RegexNameFileFilter( 059 "summary\\.txt"), FileFilterUtils.trueFileFilter()); 060 while (ite.hasNext()) { 061 File summaryText = (File) ite.next(); 062 File dataDestDir = makeRelativeDirToTargetDir(sourceDir, 063 summaryText.getParentFile(), destDir); 064 SampleDetailBuilder builder = new SampleDetailBuilder(summaryText 065 .getParentFile(), dataDestDir, destDir); 066 builder.execute(); 067 } 068 069 ite = FileUtils.iterateFiles(sourceDir, new RegexNameFileFilter( 070 ".*\\..*\\.png"), FileFilterUtils.trueFileFilter()); 071 while (ite.hasNext()) { 072 File cpuAllImages = (File) ite.next(); 073 File dataDestDir = makeRelativeDirToTargetDir(sourceDir, cpuAllImages 074 .getParentFile(), destDir); 075 MachineDetailBuilder builder = new MachineDetailBuilder(cpuAllImages 076 .getParentFile(), dataDestDir, destDir); 077 builder.execute(); 078 } 079 080 } 081 082 public File makeRelativeDirToTargetDir(File path1, File path2, File target) { 083 String relativePath = PathUtils.calculateRelativePath(path1, path2); 084 File madeDir = new File(target, relativePath); 085 madeDir.mkdirs(); 086 return madeDir; 087 } 088 089 public void setSourceDir(String dir) { 090 this.sourceDir = new File(dir); 091 } 092 093 public String getSourceDir() { 094 return sourceDir.getAbsolutePath(); 095 } 096 097 private void initProperties() throws Exception { 098 Properties p = new Properties(); 099 InputStream in = null; 100 try { 101 in = getClass().getResourceAsStream("jbento-report.properties"); 102 p.load(in); 103 } catch (Exception ex) { 104 throw ex; 105 } finally { 106 IOUtils.closeQuietly(in); 107 } 108 this.props = p; 109 } 110 111 private void initVelocity() throws Exception { 112 Properties p = new Properties(); 113 InputStream in = null; 114 try { 115 in = getClass().getResourceAsStream("velocity.properties"); 116 p.load(in); 117 } catch (Exception ex) { 118 throw ex; 119 } finally { 120 IOUtils.closeQuietly(in); 121 } 122 Velocity.init(p); 123 } 124 125 public String getDestDir() { 126 return destDir.getAbsolutePath(); 127 } 128 129 public void setDestDir(String destDir) { 130 this.destDir = new File(destDir); 131 } 132 133 }