0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 |
package com.nokia.s60tools.imaker.internal.model;
|
|
18 |
|
|
19 |
import java.io.ByteArrayInputStream;
|
|
20 |
import java.io.ByteArrayOutputStream;
|
|
21 |
import java.io.FileNotFoundException;
|
|
22 |
import java.io.IOException;
|
|
23 |
import java.io.InputStream;
|
|
24 |
import java.util.ArrayList;
|
|
25 |
import java.util.Iterator;
|
|
26 |
import java.util.List;
|
|
27 |
import java.util.Properties;
|
|
28 |
|
|
29 |
import org.eclipse.core.resources.IFile;
|
|
30 |
import org.eclipse.core.resources.IProject;
|
|
31 |
import org.eclipse.core.runtime.CoreException;
|
|
32 |
import org.eclipse.core.runtime.IPath;
|
|
33 |
|
|
34 |
import com.nokia.s60tools.imaker.IMakerKeyConstants;
|
|
35 |
import com.nokia.s60tools.imaker.IMakerUtils;
|
|
36 |
import com.nokia.s60tools.imaker.Messages;
|
|
37 |
import com.nokia.s60tools.imaker.UIVariable;
|
|
38 |
import com.nokia.s60tools.imaker.internal.managers.ProjectManager;
|
|
39 |
import com.nokia.s60tools.imaker.internal.model.iContent.IContentFactory;
|
|
40 |
import com.nokia.s60tools.imaker.internal.model.iContent.IbyEntry;
|
|
41 |
import com.nokia.s60tools.imaker.internal.wrapper.IMakerWrapperPreferences;
|
|
42 |
import com.nokia.s60tools.imaker.internal.wrapper.PlatsimManager;
|
|
43 |
|
|
44 |
public class ImakerProperties extends Properties {
|
|
45 |
public static final String SEPARATOR = ":;";
|
|
46 |
public static final String GENERATED_FILES_FOLDER = "imakerplugin";
|
|
47 |
private static final long serialVersionUID = 1L;
|
|
48 |
private List<UIVariable> variables=null;
|
|
49 |
private String activeFile = null;
|
|
50 |
private boolean used = false;
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Create imaker properties from file
|
|
54 |
* @param file
|
|
55 |
* @return
|
|
56 |
*/
|
|
57 |
public static ImakerProperties createFromFile(IFile file) {
|
|
58 |
ImakerProperties imakerPreference = new ImakerProperties();
|
|
59 |
|
|
60 |
if(file!=null) {
|
|
61 |
try {
|
|
62 |
imakerPreference.load(file.getContents());
|
|
63 |
} catch (FileNotFoundException e) {
|
|
64 |
imakerPreference = null;
|
|
65 |
} catch (IOException e) {
|
|
66 |
imakerPreference = null;
|
|
67 |
} catch (CoreException e) {
|
|
68 |
e.printStackTrace();
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
|
72 |
return imakerPreference;
|
|
73 |
}
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Create imaker properties from file
|
|
77 |
* @param file
|
|
78 |
* @return
|
|
79 |
*/
|
|
80 |
public void saveToFile(IFile file) {
|
|
81 |
if(file!=null) {
|
|
82 |
InputStream input = getAsInputStream();
|
|
83 |
try {
|
|
84 |
file.setContents(input, true, false,null);
|
|
85 |
} catch (CoreException e) {
|
|
86 |
e.printStackTrace();
|
|
87 |
}
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
public ImakerProperties() {}
|
|
92 |
|
|
93 |
public InputStream getAsInputStream() {
|
|
94 |
ByteArrayOutputStream bao = new ByteArrayOutputStream();
|
|
95 |
try {
|
|
96 |
store(bao, "iMaker properties");
|
|
97 |
} catch (IOException e) {
|
|
98 |
e.printStackTrace();
|
|
99 |
}
|
|
100 |
ByteArrayInputStream bs = new ByteArrayInputStream(bao.toString().getBytes());
|
|
101 |
return bs;
|
|
102 |
}
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Parse the contents of this properties file and create imaker command that is executable
|
|
106 |
* @param selectedProject
|
|
107 |
* @param workdir Place where the temporary iby/mk files will be placed
|
|
108 |
* @return
|
|
109 |
*/
|
|
110 |
public List<String> parseImakerCommand(IProject selectedProject, IPath workdir) {
|
|
111 |
String drive = IMakerUtils.getProjectRootLocation(selectedProject);
|
|
112 |
ArrayList<String> command = new ArrayList<String>();
|
|
113 |
|
|
114 |
String makefile = (String) get(IMakerKeyConstants.MAKEFILE);
|
|
115 |
if(makefile!=null) {
|
|
116 |
appendCommand(command,IMakerWrapperPreferences.ARG_FETCH_CONFIGURATION);
|
|
117 |
appendCommand(command,makefile);
|
|
118 |
}
|
|
119 |
addAdditionalParameters(command,(String) get(IMakerKeyConstants.TARGET_LIST)," ");
|
|
120 |
String platsim = (String) get(IMakerKeyConstants.PLATSIM_INSTANCE);
|
|
121 |
if(platsim!=null) {
|
|
122 |
command.add(IMakerKeyConstants.PLATSIM_INSTANCE +"="+parse(platsim,drive));
|
|
123 |
String run = (String)get(IMakerKeyConstants.PLATSIM_RUN);
|
|
124 |
if(run!=null&&run.equals("true")) {
|
|
125 |
command.add(IMakerKeyConstants.PLATSIM_RUN +"=1");
|
|
126 |
}
|
|
127 |
}
|
|
128 |
addAdditionalParameters(command,(String) get(IMakerKeyConstants.ADDITIONAL_PARAMETERS),SEPARATOR);
|
|
129 |
addAdditionalParameters(command, (String) get(IMakerKeyConstants.MODIFIED_SETTINGS),SEPARATOR);
|
|
130 |
String type = (String) get(IMakerKeyConstants.TYPE);
|
|
131 |
command.add(IMakerWrapperPreferences.TYPE+"="+type);
|
|
132 |
String verb = (String) get(IMakerKeyConstants.VERBOSE);
|
|
133 |
if(verb!=null) {
|
|
134 |
command.add(Messages.getString("Flashmenu.9"));
|
|
135 |
}
|
|
136 |
|
|
137 |
// parse iby files and makefile
|
|
138 |
String str = (String)get(IMakerKeyConstants.DEBUGFILES);
|
|
139 |
if(str!=null&&!str.equals("")) {
|
|
140 |
List<IbyEntry> entries = new ArrayList<IbyEntry>();
|
|
141 |
String[] entriesStr = str.split(ImakerProperties.SEPARATOR);
|
|
142 |
for (int i = 0; i < entriesStr.length; i++) {
|
|
143 |
String entryStr = entriesStr[i];
|
|
144 |
if(entryStr!=null&&!entryStr.equals("")) {
|
|
145 |
IbyEntry entry = IContentFactory.eINSTANCE.createEntryFromString(entryStr);
|
|
146 |
if(entry.isEnabled()) {
|
|
147 |
entries.add(entry);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
ProjectManager pm = new ProjectManager(selectedProject);
|
|
152 |
IPath mkfile = IMakerUtils.createIbyFiles(entries, pm, workdir);
|
|
153 |
if(mkfile!=null) {
|
|
154 |
appendCommand(command,IMakerWrapperPreferences.ARG_FETCH_CONFIGURATION);
|
|
155 |
appendCommand(command,"\""+mkfile.toOSString()+"\"");
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
return command;
|
|
160 |
}
|
|
161 |
|
|
162 |
private String parse(String instance, String env) {
|
|
163 |
if(instance==null) {
|
|
164 |
instance="1";
|
|
165 |
}
|
|
166 |
if(instance.equals(Messages.getString("PlatsimTab.0"))) {
|
|
167 |
PlatsimManager pm = new PlatsimManager(env);
|
|
168 |
int max = 1;
|
|
169 |
List<String> instances = pm.getInstances();
|
|
170 |
for (String ins : instances) {
|
|
171 |
int intIns = Integer.parseInt(ins);
|
|
172 |
if(intIns>max) max = intIns;
|
|
173 |
}
|
|
174 |
return String.valueOf(max+1);
|
|
175 |
}
|
|
176 |
return instance;
|
|
177 |
}
|
|
178 |
|
|
179 |
private void addAdditionalParameters(ArrayList<String> command,
|
|
180 |
String adds, String sep) {
|
|
181 |
if(adds==null||adds.equals("")) { //$NON-NLS-1$
|
|
182 |
return;
|
|
183 |
}
|
|
184 |
String[] parts = adds.split(sep); //$NON-NLS-1$
|
|
185 |
for (int i = 0; i < parts.length; i++) {
|
|
186 |
String part = parts[i];
|
|
187 |
if(!part.equals("")) { //$NON-NLS-1$
|
|
188 |
appendCommand(command, part);
|
|
189 |
}
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
private void appendCommand(ArrayList<String> command, String value) {
|
|
194 |
if((value!=null)&&!(value.equals(""))) { //$NON-NLS-1$
|
|
195 |
command.add(value.trim());
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
private void updateVariables() {
|
|
200 |
if(variables==null) {
|
|
201 |
return;
|
|
202 |
}
|
|
203 |
List<UIVariable> includeVariables = IMakerUtils.getCommandlineIncludeVariables(variables);
|
|
204 |
List<String> variablesToStrings = IMakerUtils.convertVariablesToStrings(includeVariables);
|
|
205 |
|
|
206 |
StringBuilder settings = new StringBuilder();
|
|
207 |
|
|
208 |
for (Iterator<String> iterator = variablesToStrings.iterator(); iterator
|
|
209 |
.hasNext();) {
|
|
210 |
String setting = iterator.next();
|
|
211 |
settings.append(setting+SEPARATOR); //$NON-NLS-1$
|
|
212 |
}
|
|
213 |
|
|
214 |
String string = settings.toString();
|
|
215 |
if(!string.equals("")) { //$NON-NLS-1$
|
|
216 |
put(IMakerKeyConstants.MODIFIED_SETTINGS, string);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
public void setVariables(List<UIVariable> variables) {
|
|
221 |
this.variables = variables;
|
|
222 |
updateVariables();
|
|
223 |
}
|
|
224 |
|
|
225 |
public void setActiveFile(String path) {
|
|
226 |
this.activeFile = path;
|
|
227 |
}
|
|
228 |
|
|
229 |
public String getActiveFile() {
|
|
230 |
return activeFile;
|
|
231 |
}
|
|
232 |
|
|
233 |
public void setUsed(boolean b) {
|
|
234 |
this.used = b;
|
|
235 |
}
|
|
236 |
|
|
237 |
public boolean isUsed() {
|
|
238 |
return this.used;
|
|
239 |
}
|
|
240 |
}
|