Ruben Laguna's blog

Sep 25, 2006 - 1 minute read - Comments - eclipse eclipsemonkey groovy groovymonkey icons java

Using GroovyMonkey to obtain all eclipse icons 2

I’ve been playing with GroovyMonkey that is more or less a patch to EclipseMonkey that allows to run other languages besides Javascript. With this Eclipse plugin you can run javascript, groovy, etc. scripts that interacts with the Eclipse API. To get an impression of what you can do with GroovyMonkey take a look to these posts (1, 2, 3, 4 ). Following those post you can make a script to download all eclipse icons from the eclipse repository. My first GroovyMonkey script generates a webpage with all eclipse icons (previously downloaded with the example scripts) to easily spot the icons.

/*
 * Menu: Get Eclipse Icons > Make web page
 * Script-Path: /EclipseIcons/monkey/make_web_page.gm
 * Kudos: ecerulm
 * License: EPL 1.0
 */

def findFilesinFolder(folder) {
  def toReturn = new ArrayList();

  folder.members().each {
    if (it instanceof org.eclipse.core.resources.IFolder) {
      toReturn.addAll(findFilesinFolder(it));
    } else {
      toReturn.add(it);
    }
  }

  return toReturn;
}
def targetProject = workspace.getRoot().getProject( 'EclipseIcons' )
def iconsFolder = targetProject.getFolder("icons");
def buf = new StringBuffer();
buf.append "

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
\n";
buf.append "

<html>
<head>
<title>
Eclipse Icons

</title>
</head>
<body>
";
def members = iconsFolder.members();
members.each { plugin ->
  if (plugin instanceof org.eclipse.core.resources.IFolder) {
    def name = plugin.getName();

    findFilesinFolder(plugin).each {arg ->;
      def location = arg.getLocation().toString();
      def l = iconsFolder.getLocation().toString().length()+1;
      location = location.substring(l);
      buf.append "<a href=\""+location+"\" title=\""+location+"\"> <img src=\""+location+"\" alt=\"location\"/></a>\n";
  }
  }
}
buf.append "
</body>
</html>
";

contents = buf.toString();
def indexHtml = iconsFolder.getFile("index.html");
if (indexHtml.exists()) {
  indexHtml.delete(false, true, null);
}
fileStream = new ByteArrayInputStream(contents.getBytes("UTF-8"));
indexHtml.create(fileStream, false, null);

If you have trouble seeing the script code try this gist

Nintendo Wii Nightly Tester Tools for Firefox 2.0