1 12 package org.eclipse.ui.externaltools.internal.launchConfigurations; 13 14 15 import java.io.File ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Path; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.core.variables.IStringVariableManager; 24 import org.eclipse.core.variables.VariablesPlugin; 25 import org.eclipse.debug.core.DebugPlugin; 26 import org.eclipse.debug.core.ILaunchConfiguration; 27 import org.eclipse.debug.ui.RefreshTab; 28 import org.eclipse.osgi.util.NLS; 29 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 30 31 37 public class ExternalToolsUtil { 38 39 48 protected static void abort(String message, Throwable exception, int code) throws CoreException { 49 throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, code, message, exception)); 50 } 51 52 64 public static IPath getLocation(ILaunchConfiguration configuration) throws CoreException { 65 String location = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String ) null); 66 if (location == null) { 67 abort(NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_Location_not_specified_by__0__1, new String [] { configuration.getName()}), null, 0); 68 } else { 69 String expandedLocation = getStringVariableManager().performStringSubstitution(location); 70 if (expandedLocation == null || expandedLocation.length() == 0) { 71 String msg = NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_invalidLocation__0_, new Object [] { configuration.getName()}); 72 abort(msg, null, 0); 73 } else { 74 File file = new File (expandedLocation); 75 if (file.isFile()) { 76 return new Path(expandedLocation); 77 } 78 79 String msg = NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_invalidLocation__0_, new Object [] { configuration.getName()}); 80 abort(msg, null, 0); 81 } 82 } 83 return null; 85 } 86 87 96 public static boolean getCaptureOutput(ILaunchConfiguration configuration) throws CoreException { 97 return configuration.getAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true); 98 } 99 100 114 public static IPath getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException { 115 String location = configuration.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String ) null); 116 if (location != null) { 117 String expandedLocation = getStringVariableManager().performStringSubstitution(location); 118 if (expandedLocation.length() > 0) { 119 File path = new File (expandedLocation); 120 if (path.isDirectory()) { 121 return new Path(expandedLocation); 122 } 123 String msg = NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_invalidDirectory__0_, new Object [] { expandedLocation, configuration.getName()}); 124 abort(msg, null, 0); 125 } 126 } 127 return null; 128 } 129 130 140 public static String [] getArguments(ILaunchConfiguration configuration) throws CoreException { 141 String args = configuration.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String ) null); 142 if (args != null) { 143 String expanded = getStringVariableManager().performStringSubstitution(args); 144 return parseStringIntoList(expanded); 145 } 146 return null; 147 } 148 149 private static IStringVariableManager getStringVariableManager() { 150 return VariablesPlugin.getDefault().getStringVariableManager(); 151 } 152 153 164 public static boolean isBuilderEnabled(ILaunchConfiguration configuration) throws CoreException { 165 return configuration.getAttribute(IExternalToolConstants.ATTR_BUILDER_ENABLED, true); 166 } 167 168 174 public static IResource[] getResourcesForBuildScope(ILaunchConfiguration configuration) throws CoreException { 175 String scope = configuration.getAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, (String ) null); 176 if (scope == null) { 177 return null; 178 } 179 180 return RefreshTab.getRefreshResources(scope); 181 } 182 183 194 public static String [] parseStringIntoList(String arguments) { 195 if (arguments == null || arguments.length() == 0) { 196 return new String [0]; 197 } 198 String [] res= DebugPlugin.parseArguments(arguments); 199 return res; 200 } 201 202 } 203 | Popular Tags |