23 August, 2006

The Sci-Fi Character Quiz

Which Fantasy/SciFi Character Are You?

Another Geek Quiz! Via Bilz. Apparently I'm a formally schooled Shakespearean actor. Who knew?

22 August, 2006

Working with the Workspace in Eclipse Plug-in Tests

Okay, I've had to figure out how to do this a number of different times that exceeds two; so now I'm writing it down.

The Situation

I want to create a file in the test runtime workspace that I can run tests against.

The Solution, v0.1 ... (beta)

@Before
protected void setUp() throws Exception {
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

   // Create a project in the runtime workspace
   IProject project = root.getProject( "My-Test-Project" );
   project.create( null );
   project.open( null );

   // Get a file from the test plug-in's bundle path
   URL url = MyTestPlugin.getDefault().getBundle().getEntry( "/" );
   URL fileUrl = new URL( url, "resources/my-source-file.txt" );
   String filePath = FileLocator.toFileURL( fileUrl ).getFile();
   File sourceFile = new File( filePath );

   // Create a folder and file in the test workspace
   IFolder folder = project.getFolder( "src" );
   folder.create( false, true, null );
   IFile file = folder.getFile( "testfile.txt" );

   // and set its contents to the file from the plug-in
   file.create( new FileInputStream( sourceFile ), false, null );
}

You will have to delete the project in tearDown. Otherwise, the next time setUp gets called, you'll get a ResourceException.

06 August, 2006

More Eclipse Monkey

Today's Eclipse Monkey offering is entirely selfish in its utility. It updates the version number of any locally modified plug-ins in my workspace.

I've reformatted it a bit to make it fit a little better on this page.

--- Came wiffling through the eclipsey wood ---
/*
 * Menu: Versions > Update Versions of Modified Plug Ins
 * Kudos: Toby Tripp
 * License: EPL 1.0
 *
 * The Update Site URL and Feature ID of the "DOM"
 * for this script:
 * DOM: http://tripp.no-ip.org/eclipse/updates/com.ttripp.eclipsemonkey.doms
 *
 * The above DOM provides the following objects:
 *  * svn - com.ttripp.eclipsemonkey.doms.subversion.SubversionResources
 *  * pluginVersion - com.ttripp.eclipsemonkey.doms.plugins.PluginsFacade
 *
 * Note that this DOM depends on the Subclipse plug-in:
 *   http://subclipse.tigris.org/update_1.2.x
 */
 function main() {
  
    var verIndex =
       Packages.com.ttripp.eclipsemonkey.doms.plugins.PluginsFacade.UPDATE_VERSION
  
    // dirtyProjects returns an array of 
    // Subversion resources (ISVNLocalResource)
    var dirtyProjects = svn.dirtyProjects();
  
    for each( project in dirtyProjects ) {
   
       // This call will increment, by one, the third (update)
       // index of the plug-ins version number.
       pluginVersion.incrementPluginVersion( project.getResource(),
                                             verIndex );
    }
 }
--- And burbled as it ran! ---

My First Eclipse Monkey Script

My mother must be so proud...

The following bit of javascript will search the current workspace for projects that are locally modified subversion resources. In other words, they're checked in to subversion, but need committing. It doesn't do much with the results except to present a dialog box. I'll show you later what you can do with that list.

To install the script, first you have to have Eclipse Monkey installed. Once you've got that set up: copy the javascript below, including the jabberwocky quote surrounding it, into the clipboard. Then, in eclipse, select the menu item "Monkey->Paste New Script" and away you go. The script will appear in the Monkey menu. Enjoy!

--- Came wiffling through the eclipsey wood ---
/*
 * Menu: Versions > Find Modified Projects
 * Kudos: Toby Tripp
 * License: EPL 1.0
 *
 * The Update Site URL and Feature ID of the "DOM" for this script:
 * DOM: http://tripp.no-ip.org/eclipse/updates/com.ttripp.eclipsemonkey.doms
 *
 * Note that this DOM depends on the Subclipse plug-in:
 *   http://subclipse.tigris.org/update_1.2.x
 */
 
 
 function main() {
  
  var dirtyProjects = svn.dirtyProjects();
  text = "\"Dirty\" Projects: (" + dirtyProjects.length + ")\n";
  
  for each( project in dirtyProjects ) {
   
   text += project.getIResource().getName() + "\n";
  }
  
  Packages.org.eclipse.jface.dialogs.MessageDialog.openInformation(  
        window.getShell(),  
        "Monkey Dialog", 
        text
     )
 }
 
--- And burbled as it ran! ---