debuggercdi/com.nokia.cdt.debug.cw.symbian/src/com/nokia/cdt/debug/cw/symbian/CarbideSourcePathComputerDelegate.java
changeset 0 fb279309251b
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2009 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 the License "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.cdt.debug.cw.symbian; 
       
    19 
       
    20 import java.util.ArrayList;
       
    21 
       
    22 import org.eclipse.cdt.debug.core.CDebugCorePlugin;
       
    23 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
       
    24 import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer;
       
    25 import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
       
    26 import org.eclipse.core.resources.IProject;
       
    27 import org.eclipse.core.resources.ResourcesPlugin;
       
    28 import org.eclipse.core.runtime.CoreException;
       
    29 import org.eclipse.core.runtime.IProgressMonitor;
       
    30 import org.eclipse.debug.core.ILaunchConfiguration;
       
    31 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
       
    32 import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
       
    33 import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
       
    34 import org.eclipse.core.runtime.Path;
       
    35 
       
    36 import com.freescale.cdt.debug.cw.core.CWPlugin;
       
    37 
       
    38 import cwdbg.PreferenceConstants;
       
    39 
       
    40 /**
       
    41  * Computes the default source lookup path for a launch configuration.
       
    42  */
       
    43 public class CarbideSourcePathComputerDelegate implements ISourcePathComputerDelegate {
       
    44 
       
    45 	/** 
       
    46 	 * Constructor for CSourcePathComputerDelegate. 
       
    47 	 */
       
    48 	public CarbideSourcePathComputerDelegate() {
       
    49 		super();
       
    50 	}
       
    51 
       
    52 	/* (non-Javadoc)
       
    53 	 * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
       
    54 	 */
       
    55 	public ISourceContainer[] computeSourceContainers( ILaunchConfiguration configuration, IProgressMonitor monitor ) throws CoreException {
       
    56 		ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers();
       
    57 		ArrayList<ISourceContainer> containers = new ArrayList<ISourceContainer>( common.length + 1 );
       
    58 		for ( int i = 0; i < common.length; ++i ) {
       
    59 			ISourceContainer sc = common[i];
       
    60 			if ( sc.getType().getId().equals( MappingSourceContainer.TYPE_ID ) )
       
    61 				sc = ((MappingSourceContainer)sc).copy();
       
    62 			containers.add( sc );
       
    63 		}
       
    64 		String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
       
    65 		if (projectName != null && projectName.length() > 0) {
       
    66 			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
       
    67 			if ( project.exists() ) {
       
    68 				containers.add( 0, new ProjectSourceContainer( project, true ) );
       
    69 			}
       
    70 		}
       
    71 		if (CWPlugin.getDefault().getPluginPreferences().getBoolean(
       
    72 				CWPlugin.PSC_FindSourceOutsideWorkspace))		
       
    73 			containers.add( 0, new AbsolutePathSourceContainer() );
       
    74 		return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] );
       
    75 	}
       
    76 }