| /******************************************************************************* |
| * Copyright (c) 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ant.internal.ui.debug; |
| |
| import org.eclipse.ant.internal.ui.AntUtil; |
| import org.eclipse.core.internal.variables.StringVariableManager; |
| import org.eclipse.core.resources.IContainer; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.debug.core.ILaunchConfiguration; |
| import org.eclipse.debug.core.sourcelookup.ISourceContainer; |
| import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate; |
| import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer; |
| import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; |
| import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; |
| import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; |
| |
| /** |
| * Computes the default source lookup path for an Ant launch configuration. |
| * The default source lookup path is the folder or project containing |
| * the Ant buildfile. If the program is not specified, the workspace |
| * is searched by default. |
| */ |
| public class AntSourcePathComputerDelegate implements ISourcePathComputerDelegate { |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor) |
| */ |
| public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { |
| String path = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String)null); |
| path= StringVariableManager.getDefault().performStringSubstitution(path); |
| ISourceContainer sourceContainer = null; |
| if (path != null) { |
| IResource resource = AntUtil.getFileForLocation(path, null); |
| if (resource != null) { |
| IContainer container = resource.getParent(); |
| if (container.getType() == IResource.PROJECT) { |
| sourceContainer = new ProjectSourceContainer((IProject)container, false); |
| } else if (container.getType() == IResource.FOLDER) { |
| sourceContainer = new FolderSourceContainer(container, false); |
| } |
| } |
| } |
| if (sourceContainer == null) { |
| sourceContainer = new WorkspaceSourceContainer(); |
| } |
| return new ISourceContainer[]{sourceContainer}; |
| } |
| } |