0
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.appdep.core.model;
|
|
19 |
|
|
20 |
import java.util.ArrayList;
|
|
21 |
import java.util.Collection;
|
|
22 |
import java.util.HashMap;
|
|
23 |
import java.util.List;
|
|
24 |
import java.util.Map;
|
|
25 |
import java.util.NoSuchElementException;
|
|
26 |
|
|
27 |
import com.nokia.s60tools.appdep.core.job.IJobProgressStatus;
|
|
28 |
import com.nokia.s60tools.appdep.exceptions.InvalidModelDataException;
|
|
29 |
import com.nokia.s60tools.appdep.resources.Messages;
|
|
30 |
import com.nokia.s60tools.util.debug.DbgUtility;
|
|
31 |
import com.nokia.s60tools.util.exceptions.JobCancelledByUserException;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Model class instance representing data that is available via dependencies cache data file.
|
|
35 |
*/
|
|
36 |
public class DependenciesCache {
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Map that can be used to get cached component by using
|
|
40 |
* component name (=Filename) as key.
|
|
41 |
* All map keys should be stored in lower case.
|
|
42 |
*/
|
|
43 |
private Map<String, ComponentPropertiesData> componentPropertiesMap;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Constructor.
|
|
47 |
*/
|
|
48 |
public DependenciesCache(){
|
|
49 |
componentPropertiesMap = new HashMap<String, ComponentPropertiesData>();
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Adds given component properties data into model.
|
|
54 |
* @param cPropData Component properties data to be added.
|
|
55 |
*/
|
|
56 |
public void addComponentPropertiesData(ComponentPropertiesData cPropData,String targetPlatformId) {
|
|
57 |
String compName = cPropData.getFilename().toLowerCase(); // Map keys are always stored in lower case
|
|
58 |
if(componentPropertiesMap.get(compName) == null){
|
|
59 |
// Only accepting the 1st instance of a component with the same name
|
|
60 |
componentPropertiesMap.put(compName, cPropData);
|
|
61 |
}
|
|
62 |
else{
|
|
63 |
// Debug reporting duplicate
|
|
64 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "Duplicate component detected: "+ cPropData.getFilename()//$NON-NLS-1$
|
|
65 |
+" ["+targetPlatformId+"]");//$NON-NLS-1$ //$NON-NLS-2$
|
|
66 |
}
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Returns all component properties of the cache file.
|
|
72 |
* The collection is not ordered.
|
|
73 |
* @return All component properties of the cache file.
|
|
74 |
*/
|
|
75 |
public Collection<ComponentPropertiesData> getAllComponentProperties() {
|
|
76 |
return componentPropertiesMap.values();
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Gets component properties data object for given component.
|
|
81 |
* @param compName Name of the component to get properties data object for.
|
|
82 |
* @return Component properties data object for given component, or throws <code>NoSuchElementException</code>
|
|
83 |
* if component is not in cache.
|
|
84 |
* @throws NoSuchElementException
|
|
85 |
*/
|
|
86 |
public ComponentPropertiesData getComponentPropertiesData(String compName){
|
|
87 |
// Map keys are always stored in lower case
|
|
88 |
ComponentPropertiesData cmpPropData = componentPropertiesMap.get(compName.toLowerCase());
|
|
89 |
if(cmpPropData == null){
|
|
90 |
throw new NoSuchElementException(Messages.getString("DependenciesCache.ComponentNotFoundFromCache_ErrMsg") + ": '" + compName + "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
91 |
}
|
|
92 |
return cmpPropData;
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Gets the components that the given component directly depends upon.
|
|
97 |
* @param componentName The name of the component.
|
|
98 |
* @return Component properties data list.
|
|
99 |
*/
|
|
100 |
public List<UsedComponentData> getDirectlyDependentComponentsFor(String compToSearchFor) {
|
|
101 |
ComponentPropertiesData cmpPropData = getComponentPropertiesData(compToSearchFor);
|
|
102 |
return cmpPropData.getUsedComponentList();
|
|
103 |
}
|
|
104 |
|
|
105 |
/**
|
|
106 |
* Gets the functions that are imported from imported component for the use
|
|
107 |
* of parent component.
|
|
108 |
* @param parentCmpName Name of the parent component that imports the functions.
|
|
109 |
* @param importedCmpName Name of the component that the functions are imported from.
|
|
110 |
* @return Imported function data list.
|
|
111 |
*/
|
|
112 |
public Collection<ImportFunctionData> getParentImportedFunctionsForComponent(String parentCmpName, String importedCmpName) {
|
|
113 |
ComponentPropertiesData cmpPropData = getComponentPropertiesData(parentCmpName);
|
|
114 |
Collection<UsedComponentData> usedComponentList = cmpPropData.getUsedComponentList();
|
|
115 |
for (UsedComponentData usedComponentData : usedComponentList) {
|
|
116 |
String componentName = usedComponentData.getComponentName();
|
|
117 |
if(componentName.equalsIgnoreCase(importedCmpName)){
|
|
118 |
return usedComponentData.getParentImportedFunctions();
|
|
119 |
}
|
|
120 |
}
|
|
121 |
throw new NoSuchElementException(Messages.getString("DependenciesCache.ImportedComponentNotFoundFromCache_ErrMsgStart") + importedCmpName //$NON-NLS-1$
|
|
122 |
+ Messages.getString("DependenciesCache.ImportedComponentNotFoundFromCache_ErrMsgEnd") //$NON-NLS-1$
|
|
123 |
+ parentCmpName + "'."); //$NON-NLS-1$
|
|
124 |
}
|
|
125 |
|
|
126 |
/**
|
|
127 |
* Gets the string array of component properties for the components
|
|
128 |
* that are using the given component.
|
|
129 |
* @param progressCallback Job progress callback object that can be used to report progress.
|
|
130 |
* Can be set to <code>null</code> when no progress information is needed.
|
|
131 |
* @param resultComponentsArrayList Array list object to return resulting components into.
|
|
132 |
* @param componentName Name of the component to search using components for.
|
|
133 |
* @param functionOrdinal Ordinal of the function to search using components for.
|
|
134 |
* This parameter can be set to <code>null</code> if we are
|
|
135 |
* only interested in components that are using the given component.
|
|
136 |
* @param totalComponentCount Total component count forming possibly from several caches.
|
|
137 |
* @throws JobCancelledByUserException
|
|
138 |
*/
|
|
139 |
public void getUsingComponents(IJobProgressStatus progressCallback,
|
|
140 |
ArrayList<ComponentPropertiesData> resultComponentsArrayList,
|
|
141 |
String componentName, String functionOrdinal,
|
|
142 |
int totalComponentCount) throws JobCancelledByUserException {
|
|
143 |
|
|
144 |
boolean reportProgress = (progressCallback != null) && (totalComponentCount > 0);
|
|
145 |
|
|
146 |
// Variables used to inform about the progress
|
|
147 |
final int hundred = 100;
|
|
148 |
// Calculating 10 percentage of components from all the components in cache
|
|
149 |
int hundredComponentsAsPercentage = reportProgress ? (hundred * hundred) / totalComponentCount: 0;
|
|
150 |
int totalPercentage = 0;
|
|
151 |
int componentCount = 0;
|
|
152 |
|
|
153 |
boolean isFunctionUsageCheck = (functionOrdinal != null);
|
|
154 |
Collection<ComponentPropertiesData> componentsColl = componentPropertiesMap.values();
|
|
155 |
for (ComponentPropertiesData cmpPropData : componentsColl) {
|
|
156 |
// Reporting progress if queried about the seeking of using components
|
|
157 |
if(reportProgress){
|
|
158 |
// Updating component count
|
|
159 |
componentCount++;
|
|
160 |
// Informing about the progress
|
|
161 |
if((componentCount % hundred) == 0){
|
|
162 |
totalPercentage = totalPercentage + hundredComponentsAsPercentage;
|
|
163 |
progressCallback.progress(totalPercentage, null);
|
|
164 |
}
|
|
165 |
}
|
|
166 |
boolean isMatch = cmpPropData.usesComponent(componentName);
|
|
167 |
if(isMatch){
|
|
168 |
// This component is using the queried component
|
|
169 |
if(isFunctionUsageCheck){
|
|
170 |
UsedComponentData usedCmpData = cmpPropData.getUsedComponent(componentName);
|
|
171 |
Collection<ImportFunctionData> parentImportedFunctions = usedCmpData.getParentImportedFunctions();
|
|
172 |
for (ImportFunctionData importFunctionData : parentImportedFunctions) {
|
|
173 |
String functionOrdinalToCompare = importFunctionData.getFunctionOrdinal();
|
|
174 |
if(functionOrdinalToCompare.equals(functionOrdinal)){
|
|
175 |
// This component is using the queried function
|
|
176 |
resultComponentsArrayList.add(cmpPropData);
|
|
177 |
break; // We can break this inner for loop and continue outermost one
|
|
178 |
}
|
|
179 |
}
|
|
180 |
}
|
|
181 |
else{
|
|
182 |
// This component is using the queried component
|
|
183 |
resultComponentsArrayList.add(cmpPropData);
|
|
184 |
}
|
|
185 |
}
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
}
|
|
190 |
|