0
|
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.core.data;
|
|
20 |
|
|
21 |
import java.io.BufferedReader;
|
|
22 |
import java.io.File;
|
|
23 |
import java.io.FileNotFoundException;
|
|
24 |
import java.io.FileReader;
|
|
25 |
import java.io.IOException;
|
|
26 |
import java.util.ArrayList;
|
|
27 |
import java.util.Collections;
|
|
28 |
import java.util.Date;
|
|
29 |
import java.util.HashMap;
|
|
30 |
import java.util.HashSet;
|
|
31 |
import java.util.Iterator;
|
|
32 |
import java.util.List;
|
|
33 |
import java.util.Map;
|
|
34 |
import java.util.NoSuchElementException;
|
|
35 |
import java.util.Set;
|
|
36 |
import java.util.regex.Pattern;
|
|
37 |
|
|
38 |
import com.nokia.s60tools.appdep.common.ProductInfoRegistry;
|
|
39 |
import com.nokia.s60tools.appdep.core.AppDepCacheIndexManager;
|
|
40 |
import com.nokia.s60tools.appdep.core.AppDepSettings;
|
|
41 |
import com.nokia.s60tools.appdep.core.ITargetPlatform;
|
|
42 |
import com.nokia.s60tools.appdep.exceptions.CacheFileDoesNotExistException;
|
|
43 |
import com.nokia.s60tools.appdep.resources.Messages;
|
|
44 |
import com.nokia.s60tools.appdep.ui.views.data.ComponentListNode;
|
|
45 |
import com.nokia.s60tools.appdep.util.AppDepConsole;
|
|
46 |
import com.nokia.s60tools.util.console.IConsolePrintUtility;
|
|
47 |
import com.nokia.s60tools.util.debug.DbgUtility;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* This cache index class stores timestamp for each component
|
|
51 |
* that is defined in the cache. The storing of the timestamp
|
|
52 |
* info enables possibility to check if cache file needs to
|
|
53 |
* be updated when compared with timestamp of real components
|
|
54 |
* residing in underneath release directory.
|
|
55 |
*
|
|
56 |
* Because the idea is to generate cache index per cache file, the class
|
|
57 |
* stores indexInstances of already created indexes and return the already
|
|
58 |
* created index object when matching cache file is passed into static
|
|
59 |
* <code>getInstance</code> method.
|
|
60 |
*/
|
|
61 |
public class CacheIndex {
|
|
62 |
|
|
63 |
/**
|
|
64 |
* Conversion factor from seconds to milliseconds.
|
|
65 |
*/
|
|
66 |
private static final long TO_MILLISEC = 1000;
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Default and initial value used for cache file version strings.
|
|
70 |
* Just making sure that version number is always a legal version string value.
|
|
71 |
*/
|
|
72 |
private static final String DEFAULT_VERSION_VALUE_STRING = "000"; //$NON-NLS-1$
|
|
73 |
|
|
74 |
/**
|
|
75 |
* Reference to the known indexInstances of this class.
|
|
76 |
*/
|
|
77 |
private static Map<String, CacheIndex> indexInstances = Collections.synchronizedMap(new HashMap<String, CacheIndex>());
|
|
78 |
|
|
79 |
/**
|
|
80 |
* This map stores the following information
|
|
81 |
* gained from main cache file:
|
|
82 |
* - key: component name with extension (equals to component name in lowercase letters)
|
|
83 |
* - IndexData class instance: byte offset from the start of the file, and
|
|
84 |
* last component modification timestamp.
|
|
85 |
*/
|
|
86 |
private Map<String, IndexData> componentCacheIndexDataMap = null;
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Reference to cache file to be indexed.
|
|
90 |
*/
|
|
91 |
private File cacheFile = null;
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Cache build status is originally <code>false</code>, and set to <code>false</code>
|
|
95 |
* after the background thread that has built the index is terminated successfully.
|
|
96 |
*/
|
|
97 |
private boolean isCacheIndexBuilt = false;
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Build directory for this cache file instance.
|
|
101 |
*/
|
|
102 |
private String buildDirectory = null;
|
|
103 |
|
|
104 |
/**
|
|
105 |
* This flag is set to <code>false</code> when
|
|
106 |
* some one uses first time getInstance() method for
|
|
107 |
* for getting instance that is already existing.
|
|
108 |
* This flag is used to prevent unnecessary update
|
|
109 |
* attempts.
|
|
110 |
*/
|
|
111 |
private boolean justCreated = true;
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Storing version information for the cache
|
|
115 |
*/
|
|
116 |
private String versionInfo = null;
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Flag if the dependencies cache is non-corrupted or not.
|
|
120 |
*/
|
|
121 |
private boolean isDependenciesFileNonCorrupted = false;
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Flag if the dependencies cache is non-corrupted or not.
|
|
125 |
*/
|
|
126 |
private boolean isSymbolsFileNonCorrupted = false;
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Data that is indexed for each component.
|
|
130 |
*/
|
|
131 |
private class IndexData{
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Component modification timestamp.
|
|
135 |
*/
|
|
136 |
private final long timestamp;
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Constructor.
|
|
140 |
* @param timestamp Component modification timestamp.
|
|
141 |
*/
|
|
142 |
public IndexData(long timestamp){
|
|
143 |
this.timestamp = timestamp;
|
|
144 |
}
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Gets component modification timestamp.
|
|
148 |
* @return component modification timestamp.
|
|
149 |
*/
|
|
150 |
public long getTimestamp() {
|
|
151 |
return timestamp;
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Returns cache index for the given cache file. Creates a new
|
|
157 |
* cache index object, if no index was previously created.
|
|
158 |
* @param cacheFile Valid cache File object to get/create cache index from.
|
|
159 |
* @param buildDirectory Build directory string to be used as seek string to cache file.
|
|
160 |
* @return Returns cache index class instance.
|
|
161 |
* @throws IOException
|
|
162 |
*/
|
|
163 |
public static CacheIndex getCacheIndexInstance(File cacheFile, String buildDirectory) throws IOException{
|
|
164 |
|
|
165 |
CacheIndex instance = null;
|
|
166 |
|
|
167 |
synchronized(indexInstances){
|
|
168 |
|
|
169 |
// Do we already have index for this cache file
|
|
170 |
instance = (CacheIndex) indexInstances.get(cacheFile.getAbsolutePath());
|
|
171 |
|
|
172 |
if( instance == null ){
|
|
173 |
// No => Creating a new cache index instance.
|
|
174 |
instance = new CacheIndex(cacheFile, buildDirectory);
|
|
175 |
indexInstances.put(cacheFile.getAbsolutePath(), instance);
|
|
176 |
}
|
|
177 |
else{
|
|
178 |
instance.setJustCreated(false);
|
|
179 |
}
|
|
180 |
|
|
181 |
} // synchronized
|
|
182 |
|
|
183 |
// Returning corresponding instance object
|
|
184 |
return (CacheIndex) instance;
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Private constructor that creates and instance and starts to build
|
|
189 |
* index at background.
|
|
190 |
* @param cacheFile Valid cache File object to create cache index from.
|
|
191 |
* @param buildDirectory Build directory string to be used as seek string to cache file.
|
|
192 |
* @throws IOException
|
|
193 |
*/
|
|
194 |
private CacheIndex(File cacheFile, String buildDirectory) throws IOException{
|
|
195 |
this.cacheFile = cacheFile;
|
|
196 |
this.buildDirectory = buildDirectory;
|
|
197 |
componentCacheIndexDataMap = Collections.synchronizedMap(new HashMap<String, IndexData>());
|
|
198 |
versionInfo = new String(DEFAULT_VERSION_VALUE_STRING); //$NON-NLS-1$
|
|
199 |
startCacheIndexBuildThread();
|
|
200 |
}
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Triggers the thread that creates the index at background.
|
|
204 |
* Set the cache index build status flag after the cache index
|
|
205 |
* has been created successfully.
|
|
206 |
* @throws IOException
|
|
207 |
*/
|
|
208 |
private void startCacheIndexBuildThread() throws IOException{
|
|
209 |
|
|
210 |
final CacheIndex indexObject = this;
|
|
211 |
|
|
212 |
Thread worker = new Thread(){
|
|
213 |
public void run() {
|
|
214 |
long runMethodStartTime = System.currentTimeMillis();
|
|
215 |
long cacheFileSizeInBytes = cacheFile.length();
|
|
216 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, this.toString() + " IndexBuildThread started: " //$NON-NLS-1$
|
|
217 |
+ new Date(runMethodStartTime).toString()
|
|
218 |
+ " for cache file: " + cacheFile.getAbsolutePath() //$NON-NLS-1$
|
|
219 |
+ " of size '" + cacheFileSizeInBytes + "' bytes."); //$NON-NLS-1$ //$NON-NLS-2$
|
|
220 |
|
|
221 |
AppDepCacheIndexManager indexMgr = AppDepCacheIndexManager.getInstance();
|
|
222 |
|
|
223 |
// We can promote building of bigger cache indices by increasing priority
|
|
224 |
boolean increasePriority = false;
|
|
225 |
// and slow down building of very small cache indices by increasing priority
|
|
226 |
boolean decreasePriority = false;
|
|
227 |
|
|
228 |
// Heuristical limit of for enabling higher priority.
|
|
229 |
int priorityIncrLimitInMegabytes = 15; // MB
|
|
230 |
// Easier to compare in bytes vs. MB because it would need zero integer division check for small cache files
|
|
231 |
long priorityIncrLimitInBytes = (1024*1024) * priorityIncrLimitInMegabytes; // bytes
|
|
232 |
if(cacheFileSizeInBytes > priorityIncrLimitInBytes){
|
|
233 |
increasePriority = true;
|
|
234 |
}
|
|
235 |
|
|
236 |
// Heuristical limit of for enabling smaller priority.
|
|
237 |
int priorityDescrLimitInKilobytes = 100; // KB
|
|
238 |
long priorityDecrLimitInBytes = 1024 * priorityDescrLimitInKilobytes; // bytes
|
|
239 |
if(cacheFileSizeInBytes < priorityDecrLimitInBytes){
|
|
240 |
decreasePriority = true;
|
|
241 |
}
|
|
242 |
// Building index
|
|
243 |
try {
|
|
244 |
indexMgr.registerCacheIndexCreationProcess(indexObject);
|
|
245 |
//
|
|
246 |
// Adjusting thread priorities if needed - check API docs if interested in what
|
|
247 |
// are the possible values for thread priorities:
|
|
248 |
// http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.lang.Thread.MIN_PRIORITY
|
|
249 |
// http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.lang.Thread.NORM_PRIORITY
|
|
250 |
// http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.lang.Thread.MAX_PRIORITY
|
|
251 |
//
|
|
252 |
if(increasePriority){
|
|
253 |
this.setPriority(this.getPriority() + 3);
|
|
254 |
}
|
|
255 |
if(decreasePriority){
|
|
256 |
this.setPriority(this.getPriority() - 3);
|
|
257 |
}
|
|
258 |
buildCacheIndex();
|
|
259 |
} catch (Exception e) {
|
|
260 |
e.printStackTrace();
|
|
261 |
String errMsg = Messages.getString("CacheIndex.CacheIndex_Generate_Failed_Msg") //$NON-NLS-1$
|
|
262 |
+ ": " + e.getMessage(); //$NON-NLS-1$
|
|
263 |
AppDepConsole.getInstance().println(errMsg, IConsolePrintUtility.MSG_ERROR);
|
|
264 |
indexMgr.unregisterCacheIndexCreationProcess(indexObject);
|
|
265 |
throw new RuntimeException(errMsg);
|
|
266 |
}
|
|
267 |
|
|
268 |
isCacheIndexBuilt = true;
|
|
269 |
indexMgr.unregisterCacheIndexCreationProcess(indexObject);
|
|
270 |
|
|
271 |
// Tracing of consumed time
|
|
272 |
long endTime = System.currentTimeMillis();
|
|
273 |
File parentDirectory = cacheFile.getParentFile();
|
|
274 |
String buildTypeNameString = parentDirectory.getName();
|
|
275 |
String targetNameString = parentDirectory.getParentFile().getName();
|
|
276 |
String platformNameString = parentDirectory.getParentFile().getParentFile().getName();
|
|
277 |
String combinedDbgInfoStr = platformNameString + "/" + targetNameString + "/" + buildTypeNameString; //$NON-NLS-1$ //$NON-NLS-2$
|
|
278 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, this.toString()
|
|
279 |
+ " IndexBuildThread ended: " + new Date(endTime).toString() //$NON-NLS-1$
|
|
280 |
+ " for cache file: " + cacheFile.getAbsolutePath()); //$NON-NLS-1$
|
|
281 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, this.toString() + "TOTAL: " + (endTime-runMethodStartTime)/1000 + " seconds (" + combinedDbgInfoStr + ")!"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
282 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, this.toString() + "COMPONENT INDEX SIZE: " + componentCacheIndexDataMap.size() + " (" + combinedDbgInfoStr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
283 |
}
|
|
284 |
};
|
|
285 |
// Kicking-off the thread
|
|
286 |
worker.start();
|
|
287 |
}
|
|
288 |
|
|
289 |
/**
|
|
290 |
* Builds the cache index and checks the integrity of cache files.
|
|
291 |
* @throws IOException
|
|
292 |
*/
|
|
293 |
private void buildCacheIndex() throws IOException{
|
|
294 |
buildCacheIndexDataFromMainCacheFile();
|
|
295 |
checkSymbolsFileIntegrity();
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Gets cache data from main cache file i.e. getting byte offsets for component property line
|
|
300 |
* locations and cached modification timestamps for the components.
|
|
301 |
* @throws FileNotFoundException
|
|
302 |
* @throws IOException
|
|
303 |
*/
|
|
304 |
private void buildCacheIndexDataFromMainCacheFile() throws FileNotFoundException, IOException {
|
|
305 |
|
|
306 |
// Creating reader for main cache file
|
|
307 |
BufferedReader bufRdr = setupBufferedReader(cacheFile);
|
|
308 |
|
|
309 |
// Reading the 1st header line from the cache file
|
|
310 |
String line = bufRdr.readLine();
|
|
311 |
versionInfo = parseVersionInfoFromHeaderLine(line); // Getting version information only from main cache file
|
|
312 |
|
|
313 |
// Reading the first actual property information line
|
|
314 |
line = bufRdr.readLine();
|
|
315 |
|
|
316 |
// This is just a debugging aid - starting
|
|
317 |
// to read from line 2 forwards
|
|
318 |
int lineno = 2;
|
|
319 |
|
|
320 |
boolean isEndMarkFound = false;
|
|
321 |
boolean isEndOfFile = false;
|
|
322 |
|
|
323 |
// After this reading of all line goes similarly
|
|
324 |
// Reading file until EOF (i.e. when null is returned)
|
|
325 |
for (; line != null; lineno++) {
|
|
326 |
|
|
327 |
isEndOfFile = false;
|
|
328 |
|
|
329 |
// Successful comparison requires that compared strings have equal case
|
|
330 |
if(isComponentDefinitionLineInMainCacheFile(line)){
|
|
331 |
// A component was found, adding it to the index
|
|
332 |
parseComponentPropertyLineAndAddToIndex(line);
|
|
333 |
}
|
|
334 |
else{
|
|
335 |
if(line.equals(CacheDataConstants.CACHE_FILE_END_MARK)){
|
|
336 |
isEndMarkFound = true;
|
|
337 |
isEndOfFile = true;
|
|
338 |
}
|
|
339 |
}
|
|
340 |
|
|
341 |
// Reading next line
|
|
342 |
line = bufRdr.readLine();
|
|
343 |
}
|
|
344 |
|
|
345 |
if(isEndMarkFound && isEndOfFile){
|
|
346 |
isDependenciesFileNonCorrupted = true;
|
|
347 |
}
|
|
348 |
}
|
|
349 |
|
|
350 |
/**
|
|
351 |
* Reads version information from the header line
|
|
352 |
* @param headerLine Header line to be checked version info fromt.
|
|
353 |
* @return Version info string, or default version value if could not parse.
|
|
354 |
*/
|
|
355 |
private String parseVersionInfoFromHeaderLine(String headerLine) {
|
|
356 |
String[] splitArr = headerLine.split(CacheDataConstants.CACHE_VERSION_INFO_SEPARATOR);
|
|
357 |
if(splitArr.length == 2){
|
|
358 |
return splitArr[1].trim();
|
|
359 |
}
|
|
360 |
return DEFAULT_VERSION_VALUE_STRING;
|
|
361 |
}
|
|
362 |
|
|
363 |
/**
|
|
364 |
* Checks if the current line is a component definition line.
|
|
365 |
* Line is component property line if the field count is the
|
|
366 |
* one that is expected for this kind of line.
|
|
367 |
* @param line Line to be checked.
|
|
368 |
* @return <code>true</code> if component definition line, otherwise <code>false</code>.
|
|
369 |
*/
|
|
370 |
static boolean isComponentDefinitionLineInMainCacheFile(String line) {
|
|
371 |
int splitCount = splitPopertyLineIntoStringArray(line).length;
|
|
372 |
if(splitCount == CacheCompPropertyField.getCompPropertyFieldCount()){
|
|
373 |
return true;
|
|
374 |
}
|
|
375 |
|
|
376 |
return false;
|
|
377 |
}
|
|
378 |
|
|
379 |
/**
|
|
380 |
* Parses the property line that constains information about the single component
|
|
381 |
* and stores the byte offset to the index map with component name.
|
|
382 |
* @param line Property line to parse component's name from.
|
|
383 |
*/
|
|
384 |
private void parseComponentPropertyLineAndAddToIndex(String line){
|
|
385 |
|
|
386 |
String compPropertiesLine = line;
|
|
387 |
|
|
388 |
String [] compPropertiesArr = splitPopertyLineIntoStringArray(compPropertiesLine);
|
|
389 |
|
|
390 |
// Using the build directory path from the currently
|
|
391 |
// used file system instead of one in the cache file which may not exist
|
|
392 |
// in case cache file was created on some another computer/substed drive.
|
|
393 |
String cmpName = compPropertiesArr[CacheCompPropertyField.FILENAME_ARR_INDX];
|
|
394 |
|
|
395 |
// Storing the modification time of the cached component
|
|
396 |
String compModifiedTimestampString = compPropertiesArr[CacheCompPropertyField.CACHE_TIMESTAMP_ARR_INDX];
|
|
397 |
long compModifiedTimestamp = TO_MILLISEC * Long.parseLong(compModifiedTimestampString);
|
|
398 |
|
|
399 |
synchronized(componentCacheIndexDataMap){
|
|
400 |
|
|
401 |
// There should not be an already existing component
|
|
402 |
if(componentCacheIndexDataMap.get(cmpName.toLowerCase()) != null){
|
|
403 |
// In case of duplicate components, only the first one is added.
|
|
404 |
// Duplicate instances are ignored, and an error message printed to concole.
|
|
405 |
String errMsg = Messages.getString("CacheIndex.DuplicateComponents_Encountered_ErrMsg"); //$NON-NLS-1$
|
|
406 |
AppDepConsole.getInstance().println(errMsg + " (" + cmpName.toLowerCase() + ")", AppDepConsole.MSG_ERROR); //$NON-NLS-1$ //$NON-NLS-2$
|
|
407 |
}
|
|
408 |
else{
|
|
409 |
componentCacheIndexDataMap.put(cmpName.toLowerCase(), new IndexData(compModifiedTimestamp));
|
|
410 |
}
|
|
411 |
|
|
412 |
} // synchronized
|
|
413 |
}
|
|
414 |
|
|
415 |
/**
|
|
416 |
* Creates file object that points to the symbols information file.
|
|
417 |
* @return File object that refers to the symbols information file.
|
|
418 |
*/
|
|
419 |
private File createSymbolsFileObject(){
|
|
420 |
String cacheDirectoryPath = cacheFile.getParentFile().getAbsolutePath();
|
|
421 |
String symbolsFilePathName = cacheDirectoryPath
|
|
422 |
+ File.separatorChar
|
|
423 |
+ ProductInfoRegistry.getCacheSymbolsFileName();
|
|
424 |
return new File(symbolsFilePathName);
|
|
425 |
}
|
|
426 |
|
|
427 |
/**
|
|
428 |
* Checks that symbols file has header with version number that matches with one
|
|
429 |
* for main cache file, and also checks up that there is correct end mark.
|
|
430 |
* @throws FileNotFoundException
|
|
431 |
* @throws IOException
|
|
432 |
*/
|
|
433 |
private void checkSymbolsFileIntegrity() throws FileNotFoundException, IOException {
|
|
434 |
|
|
435 |
// There is some room for improvement in this method because it is shortened
|
|
436 |
// from earlier version that also analyzed component data. But keeping this
|
|
437 |
// for now on because do not want to break working stuff. Now the extra
|
|
438 |
// unused code portions are cleaned up anyway.
|
|
439 |
File symbolsFile = createSymbolsFileObject();
|
|
440 |
|
|
441 |
if(! symbolsFile.exists()){
|
|
442 |
// Symbols file does not exist, and therefore there are
|
|
443 |
// no export functions related information available.
|
|
444 |
return;
|
|
445 |
}
|
|
446 |
|
|
447 |
// Creating reader for symbols cache file
|
|
448 |
BufferedReader localBufRdrVar = setupBufferedReader(symbolsFile);
|
|
449 |
|
|
450 |
// Reading the 1st header line from the cache file
|
|
451 |
String line = null;
|
|
452 |
try {
|
|
453 |
line = localBufRdrVar.readLine();
|
|
454 |
|
|
455 |
} catch (IOException e) {
|
|
456 |
// File existed but there was no data, or
|
|
457 |
// something else failed.
|
|
458 |
return;
|
|
459 |
}
|
|
460 |
|
|
461 |
if(line == null){
|
|
462 |
// File existed but there was no data
|
|
463 |
// (i.e. end of file was reached)
|
|
464 |
return;
|
|
465 |
}
|
|
466 |
|
|
467 |
// Storing version number from the header line
|
|
468 |
String symbolsFileVersion = parseVersionInfoFromHeaderLine(line);
|
|
469 |
|
|
470 |
// Reading the first actual property information line
|
|
471 |
line = localBufRdrVar.readLine();
|
|
472 |
|
|
473 |
// This is just a debugging aid - starting
|
|
474 |
// to read from line 2 forwards
|
|
475 |
int lineno = 2;
|
|
476 |
|
|
477 |
boolean isEndMarkFound = false;
|
|
478 |
boolean isEndOfFile = false;
|
|
479 |
|
|
480 |
// After this reading of all line goes similarly
|
|
481 |
// Reading file until EOF (i.e. when null is returned)
|
|
482 |
for (; line != null; lineno++) {
|
|
483 |
|
|
484 |
isEndOfFile = false;
|
|
485 |
|
|
486 |
if(line.equals(CacheDataConstants.CACHE_FILE_END_MARK)){
|
|
487 |
isEndMarkFound = true;
|
|
488 |
isEndOfFile = true;
|
|
489 |
}
|
|
490 |
|
|
491 |
// Reading next line
|
|
492 |
line = localBufRdrVar.readLine();
|
|
493 |
}
|
|
494 |
|
|
495 |
// Symbols file is non corrupted if...
|
|
496 |
// - end of file is reached, and expected end mark is found
|
|
497 |
// - symbols file is created with same appdep core version than main cache file
|
|
498 |
if((isEndMarkFound && isEndOfFile) && (symbolsFileVersion.equals(versionInfo))){
|
|
499 |
isSymbolsFileNonCorrupted = true;
|
|
500 |
}
|
|
501 |
}
|
|
502 |
|
|
503 |
/**
|
|
504 |
* Splits the property line into a string array containing property line fields.
|
|
505 |
* @param compPropertiesLine Property line to be splitted.
|
|
506 |
* @return A string array containing property line fields.
|
|
507 |
*/
|
|
508 |
static String[] splitPopertyLineIntoStringArray(String compPropertiesLine){
|
|
509 |
String fieldSepRegExp = Pattern.quote(CacheDataConstants.CACHE_FIELD_SEPARATOR);
|
|
510 |
|
|
511 |
String[] splitArr = compPropertiesLine.split(fieldSepRegExp);
|
|
512 |
return splitArr;
|
|
513 |
}
|
|
514 |
|
|
515 |
/**
|
|
516 |
* Returns modification timestamp stored in cache for the given component.
|
|
517 |
* @param cmpName The name of the component.
|
|
518 |
* @return Last modification timestamp for the component as milliseconds.
|
|
519 |
*/
|
|
520 |
public long getLastModifiedTimeForComponent(String cmpName){
|
|
521 |
Object obj = componentCacheIndexDataMap.get(cmpName.toLowerCase());
|
|
522 |
if( obj == null){
|
|
523 |
throw new NoSuchElementException();
|
|
524 |
}
|
|
525 |
IndexData idt = (IndexData) obj;
|
|
526 |
long timestamp = idt.getTimestamp();
|
|
527 |
return timestamp;
|
|
528 |
}
|
|
529 |
|
|
530 |
/**
|
|
531 |
* Gets the amount of components in cache index.
|
|
532 |
* @return The amount of components in cache index.
|
|
533 |
*/
|
|
534 |
public int getCachedComponentCount(){
|
|
535 |
return componentCacheIndexDataMap.size();
|
|
536 |
}
|
|
537 |
|
|
538 |
/**
|
|
539 |
* Returns the cache build status.
|
|
540 |
* @return Returns the isCacheIndexBuilt.
|
|
541 |
*/
|
|
542 |
private boolean isCacheIndexBuiltImpl() {
|
|
543 |
return isCacheIndexBuilt;
|
|
544 |
}
|
|
545 |
|
|
546 |
/**
|
|
547 |
* Gets the component set of all component names that
|
|
548 |
* exist in cache.
|
|
549 |
*/
|
|
550 |
public Set<String> getComponentNameSet(){
|
|
551 |
return componentCacheIndexDataMap.keySet();
|
|
552 |
}
|
|
553 |
|
|
554 |
/**
|
|
555 |
* Checks from given function info array if the function
|
|
556 |
* is virtual.
|
|
557 |
* @param functionInfoArr Function info array
|
|
558 |
* @return <code>true</code> if the function is virtual,
|
|
559 |
* otherwise <code>false</code>.
|
|
560 |
*/
|
|
561 |
public static boolean isVirtualFunctionFlagSet(String[] functionInfoArr){
|
|
562 |
String fVirtualFlag = functionInfoArr[CacheDataConstants.FUNC_IS_VIRTUAL_INDEX];
|
|
563 |
if(fVirtualFlag.trim().equals(CacheDataConstants.VIRTUAL_INDEX_FIELD_IS_TRUE_VALUE)){ //$NON-NLS-1$
|
|
564 |
return true;
|
|
565 |
}
|
|
566 |
else{
|
|
567 |
return false;
|
|
568 |
}
|
|
569 |
}
|
|
570 |
|
|
571 |
/**
|
|
572 |
* Updates cache index with latest available information.
|
|
573 |
* @throws IOException
|
|
574 |
*/
|
|
575 |
public void update() throws IOException {
|
|
576 |
// If we are acquiring cache index instance
|
|
577 |
// that has been already built previously
|
|
578 |
// we need to reset and rebuild it.
|
|
579 |
// If cache index was just created the
|
|
580 |
// building process is still going on.
|
|
581 |
if(! isJustCreated()){
|
|
582 |
// Clearing the old data
|
|
583 |
componentCacheIndexDataMap.clear();
|
|
584 |
// Doing re-build
|
|
585 |
startCacheIndexBuildThread();
|
|
586 |
}
|
|
587 |
}
|
|
588 |
|
|
589 |
/**
|
|
590 |
* Checks if cache index for this object has been created.
|
|
591 |
* @return <code>true</code> if created, otherwise <code>false</code>.
|
|
592 |
*/
|
|
593 |
private boolean isJustCreated() {
|
|
594 |
return justCreated;
|
|
595 |
}
|
|
596 |
|
|
597 |
/**
|
|
598 |
* Sets cache index creation status.
|
|
599 |
* @param justCreated set to <code>true</code> if created, otherwise set to <code>false</code>.
|
|
600 |
*/
|
|
601 |
private void setJustCreated(boolean justCreated) {
|
|
602 |
this.justCreated = justCreated;
|
|
603 |
}
|
|
604 |
|
|
605 |
/**
|
|
606 |
* Checks if there already exists cache index for given cache file.
|
|
607 |
* @param cacheFileAbsolutePathName Cache file path name for cache file/ to be checked.
|
|
608 |
* @return <code>true</code> if exists, otherwise <code>false</code>.
|
|
609 |
*/
|
|
610 |
public static boolean cacheIndexExistsFor(String cacheFileAbsolutePathName){
|
|
611 |
|
|
612 |
boolean cacheIndexExists = false;
|
|
613 |
|
|
614 |
synchronized(indexInstances){
|
|
615 |
if( indexInstances.get(cacheFileAbsolutePathName) != null){
|
|
616 |
cacheIndexExists = true;
|
|
617 |
}
|
|
618 |
} // synchronized
|
|
619 |
|
|
620 |
return cacheIndexExists;
|
|
621 |
}
|
|
622 |
|
|
623 |
/**
|
|
624 |
* Returns creation status of cache index that is under creation.
|
|
625 |
* @param cacheFileAbsolutePathName Cache file path name for cache file/ to be checked.
|
|
626 |
* @return <code>true</code> if created, otherwise <code>false</code>.
|
|
627 |
*/
|
|
628 |
public static boolean cacheIndexCreatedFor(String cacheFileAbsolutePathName){
|
|
629 |
|
|
630 |
boolean cacheIndexCreated = false;
|
|
631 |
|
|
632 |
synchronized(indexInstances){
|
|
633 |
CacheIndex indxInstance = (CacheIndex) indexInstances.get(cacheFileAbsolutePathName);
|
|
634 |
if(indxInstance != null){
|
|
635 |
return indxInstance.isCacheIndexBuiltImpl();
|
|
636 |
}
|
|
637 |
} // synchronized
|
|
638 |
|
|
639 |
return cacheIndexCreated;
|
|
640 |
}
|
|
641 |
|
|
642 |
/**
|
|
643 |
* Sets up the currently used buffered reader.
|
|
644 |
* @param file File object to user directly or user RAM-disk image for.
|
|
645 |
* @throws FileNotFoundException
|
|
646 |
*/
|
|
647 |
private BufferedReader setupBufferedReader(File file) throws FileNotFoundException{
|
|
648 |
FileReader fileRdr = new FileReader(file);
|
|
649 |
return new BufferedReader(fileRdr);
|
|
650 |
}
|
|
651 |
|
|
652 |
/**
|
|
653 |
* Returns regular expression used to split fields in cache data.
|
|
654 |
* @return regular expression used to split fields in cache data.
|
|
655 |
*/
|
|
656 |
public static String getCacheFieldSeparatorRegExp(){
|
|
657 |
return Pattern.quote(CacheDataConstants.CACHE_FIELD_SEPARATOR);
|
|
658 |
}
|
|
659 |
|
|
660 |
/**
|
|
661 |
* Returns version information string found from dependencies file's header.
|
|
662 |
* @return Three-letter string containing version info.
|
|
663 |
*/
|
|
664 |
public String getVersionInfo() {
|
|
665 |
return versionInfo;
|
|
666 |
}
|
|
667 |
|
|
668 |
/**
|
|
669 |
* Method for checking if cache is non-corrupted.
|
|
670 |
* @return <code>true</code> if cache is non-corrupted, otherwise <code>false</code>.
|
|
671 |
*/
|
|
672 |
public boolean isCacheNonCorrupted(){
|
|
673 |
return (isDependenciesFileNonCorrupted && isSymbolsFileNonCorrupted);
|
|
674 |
}
|
|
675 |
|
|
676 |
/**
|
|
677 |
* Gets build directory bound to the cache index.
|
|
678 |
* @return the buildDirectory
|
|
679 |
*/
|
|
680 |
public String getBuildDirectory() {
|
|
681 |
return buildDirectory;
|
|
682 |
}
|
|
683 |
|
|
684 |
/**
|
|
685 |
* Returns component list for the targets pointed by given settings object.
|
|
686 |
* @param settings[in] Settings to get currently selected targets from.
|
|
687 |
* @param duplicateItemsList[out] Out parameter that contains the list of duplicate
|
|
688 |
* components found from the selected targets.
|
|
689 |
* @return Component iterator for the currently selected targets.
|
|
690 |
* @throws CacheFileDoesNotExistException
|
|
691 |
* @throws IOException
|
|
692 |
*/
|
|
693 |
public static List<ComponentListNode> getComponentIteratorForGivenSettings(AppDepSettings settings, List<String> duplicateItemsList) throws CacheFileDoesNotExistException, IOException {
|
|
694 |
|
|
695 |
ArrayList<CacheIndex> cacheIndexList = new ArrayList<CacheIndex>();
|
|
696 |
|
|
697 |
// Getting all the cache indices referred by the settings
|
|
698 |
ITargetPlatform[] currentlyUsedTargetPlatforms = settings.getCurrentlyUsedTargetPlatforms();
|
|
699 |
for (int i = 0; i < currentlyUsedTargetPlatforms.length; i++) {
|
|
700 |
ITargetPlatform targetPlatform = currentlyUsedTargetPlatforms[i];
|
|
701 |
String targetPlatformId = targetPlatform.getId();
|
|
702 |
String cacheFileAbsolutePathName = settings.getCacheFileAbsolutePathName(targetPlatformId);
|
|
703 |
File cacheFile = new File(cacheFileAbsolutePathName);
|
|
704 |
if(!cacheFile.exists()){
|
|
705 |
throw new CacheFileDoesNotExistException(cacheFileAbsolutePathName);
|
|
706 |
}
|
|
707 |
String buildDirectory = settings.getBuildDir(targetPlatformId);
|
|
708 |
// Getting existing, or creating a new cache index
|
|
709 |
// for enabling faster access for cache data
|
|
710 |
CacheIndex cacheIndx = CacheIndex.getCacheIndexInstance(cacheFile, buildDirectory);
|
|
711 |
cacheIndexList.add(cacheIndx);
|
|
712 |
}
|
|
713 |
|
|
714 |
// Storing all component names here for duplicate component check
|
|
715 |
Set<String> allComponentNames = new HashSet<String>();
|
|
716 |
|
|
717 |
// Making sure that there are no previously queried results in the passes list
|
|
718 |
duplicateItemsList.clear();
|
|
719 |
|
|
720 |
// Storing component list nodes into here
|
|
721 |
List<ComponentListNode> componentList = new ArrayList<ComponentListNode>();
|
|
722 |
|
|
723 |
// Combining component lists from all selected targets
|
|
724 |
for (int i = 0; i < cacheIndexList.size(); i++) {
|
|
725 |
CacheIndex cacheIndx = cacheIndexList.get(i);
|
|
726 |
Set<String> tmpSet = cacheIndx.getComponentNameSet();
|
|
727 |
Iterator<String> tmpIter = tmpSet.iterator();
|
|
728 |
// Iterating through the whole set
|
|
729 |
while (tmpIter.hasNext()) {
|
|
730 |
String cmpName = tmpIter.next();
|
|
731 |
long lastModificationTimeForComponent = cacheIndx.getLastModifiedTimeForComponent(cmpName);
|
|
732 |
componentList.add(new ComponentListNode(cmpName, currentlyUsedTargetPlatforms[i], lastModificationTimeForComponent));
|
|
733 |
// Checking for possible duplicate component names
|
|
734 |
// and adding found duplicates to the duplicate list
|
|
735 |
checkForPossibleComponentDuplicate(duplicateItemsList, allComponentNames, cmpName);
|
|
736 |
}
|
|
737 |
}
|
|
738 |
return componentList;
|
|
739 |
}
|
|
740 |
|
|
741 |
/**
|
|
742 |
* Checks if the given component has duplicates and adds to the duplicate
|
|
743 |
* list if found.
|
|
744 |
* @param duplicateItemsList Out parameter that is duplicate item list to be updated.
|
|
745 |
* @param allComponentNames All component names found so far from the targets.
|
|
746 |
* @param cmpName Component name to check for possible duplicate instances.
|
|
747 |
*/
|
|
748 |
private static void checkForPossibleComponentDuplicate(List<String> duplicateItemsList, Set<String> allComponentNames, String cmpName) {
|
|
749 |
if(allComponentNames.contains(cmpName)){
|
|
750 |
if(!duplicateItemsList.contains(cmpName)){
|
|
751 |
duplicateItemsList.add(cmpName);
|
|
752 |
}
|
|
753 |
}
|
|
754 |
else{
|
|
755 |
allComponentNames.add(cmpName);
|
|
756 |
}
|
|
757 |
}
|
|
758 |
|
|
759 |
/**
|
|
760 |
* Updates the cache index for the given cache file.
|
|
761 |
* @param cacheFileAbsolutePathName Absolute path name pointing to the
|
|
762 |
* location of cache data file to be examined.
|
|
763 |
* @param buildDirectory Build directory string to be used as seek string to cache file.
|
|
764 |
* @throws IOException
|
|
765 |
* @throws CacheFileDoesNotExistException
|
|
766 |
*/
|
|
767 |
public static void updateCacheIndexFor(String cacheFileAbsolutePathName, String buildDirectory) throws IOException, CacheFileDoesNotExistException{
|
|
768 |
File localVarCacheFile = new File(cacheFileAbsolutePathName);
|
|
769 |
if(!localVarCacheFile.exists()){
|
|
770 |
throw new CacheFileDoesNotExistException(cacheFileAbsolutePathName);
|
|
771 |
}
|
|
772 |
// Getting existing, or creating a new cache index
|
|
773 |
// for enabling faster access for cache data
|
|
774 |
CacheIndex localCacheIndxRef = CacheIndex.getCacheIndexInstance(localVarCacheFile, buildDirectory);
|
|
775 |
localCacheIndxRef.update();
|
|
776 |
}
|
|
777 |
|
|
778 |
/**
|
|
779 |
* Checks if the cache index has been build for the queried cache file and build directory.
|
|
780 |
* @param cacheFileAbsolutePathName Absolute path name pointing to the
|
|
781 |
* location of cache data file to be examined.
|
|
782 |
* @param buildDirectory Build directory string to be used as seek string to cache file.
|
|
783 |
* @return <code>true</code> if cache index has been build for the queried cache file, otherwise <code>false</code>.
|
|
784 |
* @throws IOException
|
|
785 |
* @throws CacheFileDoesNotExistException
|
|
786 |
*/
|
|
787 |
public static boolean isCacheIndexBuilt(String cacheFileAbsolutePathName, String buildDirectory) throws IOException, CacheFileDoesNotExistException{
|
|
788 |
File cacheFile = new File(cacheFileAbsolutePathName);
|
|
789 |
if(!cacheFile.exists()){
|
|
790 |
throw new CacheFileDoesNotExistException(cacheFileAbsolutePathName);
|
|
791 |
}
|
|
792 |
// Getting existing, or creating a new cache index
|
|
793 |
// for enabling faster access for cache data
|
|
794 |
CacheIndex cacheIndx = CacheIndex.getCacheIndexInstance(cacheFile, buildDirectory);
|
|
795 |
return cacheIndx.isCacheIndexBuiltImpl();
|
|
796 |
}
|
|
797 |
}
|