root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / CompilePanelAutomationHelper.java @ 15280
History | View | Annotate | Download (6.15 KB)
1 |
/*
|
---|---|
2 |
* $Id: CompilePanelAutomationHelper.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2003 Jonathan Halliday, Julien Ponge
|
5 |
*
|
6 |
* File : CompilePanelAutomationHelper.java
|
7 |
* Description : Automation support functions for CompilePanel.
|
8 |
* Author's email : jonathan.halliday@arjuna.com
|
9 |
* Author's Website : http://www.arjuna.com
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
24 |
*/
|
25 |
package com.izforge.izpack.panels; |
26 |
|
27 |
import java.io.IOException; |
28 |
|
29 |
import net.n3.nanoxml.XMLElement; |
30 |
|
31 |
import com.izforge.izpack.installer.AutomatedInstallData; |
32 |
import com.izforge.izpack.installer.CompileHandler; |
33 |
import com.izforge.izpack.installer.CompileResult; |
34 |
import com.izforge.izpack.installer.CompileWorker; |
35 |
import com.izforge.izpack.installer.PanelAutomation; |
36 |
import com.izforge.izpack.installer.PanelAutomationHelper; |
37 |
|
38 |
/**
|
39 |
* Functions to support automated usage of the CompilePanel
|
40 |
*
|
41 |
* @author Jonathan Halliday
|
42 |
* @author Tino Schwarze
|
43 |
*/
|
44 |
public class CompilePanelAutomationHelper extends PanelAutomationHelper |
45 |
implements PanelAutomation, CompileHandler
|
46 |
{ |
47 |
private CompileWorker worker = null; |
48 |
|
49 |
private int job_max = 0; |
50 |
private String job_name = null; |
51 |
private int last_line_len = 0; |
52 |
|
53 |
/**
|
54 |
* Save data for running automated.
|
55 |
*
|
56 |
* @param installData installation parameters
|
57 |
* @param panelRoot unused.
|
58 |
*/
|
59 |
public void makeXMLData(AutomatedInstallData installData, XMLElement panelRoot) |
60 |
{ |
61 |
// not used here - during automatic installation, no automatic
|
62 |
// installation information is generated
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* Perform the installation actions.
|
67 |
*
|
68 |
* @param panelRoot The panel XML tree root.
|
69 |
*/
|
70 |
public void runAutomated(AutomatedInstallData idata, XMLElement panelRoot) |
71 |
{ |
72 |
XMLElement compiler_xml = panelRoot.getFirstChildNamed ("compiler");
|
73 |
|
74 |
String compiler = null; |
75 |
|
76 |
if (compiler_xml != null) |
77 |
compiler = compiler_xml.getContent (); |
78 |
|
79 |
if (compiler == null) |
80 |
{ |
81 |
System.out.println ("invalid automation data: could not find compiler"); |
82 |
return;
|
83 |
} |
84 |
|
85 |
XMLElement args_xml = panelRoot.getFirstChildNamed ("arguments");
|
86 |
|
87 |
String args = null; |
88 |
|
89 |
if (args_xml != null) |
90 |
args = args_xml.getContent (); |
91 |
|
92 |
if (args_xml == null) |
93 |
{ |
94 |
System.out.println ("invalid automation data: could not find compiler arguments"); |
95 |
return;
|
96 |
} |
97 |
|
98 |
try
|
99 |
{ |
100 |
this.worker = new CompileWorker (idata, this); |
101 |
this.worker.setCompiler (compiler);
|
102 |
this.worker.setCompilerArguments (args);
|
103 |
|
104 |
this.worker.run ();
|
105 |
} catch (IOException e) |
106 |
{ |
107 |
e.printStackTrace (); |
108 |
} |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Reports progress on System.out
|
113 |
*
|
114 |
* @see com.izforge.izpack.util.AbstractUIProgressHandler#startAction(String, int)
|
115 |
*/
|
116 |
public void startAction (String name, int noOfJobs) |
117 |
{ |
118 |
System.out.println ("[ Starting compilation ]"); |
119 |
this.job_name = ""; |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Reports the error to System.err
|
124 |
*
|
125 |
* @param error the error
|
126 |
* @see CompileHandler#handleCompileError(CompileResult)
|
127 |
*/
|
128 |
public void handleCompileError (CompileResult error) |
129 |
{ |
130 |
System.out.println ();
|
131 |
System.out.println ("[ Compilation failed ]"); |
132 |
System.err.println ("Command line: "+error.getCmdline()); |
133 |
System.err.println ();
|
134 |
System.err.println ("stdout of compiler:"); |
135 |
System.err.println (error.getStdout());
|
136 |
System.err.println ("stderr of compiler:"); |
137 |
System.err.println (error.getStderr());
|
138 |
// do not abort compilation, just continue
|
139 |
error.setAction (CompileResult.ACTION_CONTINUE); |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Sets state variable for thread sync.
|
144 |
*
|
145 |
* @see com.izforge.izpack.util.AbstractUIProgressHandler#stopAction()
|
146 |
*/
|
147 |
public void stopAction () |
148 |
{ |
149 |
if ((this.job_name != null) && (this.last_line_len > 0)) |
150 |
{ |
151 |
String line = this.job_name + ": done."; |
152 |
System.out.print ("\r"+line); |
153 |
for (int i = line.length(); i < this.last_line_len; i++) |
154 |
System.out.print (' '); |
155 |
System.out.println ();
|
156 |
} |
157 |
|
158 |
if (this.worker.getResult().isSuccess()) |
159 |
System.out.println ("[ Compilation successful ]"); |
160 |
} |
161 |
|
162 |
/**
|
163 |
* Tell about progress.
|
164 |
*
|
165 |
* @param val
|
166 |
* @param msg
|
167 |
* @see com.izforge.izpack.util.AbstractUIProgressHandler#progress(int, String)
|
168 |
*/
|
169 |
public void progress(int val, String msg) |
170 |
{ |
171 |
double percentage = ((double)val)*100.0d/(double)this.job_max; |
172 |
|
173 |
String percent = (new Integer ((int)percentage)).toString()+'%'; |
174 |
String line = this.job_name + ": " + percent; |
175 |
|
176 |
int line_len = line.length();
|
177 |
|
178 |
System.out.print ("\r"+line); |
179 |
for (int i = line_len; i < this.last_line_len; i++) |
180 |
System.out.print (' '); |
181 |
|
182 |
this.last_line_len = line_len;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Reports progress to System.out
|
187 |
*
|
188 |
* @param jobName The next job's name.
|
189 |
* @param max unused
|
190 |
* @param jobNo The next job's number.
|
191 |
* @see com.izforge.izpack.util.AbstractUIProgressHandler#nextStep(String, int, int)
|
192 |
*/
|
193 |
public void nextStep (String jobName, int max, int jobNo) |
194 |
{ |
195 |
if ((this.job_name != null) && (this.last_line_len > 0)) |
196 |
{ |
197 |
String line = this.job_name + ": done."; |
198 |
System.out.print ("\r"+line); |
199 |
for (int i = line.length(); i < this.last_line_len; i++) |
200 |
System.out.print (' '); |
201 |
System.out.println ();
|
202 |
} |
203 |
|
204 |
this.job_max = max;
|
205 |
this.job_name = jobName;
|
206 |
this.last_line_len = 0; |
207 |
} |
208 |
} |