core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContextDataCache.java
author timkelly
Fri, 27 Aug 2010 16:34:38 -0500
changeset 1906 6f11f5393a5c
parent 1823 7b722bddc011
permissions -rw-r--r--
for gcce and armv5 based targets for sbsv2, if the compiler prefix does not exist on disk for a particular configuraiton, attempt to perform a raptor query to reubuild the config data.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     1
/*
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     8
*
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    11
*
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    12
*/
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    13
package com.nokia.carbide.cpp.internal.api.sdk;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    14
788
e6e4e53ddc17 Add buffering to cache files to fix bug #10318 and bug #10533
Ed Swartz <ed.swartz@nokia.com>
parents: 743
diff changeset
    15
import java.io.BufferedInputStream;
e6e4e53ddc17 Add buffering to cache files to fix bug #10318 and bug #10533
Ed Swartz <ed.swartz@nokia.com>
parents: 743
diff changeset
    16
import java.io.BufferedOutputStream;
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    17
import java.io.File;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    18
import java.io.FileInputStream;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    19
import java.io.FileOutputStream;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    20
import java.io.IOException;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    21
import java.io.ObjectInputStream;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    22
import java.io.ObjectOutputStream;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    23
import java.io.ObjectStreamClass;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    24
import java.io.ObjectStreamException;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    25
import java.util.*;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    26
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    27
import org.eclipse.core.runtime.IPath;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    28
import org.eclipse.core.runtime.IStatus;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    29
import org.eclipse.core.runtime.Path;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    30
import org.eclipse.core.runtime.Platform;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    31
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    32
import com.nokia.carbide.cpp.epoc.engine.EpocEnginePlugin;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    33
import com.nokia.carbide.cpp.epoc.engine.model.sbv.ISBVView;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    34
import com.nokia.carbide.cpp.epoc.engine.preprocessor.*;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    35
import com.nokia.carbide.cpp.internal.sdk.core.model.SymbianSDK;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    36
import com.nokia.carbide.cpp.sdk.core.*;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    37
import com.nokia.carbide.internal.api.cpp.epoc.engine.preprocessor.BasicIncludeFileLocator;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    38
import com.nokia.carbide.internal.api.cpp.epoc.engine.preprocessor.MacroScanner;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    39
import com.nokia.cpp.internal.api.utils.core.ExternalFileInfoCollection;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    40
import com.nokia.cpp.internal.api.utils.core.FileUtils;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    41
import com.nokia.cpp.internal.api.utils.core.Logging;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    42
import com.nokia.cpp.internal.api.utils.core.ObjectUtils;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    43
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    44
/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    45
 * This class holds the externally gathered data for a build context,
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    46
 * such as the #include paths and macros defined in the SDK.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    47
 * <p> 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    48
 * Unlike CarbideBuildConfiguration (which, unfortunately extends 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    49
 * SymbianBuildContext), this will not be created multiple times for
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    50
 * multiple projects, but only once for a different build context
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    51
 * in an SDK or devkit.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    52
 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    53
public class SymbianBuildContextDataCache {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    54
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    55
	public static boolean DEBUG = false;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    56
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    57
	// by default, only check HRH-included files if changed in last second (for ordinary operations)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    58
	// or the last minute (when doing a long project operation).  see #startThrottle() and #stopThrottle()
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    59
	private static final long DEFAULT_HRH_INFO_CHECK_QUANTUM = 1000; // 1 sec
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    60
	private static final long THROTTLED_HRH_INFO_CHECK_QUANTUM = 60000; // 60 sec
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    61
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    62
	// compiler prefixes are very unlikely to change, but we need to check
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    63
	// occasionally in case a user installs a new one...
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    64
	private static final long DEFAULT_COMPILER_PREFIX_INFO_CHECK_QUANTUM = 15 * 60 * 1000;	// 15 minutes
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    65
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
	// This is a count of times #startProjectOperation() was called without
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    67
	// balancing #endProjectOperation().  
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    68
	private static int inProjectOperationCount;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
	private static Map<String, SymbianBuildContextDataCache> cacheMap = new HashMap<String, SymbianBuildContextDataCache>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    71
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    72
	public static synchronized SymbianBuildContextDataCache getCache(ISymbianBuildContext context) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    73
		// don't hash on ISymbianBuildContext itself since it is sometimes a ICarbideBuildConfiguration
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    74
		String key = getBuildContextKey(context);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    75
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    76
		SymbianBuildContextDataCache cache = cacheMap.get(key);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    77
		if (cache == null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    78
			cache = new SymbianBuildContextDataCache(context);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    79
			cache.loadCacheFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    80
			cacheMap.put(key, cache);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    81
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    82
		return cache;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    83
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    84
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    85
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    86
	 * @param context
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    87
	 * @return
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    89
	private static String getBuildContextKey(ISymbianBuildContext context) {
1669
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    90
		String key;
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    91
		if (context instanceof ISBSv2BuildContext) {
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    92
			// use config ID instead of platform + target since
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    93
			// platform and target can be the same for different build contexts
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    94
			ISBSv2BuildContext v2Context = (ISBSv2BuildContext) context;
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    95
			key = v2Context.getConfigID() + "/";
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    96
		}
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    97
		else {
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    98
			key = context.getPlatformString() + "/" + context.getTargetString() + "/";
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
    99
		}
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   100
		ISymbianSDK sdk = context.getSDK();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   101
		if (sdk != null)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   102
			key += sdk.getEPOCROOT();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   103
		return key;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   104
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   105
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   106
	//private File prefixFileParsed;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   107
	private List<File> hrhFilesParsed = new ArrayList<File>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   108
	private ExternalFileInfoCollection hrhFileInfo = null; 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   109
	private List<IDefine> variantHRHMacros = new ArrayList<IDefine>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   110
	private List<IDefine> compilerPrefixMacros = new ArrayList<IDefine>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   111
	private ExternalFileInfoCollection compilerPrefixFileInfo = null; 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   112
	private List<File> systemIncludes;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   113
	private ISymbianSDK sdk;
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   114
	private ISymbianBuildContext context;
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   115
	private IPath compilerPrefixFile;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   116
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   117
	private String platformString;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   118
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   119
	private String displayString;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   120
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   121
	private String contextKey;
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   122
1736
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   123
	/**
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   124
	 * One of {@link ISymbianBuilderID}
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   125
	 */
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   126
	private String builderId;
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   127
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   128
	private boolean changed;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   129
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   130
	private File cacheFile;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   131
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   132
	private SymbianBuildContextDataCache(ISymbianBuildContext context) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   133
		if (DEBUG) System.out.println("Creating cache for " + context.getDisplayString());
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   134
		this.context = context;
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   135
		this.platformString = context.getPlatformString();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   136
		this.displayString = context.getDisplayString();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   137
		this.sdk = context.getSDK();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   138
		this.contextKey = getBuildContextKey(context);
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   139
		if (context instanceof ISBSv1BuildContext) {
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   140
			builderId = ISymbianBuilderID.SBSV1_BUILDER;
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   141
		} else {
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   142
			builderId = ISymbianBuilderID.SBSV2_BUILDER;
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   143
		}
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   144
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   145
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   146
	/* (non-Javadoc)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   147
	 * @see java.lang.Object#toString()
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   148
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   149
	@Override
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   150
	public String toString() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   151
		return "Cache for " + displayString;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   152
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   153
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   154
	public List<IDefine> getVariantHRHDefines() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   155
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   156
		// we parse the variant hrh file to gather macros.  this can be time consuming so do it
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
		// once and cache the values.  only reset the cache when the hrh or any of its includes
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   158
		// has changed.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   160
		boolean buildCache = false;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   161
		
1906
6f11f5393a5c for gcce and armv5 based targets for sbsv2, if the compiler prefix does not exist on disk for a particular configuraiton, attempt to perform
timkelly
parents: 1823
diff changeset
   162
		if (hrhFileInfo == null || hrhFileInfo.getFiles().length == 0) {
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
			// hasn't been built yet, or was flushed
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
			buildCache = true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   165
		} else {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   166
			// Cache exists.  See if any of the files have changed
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   167
			if (sdk != null && hrhFileInfo.anyChanged()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   168
				buildCache = true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   169
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   170
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   171
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   172
		if (buildCache) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   173
			gatherVariantHRHDefines();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   174
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   175
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   176
		return variantHRHMacros;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   177
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   178
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   179
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   180
	 * Re-gather the #defines from the variant HRH file 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   181
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   182
	private void gatherVariantHRHDefines() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   183
		changed = true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   184
		variantHRHMacros.clear();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   185
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   186
		synchronized (this) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   187
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   188
			List<IDefine> macros = new ArrayList<IDefine>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   189
			Map<String, IDefine> namedMacros = new HashMap<String, IDefine>();
1771
bd45dfd2e7ee Remove ISymbianSDK#getPrefixFile. You can get this from ISDKBuildInfo#getPrefixFromVariantCfg().
timkelly
parents: 1736
diff changeset
   190
			
1820
5c955fcfdc3d fix npe, clear sbsv2 query cache data in memory when rebuilding sbsv2 cache from pref, other code clean-up
timkelly
parents: 1801
diff changeset
   191
			File prefixFile = null;
5c955fcfdc3d fix npe, clear sbsv2 query cache data in memory when rebuilding sbsv2 cache from pref, other code clean-up
timkelly
parents: 1801
diff changeset
   192
			if (context.getPrefixFromVariantCfg() != null){
5c955fcfdc3d fix npe, clear sbsv2 query cache data in memory when rebuilding sbsv2 cache from pref, other code clean-up
timkelly
parents: 1801
diff changeset
   193
				prefixFile = context.getPrefixFromVariantCfg().toFile();
5c955fcfdc3d fix npe, clear sbsv2 query cache data in memory when rebuilding sbsv2 cache from pref, other code clean-up
timkelly
parents: 1801
diff changeset
   194
			}
5c955fcfdc3d fix npe, clear sbsv2 query cache data in memory when rebuilding sbsv2 cache from pref, other code clean-up
timkelly
parents: 1801
diff changeset
   195
			
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   196
			ISDKBuildInfo buildInfo = sdk.getBuildInfo(builderId);
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   197
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   198
			if (prefixFile == null){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   199
				// Check that the prefix file may have become available since the SDK was scanned last.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   200
				// This can happen, for e.g., if the user opens the IDE _then_ does a subst on a drive that already has an SDK entry.
1801
1d73a4591cf8 refactoring usage for getting variant.hrh and compiler preinclude macros. Now should use ISymbianContext both for preprocessed results and getting the IPath to the file.
timkelly
parents: 1771
diff changeset
   201
				IPath prefixCheck = context.getPrefixFromVariantCfg();
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   202
				if (prefixCheck != null){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   203
					prefixFile = prefixCheck.toFile();
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   204
					((SymbianSDK)sdk).setPrefixFile(prefixCheck, builderId);
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   205
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   206
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   207
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   208
			File[] includedFiles = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   209
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   210
			if (prefixFile != null) {
840
c92830672f75 Fix 10622. Always add epco32\include to search paths when preprocessing varint HRH
timkelly
parents: 788
diff changeset
   211
				
c92830672f75 Fix 10622. Always add epco32\include to search paths when preprocessing varint HRH
timkelly
parents: 788
diff changeset
   212
				List<File> systemPaths = new ArrayList<File>();
c92830672f75 Fix 10622. Always add epco32\include to search paths when preprocessing varint HRH
timkelly
parents: 788
diff changeset
   213
				// Always add epoc32/include to the search path as this is implicit for includes in the HRH
c92830672f75 Fix 10622. Always add epco32\include to search paths when preprocessing varint HRH
timkelly
parents: 788
diff changeset
   214
				systemPaths.add(new File(sdk.getEPOCROOT() + "epoc32/include"));
c92830672f75 Fix 10622. Always add epco32\include to search paths when preprocessing varint HRH
timkelly
parents: 788
diff changeset
   215
				
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   216
				if (buildInfo instanceof ISBSv1BuildInfo) {
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   217
					// add any BSF/SBV includes so the headers are picked up from the correct location
1471
62024a5fa81d Refactor out BSF/SBV support from SBSv2 Builder data. Create new package for SBSv2Query APIs (moved from builder tests).
timkelly
parents: 1462
diff changeset
   218
					// SBSv1 only
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   219
					ISBSv1BuildInfo sbsv1BuildInfo = (ISBSv1BuildInfo)buildInfo;
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   220
					IBSFPlatform bsfPlat = sbsv1BuildInfo.getBSFCatalog().findPlatform(platformString);
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   221
					ISBVPlatform sbvPlat = sbsv1BuildInfo.getSBVCatalog().findPlatform(platformString);
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   222
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   223
					if (bsfPlat != null) {
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   224
						for (IPath path : bsfPlat.getSystemIncludePaths()) {
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   225
							systemPaths.add(path.toFile());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   226
						}
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   227
					} else if (sbvPlat != null) {
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   228
						LinkedHashMap<IPath, String> platPaths = sbvPlat.getBuildIncludePaths();
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   229
						Set<IPath> set = platPaths.keySet();
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   230
						for (IPath path : set) {
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   231
							String pathType = platPaths.get(path);
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   232
							if (pathType.equalsIgnoreCase(ISBVView.INCLUDE_FLAG_PREPEND) || pathType.equalsIgnoreCase(ISBVView.INCLUDE_FLAG_SET)){
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   233
								systemPaths.add(path.toFile());
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   234
							}
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   235
						}
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   236
					}
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   237
				} 
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   238
				
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   239
				MacroScanner scanner = new MacroScanner(
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   240
						new BasicIncludeFileLocator(null, systemPaths.toArray(new File[systemPaths.size()])),
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   241
						DefaultModelDocumentProvider.getInstance(),
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   242
						DefaultTranslationUnitProvider.getInstance());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   243
				scanner.scanFile(prefixFile);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   244
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   245
				List<IDefine> scannedMacros = (List<IDefine>)scanner.getMacroDefinitions();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   246
				for (IDefine scannedMacro : scannedMacros){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   247
					// we don't want duplicate macros, so check to see if it's already there.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   248
					// if it is, remove it and then add the newer one.  this is consistent with
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   249
					// how it would be from a compiler standpoint.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   250
					IDefine macro = namedMacros.get(scannedMacro.getName());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   251
					if (macro != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   252
						macros.remove(macro);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   253
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   254
					
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   255
					macros.add(scannedMacro);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   256
					namedMacros.put(scannedMacro.getName(), scannedMacro);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   257
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   258
				
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   259
				hrhFilesParsed.clear();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   260
				includedFiles = scanner.getIncludedFiles();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   261
				for (File inc : includedFiles) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   262
					hrhFilesParsed.add(inc);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   263
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   264
				
1736
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   265
				if (buildInfo instanceof ISBSv1BuildInfo) {
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   266
					// SBSv2 does not parse the variant.cfg file to collect macros.
1801
1d73a4591cf8 refactoring usage for getting variant.hrh and compiler preinclude macros. Now should use ISymbianContext both for preprocessed results and getting the IPath to the file.
timkelly
parents: 1771
diff changeset
   267
					List<String> variantCFGMacros = ((ISBSv1BuildContext)context).getVariantCFGMacros();
1736
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   268
					for (String cfgMacros : variantCFGMacros){
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   269
						// we don't want duplicate macros, so check to see if it's already there.
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   270
						IDefine existingMacro = namedMacros.get(cfgMacros);
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   271
						if (existingMacro != null) {
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   272
							macros.remove(existingMacro);
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   273
						}
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   274
						
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   275
						IDefine macro = DefineFactory.createSimpleFreeformDefine(cfgMacros);
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   276
						macros.add(macro);
ba74c19c6de3 fix bug 11762. Fix targettypes for MMP editor to retrieve properly depending on whether build config is SBsv1 or SBSv2.
timkelly
parents: 1669
diff changeset
   277
						namedMacros.put(macro.getName(), macro);
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   278
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   279
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   280
			} 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   281
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   282
			// cache the info about when we created the cache
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   283
			if (hrhFileInfo == null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   284
				hrhFileInfo = new ExternalFileInfoCollection(
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   285
						EpocEnginePlugin.getExternalFileInfoCache(),
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   286
						includedFiles,
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   287
						DEFAULT_HRH_INFO_CHECK_QUANTUM);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   288
			} else {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   289
				hrhFileInfo.setFiles(includedFiles);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   290
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   291
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   292
			variantHRHMacros = macros;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   293
			saveCacheFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   294
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   295
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   296
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   297
	public List<File> getPrefixFileIncludes() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   298
		return hrhFilesParsed;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   299
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   300
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   301
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   302
	public synchronized List<IDefine> getCompilerMacros(IPath prefixFile) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   303
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   304
		// we assume that the prefix file will not change often,
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   305
		// (if at all) for a build context, so dump the cache if the prefix file changes.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   306
		
1669
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   307
		if (compilerPrefixFile != null && prefixFile != null && 
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   308
			!compilerPrefixFile.equals(prefixFile)) {
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   309
			compilerPrefixFileInfo = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   310
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   311
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   312
		compilerPrefixFile = prefixFile;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   313
1906
6f11f5393a5c for gcce and armv5 based targets for sbsv2, if the compiler prefix does not exist on disk for a particular configuraiton, attempt to perform
timkelly
parents: 1823
diff changeset
   314
		if (compilerPrefixFileInfo == null || compilerPrefixFile == null ||
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   315
				compilerPrefixFileInfo.anyChanged()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   316
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   317
			changed = true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   318
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   319
			compilerPrefixMacros.clear();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   320
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   321
			synchronized (this) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   322
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   323
				List<IDefine> macros = new ArrayList<IDefine>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   324
				if (prefixFile != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   325
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   326
					List<File> userPaths = new ArrayList<File>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   327
					List<File> systemPaths = new ArrayList<File>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   328
					
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   329
					userPaths.add(prefixFile.removeLastSegments(1).toFile());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   330
					systemPaths.add(prefixFile.removeLastSegments(1).toFile());
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   331
					IPath includePath = sdk.getIncludePath();
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   332
					if (includePath != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   333
						File includeDir = includePath.toFile().getAbsoluteFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   334
						userPaths.add(includeDir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   335
						systemPaths.add(includeDir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   336
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   337
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   338
					
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   339
					// get macros from the compiler prefix file: note, this is a stupid
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   340
					// scan that will get the last version #defined, even if inside an #if.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   341
					MacroScanner scanner = new MacroScanner(
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   342
							new BasicIncludeFileLocator(userPaths.toArray(new File[userPaths.size()]), systemPaths.toArray(new File[systemPaths.size()])),
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   343
							DefaultModelDocumentProvider.getInstance(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   344
							DefaultTranslationUnitProvider.getInstance());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   345
					scanner.scanFile(prefixFile.toFile());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   346
					for (IDefine define : scanner.getMacroDefinitions()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   347
						macros.add(define);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   348
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   349
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   350
					// store off the info about what we read for this cache
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   351
					File[] files = scanner.getIncludedFiles();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   352
					
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   353
					if (compilerPrefixFileInfo == null)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   354
						compilerPrefixFileInfo = new ExternalFileInfoCollection(
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   355
								EpocEnginePlugin.getExternalFileInfoCache(),
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   356
								files,
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   357
								DEFAULT_COMPILER_PREFIX_INFO_CHECK_QUANTUM);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   358
					else
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   359
						compilerPrefixFileInfo.setFiles(files);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   360
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   361
				
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   362
				if (context instanceof ISBSv2BuildContext) {
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   363
					// add macros from raptor query
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   364
					ISBSv2BuildContext v2Context = (ISBSv2BuildContext) context;
1669
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   365
					ISBSv2ConfigQueryData configData = v2Context.getConfigQueryData();
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   366
					if (configData != null) {
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   367
						Map<String, String> buildMacros = configData.getBuildMacros();
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   368
						if (buildMacros != null) {
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   369
							for (Iterator<String> itr = buildMacros.keySet().iterator(); itr.hasNext(); ) { 
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   370
								String name = itr.next();
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   371
								String value = buildMacros.get(name);
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   372
								macros.add(DefineFactory.createDefine(name, value));
d7359f2d2080 Make sure we're getting the correct set of macros for each SBSv2 build context.
stechong
parents: 1659
diff changeset
   373
							}
1621
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   374
						}
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   375
					}
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   376
				}
393b985a50f3 Raptor scanner discovery on top of new Raptor Query API.
stechong
parents: 1479
diff changeset
   377
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   378
				compilerPrefixMacros = macros;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   379
				
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   380
				saveCacheFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   381
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   382
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   383
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   384
		return compilerPrefixMacros;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   385
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   386
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   387
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   388
	 * Get the list of #include paths detected for this context.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   389
	 * @return List or <code>null</code>
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   390
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   391
	public synchronized List<File> getSystemIncludePaths() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   392
		if (systemIncludes == null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   393
			gatherBuildContextSystemIncludePaths();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   394
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   395
		return systemIncludes;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   396
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   397
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   398
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   399
	 * Fetch the list of include paths for the build context
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   400
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   401
	private void gatherBuildContextSystemIncludePaths() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   402
		changed = true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   403
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   404
		systemIncludes = new ArrayList<File>();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   405
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   406
		if (DEBUG) System.out.println("Scanning include paths for " + displayString);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   407
		
1434
79471fd1fd69 First pass refactoring ISymbianSDK.
stechong
parents: 840
diff changeset
   408
		IBSFPlatform bsfplatform = null;
79471fd1fd69 First pass refactoring ISymbianSDK.
stechong
parents: 840
diff changeset
   409
		ISBVPlatform sbvPlatform = null;
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   410
		ISDKBuildInfo buildInfo = sdk.getBuildInfo(builderId);
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   411
		if (buildInfo instanceof ISBSv1BuildInfo) {
1471
62024a5fa81d Refactor out BSF/SBV support from SBSv2 Builder data. Create new package for SBSv2Query APIs (moved from builder tests).
timkelly
parents: 1462
diff changeset
   412
			// SBSv1 only
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   413
			ISBSv1BuildInfo sbsv1BuildInfo = (ISBSv1BuildInfo)buildInfo;
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   414
			bsfplatform = sbsv1BuildInfo.getBSFCatalog().findPlatform(platformString);
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   415
			sbvPlatform = sbsv1BuildInfo.getSBVCatalog().findPlatform(platformString);
1471
62024a5fa81d Refactor out BSF/SBV support from SBSv2 Builder data. Create new package for SBSv2Query APIs (moved from builder tests).
timkelly
parents: 1462
diff changeset
   416
		} 
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   418
		// look in the epoc32 directory of the SDK
1462
b38491fd06da More ISymbianSDK refactoring.
stechong
parents: 1434
diff changeset
   419
		IPath includePath = sdk.getIncludePath();
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   420
		if (includePath != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   421
			File includeDir = includePath.toFile().getAbsoluteFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   422
			File dir;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   423
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   424
			// get additional include directories from BSF platform, if defined
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   425
			if (bsfplatform != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   426
				IPath[] systemIncludePaths = bsfplatform.getSystemIncludePaths();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   427
				for (IPath path : systemIncludePaths) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   428
					dir = path.toFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   429
					if (dir.exists() && dir.isDirectory()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   430
						systemIncludes.add(dir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   431
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   432
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   433
			} else if (sbvPlatform != null){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   434
				
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   435
				LinkedHashMap<IPath, String> platPaths = sbvPlatform.getBuildIncludePaths();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   436
				Set<IPath> set = platPaths.keySet();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   437
				for (IPath path : set) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   438
					String pathType = platPaths.get(path);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   439
					if (pathType.equalsIgnoreCase(ISBVView.INCLUDE_FLAG_PREPEND) || pathType.equalsIgnoreCase(ISBVView.INCLUDE_FLAG_SET)){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   440
						dir = path.toFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   441
						systemIncludes.add(dir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   442
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   443
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   444
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   445
			else {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   446
				// legacy behavior 
1479
a654857ddb87 refactor out ABLD-style platform constants into ISBSv1BuildContext from ISymbianBuildContext
timkelly
parents: 1471
diff changeset
   447
				if (platformString.equals(ISBSv1BuildContext.EMULATOR_PLATFORM)) {
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   448
					dir = new File(includeDir, "wins"); //$NON-NLS-1$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   449
					if (dir.exists() && dir.isDirectory()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   450
						systemIncludes.add(dir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   451
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   452
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   453
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   454
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   455
			// add OEM dir
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   456
			dir = new File(includeDir, "oem"); //$NON-NLS-1$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   457
			if (dir.exists() && dir.isDirectory()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   458
				systemIncludes.add(dir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   459
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   460
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   461
			// and finally the normal include dir
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   462
			systemIncludes.add(includeDir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   463
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   464
			// and finally, finally, if this is an SBV add any paths with the append flag
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   465
			if (sbvPlatform != null){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   466
				
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   467
				Map<IPath, String> platPaths = sbvPlatform.getBuildIncludePaths();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   468
				Set<IPath> set = platPaths.keySet();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   469
				for (IPath path : set) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   470
					String pathType = platPaths.get(path);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   471
					if (pathType.equalsIgnoreCase(ISBVView.INCLUDE_FLAG_APPEND)){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   472
						dir = path.toFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   473
						systemIncludes.add(dir);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   474
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   475
				}	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   476
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   477
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   478
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   479
		// also search files in same folder as variant.hrh
1823
7b722bddc011 work to get EpocEngineHelper#getGlobalDefinesForConfiguration(ICarbideBuildConfiguration config, List<IPath> mmpFiles) working properly. Gets the configuration indexer data cache macros set up properly.
timkelly
parents: 1820
diff changeset
   480
		File prefix = null;
7b722bddc011 work to get EpocEngineHelper#getGlobalDefinesForConfiguration(ICarbideBuildConfiguration config, List<IPath> mmpFiles) working properly. Gets the configuration indexer data cache macros set up properly.
timkelly
parents: 1820
diff changeset
   481
		if (context.getPrefixFromVariantCfg() != null){
7b722bddc011 work to get EpocEngineHelper#getGlobalDefinesForConfiguration(ICarbideBuildConfiguration config, List<IPath> mmpFiles) working properly. Gets the configuration indexer data cache macros set up properly.
timkelly
parents: 1820
diff changeset
   482
			prefix = context.getPrefixFromVariantCfg().toFile();
7b722bddc011 work to get EpocEngineHelper#getGlobalDefinesForConfiguration(ICarbideBuildConfiguration config, List<IPath> mmpFiles) working properly. Gets the configuration indexer data cache macros set up properly.
timkelly
parents: 1820
diff changeset
   483
		}
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   484
		if (sbvPlatform != null){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   485
			// might be an alternate HRH file to use
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   486
			IPath varVarHRH = sbvPlatform.getBuildVariantHRHFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   487
			if (!varVarHRH.toFile().equals(prefix) && varVarHRH.toFile().exists()){
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   488
				prefix = varVarHRH.toFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   489
			} 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   490
		}
1659
48d0d704d5e6 fix NPE, avoid adding a null system include path.
timkelly
parents: 1621
diff changeset
   491
		if (prefix != null && prefix.getParentFile() != null) {
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   492
			systemIncludes.add(prefix.getParentFile());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   493
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   494
		
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   495
		saveCacheFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   496
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   497
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   498
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   499
	 * Let cache know that the client is beginning an operation that
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   500
	 * will iterate all the build contexts.  We use this information
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   501
	 * to optimize file info checks.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   502
	 * <p>
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   503
	 * Each call must be balanced by an {@link #endProjectOperation()} call.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   504
	 * Use a try ... finally block to make sure.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   505
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   506
	public static synchronized void startProjectOperation() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   507
		inProjectOperationCount++;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   508
		if (inProjectOperationCount == 1) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   509
			for (SymbianBuildContextDataCache cache : cacheMap.values()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   510
				cache.startThrottle();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   511
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   512
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   513
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   514
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   515
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   516
	 * Let cache know that a project-wide operation is done, so
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   517
	 * we can resume normal info checking behavior.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   518
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   519
	public static synchronized void endProjectOperation() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   520
		inProjectOperationCount--;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   521
		if (inProjectOperationCount < 0) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   522
			Logging.log(SDKCorePlugin.getDefault(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   523
					Logging.newStatus(SDKCorePlugin.getDefault(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   524
							new IllegalStateException("project operation count not balanced")));
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   525
			inProjectOperationCount = 0;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   526
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   527
		if (inProjectOperationCount == 0) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   528
			for (SymbianBuildContextDataCache cache : cacheMap.values()) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   529
				cache.stopThrottle();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   530
				cache.saveCacheFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   531
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   532
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   533
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   534
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   535
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   536
	 * Throttle file info checks on this cache if we suspect the same
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   537
	 * files will be checked over and over again in a short time (e.g. through
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   538
	 * multiple contexts on the same SDK).
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   539
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   540
	private void startThrottle() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   541
		if (hrhFileInfo != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   542
			hrhFileInfo.setRecheckQuantum(THROTTLED_HRH_INFO_CHECK_QUANTUM);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   543
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   544
		// note: compiler prefix infos already have a long delay, but
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   545
		// this is a good place to refresh
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   546
		if (compilerPrefixFileInfo != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   547
			compilerPrefixFileInfo.refresh();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   548
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   549
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   550
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   551
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   552
	 * End file info throttling.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   553
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   554
	private void stopThrottle() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   555
		if (hrhFileInfo != null)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   556
			hrhFileInfo.setRecheckQuantum(DEFAULT_HRH_INFO_CHECK_QUANTUM);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   557
		// note: compiler prefix infos already have a long delay
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   558
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   559
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   560
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   561
	 * Refresh the cached data when there are substantial changes in the given SDKs.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   562
	 * 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   563
	 * @param sdks SDKs for whose contexts the caches should be removed, or <code>null</code> for all of them
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   564
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   565
	public static synchronized void refreshForSDKs(ISymbianSDK[] sdks) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   566
		// refresh each context cache, meaning, delete its memory and disk values
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   567
		Collection<String> values = cacheMap.keySet();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   568
		String[] keyArray = (String[]) values.toArray(new String[values.size()]);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   569
		for (String key : keyArray) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   570
			SymbianBuildContextDataCache cache = cacheMap.get(key);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   571
			boolean forSDK = sdkInArray(sdks, cache.sdk);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   572
			if (forSDK) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   573
				cache.reset();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   574
				cacheMap.remove(key);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   575
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   576
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   577
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   578
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   579
	private static boolean sdkInArray(ISymbianSDK[] sdks, ISymbianSDK anSDK) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   580
		if (sdks == null)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   581
			return true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   582
		if (anSDK == null)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   583
			return false;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   584
		// object identity is not appropriate; user may have renamed or moved an SDK
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   585
		for (ISymbianSDK sdk : sdks) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   586
			if (ObjectUtils.equals(sdk.getEPOCROOT(), anSDK.getEPOCROOT())
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   587
					|| ObjectUtils.equals(sdk.getUniqueId(), anSDK.getUniqueId()))
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   588
				return true;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   589
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   590
		return false;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   591
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   592
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   593
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   594
	 * Reset the cached data for this context, ensuring it will be
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   595
	 * freshly gathered.  This deletes anything stored on disk.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   596
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   597
	public synchronized void reset() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   598
		hrhFileInfo = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   599
		compilerPrefixFileInfo = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   600
		systemIncludes = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   601
		getCacheFile().delete();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   602
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   603
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   604
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   605
	 * Get the file where we store cached data
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   606
	 * @return File in workspace plugin state storage
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   607
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   608
	protected File getCacheFile() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   609
		if (cacheFile == null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   610
			IPath statePath;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   611
			if (Platform.isRunning())
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   612
				statePath = Platform.getStateLocation(SDKCorePlugin.getDefault().getBundle());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   613
			else
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   614
				statePath = new Path(FileUtils.getTemporaryDirectory().getAbsolutePath());
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   615
			cacheFile = statePath.append(contextKey.replaceAll("[^A-Za-z0-9_]", "_") + ".dat").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   616
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   617
		return cacheFile;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   618
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   619
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   620
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   621
	 * Save cache to disk if changed.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   622
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   623
	protected void saveCacheFile() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   624
		if (!changed)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   625
			return;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   626
			
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   627
		ObjectOutputStream os = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   628
		try {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   629
			File cacheFile = getCacheFile();
788
e6e4e53ddc17 Add buffering to cache files to fix bug #10318 and bug #10533
Ed Swartz <ed.swartz@nokia.com>
parents: 743
diff changeset
   630
			if (DEBUG) System.out.print("Saving to " + cacheFile + "... "); //$NON-NLS-1$ //$NON-NLS-2$
e6e4e53ddc17 Add buffering to cache files to fix bug #10318 and bug #10533
Ed Swartz <ed.swartz@nokia.com>
parents: 743
diff changeset
   631
			os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(cacheFile)));
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   632
			doSaveCache(os);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   633
			changed = false;
788
e6e4e53ddc17 Add buffering to cache files to fix bug #10318 and bug #10533
Ed Swartz <ed.swartz@nokia.com>
parents: 743
diff changeset
   634
			if (DEBUG) System.out.println("done."); //$NON-NLS-1$
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   635
		} catch (ObjectStreamException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   636
			Logging.log(SDKCorePlugin.getDefault(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   637
					Logging.newStatus(SDKCorePlugin.getDefault(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   638
							IStatus.WARNING,
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   639
							"Tried to save uncacheable data for " + displayString, //$NON-NLS-1$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   640
							e));
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   641
		} catch (IOException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   642
			// oh well
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   643
			Logging.log(SDKCorePlugin.getDefault(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   644
					Logging.newStatus(SDKCorePlugin.getDefault(), 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   645
							IStatus.WARNING,
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   646
							"Failed to save cache state for " + displayString, //$NON-NLS-1$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   647
							e));
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   648
		} finally {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   649
			if (os != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   650
				try {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   651
					os.close();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   652
				} catch (IOException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   653
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   654
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   655
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   656
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   657
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   658
	protected void loadCacheFile() {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   659
		ObjectInputStream is = null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   660
		// Use the class loader that knows how to span plugins
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   661
		final ClassLoader classLoader = SDKCorePlugin.getDefault().getClass().getClassLoader();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   662
		File cacheFile = getCacheFile();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   663
		try {
788
e6e4e53ddc17 Add buffering to cache files to fix bug #10318 and bug #10533
Ed Swartz <ed.swartz@nokia.com>
parents: 743
diff changeset
   664
			is = new ObjectInputStream(new BufferedInputStream(new FileInputStream(cacheFile))) {
743
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   665
				/* (non-Javadoc)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   666
				 * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   667
				 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   668
				@Override
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   669
				protected Class<?> resolveClass(ObjectStreamClass desc)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   670
						throws IOException, ClassNotFoundException {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   671
					String name = desc.getName();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   672
					try {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   673
						return classLoader.loadClass(name);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   674
					} catch (ClassNotFoundException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   675
						return super.resolveClass(desc);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   676
					}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   677
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   678
			};
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   679
			doLoadCache(is);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   680
			if (DEBUG) System.out.println("Loaded cache from " + cacheFile); //$NON-NLS-1$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   681
		} catch (ClassNotFoundException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   682
			// this is probably a bug
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   683
			e.printStackTrace();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   684
		} catch (ObjectStreamException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   685
			// assume it's just out of sync (e.g. object signatures changed), so nothing in Error Log
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   686
			e.printStackTrace();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   687
			cacheFile.delete();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   688
		} catch (IOException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   689
			// oh well, not made yet
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   690
		} finally {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   691
			if (is != null) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   692
				try {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   693
					is.close();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   694
				} catch (IOException e) {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   695
				}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   696
			}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   697
			changed = false;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   698
		}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   699
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   700
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   701
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   702
	 * @param os
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   703
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   704
	private void doSaveCache(ObjectOutputStream os) throws IOException {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   705
		os.writeObject(systemIncludes);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   706
		savePath(os, compilerPrefixFile);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   707
		os.writeObject(compilerPrefixFileInfo);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   708
		os.writeObject(compilerPrefixMacros);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   709
		os.writeObject(hrhFileInfo);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   710
		os.writeObject(hrhFilesParsed);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   711
		os.writeObject(variantHRHMacros);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   712
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   713
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   714
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   715
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   716
	 * Load entries from the cache.  This must match the ordering in
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   717
	 * {@link #doSaveCache(ObjectOutputStream)}.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   718
	 * @param is
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   719
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   720
	private void doLoadCache(ObjectInputStream is) throws IOException, ClassCastException, ClassNotFoundException {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   721
		systemIncludes = loadList(is, File.class);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   722
		compilerPrefixFile = loadPath(is);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   723
		compilerPrefixFileInfo = (ExternalFileInfoCollection) is.readObject();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   724
		compilerPrefixMacros = loadList(is, IDefine.class);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   725
		hrhFileInfo = (ExternalFileInfoCollection) is.readObject();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   726
		hrhFilesParsed = loadList(is, File.class);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   727
		variantHRHMacros = loadList(is, IDefine.class);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   728
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   729
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   730
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   731
	 * Read an IPath from a portable string
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   732
	 * @param is
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   733
	 * @return an IPath constructed from a String
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   734
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   735
	private IPath loadPath(ObjectInputStream is) throws IOException, ClassCastException, ClassNotFoundException {	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   736
		String path;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   737
		path = (String) is.readObject();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   738
		if (path != null)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   739
			return Path.fromPortableString(path);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   740
		return null;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   741
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   742
	
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   743
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   744
	 * Save an IPath as a portable string
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   745
	 * @param os
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   746
	 * @param path
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   747
	 * @throws IOException
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   748
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   749
	private void savePath(ObjectOutputStream os, IPath path) throws IOException {
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   750
		os.writeObject(path != null ? path.toPortableString() : null);
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   751
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   752
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   753
	/**
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   754
	 * Load a list from the object stream, throwing if it appears to contain
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   755
	 * the wrong kind of data.
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   756
	 * @param is
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   757
	 * @param klass
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   758
	 * @return a List or <code>null</code>
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   759
	 */
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   760
	@SuppressWarnings("unchecked")
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   761
	private <T> List<T> loadList(ObjectInputStream is, Class<T> klass) throws IOException, ClassCastException, ClassNotFoundException { 
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   762
		List<T> list = (List) is.readObject();
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   763
		if (list == null || klass == null || list.size() == 0)
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   764
			return list;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   765
		if (!klass.isInstance(list.get(0)))
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   766
			throw new IOException("Class contains " + list.get(0).getClass() + ", not " + klass); //$NON-NLS-1$ //$NON-NLS-2$
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   767
		return list;
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   768
	}
78fd666a897a Fix filesystem caching performance as in bug #10318
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   769
}