debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/CarbideSourcePathComputerDelegate.java
author timkelly
Fri, 12 Mar 2010 14:18:47 -0600
changeset 1103 a5d7a2345c4a
parent 1096 96e5879cd42d
permissions -rw-r--r--
fix global carbide debugger prefs read by using proper plugin id for which prefs were written
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1096
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     1
/*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     3
* All rights reserved.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     4
* This component and the accompanying materials are made available
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     6
* which accompanies this distribution, and is available
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     8
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     9
* Initial Contributors:
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    11
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    12
* Contributors:
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    13
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    14
* Description: 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    15
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    16
*/
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    17
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    18
package com.nokia.cdt.debug.common.internal.source.lookup; 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    19
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    20
import java.util.ArrayList;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    21
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    22
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    23
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    24
import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    25
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    26
import org.eclipse.core.resources.IProject;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    27
import org.eclipse.core.resources.ResourcesPlugin;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    28
import org.eclipse.core.runtime.CoreException;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    29
import org.eclipse.core.runtime.IProgressMonitor;
1103
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    30
import org.eclipse.core.runtime.Platform;
1096
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    31
import org.eclipse.debug.core.ILaunchConfiguration;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    32
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    33
import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    34
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    35
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    36
import com.nokia.cdt.debug.common.CarbideCommonDebuggerPlugin;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    37
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    38
/**
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    39
 * Computes the default source lookup path for a launch configuration.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    40
 */
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    41
public class CarbideSourcePathComputerDelegate implements ISourcePathComputerDelegate {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    42
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    43
	/** From legacy DE support. */
1103
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    44
	public static final String PSC_FindSourceOutsideWorkspace = "com.freescale.cdt.debug.cw.PN_FindSourceOutsideWorkspace"; // $//$NON-NLS-N$
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    45
	
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    46
	/** Plugin ID to look up Carbide global debugger prefs */
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    47
	public static final String CWPluginID = "com.freescale.cdt.debug.cw.core"; // $//$NON-NLS-N$
1096
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    48
	
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    49
	/** 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    50
	 * Constructor for CSourcePathComputerDelegate. 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    51
	 */
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    52
	public CarbideSourcePathComputerDelegate() {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    53
		super();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    54
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    55
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    56
	/* (non-Javadoc)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    57
	 * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    58
	 */
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    59
	public ISourceContainer[] computeSourceContainers( ILaunchConfiguration configuration, IProgressMonitor monitor ) throws CoreException {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    60
		ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    61
		ArrayList<ISourceContainer> containers = new ArrayList<ISourceContainer>( common.length + 1 );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    62
		for ( int i = 0; i < common.length; ++i ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    63
			ISourceContainer sc = common[i];
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    64
			if ( sc.getType().getId().equals( MappingSourceContainer.TYPE_ID ) )
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    65
				sc = ((MappingSourceContainer)sc).copy();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    66
			containers.add( sc );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    67
		}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    68
		String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    69
		if (projectName != null && projectName.length() > 0) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    70
			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    71
			if ( project.exists() ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    72
				containers.add( 0, new ProjectSourceContainer( project, true ) );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    73
			}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    74
		}
1103
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    75
		
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    76
		if (Platform.getPreferencesService().getBoolean( CWPluginID, PSC_FindSourceOutsideWorkspace, false, null)){
1096
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    77
			containers.add( 0, new AbsolutePathSourceContainer() );
1103
a5d7a2345c4a fix global carbide debugger prefs read by using proper plugin id for which prefs were written
timkelly
parents: 1096
diff changeset
    78
		}
1096
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    79
		return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    80
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    81
}