0
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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.sdk;
|
|
20 |
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FileInputStream;
|
|
23 |
import java.util.HashMap;
|
|
24 |
import java.util.zip.ZipEntry;
|
|
25 |
import java.util.zip.ZipInputStream;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Utility class for getting SDK/Platform related information.
|
|
29 |
*/
|
|
30 |
public class SdkUtils {
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Platform folders that are ignored when map folders are searched.
|
|
34 |
* Win* folders are ignored if excludeWinFolders is true.
|
|
35 |
*/
|
|
36 |
private static final String[] IGNORED_PLATFORM_FOLDERS = {
|
|
37 |
"tools",//$NON-NLS-1$
|
|
38 |
"thumb"}; //$NON-NLS-1$
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Folders that are ignore when getting build types.
|
|
42 |
*/
|
|
43 |
private static final String[] IGNORED_BUILD_FOLDERS = {
|
|
44 |
"lib"}; //$NON-NLS-1$
|
|
45 |
|
|
46 |
/**
|
|
47 |
* This class is not meant to be instantiated.
|
|
48 |
*/
|
|
49 |
private SdkUtils() {
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Method goes through all SDKs and searches for folders which can contain .map files. It will collect
|
|
54 |
* all folders in to a HashMap. Tools and thumb folders are ignored. Also win* folders
|
|
55 |
* are ignored if ecludeWinFolders is true.
|
|
56 |
*
|
|
57 |
* HashMap contains e.g.:
|
|
58 |
* [S60_32 armv5 UREL][C:\Build_C\S60_3_2_200820\epoc32\release\armv5\UREL]
|
|
59 |
* [S60_32 arm9e udeb][C:\Build_C\S60_3_2_200820\epoc32\release\arm9e\UDEB]
|
|
60 |
*
|
|
61 |
* @param excludeWinFolders defines whether wins, winscw folders are excluded from the result
|
|
62 |
* @return HashMap containing sdk names and their map folders
|
|
63 |
*/
|
|
64 |
public static HashMap<String, String> getSdkMapFileFolders(boolean excludeWinFolders) {
|
|
65 |
return getSdkMapFileFolders(excludeWinFolders, false);
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Method goes through all SDKs and searches for folders which can contain .map files. It will collect
|
|
70 |
* all folders in to a HashMap. Tools and thumb folders are ignored. Also win* folders
|
|
71 |
* are ignored if ecludeWinFolders is true.
|
|
72 |
*
|
|
73 |
* HashMap contains e.g.:
|
|
74 |
* [S60_32 armv5 UREL][C:\Build_C\S60_3_2_200820\epoc32\release\armv5\UREL]
|
|
75 |
* [S60_32 arm9e udeb][C:\Build_C\S60_3_2_200820\epoc32\release\arm9e\UDEB]
|
|
76 |
*
|
|
77 |
* if epocrootPath parameter is true, then HashMap contains e.g.:
|
|
78 |
* [S60_32 armv5 UREL][Z:\]
|
|
79 |
* [S60_32 arm9e udeb][Z:\]
|
|
80 |
*
|
|
81 |
* @param excludeWinFolders defines whether wins, winscw folders are excluded from the result
|
|
82 |
* @param epocrootPath defines whether folders should be epocroot folders instead of map files folders
|
|
83 |
* @return HashMap containing sdk names and their map folders
|
|
84 |
*/
|
|
85 |
public static HashMap<String, String> getSdkMapFileFolders(boolean excludeWinFolders, boolean epocrootPath) {
|
|
86 |
try {
|
|
87 |
HashMap<String, String> folders = new HashMap<String, String>();
|
|
88 |
|
|
89 |
// get all SDKs
|
|
90 |
SdkInformation[] sdks = SdkManager.getSdkInformation();
|
|
91 |
// if SDKs exists
|
|
92 |
if (sdks != null && sdks.length > 0) {
|
|
93 |
// go through all SDKs
|
|
94 |
for (int i = 0; i < sdks.length; i++) {
|
|
95 |
SdkInformation sdk = sdks[i];
|
|
96 |
// if SDK's epocroot does not exist, ignore SDK
|
|
97 |
if (!sdk.epocRootExists())
|
|
98 |
continue;
|
|
99 |
// get all SDK's platforms
|
|
100 |
String[] platforms = sdk.getPlatforms();
|
|
101 |
// if platforms exist
|
|
102 |
if (platforms != null && platforms.length > 0) {
|
|
103 |
// go through all platforms (armv5, gcce, winscw, ...)
|
|
104 |
for (int j = 0; j < platforms.length; j++) {
|
|
105 |
String platform = platforms[j];
|
|
106 |
boolean isWinFolder = platform.toLowerCase().startsWith("win");
|
|
107 |
|
|
108 |
// ignore emulator platforms
|
|
109 |
if (isWinFolder) {
|
|
110 |
if (excludeWinFolders) {
|
|
111 |
continue;
|
|
112 |
}
|
|
113 |
// Win folder is accepted, not checking if it is in predefined platforms.
|
|
114 |
}
|
|
115 |
// ignoring platforms which shouldn't contain map files.
|
|
116 |
else if (isIgnoredPlatformFolder(platform)) {
|
|
117 |
continue;
|
|
118 |
}
|
|
119 |
|
|
120 |
// get platform's build types (urel, udeb)
|
|
121 |
String[] buildTypes = sdk.getBuildTypesForPlatform(platform);
|
|
122 |
// if build types exist
|
|
123 |
if (buildTypes != null && buildTypes.length > 0) {
|
|
124 |
// go through all build types
|
|
125 |
for (int k = 0; k < buildTypes.length; k++) {
|
|
126 |
String buildType = buildTypes[k];
|
|
127 |
// Check if is not valid build type.
|
|
128 |
if(isIgnoredBuildType(buildType)) {
|
|
129 |
continue;
|
|
130 |
}
|
|
131 |
String mapFolder = sdk.getReleaseRootDir() + File.separator;
|
|
132 |
mapFolder += platform + File.separator + buildType;
|
|
133 |
|
|
134 |
String sdkFormat = sdk.getSdkId() + " " + platform + " " + buildType;
|
|
135 |
if (epocrootPath)
|
|
136 |
folders.put(sdkFormat, sdk.getEpocRootDir());
|
|
137 |
else
|
|
138 |
folders.put(sdkFormat, mapFolder);
|
|
139 |
}
|
|
140 |
}
|
|
141 |
}
|
|
142 |
}
|
|
143 |
}
|
|
144 |
}
|
|
145 |
if (folders.size() > 0)
|
|
146 |
return folders;
|
|
147 |
} catch (Exception e) {
|
|
148 |
}
|
|
149 |
|
|
150 |
return null;
|
|
151 |
}
|
|
152 |
|
|
153 |
/**
|
|
154 |
* Checks whether given type is ignored build type
|
|
155 |
* @param buildType type to be checked
|
|
156 |
* @return true if build type is ignored, false if not
|
|
157 |
*/
|
|
158 |
private static boolean isIgnoredBuildType(String buildType) {
|
|
159 |
for(String ignoredFolder : IGNORED_BUILD_FOLDERS) {
|
|
160 |
if(ignoredFolder.equalsIgnoreCase(buildType)) {
|
|
161 |
return true;
|
|
162 |
}
|
|
163 |
}
|
|
164 |
return false;
|
|
165 |
}
|
|
166 |
|
|
167 |
/**
|
|
168 |
* checks whether given platform should be ignored
|
|
169 |
* @param platform platform to be checked
|
|
170 |
* @return true if platform should be ignored files, false if not
|
|
171 |
*/
|
|
172 |
private static boolean isIgnoredPlatformFolder(String platform) {
|
|
173 |
for(String mapFilePlatform : IGNORED_PLATFORM_FOLDERS) {
|
|
174 |
if(platform.toLowerCase().startsWith(mapFilePlatform.toLowerCase())) {
|
|
175 |
return true;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
return false;
|
|
179 |
}
|
|
180 |
|
|
181 |
/**
|
|
182 |
* Checks whether given folder contains any .map files.
|
|
183 |
* This method takes can time, if there are many files in the folder.
|
|
184 |
* @param folder folder to be checked for .map files
|
|
185 |
* @return true if folder contains .map files, false if not
|
|
186 |
*/
|
|
187 |
public static boolean folderContainsMapFiles(String folder) {
|
|
188 |
File path = new File(folder);
|
|
189 |
if (path.isDirectory() && path.exists()) {
|
|
190 |
|
|
191 |
String[] files = path.list();
|
|
192 |
if (files != null && files.length > 0) {
|
|
193 |
for (int i = 0; i < files.length; i++) {
|
|
194 |
if (files[i].endsWith(".map"))
|
|
195 |
return true;
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|
|
199 |
return false;
|
|
200 |
}
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Checks whether given zip file contains any .map files
|
|
204 |
* @param zipFilePath zip file's path
|
|
205 |
* @return true if zip file contains .map files, false if not
|
|
206 |
*/
|
|
207 |
public static boolean zipContainsMapFiles(String zipFilePath) {
|
|
208 |
try {
|
|
209 |
FileInputStream fis = new FileInputStream(zipFilePath);
|
|
210 |
ZipInputStream zis = new ZipInputStream(fis);
|
|
211 |
ZipEntry ze;
|
|
212 |
while((ze=zis.getNextEntry())!=null){
|
|
213 |
if (ze.getName().toLowerCase().endsWith("map")) { //$NON-NLS-1$
|
|
214 |
zis.closeEntry();
|
|
215 |
zis.close();
|
|
216 |
return true;
|
|
217 |
}
|
|
218 |
zis.closeEntry();
|
|
219 |
}
|
|
220 |
zis.close();
|
|
221 |
} catch (Exception e) {
|
|
222 |
}
|
|
223 |
|
|
224 |
return false;
|
|
225 |
}
|
|
226 |
}
|