|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.s60tools.appdep.export; |
|
20 |
|
21 import java.io.FileNotFoundException; |
|
22 import java.util.Date; |
|
23 |
|
24 import javax.xml.transform.TransformerException; |
|
25 |
|
26 import org.eclipse.core.runtime.IProgressMonitor; |
|
27 import org.eclipse.core.runtime.IStatus; |
|
28 import org.eclipse.core.runtime.Platform; |
|
29 import org.eclipse.core.runtime.Status; |
|
30 import org.eclipse.core.runtime.jobs.Job; |
|
31 |
|
32 import com.nokia.s60tools.appdep.core.AppDepSettings; |
|
33 import com.nokia.s60tools.appdep.core.data.ComponentNode; |
|
34 import com.nokia.s60tools.appdep.core.data.ComponentParentNode; |
|
35 import com.nokia.s60tools.appdep.core.job.IJobProgressStatus; |
|
36 import com.nokia.s60tools.appdep.resources.Messages; |
|
37 import com.nokia.s60tools.appdep.util.AppDepConsole; |
|
38 import com.nokia.s60tools.sdk.SdkInformation; |
|
39 import com.nokia.s60tools.util.console.IConsolePrintUtility; |
|
40 import com.nokia.s60tools.util.debug.DbgUtility; |
|
41 import com.nokia.s60tools.util.exceptions.JobCancelledByUserException; |
|
42 |
|
43 /** |
|
44 * Job class managing exporting UI view contents |
|
45 * into an external report. |
|
46 */ |
|
47 public class ExportJob extends Job implements IJobProgressStatus{ |
|
48 |
|
49 // |
|
50 // Private members |
|
51 // |
|
52 |
|
53 //Progress indication for components, @see ExportVisitor.COMPONENTS_EXPORT_PERCENTAGE |
|
54 private static final int PROGRESS_AFTER_PROPERTIES_PERCENTAGE = 94; |
|
55 private static final int PROGRESS_AFTER_EXPORTEDFUNCTIONS_PERCENTAGE = 96; |
|
56 private static final int PROGRESS_AFTER_XML_FILE_SAVE_PERCENTAGE = 97; |
|
57 private static final int PROGRESS_COMPLETE_PERCENTAGE = 100; |
|
58 int previousPercentage = 0; |
|
59 private IProgressMonitor monitor = null; |
|
60 private ComponentNode node; |
|
61 private String exportHTMLFileName; |
|
62 private String exportXMLFileName; |
|
63 final int steps = 100; // percentage figure |
|
64 |
|
65 /** |
|
66 * Constructor |
|
67 * @param name Job name (root component name) |
|
68 * @param node root node |
|
69 * @param exportHTMLFileName file name for exported html report |
|
70 * @param exportXMLFileName file name for exported xml report |
|
71 */ |
|
72 public ExportJob(String name, |
|
73 ComponentNode node, |
|
74 String exportHTMLFileName, |
|
75 String exportXMLFileName) { |
|
76 super(name); |
|
77 setUser(true); |
|
78 this.node = node; |
|
79 this.exportHTMLFileName = exportHTMLFileName; |
|
80 this.exportXMLFileName = exportXMLFileName; |
|
81 } |
|
82 |
|
83 /* (non-Javadoc) |
|
84 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
|
85 */ |
|
86 protected IStatus run(IProgressMonitor monitor) { |
|
87 this.monitor = monitor; |
|
88 |
|
89 IStatus status; |
|
90 |
|
91 String msg = Messages.getString("ExportJob.Exporting_Msg") +node.getName(); //$NON-NLS-1$ |
|
92 monitor.beginTask(msg , steps); |
|
93 |
|
94 try { |
|
95 long runMethodStartTime = reportStartTime(); |
|
96 export(); |
|
97 reportEndTime(runMethodStartTime); |
|
98 status = Status.OK_STATUS; |
|
99 } catch (FileNotFoundException e) { |
|
100 e.printStackTrace(); |
|
101 status = new Status( |
|
102 Status.ERROR,Platform.PI_RUNTIME, |
|
103 Status.ERROR,Messages.getString("ExportJob.Export_Failed_Msg") + "! " + Messages.getString("ExportJob.File_Not_Found_Msg") + ": " + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
104 AppDepConsole.getInstance().println(Messages.getString("ExportJob.Export_Failed_Msg") + "! " + Messages.getString("ExportJob.File_Not_Found_Msg") + ": " + e.getMessage(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
105 IConsolePrintUtility.MSG_ERROR); |
|
106 this.cancel(); |
|
107 } catch (JobCancelledByUserException e) { |
|
108 this.cancel(); |
|
109 status = Status.CANCEL_STATUS; |
|
110 } catch (TransformerException e) { |
|
111 e.printStackTrace(); |
|
112 this.cancel(); |
|
113 status = new Status( |
|
114 Status.ERROR,Platform.PI_RUNTIME, |
|
115 Status.ERROR,Messages.getString("ExportJob.Export_Failed_Msg") + "! " + Messages.getString("ExportJob.Transform_Not_Complete_Msg") + ": " + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
116 AppDepConsole.getInstance().println(Messages.getString("ExportJob.Export_Failed_Msg") + "! " + Messages.getString("ExportJob.Transform_Not_Complete_Msg") + ": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
117 + e.getMessage(), |
|
118 IConsolePrintUtility.MSG_ERROR); |
|
119 } |
|
120 |
|
121 return status; |
|
122 |
|
123 } |
|
124 |
|
125 /** |
|
126 * Reports start time of the export. |
|
127 * @return start time of the export. |
|
128 */ |
|
129 private long reportStartTime(){ |
|
130 long runMethodStartTime = System.currentTimeMillis(); |
|
131 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
132 "Export started: " //$NON-NLS-1$ |
|
133 + new Date(runMethodStartTime).toString()); |
|
134 return runMethodStartTime; |
|
135 } |
|
136 |
|
137 /** |
|
138 * Reports end time and time elapsed for the export. |
|
139 * @param runMethodStartTime start time of the export |
|
140 */ |
|
141 private void reportEndTime(long runMethodStartTime){ |
|
142 long endTime = System.currentTimeMillis(); |
|
143 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
144 "Export ended: " + new Date(endTime).toString()); //$NON-NLS-1$ |
|
145 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
146 "TOTAL: " //$NON-NLS-1$ |
|
147 + (endTime-runMethodStartTime)/1000.0 + " seconds!"); //$NON-NLS-1$ |
|
148 } |
|
149 |
|
150 /** |
|
151 * Exports XML data. |
|
152 * @throws JobCancelledByUserException |
|
153 * @throws FileNotFoundException |
|
154 * @throws TransformerException |
|
155 */ |
|
156 private void export() |
|
157 throws JobCancelledByUserException, |
|
158 FileNotFoundException, |
|
159 TransformerException |
|
160 { |
|
161 AppDepSettings st = AppDepSettings.getActiveSettings(); |
|
162 SdkInformation sdkInfo = st.getCurrentlyUsedSdk(); |
|
163 |
|
164 progress(0, Messages.getString("ExportJob.Components_Str")); //$NON-NLS-1$ |
|
165 |
|
166 ExportVisitor visitor = new ExportVisitor(sdkInfo.getSdkId(), |
|
167 st.getCurrentlyUsedTargetPlatformsAsString(), |
|
168 st.getBuildType().getBuildTypeDescription(), |
|
169 node.getName(), node.getFullName(), |
|
170 this); |
|
171 |
|
172 //Progress will go up to ExportVisitor.COMPONENTS_EXPORT_PERCENTAGE = 85 |
|
173 ((ComponentParentNode)node).accept(visitor); |
|
174 |
|
175 visitor.createProperties(); |
|
176 |
|
177 progress(PROGRESS_AFTER_PROPERTIES_PERCENTAGE, Messages.getString("ExportJob.Exported_Functions_Str")); //$NON-NLS-1$ |
|
178 |
|
179 visitor.createExportedFunctions(); |
|
180 |
|
181 progress(PROGRESS_AFTER_EXPORTEDFUNCTIONS_PERCENTAGE, Messages.getString("ExportJob.XML_Str")); //$NON-NLS-1$ |
|
182 |
|
183 XMLUtils.parseXML(visitor.toString(), exportHTMLFileName); |
|
184 |
|
185 //Currently no one will |
|
186 if(AppDepSettings.getActiveSettings().isExportXMLreport()){ |
|
187 progress(PROGRESS_AFTER_XML_FILE_SAVE_PERCENTAGE, Messages.getString("ExportJob.File_Writing_Str")); //$NON-NLS-1$ |
|
188 visitor.toFile(exportXMLFileName); |
|
189 } |
|
190 |
|
191 progress(PROGRESS_COMPLETE_PERCENTAGE, Messages.getString("ExportJob.Complete_Str")); //$NON-NLS-1$ |
|
192 |
|
193 } |
|
194 |
|
195 /* (non-Javadoc) |
|
196 * @see com.nokia.s60tools.appdep.core.job.IJobProgressStatus#progress(int, java.lang.String) |
|
197 */ |
|
198 public void progress(int percentage, String prosessing) |
|
199 throws JobCancelledByUserException { |
|
200 |
|
201 if (isCanceled()){ |
|
202 String msg = Messages.getString("ExportJob.Export_Canceled_By_User_Msg") //$NON-NLS-1$ |
|
203 + "."; //$NON-NLS-1$ |
|
204 AppDepConsole.getInstance().println(msg); |
|
205 throw new JobCancelledByUserException(msg); |
|
206 } |
|
207 |
|
208 monitor.subTask(percentage + Messages.getString("ExportJob.Percent_Complete_Msg") //$NON-NLS-1$ |
|
209 + "." //$NON-NLS-1$ |
|
210 + Messages.getString("ExportJob.Processing_Msg") //$NON-NLS-1$ |
|
211 + ": " //$NON-NLS-1$ |
|
212 + prosessing); |
|
213 monitor.worked(percentage - previousPercentage); |
|
214 |
|
215 previousPercentage = percentage; |
|
216 |
|
217 } |
|
218 |
|
219 /* (non-Javadoc) |
|
220 * @see com.nokia.s60tools.appdep.core.job.IJobProgressStatus#isCanceled() |
|
221 */ |
|
222 public boolean isCanceled() { |
|
223 return monitor.isCanceled(); |
|
224 } |
|
225 |
|
226 } |