Drawing Hands by M.C. Escher (1948)

Jeff Mesnil


“Find Missing Headers” Monkey Script

On March 20th, 2006 in eclipse

Still playing with Eclipse Monkey.

I wrote this simple script based on the org.eclipse.dash.doms resources DOM. It looks for Java files to find the files which are missing copyright headers. In my script it is looking for the Eclipse Foundation copyright (Copyright (c) 2005 Eclipse Foundation).

 --- Came wiffling through the eclipsey wood ---
   /*
    * Menu: Find Missing Headers
    * Kudos: Jeff Mesnil
    *  License: EPL 1.0
    * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.dash.doms
    */

   function main() {
     var files = resources.filesMatching(".*\\.java");
     var match;
     for each( file in files ) { 
       file.removeMyTasks(  );
       if (!file.lines[1].string.match(/\* Copyright \(c\) 2005 Eclipse Foundation/)) {
            file.lines[1].addMyTask(file);
       }
     }
       window.getActivePage().showView("org.eclipse.ui.views.TaskList");
   }

   --- And burbled as it ran! ---

If I run it on my workspace with the imported org.eclipse.eclipsemonkey plug-in, it shows that one file is missing the copyright header: Java Files missing copyright headers

2 Responses to ““Find Missing Headers” Monkey Script”

  1. Gunnar Wagenknecht Says:

    There is a plug-in at Eclipse.org that does similar things. It walks through the files and update headers automatically (adding missing headers, updating years). I think it can be easily customized to your comment header.

    http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.releng.tools/

  2. jmesnil Says:

    Thanks Gunnar, I did not know that the releng plug-in could do that.

    But now I need to find another example of a Monkey Script which is not already offered by a plug-in ;-)