1 22 23 package com.izforge.izpack.panels; 24 25 import java.io.IOException ; 26 27 import net.n3.nanoxml.XMLElement; 28 29 import com.izforge.izpack.installer.AutomatedInstallData; 30 import com.izforge.izpack.installer.CompileHandler; 31 import com.izforge.izpack.installer.CompileResult; 32 import com.izforge.izpack.installer.CompileWorker; 33 import com.izforge.izpack.installer.PanelAutomation; 34 import com.izforge.izpack.installer.PanelAutomationHelper; 35 36 42 public class CompilePanelAutomationHelper extends PanelAutomationHelper implements PanelAutomation, 43 CompileHandler 44 { 45 46 private CompileWorker worker = null; 47 48 private int job_max = 0; 49 50 private String job_name = null; 51 52 private int last_line_len = 0; 53 54 60 public void makeXMLData(AutomatedInstallData installData, XMLElement panelRoot) 61 { 62 } 65 66 71 public boolean runAutomated(AutomatedInstallData idata, XMLElement panelRoot) 72 { 73 XMLElement compiler_xml = panelRoot.getFirstChildNamed("compiler"); 74 75 String compiler = null; 76 77 if (compiler_xml != null) compiler = compiler_xml.getContent(); 78 79 if (compiler == null) 80 { 81 System.out.println("invalid automation data: could not find compiler"); 82 return false; 83 } 84 85 XMLElement args_xml = panelRoot.getFirstChildNamed("arguments"); 86 87 String args = null; 88 89 if (args_xml != null) args = args_xml.getContent(); 90 91 if (args_xml == null) 92 { 93 System.out.println("invalid automation data: could not find compiler arguments"); 94 return false; 95 } 96 97 try 98 { 99 this.worker = new CompileWorker(idata, this); 100 this.worker.setCompiler(compiler); 101 this.worker.setCompilerArguments(args); 102 103 this.worker.run(); 104 105 return this.worker.getResult().isSuccess(); 106 } 107 catch (IOException e) 108 { 109 e.printStackTrace(); 110 return false; 111 } 112 } 113 114 119 public void startAction(String name, int noOfJobs) 120 { 121 System.out.println("[ Starting compilation ]"); 122 this.job_name = ""; 123 } 124 125 131 public void handleCompileError(CompileResult error) 132 { 133 System.out.println(); 134 System.out.println("[ Compilation failed ]"); 135 System.err.println("Command line: " + error.getCmdline()); 136 System.err.println(); 137 System.err.println("stdout of compiler:"); 138 System.err.println(error.getStdout()); 139 System.err.println("stderr of compiler:"); 140 System.err.println(error.getStderr()); 141 error.setAction(CompileResult.ACTION_ABORT); 143 } 144 145 150 public void stopAction() 151 { 152 if ((this.job_name != null) && (this.last_line_len > 0)) 153 { 154 String line = this.job_name + ": done."; 155 System.out.print("\r" + line); 156 for (int i = line.length(); i < this.last_line_len; i++) 157 System.out.print(' '); 158 System.out.println(); 159 } 160 161 if (this.worker.getResult().isSuccess()) System.out.println("[ Compilation successful ]"); 162 } 163 164 171 public void progress(int val, String msg) 172 { 173 double percentage = ((double) val) * 100.0d / (double) this.job_max; 174 175 String percent = (new Integer ((int) percentage)).toString() + '%'; 176 String line = this.job_name + ": " + percent; 177 178 int line_len = line.length(); 179 180 System.out.print("\r" + line); 181 for (int i = line_len; i < this.last_line_len; i++) 182 System.out.print(' '); 183 184 this.last_line_len = line_len; 185 } 186 187 195 public void nextStep(String jobName, int max, int jobNo) 196 { 197 if ((this.job_name != null) && (this.last_line_len > 0)) 198 { 199 String line = this.job_name + ": done."; 200 System.out.print("\r" + line); 201 for (int i = line.length(); i < this.last_line_len; i++) 202 System.out.print(' '); 203 System.out.println(); 204 } 205 206 this.job_max = max; 207 this.job_name = jobName; 208 this.last_line_len = 0; 209 } 210 } 211 | Popular Tags |