org.jmlspecs.eclipse.jdt.internal.esc2
Class Utils

java.lang.Object
  extended by org.jmlspecs.eclipse.jdt.internal.esc2.Utils

public class Utils
extends java.lang.Object

This class contains a number of (static) utility methods for use in plugins.

Author:
David R. Cok

Field Summary
static java.lang.String eol
          A convenience holder for the end-of-line String for the current platform.
 
Constructor Summary
Utils()
           
 
Method Summary
static ICommand[] addBuilder(IProject project, ICommand[] commands, IProjectDescription description, java.lang.String builder, boolean enabled)
          Adds the given builder to the list of commands.
static void addBuilder(IProject project, java.lang.String builder)
          Adds an enabled builder to the given project
static boolean addNature(IProject project, java.lang.String natureId)
          Adds the given nature to the given project, if it is not already added
static java.lang.String doubleBackslash(java.lang.String s)
          This method does what I think s.replaceAll("\\","\\\\") is supposed to do, but that crashes.
static int execAndWait(java.lang.String[] args)
           
static int execAndWait(java.lang.String command, java.lang.String[] env, java.io.File cd)
           
static java.lang.String findPluginResource(java.lang.String pluginName, java.lang.String path)
          Returns the absolute file system location of a file inside a plugin.
static boolean isBuilderEnabled(IProject p, java.lang.String builder)
          Checks whether a project is enabled for a given builder (both has the builder and the builder is turned on).
static boolean isDisabledCommand(ICommand c, java.lang.String b)
          This routine checks whether the given command is a disabled instance of the given builder.
static boolean isEnabledCommand(ICommand c, java.lang.String b)
          This routine checks whether the given command is an enabled instance of the given builder.
static ICommand newDisabledCommand(IProject project, IProjectDescription description, java.lang.String builder)
          This method creates a new builder command of the specified type, but in a disabled state.
static void readAllInput(java.io.InputStream i, java.io.OutputStream o)
          Reads input from the input and writes it to the output until the input stream runs out of data, but does all this in a new thread.
static ICommand[] removeBuilder(ICommand[] commands, java.lang.String builder)
          Removes the given builder from the list of commands.
static void removeBuilder(IProject project, java.lang.String builder)
          Removes the given builder from a project.
static boolean removeNature(IProject project, java.lang.String natureId)
          Removes the given nature from the given project, if it is present
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eol

public static final java.lang.String eol
A convenience holder for the end-of-line String for the current platform.

Constructor Detail

Utils

public Utils()
Method Detail

addNature

public static boolean addNature(IProject project,
                                java.lang.String natureId)
                         throws org.eclipse.core.runtime.CoreException
Adds the given nature to the given project, if it is not already added

Parameters:
project - The project to add the nature to
natureId - The nature to add
Returns:
true if the nature is added, false if the nature was already present
Throws:
org.eclipse.core.runtime.CoreException

removeNature

public static boolean removeNature(IProject project,
                                   java.lang.String natureId)
                            throws org.eclipse.core.runtime.CoreException
Removes the given nature from the given project, if it is present

Parameters:
project - The project to remove the nature from
natureId - The nature to remove
Returns:
true if the nature was removed, false if the nature was not present
Throws:
org.eclipse.core.runtime.CoreException

isEnabledCommand

public static boolean isEnabledCommand(ICommand c,
                                       java.lang.String b)
This routine checks whether the given command is an enabled instance of the given builder.

Parameters:
c - The command to be tested
b - The builder
Returns:
true if the command is a enabled instance of the builder, false otherwise

isDisabledCommand

public static boolean isDisabledCommand(ICommand c,
                                        java.lang.String b)
This routine checks whether the given command is a disabled instance of the given builder. This may well be fragile with version changes.

Parameters:
c - The command to be tested
b - The builder
Returns:
true if the command is a disabled instance of the builder, false otherwise

newDisabledCommand

public static ICommand newDisabledCommand(IProject project,
                                          IProjectDescription description,
                                          java.lang.String builder)
                                   throws org.eclipse.core.runtime.CoreException
This method creates a new builder command of the specified type, but in a disabled state. It is not valid if there already is a builder of this type present.

Parameters:
project - The project to which this will belong
description - The project description
builder - The builder name
Returns:
the new builder command
Throws:
org.eclipse.core.runtime.CoreException

addBuilder

public static ICommand[] addBuilder(IProject project,
                                    ICommand[] commands,
                                    IProjectDescription description,
                                    java.lang.String builder,
                                    boolean enabled)
                             throws org.eclipse.core.runtime.CoreException
Adds the given builder to the list of commands.

Parameters:
project - The project whose commands are being added to
commands - The current set of project commands
description - The current project's description
builder - The name of the builder to add, if not already present.
enabled - If true, the builder is installed in the enabled state, if false it is installed in the disabled state
Returns:
The resulting set of commands.
Throws:
org.eclipse.core.runtime.CoreException

addBuilder

public static void addBuilder(IProject project,
                              java.lang.String builder)
                       throws org.eclipse.core.runtime.CoreException
Adds an enabled builder to the given project

Parameters:
project - The project to add a builder to
builder - The builder to add
Throws:
org.eclipse.core.runtime.CoreException

removeBuilder

public static ICommand[] removeBuilder(ICommand[] commands,
                                       java.lang.String builder)
Removes the given builder from the list of commands.

Parameters:
commands - The current set of project commands
builder - The name of the builder to remove, if present.
Returns:
The resulting set of commands.

removeBuilder

public static void removeBuilder(IProject project,
                                 java.lang.String builder)
                          throws org.eclipse.core.runtime.CoreException
Removes the given builder from a project.

Parameters:
project - The project whose builder is to be removed
builder - The name of the builder to remove, if present.
Throws:
org.eclipse.core.runtime.CoreException

isBuilderEnabled

public static boolean isBuilderEnabled(IProject p,
                                       java.lang.String builder)
                                throws org.eclipse.core.runtime.CoreException
Checks whether a project is enabled for a given builder (both has the builder and the builder is turned on).

Parameters:
p - The project to check
builder - The id of the builder to look for
Returns:
true if the project has the builder and it is enabled, false otherwise
Throws:
org.eclipse.core.runtime.CoreException

findPluginResource

public static java.lang.String findPluginResource(java.lang.String pluginName,
                                                  java.lang.String path)
                                           throws java.io.IOException
Returns the absolute file system location of a file inside a plugin.

Parameters:
pluginName - The name of the plugin
path - The path (as a String) of the file within the plugin
Returns:
The absolute file system location of the target file
Throws:
java.io.IOException

doubleBackslash

public static java.lang.String doubleBackslash(java.lang.String s)
This method does what I think s.replaceAll("\\","\\\\") is supposed to do, but that crashes.

Parameters:
s - Input string
Returns:
the input string with any occurrence of a backslash replaced by a double backslash

readAllInput

public static void readAllInput(java.io.InputStream i,
                                java.io.OutputStream o)
Reads input from the input and writes it to the output until the input stream runs out of data, but does all this in a new thread.

Parameters:
i - Stream to read from
o - Stream to write to

execAndWait

public static int execAndWait(java.lang.String[] args)
                       throws java.io.IOException,
                              java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

execAndWait

public static int execAndWait(java.lang.String command,
                              java.lang.String[] env,
                              java.io.File cd)
                       throws java.io.IOException,
                              java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException