Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2011-12-14 11:08:04 +0000
committerUwe Stieber2011-12-14 11:08:04 +0000
commit29478972c85f3252a3ec256abac992547d561b1d (patch)
tree103be2c027ab5a3185d618f2146f78bd770d41f3 /target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting
parentb858131d302f6fefc5c44ea4defeb88a06499749 (diff)
downloadorg.eclipse.tcf-29478972c85f3252a3ec256abac992547d561b1d.tar.gz
org.eclipse.tcf-29478972c85f3252a3ec256abac992547d561b1d.tar.xz
org.eclipse.tcf-29478972c85f3252a3ec256abac992547d561b1d.zip
Target Explorer: Fix basic script execution
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/META-INF/MANIFEST.MF5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java62
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.properties2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java83
5 files changed, 147 insertions, 7 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/META-INF/MANIFEST.MF
index 8be76668f..6d7c73bcc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/META-INF/MANIFEST.MF
@@ -12,3 +12,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
+Export-Package: org.eclipse.tcf.te.tcf.core.scripting.activator;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.scripting.interfaces,
+ org.eclipse.tcf.te.tcf.core.scripting.launcher,
+ org.eclipse.tcf.te.tcf.core.scripting.nls;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.scripting.parser
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java
index 24b4cb2d1..49532097f 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java
@@ -16,9 +16,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.core.Command;
import org.eclipse.tcf.protocol.IChannel;
import org.eclipse.tcf.protocol.IChannel.IChannelListener;
import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.IService;
import org.eclipse.tcf.te.runtime.callback.Callback;
import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
@@ -163,7 +165,7 @@ public class ScriptLauncher extends PlatformObject implements IScriptLauncher {
/**
* Executes the script launch.
*/
- protected void executeLaunch() {
+ protected void executeLaunch() {
// Get the script properties container
final IPropertiesContainer properties = getProperties();
if (properties == null) {
@@ -188,10 +190,68 @@ public class ScriptLauncher extends PlatformObject implements IScriptLauncher {
// Create the script parser instance
Parser parser = new Parser(script);
try {
+ // Parse the script
Token[] tokens = parser.parse();
+
+ // And execute the tokens extracted, one by one sequentially
+ if (tokens != null && tokens.length > 0) {
+ executeToken(tokens, 0);
+ } else {
+ invokeCallback(Status.OK_STATUS, null);
+ return;
+ }
} catch (IOException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.ScriptLauncher_error_parsingScript, e.getLocalizedMessage()),
+ e);
+ invokeCallback(status, null);
+ return;
+ }
+ }
+ /**
+ * Executes the token at the given index.
+ *
+ * @param tokens The tokens. Must not be <code>null</code>.
+ * @param index The index.
+ */
+ @SuppressWarnings("unused")
+ protected void executeToken(final Token[] tokens, final int index) {
+ Assert.isNotNull(tokens);
+
+ if (index < 0 || index >= tokens.length) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.ScriptLauncher_error_illegalIndex, Integer.valueOf(index)),
+ new IllegalArgumentException("index")); //$NON-NLS-1$
+ invokeCallback(status, null);
+ return;
}
+
+ Token token = tokens[index];
+
+ IService service = channel.getRemoteService(token.getServiceName());
+ new Command(channel, service, token.getCommandName(), token.getArguments()) {
+
+ @Override
+ public void done(Exception error, Object[] args) {
+ if (error == null) {
+ // Execute the next token
+ int nextIndex = index + 1;
+ if (nextIndex == tokens.length) {
+ // All tokens executed
+ invokeCallback(Status.OK_STATUS, null);
+ } else {
+ executeToken(tokens, nextIndex);
+ }
+ } else {
+ // Stop the execution
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.ScriptLauncher_error_parsingScript, error.getLocalizedMessage()),
+ error);
+ invokeCallback(status, null);
+ }
+ }
+ };
}
/**
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.java
index 66faf9001..913c19ddd 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.java
@@ -33,5 +33,7 @@ public class Messages extends NLS {
public static String ScriptLauncher_error_channelNotConnected;
public static String ScriptLauncher_error_missingScript;
public static String ScriptLauncher_error_illegalNullArgument;
+ public static String ScriptLauncher_error_illegalIndex;
public static String ScriptLauncher_error_parsingScript;
+ public static String ScriptLauncher_error_executionFailed;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.properties
index a49ef82fa..331c80c58 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/nls/Messages.properties
@@ -7,4 +7,6 @@ ScriptLauncher_error_channelConnectFailed=Failed to connect channel for peer ''{
ScriptLauncher_error_channelNotConnected=Channel is not connected!
ScriptLauncher_error_missingScript=Illegal argument: Script must be specified!
ScriptLauncher_error_illegalNullArgument=Illegal argument: ''{0}'' has to be not null.
+ScriptLauncher_error_illegalIndex=Illegal index ''{0}''.
ScriptLauncher_error_parsingScript=Parsing of the script failed.\n\nPossible Cause:\n{0}
+ScriptLauncher_error_executionFailed=Script execution failed.\n\nPossible Cause:\n{0}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java
index 409c9e1ca..087765d99 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java
@@ -19,6 +19,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.protocol.JSON;
/**
* Script parser implementation.
@@ -73,6 +74,9 @@ public class Parser {
// Parse the arguments
parseArguments(token, arguments);
+
+ // Add the token to the list
+ tokens.add(token);
}
}
@@ -101,6 +105,25 @@ public class Parser {
String tok = tokenizer.nextToken();
if (tok == null || "".equals(tok.trim())) continue; //$NON-NLS-1$
+ if (tok.startsWith("\"")) { //$NON-NLS-1$
+ // String type
+
+ String fullTok = tok;
+ boolean complete = isComplete(fullTok, '"', '"');
+ while (!complete && tokenizer.hasMoreTokens()) {
+ fullTok = fullTok + " " + tokenizer.nextToken(); //$NON-NLS-1$
+ complete = isComplete(fullTok, '"', '"');
+ }
+
+ if (complete) {
+ fullTok = fullTok.trim();
+ if (fullTok.startsWith("\"")) fullTok = fullTok.substring(1); //$NON-NLS-1$
+ if (fullTok.endsWith("\"")) fullTok = fullTok.substring(0, fullTok.length() - 1); //$NON-NLS-1$
+ token.addArgument(fullTok);
+ continue;
+ }
+ }
+
if ("true".equalsIgnoreCase(tok) || "false".equalsIgnoreCase(tok)) { //$NON-NLS-1$ //$NON-NLS-2$
token.addArgument(Boolean.valueOf(tok));
continue;
@@ -110,33 +133,73 @@ public class Parser {
Integer i = Integer.decode(tok);
token.addArgument(i);
continue;
- } catch (NumberFormatException e) {}
+ } catch (NumberFormatException e) { /* ignored on purpose */ }
try {
Long l = Long.decode(tok);
token.addArgument(l);
continue;
- } catch (NumberFormatException e) {}
+ } catch (NumberFormatException e) { /* ignored on purpose */ }
try {
Float f = Float.valueOf(tok);
token.addArgument(f);
continue;
- } catch (NumberFormatException e) {}
+ } catch (NumberFormatException e) { /* ignored on purpose */ }
try {
Double d = Double.valueOf(tok);
token.addArgument(d);
continue;
- } catch (NumberFormatException e) {}
+ } catch (NumberFormatException e) { /* ignored on purpose */ }
// If it starts with '{' or '[', it's a map or list type
if (tok.startsWith("{")) { //$NON-NLS-1$
// Map type
+
+ String fullTok = tok;
+ boolean complete = isComplete(fullTok, '{', '}');
+ while (!complete && tokenizer.hasMoreTokens()) {
+ fullTok = fullTok + " " + tokenizer.nextToken(); //$NON-NLS-1$
+ complete = isComplete(fullTok, '{', '}');
+ }
+
+ if (complete) {
+ fullTok = fullTok + "\0"; //$NON-NLS-1$
+ try {
+ Object[] args = JSON.parseSequence(fullTok.getBytes());
+ if (args != null) {
+ for (Object arg : args) {
+ if (arg != null) token.addArgument(arg);
+ }
+ continue;
+ }
+ } catch (IOException e) { /* ignored on purpose */ e.printStackTrace(); }
+ }
}
if (tok.startsWith("[")) { //$NON-NLS-1$
// List type
+
+ String fullTok = tok;
+ boolean complete = isComplete(fullTok, '[', ']');
+ while (!complete && tokenizer.hasMoreTokens()) {
+ fullTok = fullTok + " " + tokenizer.nextToken(); //$NON-NLS-1$
+ complete = isComplete(fullTok, '[', ']');
+ }
+
+ if (complete) {
+ fullTok = fullTok + "\0"; //$NON-NLS-1$
+ try {
+ Object[] args = JSON.parseSequence(fullTok.getBytes());
+ if (args != null) {
+ for (Object arg : args) {
+ if (arg != null) token.addArgument(arg);
+ }
+ continue;
+ }
+ } catch (IOException e) { /* ignored on purpose */ }
+ }
}
// Add the argument token as is
@@ -160,10 +223,18 @@ public class Parser {
int countOpening = 0;
int countClosing = 0;
+ boolean same = opening == closing;
+
for (int i = 0; i < tok.length(); i++) {
char c = tok.charAt(i);
- if (c == opening) { countOpening++; continue; }
- if (c == closing) { countClosing++; continue; }
+
+ if (c == opening && same) {
+ if (countOpening > countClosing) countClosing++;
+ else countOpening++;
+ } else {
+ if (c == opening) { countOpening++; continue; }
+ if (c == closing) { countClosing++; continue; }
+ }
}
return countOpening > 0 && countOpening == countClosing;

Back to the top