eclipse plugin: better way of running wmlscope,

...so the user can get some feedback
This commit is contained in:
Timotei Dolean 2010-07-10 13:24:11 +00:00
parent deaf903e25
commit 92c0aca656
13 changed files with 450 additions and 271 deletions

View file

@ -57,13 +57,13 @@
</groupMarker>
</menu>
<action
class="wesnoth_eclipse_plugin.action.RunWMLScopeOnSelection"
class="wesnoth_eclipse_plugin.action.RunWMLIndentOnSelection"
id="action.proj.wmlindent"
label="Run &quot;wmlindent&quot; on the project this file"
menubarPath="plugin.wmltoolsProjMenu/wmltoolsProjMenuMarker">
</action>
<action
class="wesnoth_eclipse_plugin.action.RunWMLIndentOnSelection"
class="wesnoth_eclipse_plugin.action.RunWMLScopeOnSelection"
id="action.proj.wmlscope"
label="Run &quot;wmlscope&quot; on the project"
menubarPath="plugin.wmltoolsProjMenu/wmltoolsProjMenuMarker">

View file

@ -18,4 +18,9 @@ public class Constants
public static final int WIZ_MaxGroupsOnPage = 4;
public static final int WIZ_MaxWizardPageHeight = 220;
/** Tool invoker constants **/
public static final int TI_SHOW_OUTPUT = 1;
public static final int TI_SHOW_OUTPUT_USER = 2;
//public static final byte SHOW_OUTPUT = 4;
}

View file

@ -19,12 +19,12 @@ import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
public class OpenScenarioInGame implements IObjectActionDelegate
{
public OpenScenarioInGame()
{
public OpenScenarioInGame() {
}
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart){
public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
}
@Override
@ -35,7 +35,7 @@ public class OpenScenarioInGame implements IObjectActionDelegate
WorkspaceUtils.getSelectedFolder() == null)
{
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(),
"Please select a campaign or a resource inside the campaign project before.");
"Please select a campaign or a resource inside the campaign project before.");
return;
}
@ -50,7 +50,8 @@ public class OpenScenarioInGame implements IObjectActionDelegate
return;
}
try{
try
{
String campaignId = ProjectUtils.getCampaignID();
String scenarioId = ProjectUtils.getScenarioID(WorkspaceUtils.getPathRelativeToUserDir(selectedFile));
@ -69,19 +70,20 @@ public class OpenScenarioInGame implements IObjectActionDelegate
String workingDir = Preferences.getString(Constants.P_WESNOTH_WORKING_DIR);
if (workingDir.isEmpty())
workingDir = wesnothExec.substring(0,wesnothExec.lastIndexOf(new File(wesnothExec).getName()));
workingDir = wesnothExec.substring(0, wesnothExec.lastIndexOf(new File(wesnothExec).getName()));
// we need to add the working dir (backward compatibility)
args.add(workingDir);
System.out.printf("Launching args: %s \n", args);
ExternalToolInvoker.launchTool(wesnothExec, args, true, false,true, WorkspaceUtils.getWorkbenchWindow());
}
catch (Exception e) {
ExternalToolInvoker.launchTool(wesnothExec, args, Constants.TI_SHOW_OUTPUT | Constants.TI_SHOW_OUTPUT_USER, true);
} catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void selectionChanged(IAction action, ISelection selection){
public void selectionChanged(IAction action, ISelection selection)
{
}
}

View file

@ -5,15 +5,16 @@ package wesnoth_eclipse_plugin.action;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.progress.WorkbenchJob;
import wesnoth_eclipse_plugin.utils.EditorUtils;
import wesnoth_eclipse_plugin.utils.WMLTools;
@ -33,41 +34,47 @@ public class RunWMLIndentOnSelection implements IObjectActionDelegate
@Override
public void run(IAction action)
{
WorkbenchJob job = new WorkbenchJob("Running WMLIndent") {
WorkspaceJob job = new WorkspaceJob("Running WMLIndent") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
public IStatus runInWorkspace(final IProgressMonitor monitor)
{
final IEditorReference[] files =
WorkspaceUtils.getWorkbenchWindow().getPages()[0].getEditorReferences();
monitor.beginTask("wmlindent", files.length * 5 + 50);
monitor.subTask("saving files...");
for (IEditorReference file : files)
{
monitor.worked(5);
if (file.isDirty())
file.getEditor(false).doSave(null);
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run()
{
monitor.subTask("saving files...");
for (IEditorReference file : files)
{
monitor.worked(5);
if (file.isDirty())
file.getEditor(false).doSave(null);
}
IFile selFile = WorkspaceUtils.getSelectedFile();
monitor.subTask("wmlindent");
if (selFile != null)
{
EditorUtils.openEditor(selFile, true);
String stdin = EditorUtils.getEditorDocument().get();
EditorUtils.replaceEditorText(WMLTools.runWMLIndent(null, stdin, false, false, false));
}
else
// project selection
{
// run wmlindent on project
IProject project = WorkspaceUtils.getSelectedProject();
WMLTools.runWMLIndent(project.getLocation().toOSString(), null, false, true, false);
}
monitor.worked(50);
IFile selFile = WorkspaceUtils.getSelectedFile();
monitor.subTask("wmlindent");
if (selFile != null)
{
EditorUtils.openEditor(selFile, true);
String stdin = EditorUtils.getEditorDocument().get();
EditorUtils.replaceEditorText(WMLTools.runWMLIndent(null, stdin, false, false, false));
}
else
// project selection
{
// run wmlindent on project
IProject project = WorkspaceUtils.getSelectedProject();
WMLTools.runWMLIndent(project.getLocation().toOSString(), null, false, true, false);
}
monitor.worked(50);
};
});
monitor.done();
return Status.OK_STATUS;
};
}
};
job.schedule();
}

View file

@ -3,8 +3,7 @@
*/
package wesnoth_eclipse_plugin.action;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@ -13,8 +12,8 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.progress.WorkbenchJob;
import wesnoth_eclipse_plugin.builder.ExternalToolInvoker;
import wesnoth_eclipse_plugin.utils.WMLTools;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
@ -32,37 +31,31 @@ public class RunWMLScopeOnSelection implements IObjectActionDelegate
public void run(IAction action)
{
WorkbenchJob job = new WorkbenchJob("Running WMLScope") {
IEditorReference[] files =
WorkspaceUtils.getWorkbenchWindow().getPages()[0].getEditorReferences();
for (IEditorReference file : files)
{
if (file.isDirty())
file.getEditor(false).doSave(null);
}
final String path = WorkspaceUtils.getSelectedResource().getLocation().toOSString();
WorkspaceJob job = new WorkspaceJob("Running WMLScope") {
private ExternalToolInvoker tool = WMLTools.runWMLScope(path, true, true);
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
protected void canceling()
{
final IEditorReference[] files =
WorkspaceUtils.getWorkbenchWindow().getPages()[0].getEditorReferences();
tool.kill();
}
monitor.beginTask("wmlscope", files.length * 5 + 50);
monitor.subTask("saving files...");
for (IEditorReference file : files)
{
monitor.worked(5);
if (file.isDirty())
file.getEditor(false).doSave(null);
}
IFile selFile = WorkspaceUtils.getSelectedFile();
monitor.subTask("wmlscope");
if (selFile != null)
{
WMLTools.runWMLScope(selFile.getLocation().toOSString(), false, true);
}
else
// project selection
{
// run wmlscope on project
IProject project = WorkspaceUtils.getSelectedProject();
WMLTools.runWMLScope(project.getLocation().toOSString(), true, true);
}
monitor.worked(50);
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor)
{
monitor.beginTask("wmlscope is running...", 50);
monitor.worked(10);
tool.waitForTool();
monitor.done();
return Status.OK_STATUS;
}

View file

@ -8,22 +8,30 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.Constants;
import wesnoth_eclipse_plugin.utils.MyRunnable;
/**
* @author Timotei Dolean
*
*/
public class ExternalToolInvoker
{
private Process process_;
private ProcessBuilder processBuilder_;
private Thread processThread_;
private Thread attachedThread_;
private BufferedReader bufferedReaderOutput_;
private BufferedReader bufferedReaderError_;
private boolean threadStarted_;
private String outputContent_;
private String errorContent_;
/**
* Creates an external tool invoker with specified options
@ -31,9 +39,8 @@ public class ExternalToolInvoker
* @param fileName the file name to be invoked
* @param arguments the arguments passed to the file
* @param useThread true if the process will run in a thread
* @throws IOException
*/
public ExternalToolInvoker(String fileName, List<String> arguments, boolean useThread) throws IOException {
public ExternalToolInvoker(String fileName, List<String> arguments, boolean useThread) {
List<String> commandline = new ArrayList<String>();
commandline.add(fileName);
if (arguments != null)
@ -42,7 +49,6 @@ public class ExternalToolInvoker
processBuilder_ = new ProcessBuilder(commandline);
if (useThread)
{
threadStarted_ = true;
processThread_ = new Thread(new Runnable() {
@Override
public void run()
@ -53,8 +59,6 @@ public class ExternalToolInvoker
bufferedReaderOutput_ = new BufferedReader(new InputStreamReader(process_.getInputStream()));
bufferedReaderError_ = new BufferedReader(new InputStreamReader(process_.getErrorStream()));
threadStarted_ = true;
} catch (IOException e)
{
e.printStackTrace();
@ -64,17 +68,23 @@ public class ExternalToolInvoker
}
}
public void run() throws IOException
public void run()
{
if (processThread_ == null)
try
{
process_ = processBuilder_.start();
if (processThread_ == null)
{
process_ = processBuilder_.start();
bufferedReaderOutput_ = new BufferedReader(new InputStreamReader(process_.getInputStream()));
bufferedReaderError_ = new BufferedReader(new InputStreamReader(process_.getErrorStream()));
bufferedReaderOutput_ = new BufferedReader(new InputStreamReader(process_.getInputStream()));
bufferedReaderError_ = new BufferedReader(new InputStreamReader(process_.getErrorStream()));
}
else
processThread_.start();
} catch (IOException e)
{
e.printStackTrace();
}
else
processThread_.start();
}
/**
@ -82,7 +92,7 @@ public class ExternalToolInvoker
*
* @return the return value of the tool
*/
public int waitFor()
public int waitForTool()
{
if (process_ == null)
return 0;
@ -90,13 +100,17 @@ public class ExternalToolInvoker
try
{
return process_.waitFor();
} catch (Exception e)
} catch (InterruptedException e)
{
e.printStackTrace();
return -1;
}
}
public String getOutputContent()
{
return outputContent_;
}
public String readOutputLine()
{
if (process_ == null || bufferedReaderOutput_ == null)
@ -112,6 +126,11 @@ public class ExternalToolInvoker
}
}
public String getErrorContent()
{
return errorContent_;
}
public String readErrorLine()
{
if (process_ == null || bufferedReaderError_ == null)
@ -156,16 +175,9 @@ public class ExternalToolInvoker
try
{
if (process_ != null)
{
process_.exitValue();
bufferedReaderError_.close();
bufferedReaderOutput_.close();
}
else
return false;
} catch (IOException e)
{
e.printStackTrace();
} catch (IllegalThreadStateException e)
{
// the process hasn't exited
@ -174,20 +186,43 @@ public class ExternalToolInvoker
return true;
}
public void waitForThreadStart()
public void kill()
{
// no thread
if (processThread_ == null)
return;
try
{
while (!threadStarted_)
Thread.sleep(1);
} catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("start");
if (process_ != null)
process_.destroy();
if (processThread_ != null)
processThread_.interrupt();
}
/**
* Gets the owned thread used to run the process.
* This is non-null if the tool was invoked with "useThread=true"
*
* @return
*/
public Thread getOwnThread()
{
return processThread_;
}
/**
* Gets the attached thread, usually when someone runs this tool in another thread
*
* @return
*/
public Thread getAttachedThread()
{
return attachedThread_;
}
/**
* Sets the attached thread
*
* @param thread
*/
public void setAttachedThread(Thread thread)
{
attachedThread_ = thread;
}
/**
@ -195,94 +230,109 @@ public class ExternalToolInvoker
*
* @param fileName the full path to the executable to be launched
* @param args the arguments list
* @param showOutput true to show tool's ouput (stdout and stderr)
* @param waitFor true to wait till the program ends and show the output
* at the end of the program or false to show it as it arrises
* @param useThread true to launch the tool on a separate thread
* @param outputFlags a composition of flags used for output
* @param useThread true to launch the tool on a separate thread.
* If this is false the method will wait for the tool to end
* @param workbenchWindow the workbench window used to show messages
* (if null no messages will be triggered)
* @return
*/
public static boolean launchTool(final String fileName, final List<String> args, final boolean showOutput,
final boolean waitFor, final boolean useThread, final IWorkbenchWindow workbenchWindow)
public static ExternalToolInvoker launchTool(final String fileName, final List<String> args,
final int outputFlags, final boolean useThread)
{
// we need a new thread so we won't block the caller
Thread launcherThread = new Thread(new Runnable() {
@Override
public void run()
final ExternalToolInvoker toolInvoker = new ExternalToolInvoker(fileName, args, useThread);
MessageConsoleStream stream = null;
if ((outputFlags & Constants.TI_SHOW_OUTPUT_USER) == Constants.TI_SHOW_OUTPUT_USER)
{
MessageConsole console = new MessageConsole("", null);
//console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
stream = console.newMessageStream();
}
if (useThread)
{
toolInvoker.run();
Thread outputStreamThread = new Thread(new MyRunnable<MessageConsoleStream>(stream) {
@Override
public void run()
{
try
{
String line = "";
while (!toolInvoker.processEnded())
{
if ((line = toolInvoker.readOutputLine()) != null)
{
System.out.println(line);
if (runnableObject_ != null)
runnableObject_.write(line + "\n");
}
}
} catch (IOException e)
{
e.printStackTrace();
}
}
});
Thread errorStreamThread = new Thread(new MyRunnable<MessageConsoleStream>(stream) {
@Override
public void run()
{
try
{
String line = "";
while (!toolInvoker.processEnded())
{
if ((line = toolInvoker.readErrorLine()) != null)
{
System.out.println(line);
if (runnableObject_ != null)
runnableObject_.write(line + "\n");
}
}
System.out.println("tool exited.");
//if (toolInvoker.waitFor() != 0)
//{
// GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(),
// "The tool returned a non-zero value.");
//}
} catch (IOException e)
{
e.printStackTrace();
}
}
});
outputStreamThread.start();
errorStreamThread.start();
}
else
{
try
{
try
if ((outputFlags & Constants.TI_SHOW_OUTPUT) == Constants.TI_SHOW_OUTPUT)
{
final ExternalToolInvoker toolInvoker = new ExternalToolInvoker(fileName, args, useThread);
toolInvoker.run();
if (waitFor)
String line = "";
while ((line = toolInvoker.readOutputLine()) != null)
{
if (toolInvoker.waitFor() != 0 && workbenchWindow != null)
{
GUIUtils.showMessageBox(workbenchWindow, "The tool returned a non-zero value.");
}
if (stream != null)
stream.write(line + "\n");
System.out.println(line);
}
if (showOutput)
while ((line = toolInvoker.readErrorLine()) != null)
{
if (waitFor)
{
String line = "";
while ((line = toolInvoker.readOutputLine()) != null)
{
System.out.println(line);
}
while ((line = toolInvoker.readErrorLine()) != null)
{
System.out.println(line);
}
System.out.println("tool exited.");
}
else
{
Thread outputStreamThread = new Thread(new Runnable() {
@Override
public void run()
{
String line = "";
while (!toolInvoker.processEnded())
{
if ((line = toolInvoker.readOutputLine()) != null)
System.out.println(line);
}
}
});
Thread errorStreamThread = new Thread(new Runnable() {
@Override
public void run()
{
String line = "";
while (!toolInvoker.processEnded())
{
if ((line = toolInvoker.readErrorLine()) != null)
System.out.println(line);
}
System.out.println("tool exited.");
if (toolInvoker.waitFor() != 0)
{
GUIUtils.showMessageBox(workbenchWindow, "The tool returned a non-zero value.");
}
}
});
outputStreamThread.start();
errorStreamThread.start();
}
if (stream != null)
stream.write(line + "\n");
System.out.println(line);
}
System.out.println("tool exited.");
}
catch (Exception e)
{
e.printStackTrace();
}
} catch (IOException e)
{
e.printStackTrace();
}
});
launcherThread.start();
return true;
}
return toolInvoker;
}
}

View file

@ -30,8 +30,8 @@ public class EditorActions
}
System.out.printf("Running: [%s] with args: %s\n", editorPath, getLaunchEditorArguments(mapName, workingDir));
ExternalToolInvoker.launchTool(editorPath, getLaunchEditorArguments(mapName, workingDir), true, false, true,
WorkspaceUtils.getWorkbenchWindow());
ExternalToolInvoker.launchTool(editorPath, getLaunchEditorArguments(mapName, workingDir),
Constants.TI_SHOW_OUTPUT_USER | Constants.TI_SHOW_OUTPUT, true);
}
public static List<String> getLaunchEditorArguments(String mapName, String workingDir)

View file

@ -57,7 +57,7 @@ public class PreprocessorActions
System.out.printf("preprocessing : %s\n", arguments);
wesnoth.run();
if (waitForIt)
wesnoth.waitFor();
wesnoth.waitForTool();
return true;
}
catch (Exception e) {

View file

@ -6,9 +6,11 @@ package wesnoth_eclipse_plugin.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorReference;
import wesnoth_eclipse_plugin.Activator;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class TestHandler extends AbstractHandler
{
@ -17,13 +19,95 @@ public class TestHandler extends AbstractHandler
{
//String stdin = EditorUtils.getEditorDocument().get();
//EditorUtils.replaceEditorText(WMLTools.runWMLIndent(null, stdin, false, false, false));
IEditorReference[] files =
Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getPages()[0].getEditorReferences();
for (IEditorReference file : files)
{
if (file.isDirty())
file.getEditor(false).doSave(null);
}
// IEditorReference[] files =
// Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getPages()[0].getEditorReferences();
// for (IEditorReference file : files)
// {
// if (file.isDirty())
// file.getEditor(false).doSave(null);
// }
// ProgressMonitorDialog dialog = new ProgressMonitorDialog(Activator.getShell());
// try
// {
// dialog.run(true, true, new IRunnableWithProgress() {
// @Override
// public void run(IProgressMonitor monitor)
// {
// monitor.beginTask("Some nice progress message here ...", 100);
// // execute the task ...
// try
// {
// Thread.sleep(2000);
// } catch (InterruptedException e)
// {
// e.printStackTrace();
// }
// monitor.done();
// }
// });
// } catch (InvocationTargetException e)
// {
// e.printStackTrace();
// } catch (InterruptedException e)
// {
// e.printStackTrace();
// }
// UIJob job1 = new UIJob("My the job") {
//
// @Override
// public IStatus runInUIThread(IProgressMonitor monitor)
// {
// monitor.beginTask("Some nice progress message here ...", 100);
// // execute the task ...try
// try
// {
// Thread.sleep(2000);
// } catch (InterruptedException e)
// {
// e.printStackTrace();
// }
// monitor.done();
// return Status.OK_STATUS;
// }
// };
// //job1.schedule();
// WorkbenchJob job2 = new WorkbenchJob("asdasdd ") {
//
// @Override
// public IStatus runInUIThread(IProgressMonitor monitor)
// {
// monitor.beginTask("Some nice progress message here ...", 100);
// // execute the task ...try
// try
// {
// Thread.sleep(2000);
// } catch (InterruptedException e)
// {
// e.printStackTrace();
// }
// monitor.done();
// return Status.OK_STATUS;
// }
// };
// job2.schedule();
new WorkspaceJob("My new job") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException
{
monitor.beginTask("Some nice progress message here ...", 100);
// execute the task ...try
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
monitor.done();
return Status.OK_STATUS;
}
}.schedule();
//job.schedule();
return null;
}
}

View file

@ -18,55 +18,55 @@ public class AntUtils
{
/**
* Runs the specified ant file, and returns the output of the runned file
*
* @param antFile
* @param properties the hasmap with userproperties to be added to the ant file
* @param recordOutput true if the output of the runned file should be recorded and returned
* @return null if the build didn't success
*/
public static String runAnt(String antFile, HashMap<String,String> properties, boolean recordOutput)
{
final Project project = new Project();
ByteArrayOutputStream out=null;
public static String runAnt(String antFile, HashMap<String, String> properties, boolean recordOutput)
{
Project project = new Project();
ByteArrayOutputStream out = null;
try
{
out = new ByteArrayOutputStream();
if (recordOutput)
project.addBuildListener(AntUtils.createLogger(out));
project.init();
File buildFile = new File(antFile);
ProjectHelper.configureProject(project, buildFile);
try
{
out = new ByteArrayOutputStream();
if (recordOutput)
project.addBuildListener(AntUtils.createLogger(out));
project.init();
File buildFile = new File(antFile);
ProjectHelper.configureProject(project, buildFile);
Iterator<String> iterator = properties.keySet().iterator();
while (iterator.hasNext())
{
String key = iterator.next();
String value = properties.get(key);
project.setUserProperty(key,value);
}
project.executeTarget(project.getDefaultTarget());
Iterator<String> iterator = properties.keySet().iterator();
while (iterator.hasNext())
{
String key = iterator.next();
String value = properties.get(key);
project.setUserProperty(key, value);
}
project.executeTarget(project.getDefaultTarget());
return out.toString();
}
catch (Exception exc)
{
exc.printStackTrace();
return null;
}
}
return out.toString();
} catch (Exception exc)
{
exc.printStackTrace();
return null;
}
}
/**
* Creates the default build logger for sending build events to the ant log.
* Creates the default build logger for sending build events to the ant log.
*/
private static BuildLogger createLogger( ByteArrayOutputStream out )
{
DefaultLogger logger = new DefaultLogger();
private static BuildLogger createLogger(ByteArrayOutputStream out)
{
DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(new PrintStream(out));
logger.setErrorPrintStream(new PrintStream(out));
logger.setEmacsMode(false);
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(new PrintStream(out));
logger.setErrorPrintStream(new PrintStream(out));
logger.setEmacsMode(false);
return logger;
}
return logger;
}
}

View file

@ -0,0 +1,19 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.utils;
public class MyRunnable<T> implements Runnable
{
protected final T runnableObject_;
public MyRunnable(T t) {
this.runnableObject_ = t;
}
@Override
public void run()
{
}
}

View file

@ -21,38 +21,6 @@ import wesnoth_eclipse_plugin.preferences.Preferences;
public class WMLTools
{
/**
* Runs "wmllint" on the specified resource (directory/file)
*
* @param resourcePath the full path of the target where "wmllint" will be runned on
* @param writeToConsole true to write the output of "wmllint" in user's console
* @param dryrun true to run "wmllint" in dry mode - i.e. no changes in the config file.
* @param useThread whether the tool should be runned in a new thread or not
*/
public static String runWMLLint(String resourcePath, boolean dryrun, boolean writeToConsole, boolean useThread)
{
if (!checkPrerequisites(resourcePath, "wmllint"))
return null;
File wmllintFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) + "wmllint");
List<String> arguments = new ArrayList<String>();
arguments.add(wmllintFile.getAbsolutePath());
if (dryrun)
arguments.add("--dryrun");
arguments.add("--verbose");
//arguments.add("-v");
//arguments.add("-v");
arguments.add("--nospellcheck");
// add default core directory
arguments.add(Preferences.getString(Constants.P_WESNOTH_WORKING_DIR) +
Path.SEPARATOR + "data/core");
arguments.add(resourcePath);
return runPythonScript(arguments, null, useThread, writeToConsole, "Wmllint result: ");
}
/**
* Runs "wmlindent" on the specified resource (directory/file)
*
@ -85,6 +53,38 @@ public class WMLTools
return runPythonScript(arguments, stdin, useThread, writeToConsole, "Wmlindent result: ");
}
/**
* Runs "wmllint" on the specified resource (directory/file)
*
* @param resourcePath the full path of the target where "wmllint" will be runned on
* @param writeToConsole true to write the output of "wmllint" in user's console
* @param dryrun true to run "wmllint" in dry mode - i.e. no changes in the config file.
* @param useThread whether the tool should be runned in a new thread or not
*/
public static String runWMLLint(String resourcePath, boolean dryrun, boolean writeToConsole, boolean useThread)
{
if (!checkPrerequisites(resourcePath, "wmllint"))
return null;
File wmllintFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) + "wmllint");
List<String> arguments = new ArrayList<String>();
arguments.add(wmllintFile.getAbsolutePath());
if (dryrun)
arguments.add("--dryrun");
arguments.add("--verbose");
//arguments.add("-v");
//arguments.add("-v");
arguments.add("--nospellcheck");
// add default core directory
arguments.add(Preferences.getString(Constants.P_WESNOTH_WORKING_DIR) +
Path.SEPARATOR + "data/core");
arguments.add(resourcePath);
return runPythonScript(arguments, null, useThread, writeToConsole, "Wmllint result: ");
}
/**
* Runs "wmlscope" on the specified resource (directory/file)
*
@ -93,7 +93,7 @@ public class WMLTools
* @param useThread whether the tool should be runned in a new thread or not
* @return
*/
public static String runWMLScope(String resourcePath, boolean writeToConsole, boolean useThread)
public static ExternalToolInvoker runWMLScope(String resourcePath, boolean writeToConsole, boolean useThread)
{
if (!checkPrerequisites(resourcePath, "wmlscope"))
return null;
@ -104,11 +104,14 @@ public class WMLTools
arguments.add(wmlscopeFile.getAbsolutePath());
// add default core directory
arguments.add("-w");
arguments.add("2");
arguments.add(Preferences.getString(Constants.P_WESNOTH_WORKING_DIR) +
Path.SEPARATOR + "data/core");
arguments.add(resourcePath);
return runPythonScript(arguments, null, useThread, writeToConsole, "Wmlscope result: ");
return ExternalToolInvoker.launchTool("python", arguments, Constants.TI_SHOW_OUTPUT | Constants.TI_SHOW_OUTPUT_USER,
useThread);
}
/**
@ -170,7 +173,7 @@ public class WMLTools
if (writeToConsole)
{
MessageConsole console = new MessageConsole(consoleTitle, null);
console.activate();
//console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
stream = console.newMessageStream();
}

View file

@ -85,6 +85,22 @@ public class WorkspaceUtils
return getSelectedStructuredSelection(WorkspaceUtils.getWorkbenchWindow());
}
public static IResource getSelectedResource()
{
IResource res = getSelectedFile();
if (res != null)
return res;
res = getSelectedFolder();
if (res != null)
return res;
res = getSelectedProject();
if (res != null)
return res;
return null;
}
/**
* Returns the first WorkbenchWindow available. This is not always the same
* with ActiveWorkbecnWindow