mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Moved the new static methods from AbstractCLaunchDelegate to the new utility class.
This commit is contained in:
parent
f47d98447d
commit
f9fa5b5f7f
3 changed files with 151 additions and 107 deletions
|
@ -1,3 +1,8 @@
|
|||
2006-05-17 Mikhail Khodjaiants
|
||||
Moved the new static methods from AbstractCLaunchDelegate to the new utility class.
|
||||
* AbstractCLaunchDelegate.java
|
||||
+ LaunchUtils.java
|
||||
|
||||
2006-04-03 Mikhail Khodjaiants
|
||||
Fix for bug 134581: Unable to set advanced debugger options.
|
||||
* CDebuggerTab.java
|
||||
|
|
|
@ -53,8 +53,6 @@ import org.eclipse.core.runtime.IStatus;
|
|||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.variables.IStringVariableManager;
|
||||
import org.eclipse.core.variables.VariablesPlugin;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
@ -127,7 +125,7 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
|
|||
protected IPath getWorkingDirectoryPath(ILaunchConfiguration config) throws CoreException {
|
||||
String location = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null);
|
||||
if (location != null) {
|
||||
String expandedLocation = getStringVariableManager().performStringSubstitution(location);
|
||||
String expandedLocation = LaunchUtils.getStringVariableManager().performStringSubstitution(location);
|
||||
if (expandedLocation.length() > 0) {
|
||||
return new Path(expandedLocation);
|
||||
}
|
||||
|
@ -191,10 +189,6 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
|
|||
return new Path(path);
|
||||
}
|
||||
|
||||
private static IStringVariableManager getStringVariableManager() {
|
||||
return VariablesPlugin.getDefault().getStringVariableManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param launch
|
||||
* @param config
|
||||
|
@ -249,29 +243,16 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
|
|||
* @return the program arguments as a String
|
||||
*/
|
||||
public static String getProgramArguments(ILaunchConfiguration config) throws CoreException {
|
||||
String args = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
|
||||
if (args != null) {
|
||||
args = getStringVariableManager().performStringSubstitution(args);
|
||||
}
|
||||
return args;
|
||||
|
||||
return LaunchUtils.getProgramArguments(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the program arguments as an array of individual arguments.
|
||||
*
|
||||
* @return the program arguments as an array of individual arguments
|
||||
*/
|
||||
public static String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException {
|
||||
return parseArguments(getProgramArguments(config));
|
||||
}
|
||||
|
||||
private static String[] parseArguments(String args) {
|
||||
if (args == null)
|
||||
return new String[0];
|
||||
ArgumentParser parser = new ArgumentParser(args);
|
||||
String[] res = parser.parseArguments();
|
||||
|
||||
return res;
|
||||
public String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException {
|
||||
return LaunchUtils.getProgramArgumentsArray(config);
|
||||
}
|
||||
|
||||
protected ICDebugConfiguration getDebugConfig(ILaunchConfiguration config) throws CoreException {
|
||||
|
@ -446,89 +427,6 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
|
|||
return null;
|
||||
}
|
||||
|
||||
private static class ArgumentParser {
|
||||
|
||||
private String fArgs;
|
||||
private int fIndex = 0;
|
||||
private int ch = -1;
|
||||
|
||||
public ArgumentParser(String args) {
|
||||
fArgs = args;
|
||||
}
|
||||
|
||||
public String[] parseArguments() {
|
||||
ArrayList v = new ArrayList();
|
||||
|
||||
ch = getNext();
|
||||
while (ch > 0) {
|
||||
while (Character.isWhitespace((char)ch))
|
||||
ch = getNext();
|
||||
|
||||
if (ch == '"') {
|
||||
v.add(parseString());
|
||||
} else {
|
||||
v.add(parseToken());
|
||||
}
|
||||
}
|
||||
|
||||
String[] result = new String[v.size()];
|
||||
v.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private int getNext() {
|
||||
if (fIndex < fArgs.length())
|
||||
return fArgs.charAt(fIndex++);
|
||||
return -1;
|
||||
}
|
||||
|
||||
private String parseString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
ch = getNext();
|
||||
while (ch > 0 && ch != '"') {
|
||||
if (ch == '\\') {
|
||||
ch = getNext();
|
||||
if (ch != '"') { // Only escape double quotes
|
||||
buf.append('\\');
|
||||
}
|
||||
}
|
||||
if (ch > 0) {
|
||||
buf.append((char)ch);
|
||||
ch = getNext();
|
||||
}
|
||||
}
|
||||
|
||||
ch = getNext();
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private String parseToken() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
while (ch > 0 && !Character.isWhitespace((char)ch)) {
|
||||
if (ch == '\\') {
|
||||
ch = getNext();
|
||||
if (ch > 0) {
|
||||
if (ch != '"') { // Only escape double quotes
|
||||
buf.append('\\');
|
||||
}
|
||||
buf.append((char)ch);
|
||||
ch = getNext();
|
||||
} else if (ch == -1) { // Don't lose a trailing backslash
|
||||
buf.append('\\');
|
||||
}
|
||||
} else if (ch == '"') {
|
||||
buf.append(parseString());
|
||||
} else {
|
||||
buf.append((char)ch);
|
||||
ch = getNext();
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively creates a set of projects referenced by the current project
|
||||
*
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.variables.IStringVariableManager;
|
||||
import org.eclipse.core.variables.VariablesPlugin;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
/**
|
||||
* Utility methods.
|
||||
*/
|
||||
public class LaunchUtils {
|
||||
|
||||
private static class ArgumentParser {
|
||||
|
||||
private String fArgs;
|
||||
|
||||
private int fIndex = 0;
|
||||
|
||||
private int ch = -1;
|
||||
|
||||
public ArgumentParser( String args ) {
|
||||
fArgs = args;
|
||||
}
|
||||
|
||||
public String[] parseArguments() {
|
||||
ArrayList v = new ArrayList();
|
||||
ch = getNext();
|
||||
while( ch > 0 ) {
|
||||
while( Character.isWhitespace( (char)ch ) )
|
||||
ch = getNext();
|
||||
if ( ch == '"' ) {
|
||||
v.add( parseString() );
|
||||
}
|
||||
else {
|
||||
v.add( parseToken() );
|
||||
}
|
||||
}
|
||||
String[] result = new String[v.size()];
|
||||
v.toArray( result );
|
||||
return result;
|
||||
}
|
||||
|
||||
private int getNext() {
|
||||
if ( fIndex < fArgs.length() )
|
||||
return fArgs.charAt( fIndex++ );
|
||||
return -1;
|
||||
}
|
||||
|
||||
private String parseString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
ch = getNext();
|
||||
while( ch > 0 && ch != '"' ) {
|
||||
if ( ch == '\\' ) {
|
||||
ch = getNext();
|
||||
if ( ch != '"' ) { // Only escape double quotes
|
||||
buf.append( '\\' );
|
||||
}
|
||||
}
|
||||
if ( ch > 0 ) {
|
||||
buf.append( (char)ch );
|
||||
ch = getNext();
|
||||
}
|
||||
}
|
||||
ch = getNext();
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private String parseToken() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while( ch > 0 && !Character.isWhitespace( (char)ch ) ) {
|
||||
if ( ch == '\\' ) {
|
||||
ch = getNext();
|
||||
if ( ch > 0 ) {
|
||||
if ( ch != '"' ) { // Only escape double quotes
|
||||
buf.append( '\\' );
|
||||
}
|
||||
buf.append( (char)ch );
|
||||
ch = getNext();
|
||||
}
|
||||
else if ( ch == -1 ) { // Don't lose a trailing backslash
|
||||
buf.append( '\\' );
|
||||
}
|
||||
}
|
||||
else if ( ch == '"' ) {
|
||||
buf.append( parseString() );
|
||||
}
|
||||
else {
|
||||
buf.append( (char)ch );
|
||||
ch = getNext();
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For given launch configuration returns the program arguments as
|
||||
* an array of individual arguments.
|
||||
*/
|
||||
public static String[] getProgramArgumentsArray( ILaunchConfiguration config ) throws CoreException {
|
||||
return parseArguments( getProgramArguments( config ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the program arguments as a String.
|
||||
*/
|
||||
public static String getProgramArguments(ILaunchConfiguration config) throws CoreException {
|
||||
String args = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
|
||||
if (args != null) {
|
||||
args = getStringVariableManager().performStringSubstitution(args);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*/
|
||||
public static IStringVariableManager getStringVariableManager() {
|
||||
return VariablesPlugin.getDefault().getStringVariableManager();
|
||||
}
|
||||
|
||||
private static String[] parseArguments( String args ) {
|
||||
if ( args == null )
|
||||
return new String[0];
|
||||
ArgumentParser parser = new ArgumentParser( args );
|
||||
String[] res = parser.parseArguments();
|
||||
return res;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue