eclipse plugin: Add a new parameter for install name for the wml tools

This commit is contained in:
Timotei Dolean 2011-08-02 19:35:10 +00:00
parent df649344f0
commit d77c2ccae8
5 changed files with 80 additions and 58 deletions

View file

@ -19,13 +19,6 @@ import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.wesnoth.Constants; import org.wesnoth.Constants;
import org.wesnoth.Logger; import org.wesnoth.Logger;
import org.wesnoth.Messages; import org.wesnoth.Messages;
@ -44,6 +37,14 @@ import org.wesnoth.utils.WorkspaceUtils;
import org.wesnoth.wml.SimpleWMLParser; import org.wesnoth.wml.SimpleWMLParser;
import org.wesnoth.wml.WMLConfig; import org.wesnoth.wml.WMLConfig;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* The builder does the following steps in order to create and ensure * The builder does the following steps in order to create and ensure
* a correct PDL (Project Dependency Lits) * a correct PDL (Project Dependency Lits)
@ -324,10 +325,11 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
} }
@SuppressWarnings( "unused" ) @SuppressWarnings( "unused" )
private void runWMLLint( IProgressMonitor monitor, IFile file ) private void runWMLLint( String installName, IProgressMonitor monitor, IFile file )
{ {
monitor.subTask( String.format( "Running WMLlint on file %s ...", file.getName( ) ) ); monitor.subTask( String.format( "Running WMLlint on file %s ...", file.getName( ) ) );
ExternalToolInvoker tool = WMLTools.runWMLLint(file.getLocation().toOSString(), false, false); ExternalToolInvoker tool = WMLTools.runWMLLint( installName,
file.getLocation().toOSString(), false, false );
tool.waitForTool(); tool.waitForTool();
try { try {
@ -351,10 +353,11 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
* @throws CoreException * @throws CoreException
*/ */
@SuppressWarnings( "unused" ) @SuppressWarnings( "unused" )
private void runWMLScope( IProgressMonitor monitor, IFile file ) private void runWMLScope( String installName, IProgressMonitor monitor, IFile file )
{ {
monitor.subTask( String.format( "Running WMLScope on file %s ...", file.getName( ) ) ); monitor.subTask( String.format( "Running WMLScope on file %s ...", file.getName( ) ) );
ExternalToolInvoker tool = WMLTools.runWMLScope( file.getLocation().toOSString(), false ); ExternalToolInvoker tool = WMLTools.runWMLScope( installName,
file.getLocation().toOSString(), false );
tool.waitForTool(); tool.waitForTool();
try { try {

View file

@ -103,10 +103,11 @@ public class Define
* @param file * @param file
* @return Returns a map of defines * @return Returns a map of defines
*/ */
public static Map<String, Define> readDefines(String file) public static Map<String, Define> readDefines( String installName, String file )
{ {
DefinesSAXHandler handler = (DefinesSAXHandler) ResourceUtils. DefinesSAXHandler handler = (DefinesSAXHandler) ResourceUtils.
getWMLSAXHandlerFromResource(file, new DefinesSAXHandler()); getWMLSAXHandlerFromResource( installName, file,
new DefinesSAXHandler( ) );
if (handler != null){ if (handler != null){
Logger.getInstance().log("loaded " + handler.getDefines().size() + " defines for file:" + file); //$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ Logger.getInstance().log("loaded " + handler.getDefines().size() + " defines for file:" + file); //$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.wesnoth.Constants; import org.wesnoth.Constants;
import org.wesnoth.Logger; import org.wesnoth.Logger;
import org.wesnoth.builder.DependencyListBuilder; import org.wesnoth.builder.DependencyListBuilder;
@ -33,6 +32,8 @@ import org.wesnoth.wml.WMLConfig;
import org.wesnoth.wml.WMLTag; import org.wesnoth.wml.WMLTag;
import org.wesnoth.wml.WMLVariable; import org.wesnoth.wml.WMLVariable;
import org.eclipse.core.resources.IProject;
/** /**
* A class that stores some project specific infos * A class that stores some project specific infos
* for current session. * for current session.
@ -202,7 +203,7 @@ public class ProjectCache implements Serializable
if (definesFile_.exists() == false) if (definesFile_.exists() == false)
return; return;
defines_ = Define.readDefines(definesFile_.getAbsolutePath()); defines_ = Define.readDefines( getInstallName( ), definesFile_.getAbsolutePath( ) );
definesTimestamp_ = definesFile_.lastModified( ); definesTimestamp_ = definesFile_.lastModified( );
} }

View file

@ -28,6 +28,19 @@ import java.util.Set;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.builder.DependencyListNode;
import org.wesnoth.preferences.Preferences.Paths;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.templates.ReplaceableParameter;
import org.wesnoth.templates.TemplateProvider;
import org.wesnoth.wml.SimpleWMLParser;
import org.wesnoth.wml.WMLMacroCall;
import org.wesnoth.wml.WMLRoot;
import org.wesnoth.wml.WmlFactory2;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
@ -47,18 +60,7 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.builder.DependencyListNode;
import org.wesnoth.preferences.Preferences.Paths;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.templates.ReplaceableParameter;
import org.wesnoth.templates.TemplateProvider;
import org.wesnoth.wml.SimpleWMLParser;
import org.wesnoth.wml.WMLMacroCall;
import org.wesnoth.wml.WMLRoot;
import org.wesnoth.wml.WmlFactory2;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
@ -491,10 +493,10 @@ public class ResourceUtils
* @param saxHandler The SAX Handler used to handle the parsed wml * @param saxHandler The SAX Handler used to handle the parsed wml
* @return * @return
*/ */
public static DefaultHandler getWMLSAXHandlerFromResource(String resourcePath, public static DefaultHandler getWMLSAXHandlerFromResource( String installName,
DefaultHandler saxHandler) String resourcePath, DefaultHandler saxHandler)
{ {
ExternalToolInvoker parser = WMLTools.runWMLParser2(resourcePath); ExternalToolInvoker parser = WMLTools.runWMLParser2( installName, resourcePath);
if (parser == null) if (parser == null)
return null; return null;
try{ try{

View file

@ -19,6 +19,13 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.installs.WesnothInstallsUtils;
import org.wesnoth.preferences.Preferences;
import org.wesnoth.preferences.Preferences.Paths;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.resources.WorkspaceJob;
@ -27,12 +34,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsole;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.installs.WesnothInstallsUtils;
import org.wesnoth.preferences.Preferences;
import org.wesnoth.preferences.Preferences.Paths;
public class WMLTools public class WMLTools
{ {
@ -46,10 +47,11 @@ public class WMLTools
* @param stderr The array of streams where to output the stderr content * @param stderr The array of streams where to output the stderr content
* @return null if there were errors or an ExternalToolInvoker instance * @return null if there were errors or an ExternalToolInvoker instance
*/ */
public static ExternalToolInvoker runWMLIndent(String resourcePath, String stdin, public static ExternalToolInvoker runWMLIndent( String installName,
boolean dryrun, OutputStream[] stdout, OutputStream[] stderr) String resourcePath, String stdin, boolean dryrun,
OutputStream[] stdout, OutputStream[] stderr )
{ {
Paths paths = Preferences.getPaths( WesnothInstallsUtils.getInstallNameForResource( resourcePath ) ); Paths paths = Preferences.getPaths( installName );
//wmlindent only check first //wmlindent only check first
if ( !checkWMLTool( paths, Tools.WMLINDENT.toString( ) ) ) //$NON-NLS-1$ if ( !checkWMLTool( paths, Tools.WMLINDENT.toString( ) ) ) //$NON-NLS-1$
@ -82,9 +84,10 @@ public class WMLTools
* @param resourcePath * @param resourcePath
* @return null if there were errors or an ExternalToolInvoker instance * @return null if there were errors or an ExternalToolInvoker instance
*/ */
public static ExternalToolInvoker runWMLParser2(String resourcePath) public static ExternalToolInvoker runWMLParser2( String installName,
String resourcePath )
{ {
Paths paths = Preferences.getPaths( WesnothInstallsUtils.getInstallNameForResource( resourcePath ) ); Paths paths = Preferences.getPaths( installName );
if ( !ResourceUtils.isValidFilePath( resourcePath ) || if ( !ResourceUtils.isValidFilePath( resourcePath ) ||
!checkWMLTool( paths, "wesnoth/wmlparser2.py" ) ) //$NON-NLS-1$ !checkWMLTool( paths, "wesnoth/wmlparser2.py" ) ) //$NON-NLS-1$
@ -129,9 +132,11 @@ public class WMLTools
* @param showProgress true to show the progress of the tool * @param showProgress true to show the progress of the tool
* @return null if there were errors or an ExternalToolInvoker instance * @return null if there were errors or an ExternalToolInvoker instance
*/ */
public static ExternalToolInvoker runWMLLint(String resourcePath, boolean dryrun, boolean showProgress) public static ExternalToolInvoker runWMLLint( String installName,
String resourcePath, boolean dryrun, boolean showProgress )
{ {
return runWMLLint(resourcePath, dryrun, showProgress, new OutputStream[0], new OutputStream[0]); return runWMLLint( installName, resourcePath, dryrun, showProgress,
new OutputStream[0], new OutputStream[0]);
} }
/** /**
@ -143,10 +148,11 @@ public class WMLTools
* @param stdout The array of streams where to output the stdout content * @param stdout The array of streams where to output the stdout content
* @param stderr The array of streams where to output the stderr content * @param stderr The array of streams where to output the stderr content
*/ */
public static ExternalToolInvoker runWMLLint(String resourcePath, boolean dryrun, public static ExternalToolInvoker runWMLLint( String installName,
boolean showProgress, OutputStream[] stdout, OutputStream[] stderr) String resourcePath, boolean dryrun, boolean showProgress,
OutputStream[] stdout, OutputStream[] stderr )
{ {
Paths paths = Preferences.getPaths( WesnothInstallsUtils.getInstallNameForResource( resourcePath ) ); Paths paths = Preferences.getPaths( installName );
if ( !ResourceUtils.isValidFilePath( resourcePath ) || if ( !ResourceUtils.isValidFilePath( resourcePath ) ||
!checkWMLTool( paths, Tools.WMLLINT.toString( ) ) ) !checkWMLTool( paths, Tools.WMLLINT.toString( ) ) )
@ -184,9 +190,11 @@ public class WMLTools
* @param resourcePath the full path of the target where "wmlindent" will be runned on * @param resourcePath the full path of the target where "wmlindent" will be runned on
* @return null if there were errors or an ExternalToolInvoker instance * @return null if there were errors or an ExternalToolInvoker instance
*/ */
public static ExternalToolInvoker runWMLScope(String resourcePath, boolean showProgress) public static ExternalToolInvoker runWMLScope( String installName,
String resourcePath, boolean showProgress )
{ {
return runWMLScope(resourcePath, showProgress, new OutputStream[0], new OutputStream[0]); return runWMLScope( installName, resourcePath, showProgress,
new OutputStream[0], new OutputStream[0] );
} }
/** /**
@ -197,10 +205,11 @@ public class WMLTools
* @param stderr The array of streams where to output the stderr content * @param stderr The array of streams where to output the stderr content
* @return null if there were errors or an ExternalToolInvoker instance * @return null if there were errors or an ExternalToolInvoker instance
*/ */
public static ExternalToolInvoker runWMLScope(String resourcePath, boolean showProgress, public static ExternalToolInvoker runWMLScope( String installName,
String resourcePath, boolean showProgress,
OutputStream[] stdout, OutputStream[] stderr ) OutputStream[] stdout, OutputStream[] stderr )
{ {
Paths paths = Preferences.getPaths( WesnothInstallsUtils.getInstallNameForResource( resourcePath ) ); Paths paths = Preferences.getPaths( installName );
if ( !ResourceUtils.isValidFilePath( resourcePath ) || if ( !ResourceUtils.isValidFilePath( resourcePath ) ||
!checkWMLTool( paths, Tools.WMLSCOPE.toString( ) ) ) !checkWMLTool( paths, Tools.WMLSCOPE.toString( ) ) )
@ -243,6 +252,7 @@ public class WMLTools
*/ */
public static void runWMLToolAsWorkspaceJob( final Tools tool, final String targetPath ) public static void runWMLToolAsWorkspaceJob( final Tools tool, final String targetPath )
{ {
//TODO: remove/rework this hackish method.
if (tool == Tools.WESNOTH_ADDON_MANAGER) if (tool == Tools.WESNOTH_ADDON_MANAGER)
return; return;
@ -280,6 +290,7 @@ public class WMLTools
String location; String location;
IResource resource = null; IResource resource = null;
String installName = Preferences.getDefaultInstallName( );
IFile selFile = WorkspaceUtils.getSelectedFile(); IFile selFile = WorkspaceUtils.getSelectedFile();
if (targetPath != null) if (targetPath != null)
@ -296,6 +307,8 @@ public class WMLTools
resource = WorkspaceUtils.getSelectedContainer(); resource = WorkspaceUtils.getSelectedContainer();
location = resource.getLocation().toOSString(); location = resource.getLocation().toOSString();
} }
installName = WesnothInstallsUtils.getInstallNameForResource( resource );
} }
switch(tool) switch(tool)
@ -305,18 +318,20 @@ public class WMLTools
{ {
String stdin = EditorUtils.getEditorDocument().get(); String stdin = EditorUtils.getEditorDocument().get();
// don't output to stdout as we will put that in the editor // don't output to stdout as we will put that in the editor
toolInvoker = WMLTools.runWMLIndent(null, stdin, false, toolInvoker = WMLTools.runWMLIndent( installName,
null, stdout); null, stdin, false, null, stdout );
} }
else else
toolInvoker = WMLTools.runWMLIndent(location, null, false, toolInvoker = WMLTools.runWMLIndent( installName,
stdout, stderr); location, null, false, stdout, stderr );
break; break;
case WMLLINT: case WMLLINT:
toolInvoker = WMLTools.runWMLLint(location, true, false, stdout, stderr); toolInvoker = WMLTools.runWMLLint( installName,
location, true, false, stdout, stderr );
break; break;
case WMLSCOPE: case WMLSCOPE:
toolInvoker = WMLTools.runWMLScope(location, false, stdout, stderr); toolInvoker = WMLTools.runWMLScope( installName,
location, false, stdout, stderr );
break; break;
} }
monitor.worked(50); monitor.worked(50);