funcTests: includes

This commit is contained in:
Kirill Kalishev
2011-08-17 13:52:53 +04:00
parent 5626c913af
commit de30404984
5 changed files with 84 additions and 12 deletions
@@ -1,6 +1,3 @@
%% Features tested:
%% - typahead in the "Goto class" dialog
%% - select in an unitialized project view pane (project, packages)
%action CloseProject
%call openProjectClone(../community/platform/funcTests/project1)
%action GotoClass
@@ -0,0 +1 @@
%include ../community/platform/funcTests/project1/module1/scripts/selectIn/projectView.ijs
@@ -44,10 +44,7 @@ public class PlaybackCallFacade {
public static AsyncResult<String> openProjectClone(final PlaybackContext context, String path) {
try {
File parentDir = FileUtil.createTempDirectory("funcTest", "");
File sourceDir = new File(path);
if (!sourceDir.isAbsolute()) {
sourceDir = new File(System.getProperty("work.dir"), path);
}
File sourceDir = getFile(path);
FileUtil.copyDir(sourceDir, parentDir);
File projectDir = new File(parentDir, sourceDir.getName());
@@ -57,7 +54,15 @@ public class PlaybackCallFacade {
return new AsyncResult.Rejected<String>("Cannot create temp directory for clone");
}
}
public static File getFile(String path) {
File sourceDir = new File(path);
if (!sourceDir.isAbsolute()) {
sourceDir = new File(System.getProperty("work.dir"), path);
}
return sourceDir;
}
public static AsyncResult<String> openProject(final PlaybackContext context, String path) {
final AsyncResult<String> result = new AsyncResult<String>();
final ProjectManager pm = ProjectManager.getInstance();
@@ -21,11 +21,14 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.ui.playback.commands.*;
import com.intellij.openapi.ui.playback.commands.ActionCommand;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.text.StringTokenizer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class PlaybackRunner {
@@ -113,12 +116,34 @@ public class PlaybackRunner {
}
private void parse() {
final StringTokenizer tokens = new StringTokenizer(myScript, "\n");
int line = 0;
includeScript(myScript, myCommands, 0);
}
private void includeScript(String scriptText, ArrayList<PlaybackCommand> commandList, int line) {
final StringTokenizer tokens = new StringTokenizer(scriptText, "\n");
while (tokens.hasMoreTokens()) {
final String eachLine = tokens.nextToken();
final PlaybackCommand cmd = createCommand(eachLine, line++);
myCommands.add(cmd);
String includeCmd = AbstractCommand.CMD_PREFIX + "include";
if (eachLine.startsWith(includeCmd)) {
File file = PlaybackCallFacade.getFile(eachLine.substring(includeCmd.length()).trim());
if (!file.exists()) {
commandList.add(new ErrorCommand("Cannot find file to include: " + file.getAbsolutePath(), line));
return;
}
try {
String include = FileUtil.loadFile(file);
myCommands.add(new PrintCommand(eachLine, line));
includeScript(include, commandList, 0);
}
catch (IOException e) {
commandList.add(new ErrorCommand("Error reading file: " + file.getAbsolutePath(), line));
return;
}
} else {
final PlaybackCommand cmd = createCommand(eachLine, line++);
commandList.add(cmd);
}
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.ui.playback.commands;
import com.intellij.openapi.ui.playback.PlaybackRunner;
import com.intellij.openapi.util.ActionCallback;
import java.awt.*;
/**
* Created by IntelliJ IDEA.
* User: kirillk
* Date: 8/17/11
* Time: 1:12 PM
* To change this template use File | Settings | File Templates.
*/
public class PrintCommand extends AbstractCommand {
private String myText;
public PrintCommand(String text, int line) {
super("", line);
myText = text;
}
@Override
protected ActionCallback _execute(PlaybackRunner.StatusCallback cb, Robot robot, boolean directActionCall) {
cb.message(myText, getLine());
return new ActionCallback.Done();
}
}