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 |
|
|
18 |
package com.nokia.s60tools.imaker.internal.managers;
|
|
19 |
|
|
20 |
import java.io.BufferedWriter;
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FileNotFoundException;
|
|
23 |
import java.io.FileOutputStream;
|
|
24 |
import java.io.IOException;
|
|
25 |
import java.io.OutputStreamWriter;
|
|
26 |
import java.io.Writer;
|
|
27 |
import java.util.ArrayList;
|
|
28 |
import java.util.HashMap;
|
|
29 |
import java.util.List;
|
|
30 |
|
|
31 |
import org.eclipse.core.resources.IFolder;
|
|
32 |
import org.eclipse.core.resources.IProject;
|
|
33 |
import org.eclipse.core.resources.IResource;
|
|
34 |
import org.eclipse.core.resources.IResourceVisitor;
|
|
35 |
import org.eclipse.core.runtime.CoreException;
|
|
36 |
import org.eclipse.core.runtime.IPath;
|
|
37 |
import org.eclipse.core.runtime.Path;
|
|
38 |
|
|
39 |
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
|
|
40 |
import com.nokia.carbide.cdt.builder.EpocEngineHelper;
|
|
41 |
import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
|
|
42 |
import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
|
|
43 |
import com.nokia.s60tools.imaker.IMakerUtils;
|
|
44 |
import com.nokia.s60tools.imaker.internal.model.iContent.IContentFactory;
|
|
45 |
import com.nokia.s60tools.imaker.internal.model.iContent.IbyEntry;
|
|
46 |
import com.nokia.s60tools.imaker.internal.model.iContent.ImageContent;
|
|
47 |
|
|
48 |
public class ProjectManager {
|
|
49 |
public static final String NEW_ITEM = "<New Configuration>";
|
|
50 |
public static final String IBY_FILENAME_PREFIX = "imaker_additional_";
|
|
51 |
public static final String IBY_FOLDER_NAME = "rombuild";
|
|
52 |
public static final String MAKEFILE_NAME = "imaker_additions.mk";
|
|
53 |
|
|
54 |
private String activeFile = "";
|
|
55 |
private IProject project;
|
|
56 |
private ArrayList<IResource> imakerFiles;
|
|
57 |
|
|
58 |
public ProjectManager(IProject project) {
|
|
59 |
this.imakerFiles = new ArrayList<IResource>();
|
|
60 |
this.project = project;
|
|
61 |
}
|
|
62 |
|
|
63 |
public String getActiveFile() {
|
|
64 |
return activeFile;
|
|
65 |
}
|
|
66 |
|
|
67 |
public void setActiveFile(String newActive) {
|
|
68 |
activeFile = newActive;
|
|
69 |
|
|
70 |
}
|
|
71 |
|
|
72 |
public IProject getProject() {
|
|
73 |
return project;
|
|
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* @return The root location of the project
|
|
78 |
*/
|
|
79 |
public String getRoot() {
|
|
80 |
return IMakerUtils.getProjectRootLocation(project);
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Returns the imaker file in the specified location
|
|
86 |
* @param location
|
|
87 |
* @return
|
|
88 |
*/
|
|
89 |
public IResource getImakerFile(IPath location) {
|
|
90 |
IResource ret = null;
|
|
91 |
for (IResource resource : getImakerFiles()) {
|
|
92 |
if(resource.getLocation().equals(location)) {
|
|
93 |
ret = resource;
|
|
94 |
break;
|
|
95 |
}
|
|
96 |
}
|
|
97 |
return ret;
|
|
98 |
}
|
|
99 |
|
|
100 |
// public IFile getImakerMakeFile() {
|
|
101 |
// IFolder pfolder = project.getFolder(IBY_FOLDER_NAME);
|
|
102 |
// IFile mk = pfolder.getFile(MAKEFILE_NAME);
|
|
103 |
// if(mk.exists()) {
|
|
104 |
// return mk;
|
|
105 |
// } else {
|
|
106 |
// return null;
|
|
107 |
// }
|
|
108 |
// }
|
|
109 |
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Returns all imaker files in the selected project
|
|
113 |
* @return
|
|
114 |
*/
|
|
115 |
public List<IResource> getImakerFiles() {
|
|
116 |
imakerFiles.clear();
|
|
117 |
try {
|
|
118 |
project.accept(new ImakerResourceVisitor(imakerFiles));
|
|
119 |
} catch (CoreException e) {
|
|
120 |
e.printStackTrace();
|
|
121 |
}
|
|
122 |
return imakerFiles;
|
|
123 |
}
|
|
124 |
|
|
125 |
private class ImakerResourceVisitor implements IResourceVisitor {
|
|
126 |
|
|
127 |
private ArrayList<IResource> list;
|
|
128 |
|
|
129 |
/**
|
|
130 |
* @param imps
|
|
131 |
*/
|
|
132 |
public ImakerResourceVisitor(ArrayList<IResource> imps) {
|
|
133 |
this.list = imps;
|
|
134 |
}
|
|
135 |
|
|
136 |
/* (non-Javadoc)
|
|
137 |
* @see org.eclipse.core.resources.IResourceVisitor#visit(org.eclipse.core.resources.IResource)
|
|
138 |
*/
|
|
139 |
// @Override
|
|
140 |
public boolean visit(IResource res) throws CoreException {
|
|
141 |
String name = res.getName();
|
|
142 |
if(name.endsWith(".imp")) {
|
|
143 |
list.add(res);
|
|
144 |
}
|
|
145 |
if(res instanceof IFolder) {
|
|
146 |
if(name.equals("src") || name.equals("inc")) {
|
|
147 |
return false;
|
|
148 |
}
|
|
149 |
}
|
|
150 |
return true;
|
|
151 |
}
|
|
152 |
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Creates new iby file to the specified location, with the specified content
|
|
157 |
* @param basename The name of the iby file, without the extension
|
|
158 |
* @param content The contents fo iby file
|
|
159 |
* @param path parent folder of the iby file
|
|
160 |
* @return The location or path of the newly created file
|
|
161 |
*/
|
|
162 |
public IPath createIbyFile(String basename, String content, IPath path) {
|
|
163 |
File parent = path.toFile();
|
|
164 |
createFolder(parent);
|
|
165 |
path = path.append(basename+".iby");
|
|
166 |
File file = path.toFile();
|
|
167 |
|
|
168 |
FileOutputStream fo;
|
|
169 |
try {
|
|
170 |
if(!file.exists()) {
|
|
171 |
file.createNewFile();
|
|
172 |
}
|
|
173 |
fo = new FileOutputStream(file);
|
|
174 |
OutputStreamWriter osw = new OutputStreamWriter(fo);
|
|
175 |
|
|
176 |
Writer out = new BufferedWriter(osw);
|
|
177 |
out.write(content);
|
|
178 |
out.flush();
|
|
179 |
out.close();
|
|
180 |
return new Path(file.getAbsolutePath());
|
|
181 |
} catch (FileNotFoundException e) {
|
|
182 |
e.printStackTrace();
|
|
183 |
} catch (IOException e) {
|
|
184 |
e.printStackTrace();
|
|
185 |
}
|
|
186 |
return null;
|
|
187 |
}
|
|
188 |
|
|
189 |
private void createFolder(File folder) {
|
|
190 |
if(folder!=null&&!folder.exists()) {
|
|
191 |
String parent = folder.getParent();
|
|
192 |
File f = new File(parent);
|
|
193 |
createFolder(f);
|
|
194 |
folder.mkdir();
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
public IPath createAdditionsMakefile(List<IPath> files, IPath path) {
|
|
199 |
createFolder(path.toFile());
|
|
200 |
IPath mk = path.append(MAKEFILE_NAME);
|
|
201 |
File mkFile = mk.toFile();
|
|
202 |
|
|
203 |
FileOutputStream fo;
|
|
204 |
try {
|
|
205 |
StringBuffer sb = new StringBuffer();
|
|
206 |
for (IPath p : files) {
|
|
207 |
File f = p.toFile();
|
|
208 |
String name = f.getName();
|
|
209 |
int index = name.lastIndexOf('_');
|
|
210 |
String loc = name.substring(index+1, name.length()-4);
|
|
211 |
loc = loc.toUpperCase();
|
|
212 |
sb.append(loc+"_OBY += " + f.getAbsolutePath()+"\n");
|
|
213 |
}
|
|
214 |
|
|
215 |
fo = new FileOutputStream(mkFile);
|
|
216 |
OutputStreamWriter osw = new OutputStreamWriter(fo);
|
|
217 |
|
|
218 |
Writer out = new BufferedWriter(osw);
|
|
219 |
out.write(sb.toString());
|
|
220 |
out.flush();
|
|
221 |
out.close();
|
|
222 |
return new Path(mkFile.getAbsolutePath());
|
|
223 |
} catch (FileNotFoundException e) {
|
|
224 |
e.printStackTrace();
|
|
225 |
} catch (IOException e) {
|
|
226 |
e.printStackTrace();
|
|
227 |
}
|
|
228 |
return null;
|
|
229 |
}
|
|
230 |
|
|
231 |
/**
|
|
232 |
* Populate the model of the dialog with content from the selected project
|
|
233 |
* @param ic
|
|
234 |
*/
|
|
235 |
public void populate(ImageContent ic) {
|
|
236 |
ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
|
|
237 |
if (cpi != null) {
|
|
238 |
ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
|
|
239 |
String filename = null;
|
|
240 |
|
11
|
241 |
// boolean debug = "udeb".equalsIgnoreCase(buildConfig.getTargetString());
|
0
|
242 |
// add the binaries and any resource-type files generated by all mmp files in the project
|
|
243 |
for (IPath mmp : EpocEngineHelper.getMMPFilesForBuildConfiguration(buildConfig)) {
|
|
244 |
IPath hp = EpocEngineHelper.getHostPathForExecutable(buildConfig, mmp);
|
|
245 |
IPath tp = EpocEngineHelper.getTargetPathForExecutable(buildConfig, mmp);
|
|
246 |
|
|
247 |
filename = hp.segment(hp.segmentCount()-1);
|
|
248 |
|
|
249 |
// add component executable
|
|
250 |
if (hp != null) {
|
11
|
251 |
addEntry(ic, hp.toOSString(), tp.toOSString(), filename);
|
0
|
252 |
}
|
|
253 |
|
|
254 |
HashMap<String, String> hostTargetRSRCMap = EpocEngineHelper.getHostAndTargetResources(buildConfig, mmp);
|
|
255 |
// Add resource files...
|
|
256 |
for (String key : hostTargetRSRCMap.keySet()) {
|
|
257 |
filename = new File(key).getName();
|
11
|
258 |
addEntry(ic, key, hostTargetRSRCMap.get(key),filename);
|
0
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
// check the project for image makefiles
|
|
263 |
HashMap<String, String> hostTargetImagesMap = EpocEngineHelper.getHostAndTargetImages(buildConfig);
|
|
264 |
for (String key : hostTargetImagesMap.keySet()) {
|
|
265 |
filename = new File(key).getName();
|
11
|
266 |
addEntry(ic, key, hostTargetImagesMap.get(key), filename);
|
0
|
267 |
}
|
|
268 |
}
|
|
269 |
}
|
|
270 |
|
11
|
271 |
private void addEntry(ImageContent ic,
|
0
|
272 |
String hp, String tp, String filename) {
|
|
273 |
IbyEntry entry = IContentFactory.eINSTANCE.createIbyEntry();
|
|
274 |
if(hp.length()>2) {
|
|
275 |
hp = hp.substring(2);
|
|
276 |
}
|
|
277 |
entry.setFile(hp);
|
|
278 |
|
|
279 |
if(tp!=null&&!tp.endsWith(filename)) {
|
|
280 |
if(tp.endsWith(File.separator)) {
|
|
281 |
tp = tp + filename;
|
|
282 |
} else {
|
|
283 |
tp = tp + File.separator + filename;
|
|
284 |
}
|
|
285 |
}
|
|
286 |
if(tp!=null) {
|
|
287 |
tp = tp.substring(2);
|
|
288 |
}
|
|
289 |
entry.setTarget(tp);
|
|
290 |
boolean contains = false;
|
|
291 |
for (IbyEntry e : ic.getEntries()) {
|
|
292 |
if(e.equals(entry)) {
|
|
293 |
contains = true;
|
|
294 |
break;
|
|
295 |
}
|
|
296 |
}
|
|
297 |
if(!contains) {
|
|
298 |
ic.getEntries().add(entry);
|
|
299 |
}
|
|
300 |
}
|
|
301 |
}
|