1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 import org.eclipse.ant.internal.ui.AntUtil; 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.variables.IStringVariableManager; 18 import org.eclipse.core.variables.VariablesPlugin; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate; 21 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 22 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 23 24 31 public class AntMigrationDelegate implements ILaunchConfigurationMigrationDelegate { 32 33 39 protected IFile getFileForCandidate(ILaunchConfiguration candidate) { 40 IFile file= null; 41 String expandedLocation= null; 42 String location= null; 43 IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); 44 try { 45 location= candidate.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String )null); 46 if (location != null) { 47 expandedLocation= manager.performStringSubstitution(location); 48 if (expandedLocation != null) { 49 file= AntUtil.getFileForLocation(expandedLocation, null); 50 } 51 } 52 } catch (CoreException e) { 53 } 54 return file; 55 } 56 57 60 public boolean isCandidate(ILaunchConfiguration candidate) throws CoreException { 61 IResource[] mappedResources = candidate.getMappedResources(); 62 if (mappedResources != null && mappedResources.length > 0) { 63 return false; 64 } 65 return getFileForCandidate(candidate) != null; 66 } 67 68 71 public void migrate(ILaunchConfiguration candidate) throws CoreException { 72 IFile file = getFileForCandidate(candidate); 73 ILaunchConfigurationWorkingCopy wc = candidate.getWorkingCopy(); 74 wc.setMappedResources(new IResource[] {file}); 75 wc.doSave(); 76 } 77 } | Popular Tags |