debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SymbianSourceContainer.java
author timkelly
Thu, 11 Mar 2010 13:45:01 -0600
changeset 1096 96e5879cd42d
child 2046 f375c7305c9d
permissions -rw-r--r--
Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
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 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
    21
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
    22
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
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.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
    24
import org.eclipse.core.runtime.IPath;
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.core.runtime.Path;
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.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
    27
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
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.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
    29
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    30
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    31
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    32
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
    33
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    34
/**
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    35
 * Used to attempt to map missing files to ones in EPOCROOT.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    36
 * For example, if source files are built on drive M but
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    37
 * the SDK and sources are on drive R then it will replace
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    38
 * the source's device ID with the EPOCROOT path and see
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    39
 * if the file exists. If so a path mapping entry will be 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    40
 * created to map from that drive to EPOCROOT.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    41
 */
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    42
public class SymbianSourceContainer extends MappingSourceContainer {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    43
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    44
	private Path epocRoot;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    45
	public static final String TYPE_ID = CarbideCommonDebuggerPlugin.PLUGIN_ID + ".containerType.mapping";	 //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    46
	public static final String CONTAINER_NAME = "Symbian SDK Root Locator";	 //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    47
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    48
	public SymbianSourceContainer(Path epocRoot)
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
		super(CONTAINER_NAME);
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    51
		this.epocRoot = epocRoot;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    52
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    53
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    54
	@Override
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    55
	public ISourceContainerType getType() {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    56
		return getSourceContainerType( TYPE_ID );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    57
	}
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
	protected Object[] findSourceElements(String name, ISourceContainer[] containers) 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
		Object[] result = super.findSourceElements(name, containers);
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    61
		if (result.length == 0)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    62
		{
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    63
			Path sourcePath = new Path( name );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    64
			MapEntrySourceContainer mapping = new MapEntrySourceContainer(sourcePath.uptoSegment(0), epocRoot);
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    65
			ISourceLookupDirector director = this.getDirector();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    66
			if (director != null)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    67
				mapping.init(director);
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    68
			result = mapping.findSourceElements(name);
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    69
			if (result.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
			{
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    71
				if (!mapping.getBackendPath().equals(mapping.getLocalPath())){
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    72
					addMapEntry(mapping);
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
				if (director != null)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    75
				{
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    76
					ILaunchConfigurationWorkingCopy configuration = director.getLaunchConfiguration().getWorkingCopy();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    77
					configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, director.getMemento());
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    78
					configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, director.getId());
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    79
					configuration.doSave();					
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
			}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    82
			else
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    83
			{
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    84
				// Check to see if this is an absolute path inside the SDK.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    85
				// Absolute paths are usually caught by the AbsolutePathSourceContainer but
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    86
				// if there is not one present then this will work for files in the SDK.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    87
				if (epocRoot.isPrefixOf(sourcePath))
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    88
				{
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    89
					result = new AbsolutePathSourceContainer().findSourceElements(name);
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    90
				}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    91
			}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    92
		}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    93
		return result;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    94
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    95
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    96
	public IPath getEpocRoot() {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    97
		return epocRoot;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    98
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    99
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
   100
}