KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > launchConfigurations > AntMigrationDelegate


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
25  * Delegate for migrating Ant launch configurations.
26  * The migration process involves a resource mapping being created such that launch configurations
27  * can be filtered from the launch configuration dialog based on resource availability.
28  *
29  * @since 3.2
30  */

31 public class AntMigrationDelegate implements ILaunchConfigurationMigrationDelegate {
32     
33     /**
34      * Method to get the file for the specified launch configuration that should be mapped to the launch configuration
35      *
36      * @param candidate the launch configuration that the file will be mapped to.
37      * @return the buildfile or <code>null</code> if not in the workspace
38      */

39     protected IFile getFileForCandidate(ILaunchConfiguration candidate) {
40         IFile file= null;
41         String JavaDoc expandedLocation= null;
42         String JavaDoc location= null;
43         IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
44         try {
45             location= candidate.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String JavaDoc)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     /* (non-Javadoc)
58      * @see org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate#isCandidate()
59      */

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     /* (non-Javadoc)
69      * @see org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate#migrate(org.eclipse.debug.core.ILaunchConfiguration)
70      */

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