RSS Feed for This PostCurrent Article

Java: Insert Copyright Header into Source Code

The Eclipse repository contains a tool that will fix copyrights in your code. It will insert copyrights into any files that are missing them, and will also attempt to insert the additional year for modified files (e.g. “2007, 2008”). To do the latter, the tool compares all files against the last revision from the previous year to see if there were any changes. So even if you didn’t change the file for this check in, it might be fixing the copyright for a previous change in the current year.

Here are the steps to load and run the fix copyrights tool.

  1. Load module org.eclipse.releng.tools from repository /cvsroot/eclipse on dev.eclipse.org.
  2. Export the plugin to your plugins directory by selecting Export… from the popup menu and then Deployable plugins and fragments
  3. Restart Eclipse to pick up the new plugin (shortcut is to choose File > Switch Workspace and indicate the same workspace).
  4. Go to Window > Preferences > Copyright Tool to set your copyright preferences.
  5. Set default creation year in the preferences to 2008 and default revision year to 2008. Click OK to save the preferences.
  6. Switch to the Resource perspective.
  7. Select all projects for which you want to run the tool and select Advanced Fix Copyrights from the context menu.
  8. Perform a team synchronization on the changed projects and commit the changes.


Trackback URL


RSS Feed for This Post2 Comment(s)

  1. Ken Gilmer | Jan 12, 2009 | Reply

    For Eclipse 3.3.2, the plugin has a compile error. Most likely the API has changed. I got it to compile by changing:

    SourceFile.java, Line 78:

    textFileBufferManager= FileBuffers.createTextFileBufferManager();

    To:

    textFileBufferManager= FileBuffers.getTextFileBufferManager();

  2. AndyJ | Mar 18, 2009 | Reply

    As of at least Eclipse 3.4, you can install these tools as a plugin using the Software Updates system instead of checking out, compiling and exporting the plugin.

Sorry, comments for this entry are closed at this time.