eclipse plugin: add wmlscope tool frontend

This commit is contained in:
Timotei Dolean 2010-07-09 19:39:40 +00:00
parent c720ee800b
commit ce3c988b13
4 changed files with 202 additions and 61 deletions

View file

@ -36,22 +36,37 @@
class="wesnoth_eclipse_plugin.builder.ToggleNatureAction"
enablesFor="+"
icon="icons/wesnoth-icon_16.png"
id="actions.addRemoveNature"
id="action.proj.addRemoveNature"
label="Add/Remove Sample Nature"
menubarPath="_wesnoth">
</action>
<action
class="wesnoth_eclipse_plugin.action.WesnothProjectReport"
icon="icons/wesnoth-icon_16.png"
id="action.wesnothProjectReport"
id="action.proj.report"
label="Wesnoth project report"
menubarPath="_wesnoth">
</action>
<menu
icon="icons/wesnoth-icon_16.png"
id="plugin.wmltoolsProjMenu"
label="WML Tools"
path="_wesnoth">
<groupMarker
name="wmltoolsProjMenuMarker">
</groupMarker>
</menu>
<action
class="wesnoth_eclipse_plugin.action.RunWMLScopeOnSelection"
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"
id="Wesnoth Eclipse Plugin.action7"
label="Run &quot;wmlindent&quot; on the project this file"
menubarPath="_wesnoth">
id="action.proj.wmlscope"
label="Run &quot;wmlscope&quot; on the project"
menubarPath="plugin.wmltoolsProjMenu/wmltoolsProjMenuMarker">
</action>
</objectContribution>
<objectContribution
@ -63,7 +78,7 @@
class="wesnoth_eclipse_plugin.action.ImportMap"
enablesFor="1"
icon="icons/wesnoth_editor-icon_16.png"
id="actions.importmap"
id="action.maps.importmap"
label="Import map"
menubarPath="_wesnoth">
</action>
@ -77,7 +92,7 @@
class="wesnoth_eclipse_plugin.action.OpenMapInEditor"
enablesFor="1"
icon="icons/wesnoth_editor-icon_16.png"
id="actions.openMapInEditor"
id="action.map.openMapInEditor"
label="Open map in editor"
menubarPath="_wesnoth">
</action>
@ -91,7 +106,7 @@
class="wesnoth_eclipse_plugin.action.OpenScenarioInGame"
enablesFor="1"
icon="icons/wesnoth-icon_16.png"
id="action.openScenarioInGame"
id="action.cfg.openScenarioInGame"
label="Open Scenario in game"
menubarPath="_wesnoth">
</action>
@ -106,42 +121,50 @@
</menu>
<action
class="wesnoth_eclipse_plugin.action.ShowPreprocessedConfig"
id="action.preprocessedConfig"
id="action.cfg.preprocessedConfig"
label="Show preprocessed file"
menubarPath="plugin.preprocessorMenu/preprocessorMenuMarker">
</action>
<action
class="wesnoth_eclipse_plugin.action.ShowPlainPreprocessedConfig"
id="action.plainPreprocessedconfig"
id="action.cfg.plainPreprocessedconfig"
label="Show plain preprocessed file"
menubarPath="plugin.preprocessorMenu/preprocessorMenuMarker">
</action>
<menu
icon="icons/wesnoth-icon_16.png"
id="plugin.wmltoolsMenu"
id="plugin.wmltoolsCfgMenu"
label="WML Tools"
path="_wesnoth">
<groupMarker
name="wmltoolsMenuMarker">
name="wmltoolsCfgMenuMarker">
</groupMarker>
</menu>
<action
class="wesnoth_eclipse_plugin.action.RunWMLLintOnFile"
id="Wesnoth Eclipse Plugin.action5"
id="action.cfg.wmllintOnFile"
label="Run &quot;wmllint&quot; on this file"
menubarPath="plugin.wmltoolsMenu/wmltoolsMenuMarker">
menubarPath="plugin.wmltoolsCfgMenu/wmltoolsCfgMenuMarker">
</action>
<!--
<action
class="wesnoth_eclipse_plugin.action.RunWMLLintOnPreprocFile"
id="Wesnoth Eclipse Plugin.action6"
id="action.cfg.wmllintOnPreprocFile"
label="Run &quot;wmllint&quot; on preprocessed file"
menubarPath="plugin.wmltoolsMenu/wmltoolsMenuMarker">
menubarPath="plugin.wmltoolsCfgMenu/wmltoolsCfgMenuMarker">
</action>
-->
<action
class="wesnoth_eclipse_plugin.action.RunWMLScopeOnSelection"
id="action.cfg.wmlscope"
label="Run &quot;wmlscope&quot; on this file"
menubarPath="plugin.wmltoolsCfgMenu/wmltoolsCfgMenuMarker">
</action>
<action
class="wesnoth_eclipse_plugin.action.RunWMLIndentOnSelection"
id="Wesnoth Eclipse Plugin.action7"
id="action.cfg.wmlindent"
label="Run &quot;wmlindent&quot; on this file"
menubarPath="plugin.wmltoolsMenu/wmltoolsMenuMarker">
menubarPath="plugin.wmltoolsCfgMenu/wmltoolsCfgMenuMarker">
</action>
</objectContribution>
</extension>

View file

@ -5,11 +5,15 @@ package wesnoth_eclipse_plugin.action;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
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.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;
@ -29,31 +33,43 @@ public class RunWMLIndentOnSelection implements IObjectActionDelegate
@Override
public void run(IAction action)
{
IFile selFile = WorkspaceUtils.getSelectedFile();
if (selFile != null)
{
EditorUtils.openEditor(selFile, true);
String stdin = EditorUtils.getEditorDocument().get();
EditorUtils.replaceEditorText(WMLTools.runWMLIndent(null, stdin, false, false, false));
//WMLTools.runWMLIndent(WorkspaceUtils.getPathRelativeToUserDir(WorkspaceUtils.getSelectedFile()), null,
// false, true, false);
}
else
// project selection
{
// save currently opened files
final IEditorReference[] files =
WorkspaceUtils.getWorkbenchWindow().getPages()[0].getEditorReferences();
for (IEditorReference file : files)
WorkbenchJob job = new WorkbenchJob("Running WMLIndent") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
if (file.isDirty())
file.getEditor(false).doSave(null);
}
final IEditorReference[] files =
WorkspaceUtils.getWorkbenchWindow().getPages()[0].getEditorReferences();
// run wmlindent on project
IProject project = WorkspaceUtils.getSelectedProject();
WMLTools.runWMLIndent(project.getLocation().toOSString(), null, false, true, false);
}
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);
}
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();
}
@Override

View file

@ -0,0 +1,77 @@
/**
* @author Timotei Dolean
*/
package wesnoth_eclipse_plugin.action;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
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.ui.IEditorReference;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.progress.WorkbenchJob;
import wesnoth_eclipse_plugin.utils.WMLTools;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
public class RunWMLScopeOnSelection implements IObjectActionDelegate
{
public RunWMLScopeOnSelection() {
}
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
}
@Override
public void run(IAction action)
{
WorkbenchJob job = new WorkbenchJob("Running WMLScope") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
final IEditorReference[] files =
WorkspaceUtils.getWorkbenchWindow().getPages()[0].getEditorReferences();
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);
monitor.done();
return Status.OK_STATUS;
}
};
job.schedule();
}
@Override
public void selectionChanged(IAction action, ISelection selection)
{
}
}

View file

@ -22,20 +22,19 @@ import wesnoth_eclipse_plugin.preferences.Preferences;
public class WMLTools
{
/**
* Runs "wmllint" on the specified file
* Runs "wmllint" on the specified resource (directory/file)
*
* @param filePath the full path of the target file where "wmllint" will be runned on
* @param writeToConsole true to write the output of "wmllint" in console
* @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
* @param useThread whether the tool should be runned in a new thread or not
*/
public static String runWMLLint(String filePath, boolean dryrun, boolean writeToConsole, boolean useThread)
public static String runWMLLint(String resourcePath, boolean dryrun, boolean writeToConsole, boolean useThread)
{
if (!checkPrerequisites(filePath, "wmllint"))
if (!checkPrerequisites(resourcePath, "wmllint"))
return null;
File wmllintFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) +
Path.SEPARATOR + "wmllint");
File wmllintFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) + "wmllint");
List<String> arguments = new ArrayList<String>();
@ -49,43 +48,69 @@ public class WMLTools
// add default core directory
arguments.add(Preferences.getString(Constants.P_WESNOTH_WORKING_DIR) +
Path.SEPARATOR + "data/core");
arguments.add(filePath);
arguments.add(resourcePath);
return runPythonScript(arguments, null, useThread, writeToConsole, "Wmllint result: ");
}
/**
* Runs "wmlindent" on the specified file
* Runs "wmlindent" on the specified resource (directory/file)
*
* @param filePath the full path of the target file where "wmlindent" will be runned on
* @param writeToConsole true to write the output of "wmlindent" in console
* @param resourcePath the full path of the target where "wmlindent" will be runned on
* @param writeToConsole true to write the output of "wmlindent" in user's console
* @param stdin the standard input string to feed "wmlindent"
* @param dryrun true to run "wmlindent" in dry mode - i.e. no changes in the config file.
* @param useThread whether the tool should be runned in a new thread
* @param useThread whether the tool should be runned in a new thread or not
*/
public static String runWMLIndent(String filePath, String stdin,
public static String runWMLIndent(String resourcePath, String stdin,
boolean dryrun, boolean writeToConsole, boolean useThread)
{
if (!checkPrerequisites(null, "wmlindent")) // wmlindent only check first
return null;
File wmllintFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) +
Path.SEPARATOR + "wmlindent");
File wmllintFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) + "/wmlindent");
List<String> arguments = new ArrayList<String>();
arguments.add(wmllintFile.getAbsolutePath());
if (filePath != null)
if (resourcePath != null)
{
if (!checkPrerequisites(filePath, null))
if (!checkPrerequisites(resourcePath, null))
return null;
if (dryrun)
arguments.add("--dryrun");
arguments.add("--verbose");
arguments.add(filePath);
arguments.add(resourcePath);
}
return runPythonScript(arguments, stdin, useThread, writeToConsole, "Wmlindent result: ");
}
/**
* Runs "wmlscope" on the specified resource (directory/file)
*
* @param resourcePath the full path of the target where "wmlindent" will be runned on
* @param writeToConsole true to write the output of "wmlindent" in user's console
* @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)
{
if (!checkPrerequisites(resourcePath, "wmlscope"))
return null;
File wmlscopeFile = new File(Preferences.getString(Constants.P_WESNOTH_WMLTOOLS_DIR) + "/wmlscope");
List<String> arguments = new ArrayList<String>();
arguments.add(wmlscopeFile.getAbsolutePath());
// 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, "Wmlscope result: ");
}
/**
* Checks if a wmlTool (that is in the wml tools directory) and
* an additional file that is target of the tool exist / are valid.
@ -133,7 +158,7 @@ public class WMLTools
ExternalToolInvoker pyscript = new ExternalToolInvoker("python", arguments, useThread);
System.out.println(arguments);
pyscript.run();
if (stdin != null && !stdin.isEmpty())
if (stdin != null)
{
//pyscript.waitForThreadStart();
BufferedWriter stdinStream = new BufferedWriter(new OutputStreamWriter(pyscript.getOutputStream()));