author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 02 Sep 2010 15:18:58 -0700 | |
changeset 484 | f5df819c1852 |
parent 470 | d4809db37847 |
permissions | -rw-r--r-- |
462 | 1 |
/** |
2 |
* Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "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 |
* Symbian Foundation - initial contribution. |
|
11 |
* Contributors: |
|
12 |
* Description: |
|
13 |
* Overview: |
|
14 |
* Details: |
|
15 |
* Platforms/Drives/Compatibility: |
|
16 |
* Assumptions/Requirement/Pre-requisites: |
|
17 |
* Failures and causes: |
|
18 |
*/ |
|
19 |
package org.symbian.tools.wrttools.core.deploy.emulator; |
|
20 |
||
21 |
import java.io.File; |
|
22 |
import java.io.FileInputStream; |
|
23 |
import java.io.FileOutputStream; |
|
24 |
import java.io.IOException; |
|
25 |
import java.io.InputStream; |
|
26 |
import java.io.OutputStream; |
|
27 |
||
28 |
import org.eclipse.core.runtime.CoreException; |
|
29 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
30 |
import org.eclipse.core.runtime.IStatus; |
|
31 |
import org.eclipse.core.runtime.PlatformObject; |
|
32 |
import org.eclipse.core.runtime.Status; |
|
33 |
import org.eclipse.ui.IMemento; |
|
468
a05c6e5cc7d9
Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
462
diff
changeset
|
34 |
import org.symbian.tools.tmw.core.projects.ITMWProject; |
462 | 35 |
import org.symbian.tools.tmw.core.runtimes.IPackager; |
36 |
import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; |
|
37 |
import org.symbian.tools.wrttools.Activator; |
|
38 |
||
39 |
public class Emulator extends PlatformObject implements IDeploymentTarget { |
|
40 |
@Override |
|
41 |
public int hashCode() { |
|
42 |
final int prime = 31; |
|
43 |
int result = 1; |
|
44 |
result = prime * result + ((id == null) ? 0 : id.hashCode()); |
|
45 |
result = prime * result + ((path == null) ? 0 : path.hashCode()); |
|
46 |
return result; |
|
47 |
} |
|
48 |
||
49 |
@Override |
|
50 |
public boolean equals(Object obj) { |
|
51 |
if (this == obj) { |
|
52 |
return true; |
|
53 |
} |
|
54 |
if (obj == null) { |
|
55 |
return false; |
|
56 |
} |
|
57 |
if (getClass() != obj.getClass()) { |
|
58 |
return false; |
|
59 |
} |
|
60 |
Emulator other = (Emulator) obj; |
|
61 |
if (id == null) { |
|
62 |
if (other.id != null) { |
|
63 |
return false; |
|
64 |
} |
|
65 |
} else if (!id.equals(other.id)) { |
|
66 |
return false; |
|
67 |
} |
|
68 |
if (path == null) { |
|
69 |
if (other.path != null) { |
|
70 |
return false; |
|
71 |
} |
|
72 |
} else if (!path.equals(other.path)) { |
|
73 |
return false; |
|
74 |
} |
|
75 |
return true; |
|
76 |
} |
|
77 |
||
78 |
private final String id; |
|
79 |
private final String path; |
|
80 |
||
81 |
public Emulator(String id, String path) { |
|
82 |
this.id = id; |
|
83 |
this.path = path; |
|
84 |
} |
|
85 |
||
86 |
public String getId() { |
|
87 |
return id; |
|
88 |
} |
|
89 |
||
90 |
public String getName() { |
|
91 |
return id; |
|
92 |
} |
|
93 |
||
94 |
public String getDescription() { |
|
95 |
return path; |
|
96 |
} |
|
97 |
||
468
a05c6e5cc7d9
Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
462
diff
changeset
|
98 |
public IStatus deploy(ITMWProject project, IPackager packager, IProgressMonitor monitor) |
462 | 99 |
throws CoreException { |
100 |
final File application = packager.packageApplication(project, monitor); |
|
101 |
final File outputFile = new File(path); |
|
102 |
if (!outputFile.isDirectory()) { |
|
103 |
outputFile.mkdir(); |
|
104 |
} |
|
105 |
||
106 |
final File out = new File(outputFile + "/" + application.getName()); //$NON-NLS-1$ |
|
107 |
deployWidget(application, out); |
|
108 |
return new Status( |
|
109 |
IStatus.OK, |
|
110 |
Activator.PLUGIN_ID, |
|
111 |
"Application was successfully deployed to emulator. You will need to complete installation process using your emulator UI."); |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Deploys the widget from the source to the destination path of the emulator. |
|
116 |
* @param inputFile the actual widget path from where widget needs to be deployed. |
|
117 |
* @param outputFile the path of the emulator where the widget will be deoplyed. |
|
118 |
*/ |
|
119 |
private void deployWidget(File inputFile, File outputFile) throws CoreException { |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
120 |
InputStream in = null; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
121 |
OutputStream out = null; |
462 | 122 |
try { |
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
123 |
in = new FileInputStream(inputFile); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
124 |
out = new FileOutputStream(outputFile); |
462 | 125 |
int c; |
126 |
||
127 |
while ((c = in.read()) != -1) { |
|
128 |
out.write(c); |
|
129 |
} |
|
130 |
} catch (IOException e) { |
|
131 |
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Application deployment failed", e)); |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
132 |
} finally { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
133 |
if (in != null) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
134 |
try { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
135 |
in.close(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
136 |
} catch (IOException e) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
137 |
Activator.log(e); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
138 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
139 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
140 |
if (out != null) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
141 |
try { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
142 |
out.close(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
143 |
} catch (IOException e) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
144 |
Activator.log(e); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
145 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
146 |
} |
462 | 147 |
} |
148 |
} |
|
149 |
||
150 |
public void save(IMemento memento) { |
|
151 |
// Do nothing |
|
152 |
} |
|
153 |
||
468
a05c6e5cc7d9
Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
462
diff
changeset
|
154 |
public void init(ITMWProject project, IPackager packager, IMemento memento) { |
462 | 155 |
// Do nothing |
156 |
} |
|
157 |
} |