14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 package com.nokia.carbide.cpp.project.core; |
17 package com.nokia.carbide.cpp.project.core; |
18 |
18 |
19 import java.io.File; |
19 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
20 import java.util.List; |
20 import com.nokia.carbide.cdt.builder.EpocEngineHelper; |
21 import java.util.Map; |
21 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; |
|
22 import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo; |
|
23 import com.nokia.carbide.cpp.internal.api.project.core.ProjectCorePluginUtility; |
|
24 import com.nokia.carbide.cpp.internal.project.core.Messages; |
|
25 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext; |
|
26 import com.nokia.cpp.internal.api.utils.core.Logging; |
22 |
27 |
23 import org.eclipse.cdt.core.CCorePlugin; |
28 import org.eclipse.cdt.core.CCorePlugin; |
24 import org.eclipse.cdt.core.CProjectNature; |
29 import org.eclipse.cdt.core.CProjectNature; |
25 import org.eclipse.cdt.core.model.CoreModel; |
30 import org.eclipse.cdt.core.model.CoreModel; |
26 import org.eclipse.cdt.core.model.ICProject; |
31 import org.eclipse.cdt.core.model.ICProject; |
27 import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
32 import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
28 import org.eclipse.cdt.internal.core.model.CModelManager; |
33 import org.eclipse.cdt.internal.core.model.CModelManager; |
29 import org.eclipse.core.filesystem.URIUtil; |
34 import org.eclipse.core.filesystem.URIUtil; |
30 import org.eclipse.core.resources.IContainer; |
35 import org.eclipse.core.resources.*; |
31 import org.eclipse.core.resources.IProject; |
36 import org.eclipse.core.runtime.*; |
32 import org.eclipse.core.resources.IProjectDescription; |
|
33 import org.eclipse.core.resources.IResource; |
|
34 import org.eclipse.core.resources.IWorkspace; |
|
35 import org.eclipse.core.resources.IWorkspaceDescription; |
|
36 import org.eclipse.core.resources.ResourcesPlugin; |
|
37 import org.eclipse.core.runtime.CoreException; |
|
38 import org.eclipse.core.runtime.IPath; |
|
39 import org.eclipse.core.runtime.IProgressMonitor; |
|
40 import org.eclipse.core.runtime.IStatus; |
|
41 import org.eclipse.core.runtime.NullProgressMonitor; |
|
42 import org.eclipse.core.runtime.Path; |
|
43 import org.eclipse.core.runtime.Plugin; |
|
44 import org.eclipse.core.runtime.Status; |
|
45 import org.osgi.framework.BundleContext; |
37 import org.osgi.framework.BundleContext; |
46 |
38 |
47 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
39 import java.io.File; |
48 import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo; |
40 import java.text.MessageFormat; |
49 import com.nokia.carbide.cpp.internal.api.project.core.ProjectCorePluginUtility; |
41 import java.text.NumberFormat; |
50 import com.nokia.carbide.cpp.internal.project.core.Messages; |
42 import java.util.List; |
51 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext; |
43 import java.util.Map; |
52 import com.nokia.cpp.internal.api.utils.core.Logging; |
|
53 |
44 |
54 /** |
45 /** |
55 * The activator class controls the plug-in life cycle |
46 * The activator class controls the plug-in life cycle |
56 */ |
47 */ |
57 public class ProjectCorePlugin extends Plugin { |
48 public class ProjectCorePlugin extends Plugin { |
134 * @param location the full file system path where the .project file should be created. pass null to use the default location. |
127 * @param location the full file system path where the .project file should be created. pass null to use the default location. |
135 * @return the newly created IProject |
128 * @return the newly created IProject |
136 * @throws CoreException |
129 * @throws CoreException |
137 */ |
130 */ |
138 public static IProject createProject(String name, String location) throws CoreException { |
131 public static IProject createProject(String name, String location) throws CoreException { |
|
132 projectCreationStartTime = System.currentTimeMillis(); |
139 IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(name); |
133 IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(name); |
140 |
134 |
141 if (!projectHandle.exists()) { |
135 if (!projectHandle.exists()) { |
142 IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
136 IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
143 |
137 |
223 * The String value in pkgMappings is same as {@link ISISBuilderInfo#setPKGFile(String)} |
217 * The String value in pkgMappings is same as {@link ISISBuilderInfo#setPKGFile(String)} |
224 * @param monitor progress monitor for this operation. |
218 * @param monitor progress monitor for this operation. |
225 * @return the ICProject handle |
219 * @return the ICProject handle |
226 * @throws CoreException |
220 * @throws CoreException |
227 */ |
221 */ |
228 public static ICProject postProjectCreatedActions(IProject project, String projectRelativeBldInfPath, |
222 public static ICProject postProjectCreatedActions(final IProject project, String projectRelativeBldInfPath, |
229 List<ISymbianBuildContext> buildConfigs, List<String> infComponentsList, String debugMMP, |
223 List<ISymbianBuildContext> buildConfigs, List<String> infComponentsList, String debugMMP, |
230 Map<ISymbianBuildContext, String> pkgMappings, IProgressMonitor monitor) throws CoreException { |
224 Map<ISymbianBuildContext, String> pkgMappings, IProgressMonitor monitor) throws CoreException { |
231 |
225 |
232 if (project == null || !project.exists()) { |
226 if (project == null || !project.exists()) { |
233 throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, 0, "Invalid project passed into postProjectCreatedActions", null)); //$NON-NLS-1$ |
227 throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, 0, "Invalid project passed into postProjectCreatedActions", null)); //$NON-NLS-1$ |
296 } |
290 } |
297 |
291 |
298 workspaceDesc.setAutoBuilding(autoBuilding); |
292 workspaceDesc.setAutoBuilding(autoBuilding); |
299 workspace.setDescription(workspaceDesc); |
293 workspace.setDescription(workspaceDesc); |
300 |
294 |
|
295 reportProjectCreationStats(project); |
|
296 |
301 return cProject; |
297 return cProject; |
|
298 } |
|
299 |
|
300 private static void reportProjectCreationStats(final IProject project) { |
|
301 if (projectCreationStartTime < 0) |
|
302 return; |
|
303 |
|
304 Thread t = new Thread() { |
|
305 public void run() { |
|
306 long resourceCount = countResources(project); |
|
307 NumberFormat nfTime = NumberFormat.getNumberInstance(); |
|
308 nfTime.setMaximumFractionDigits(2); |
|
309 nfTime.setMinimumFractionDigits(2); |
|
310 double creationTime = (System.currentTimeMillis() - projectCreationStartTime) / 1000.0; |
|
311 int mmpCount = getMMPFileCount(project); |
|
312 log(new Status(IStatus.INFO, getUniqueId(), |
|
313 MessageFormat.format(Messages.getString("ProjectCorePlugin.ProjectCreationStatsFormat"), //$NON-NLS-1$ |
|
314 project.getName(), resourceCount, mmpCount, nfTime.format(creationTime)))); |
|
315 projectCreationStartTime = -1; |
|
316 } |
|
317 |
|
318 private int getMMPFileCount(final IProject project) { |
|
319 int mmpCount; |
|
320 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project); |
|
321 if (cpi.isBuildingFromInf()) |
|
322 mmpCount = EpocEngineHelper.getMMPFilesForProject(cpi).size(); |
|
323 else |
|
324 mmpCount = cpi.getNormalInfBuildComponents().size(); |
|
325 return mmpCount; |
|
326 } |
|
327 |
|
328 private long countResources(IProject project) { |
|
329 final long count[] = { 0 }; |
|
330 try { |
|
331 project.accept(new IResourceProxyVisitor() { |
|
332 public boolean visit(IResourceProxy proxy) throws CoreException { |
|
333 count[0]++; |
|
334 return true; |
|
335 } |
|
336 }, 0); |
|
337 } catch (CoreException e) { |
|
338 log(e); |
|
339 } |
|
340 return count[0]; |
|
341 } |
|
342 }; |
|
343 t.start(); |
302 } |
344 } |
303 |
345 |
304 public static void log(IStatus status) { |
346 public static void log(IStatus status) { |
305 Logging.log(plugin, status); |
347 Logging.log(plugin, status); |
306 } |
348 } |