IntelliJ Community . MirrorPlugin

 
MirrorPlugin 

HOME INDEX SEARCH CHANGES GO  

MirrorPlugin

What is it?

The Mirror plugin generates JUnit test skeletons. It monitors changes to the source tree (file and directory additions, deletions, renames and moves), and makes sympathetic changes (builds test skeletons) under a mirror directory which you specify.

The files in the mirror directory are created using Velocity templates.

You have complete control over what the Velocity templates generate, but the original intention was to somehow automate the creation of JUnit test skeletons. Yeah, I know, you should generate your tests before you start coding, but I'm lazy and forgetful.

Sample Velocity templates provided are called:

  • mirror_java.vm - To create a JUnit test skeleton for any java files in your source path.
  • mirror_master.vm - To create a JUnit package test skeleton for each directory in your source path.
  • dump_variables.vm - To list all the Velocity variables that you can use in your Velocity templates.

If you need to mirror files other than java files, for example, txt files, then you can create a Velocity template called mirror_txt.vm. If no template is found for a file extension, then no mirror file can be created. You get the idea.

Change History

Most Recent

  • 22 Oct 2002 User can specify the mirror output directory.
  • 11 Oct 2002 Fixed NPE loading icon.
  • 04 Oct 2002 Idea now ships with JDOM 1.0 beta 7 instead of beta 8, so I had to remove a 1.0 beta 8 "getAttributeValue(String,String)" method invocation.
  • 26 Sep 2002 Minor template changes for JUnit 3.8.1
  • 06 Sep 2002 Added a configuration panel (accessed via File/Project Properties/MirrorPlugin). Velocity variables can now be added/deleted/edited interactively. The variables are stored using 'var' elements in your project file. You can define either simple strings, or you can specify the name of a class to be instantiated. This way, you can customize the variables available in your Velocity templates without having to modify the Mirror plugin source.

Others

Click the 'action' link next to the zip file at the bottom of this page.

Credits

A big thankyou to StefanMainz for introducing me to the wonders of the Velocity template engine with his NewFromTemplatePlugin. Stefan, there are still vestiges of your code in the Mirror plugin - duely credited, of course.

A Practical Use: JUnit Test Skeleton Maintenance

The Velocity templates supplied with the plugin will do the following:

  1. Create a JUnit test skeleton file in the mirror directory for each source file added.
  2. For each source directory a "master" mirror file will be generated containing java code that will run the JUnit tests for that package and any subpackages.
  3. List all the Velocity variables that you have available. You can delete this list by removing the line
      #parse ("dump_variables.vm")
from the two templates (mirror_java.vm and mirror_master.vm).

If you already have an existing source tree, then you can force the generation of the JUnit skeletons by right-clicking the source file (or directory) in the Project View and selecting the "Mirror" command.

Limitations

  1. You must manually add the mirror output directory to your project source paths as there is currently no way (that I can see) to do this programmatically.
  2. If you rename a source file, then the mirror file will also be renamed, but the class names within the mirror file will remain unchanged. Judicious application of your keyboard typing skills to the offending mirror files should remedy the problem.
  3. As shipped, the JUnit skeletons cause IDEA to complain about unresolved package names - but they compile and run OK. I'm willing to put up with this because I like the way the mirror file names line up under the source files in the Project View (pretty lame, but it's the best excuse I've got). If you dont like the warnings, then you can change the templates to make the package names match the directory names.
  4. Due to catastrophic brain failure on the part of the author, the automatic generation of a test case for each method in a class will almost certainly not work! The new Psi API looks promising (and better anyway) as a solution.

How to install

  1. Unzip MirrorPlugin.zip to a directory of your choice.
  2. Open the MirrorPlugin.ipr project file in IDEA.
  3. Edit the build.xml file and adjust the property called "dir.idea" to match your IDEA installation directory:
    • property name="dir.idea" value="d:/java/idea660"
  4. Run the default ant build target (which is "all"). This will:
    • Compile the plugin into a jar.
    • Copy the jar to $IDEA_HOME$/plugins.
    • Copy sample Velocity macros to $IDEA_HOME$/plugins/templates.
  5. Stop and restart IDEA.
  6. The MirrorPlugin is disabled by default. You will have to get into File | Project Properties | MirrorPlugin and enable it.

How to use

  1. Open the Project Properties dialog and select MirrorPlugin. You can add your own Velocity variables here (which may define strings or classes). Each variable describes a named String or class that can be referenced in your Velocity templates.
  2. Dont forget to check the 'Enable Mirror Plugin' checkbox.
  3. Set the variable MIRROR_OUTPUT_PATH to where you want to store files generated by the mirror plugin. It may be a relative path. You will be prompted to create it and add it to your project source path.
  4. Add the MIRROR_OUTPUT_PATH to your project source path - the plugin will not work unless this is done.
  5. Now create a class, or right-click an existing class and choose the "Mirror" command.
  6. As supplied, a new directory under your project called "tst" should appear.
  7. To run the JUnit tests, right-click a mirror class and choose either the "Test" or "Run" command. It doesn't matter which, because "Run" invokes the main method which the templates, as supplied, generate, and "Test" uses introspection to run the tests.

Feature Request

It would be good if the location of the MIRROR_DIRECTORY, and not just the name could be set in the variables.-- FlorianHehlen - 17 Oct 2002

Done in 1.11

Note that MIRROR_DIRECTORY variable has now been replaced by two variables:

  • MIRROR_OUTPUT_PATH - the output path (may be relative). This initially defaults to the 'tst' directory under your project.
  • MIRROR_PACKAGE_PREFIX - the package prefix (e.g. tst) for generated source files.

-- AndrewArmstrong - 22 Oct 2002

IntelliJPluginWebForm
IntelliJPluginName: MirrorPlugin
IntelliJPluginVersion: 1.14
IntelliJPluginVendor: AndrewArmstrong
IntelliJPluginBinary: http://www.intellij.org/twiki/pub/Main/MirrorPlugin/MirrorPlugin.jar
IntelliJPluginSource: http://www.intellij.org/twiki/pub/Main/MirrorPlugin/MirrorPlugin.zip
IntelliJPluginClassification:
TopicClassification: IntelliJPluginArchive
TopicShortDescription: The Mirror plugin generates JUnit test skeletons. It monitors changes to the source tree and uses Apache Velocity to build test skeletons under a mirror directory that you specify.
TestedOnOS: OsWin2K
ShouldRunOnOS: AnyOS

Attachment: sort Action: Size: Date: Who: Comment:
MirrorPlugin.zip action 117578 07 Nov 2002 - 09:53 AndrewArmstrong Fixed missing gif file in zip - again :-/

e d i t a t t a c h r e f - b y d i f f s m o r e
Have ideas, requests, problems regarding this site? Send feedback.
Copyright © 2000-2003 by the contributing authors. All materials at intellij.org are the property of the contributing authors.