Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Tigerstripe Simple Plugin Tutorial"

(Creating a simple Tigerstripe plugin)
 
Line 1: Line 1:
=Create a new Tigerstripe Plug-in Project=
 
  
 
This tutorial will walk you through creating your own '''[[Tigerstripe_Glossary#Tigerstripe Plugin|Tigerstripe Plugin]]''' plug-in for your code.  By writing your own '''[[Tigerstripe_Glossary#Tigerstripe Plugin|plugin]]''', you can define your own rules and conventions for the code that is generated from a '''[[Tigerstripe_Glossary#Tigerstripe Project|Tigerstripe Model Project]]'''.
 
This tutorial will walk you through creating your own '''[[Tigerstripe_Glossary#Tigerstripe Plugin|Tigerstripe Plugin]]''' plug-in for your code.  By writing your own '''[[Tigerstripe_Glossary#Tigerstripe Plugin|plugin]]''', you can define your own rules and conventions for the code that is generated from a '''[[Tigerstripe_Glossary#Tigerstripe Project|Tigerstripe Model Project]]'''.
Line 6: Line 5:
  
 
As you work through this tutorial, you will generate a simple java class, based on a single entity. You will see how easy it is to modify and enhance the generated code in templates.
 
As you work through this tutorial, you will generate a simple java class, based on a single entity. You will see how easy it is to modify and enhance the generated code in templates.
 +
 +
=Create a new Tigerstripe Plug-in Project=
  
 
'''[[Tigerstripe_Glossary#Tigerstripe Plugin Project|Tigerstripe Plugin Projects]]''' share some common behavior with standard '''[[Tigerstripe_Glossary#Tigerstripe Project|Tigerstripe Model Projects]]''' except that a '''[[Tigerstripe_Glossary#Tigerstripe Plugin Project|plugin project]]''' contains details of a plug-in that you can use to generate output based on a model.  
 
'''[[Tigerstripe_Glossary#Tigerstripe Plugin Project|Tigerstripe Plugin Projects]]''' share some common behavior with standard '''[[Tigerstripe_Glossary#Tigerstripe Project|Tigerstripe Model Projects]]''' except that a '''[[Tigerstripe_Glossary#Tigerstripe Plugin Project|plugin project]]''' contains details of a plug-in that you can use to generate output based on a model.  
Line 18: Line 19:
 
* Additional .jar files
 
* Additional .jar files
  
To create a new '''[[Tigerstripe_Glossary#Tigerstripe Plugin Project|Tigerstripe Plugin Project]]''':
+
To create a new '''[[Tigerstripe_Glossary#Tigerstripe Plugin Project|Tigerstripe Plugin Project]]''':
  
# From the '''File''' menu, select '''New''' and click Project. The New Tigerstripe Plug-in Project dialog box opens.
+
# From the '''File''' menu, select '''New''' and click Project. Select the '''Tigerstripe Plugin Project''' under the '''Tigerstripe''' heading. The '''New Tigerstripe Plug-in Project dialog''' box opens.
 
# Enter a name for the plug-in.
 
# Enter a name for the plug-in.
#* For this tutorial, the name is SimplePluginProject.
+
#* For this tutorial, the name is ''SimplePluginProject''.
 
# Click '''Finish''' to create the new plug-in. An editor displays that appears similar to the standard Tigerstripe Project Editor.
 
# Click '''Finish''' to create the new plug-in. An editor displays that appears similar to the standard Tigerstripe Project Editor.
 
# Enter a description and version number for your new plug-in in the appropriate text boxes and click Save.
 
# Enter a description and version number for your new plug-in in the appropriate text boxes and click Save.
Line 30: Line 31:
 
=Create Global Plug-in Properties=
 
=Create Global Plug-in Properties=
  
In some situations, you may want the user of your plug-in to be able to specify the value for a particular property when they run the plug-in. Such as:
+
In many situations, you may want the user of your plug-in to be able to specify the value for a particular property when they run the plug-in. Such as:
 
+
    *
+
 
+
      Setting the name of a Directory
+
    *
+
  
      Flagging the adoptions of certain behavior
+
* Setting the name of a Directory
 +
* Flagging the adoption of certain optional behavior
  
These tasks can be accomplished by creating Global Properties. Complete the following procedure to create Global Properties:
+
These tasks can be accomplished by creating [[Tigerstripe_Glossary#Global Properties|Global Properties]].
  
To create global plug-in properties:
+
To create [[Tigerstripe_Glossary#Global Properties|Global Properties]]:
  
  1.
+
# Click the '''Properties''' tab in the '''Plug-in Project Editor'''.
      Click the Properties tab in the Plug-in Project Editor.
+
# Select '''Global Properties''' and click '''Add''' to create a new property.
  2.
+
# Enter a name for your property and click '''OK'''.
      Select Global Properties and click Add to create a new property.
+
#* For this tutorial, the name is ''directoryName''.
  3.
+
# Complete step 1 through step 3 to create a second property named ''flag''.
      Enter a name for your property and click OK.
+
# Change the ''flag'' property type to '''Boolean'''.
      For this tutorial, the name is directoryName.
+
# Review the [[Tigerstripe_Glossary#Global Properties|Global Properties]] for the plug-in and add any required ''Tool tip text'' or ''Default values''.
  4.
+
# Click '''Save'''.
      Complete step 1 through step 3 to create a second property named flag.
+
  5.
+
      Change the flag property type to Boolean.
+
  6.
+
      Review the Global Properties for the plug-in and add any required tool tip text or default values.
+
  7.
+
      Click Save.
+
  
  
  
Create Velocity Templates
+
=Create Velocity Templates=
Defining your output.
+
  
A plug-in contains one or more templates, which contain information from relevant artifacts (i.e Entities) in the model within a particular project in which the plug-in is run. Tigerstripe uses an apache utility called Velocity to create the output.  For more information about Velocity, refer to http://jakarta.apache.org/velocity/index.html.  
+
A plug-in contains one or more '''[[Tigerstripe_Glossary#Velocity Template|Velocity Templates]]''', which contain information from relevant artifacts (i.e Entities) in the model within a particular project in which the plug-in is run. Tigerstripe uses an apache utility called Velocity to create the output.  For more information about Velocity, refer to http://jakarta.apache.org/velocity/index.html.  
  
 
In this tutorial, you will create a template file. Complete the following procedure to create a template file.
 
In this tutorial, you will create a template file. Complete the following procedure to create a template file.

Revision as of 08:37, 10 January 2008

This tutorial will walk you through creating your own Tigerstripe Plugin plug-in for your code. By writing your own plugin, you can define your own rules and conventions for the code that is generated from a Tigerstripe Model Project.

In many cases, you may want to write your own plugin so that you can create code according to your own organizations standards, or you may need some HTML to document your project model. Furthermore, by creating your own plugin you can distribute it to other users within your organization to ensure that all users are using the same coding rules and conventions when generating code.

As you work through this tutorial, you will generate a simple java class, based on a single entity. You will see how easy it is to modify and enhance the generated code in templates.

Create a new Tigerstripe Plug-in Project

Tigerstripe Plugin Projects share some common behavior with standard Tigerstripe Model Projects except that a plugin project contains details of a plug-in that you can use to generate output based on a model.

A Tigerstripe Plugin Project includes the following:

  • Global Properties – Used to allow specific information for use in a given Tigerstripe Project. For example, the name of a directory where certain file types should be created.
  • Rules] – Define the actual behavior of the plug-in.
  • Runtime references – Specify additional files required by the plug-in at run-time (eg .jar files).
  • Velocity templates.
  • Java source files for enhanced behavior.
  • Additional .jar files

To create a new Tigerstripe Plugin Project:

  1. From the File menu, select New and click Project. Select the Tigerstripe Plugin Project under the Tigerstripe heading. The New Tigerstripe Plug-in Project dialog box opens.
  2. Enter a name for the plug-in.
    • For this tutorial, the name is SimplePluginProject.
  3. Click Finish to create the new plug-in. An editor displays that appears similar to the standard Tigerstripe Project Editor.
  4. Enter a description and version number for your new plug-in in the appropriate text boxes and click Save.

Note: Click Help and select Help Contents for more information about the other options available in the New Tigerstripe Plug-in Project dialog box.

Create Global Plug-in Properties

In many situations, you may want the user of your plug-in to be able to specify the value for a particular property when they run the plug-in. Such as:

  • Setting the name of a Directory
  • Flagging the adoption of certain optional behavior

These tasks can be accomplished by creating Global Properties.

To create Global Properties:

  1. Click the Properties tab in the Plug-in Project Editor.
  2. Select Global Properties and click Add to create a new property.
  3. Enter a name for your property and click OK.
    • For this tutorial, the name is directoryName.
  4. Complete step 1 through step 3 to create a second property named flag.
  5. Change the flag property type to Boolean.
  6. Review the Global Properties for the plug-in and add any required Tool tip text or Default values.
  7. Click Save.


Create Velocity Templates

A plug-in contains one or more Velocity Templates, which contain information from relevant artifacts (i.e Entities) in the model within a particular project in which the plug-in is run. Tigerstripe uses an apache utility called Velocity to create the output. For more information about Velocity, refer to http://jakarta.apache.org/velocity/index.html.

In this tutorial, you will create a template file. Complete the following procedure to create a template file.

To create a template file:

  1.
     Select the Templates directory in the Tigerstripe Explorer.
  2.
     From the File menu, click New, and select Other. You can also accomplish this step by right-clicking on the Templates directory. From the shortcut menu, click New and select Other.
  3. Select General and click File from then specify a filename for the file you wish to create.
     For this tutorial, name the file simpleTemplate.vm. 
     You will save your template file in the Templates directory of your SimplePluginProject. The file must be in the Templates directory, but the .vm file extension is simply a convention.  You could use another suffix.

A text editor will open. In this template you will need to use Velocity syntax. Some brief points are about Velocity are as follows:

   * Use ##  to indicate a Velocity comment.
   * Use # to call Velocity directives. For example, #set.
   * Use $ to indicate variables.
   * All other text entered will appear in the output file.

To create a basic Java class:

In this procedure you will create a basic Java class based on an entity.

  1. Enter the following text into your text editor:
     ## This is simpleTemplate.vm
     // This file was generated using "simpleTemplate.vm"
     public class  $artifact.Name {
         private boolean myBoolean = $pluginRef.Properties.getProperty("flag") ;
     }
  2. Save your changes. Your text editor should look similar to the following image.

The first line is a comment internal to the template and this text will not appear in the final output. The following line will appear in the final output. It is good practice to enter this information so you can easily determine what template your generated files utilized.

The $artifact.Name in the public class line and will be replaced with the name of the artifact against which this template is run. For example, in the Simple Tutorial Project this would be either Order or OrderFacade.

Finally the reference $pluginRef.Properties.getProperty("flag") is replaced with the value of the flag.

Note: This information comes directly from the plug-in property, and not the artifact.

The next step is to set when this template is executed. Define a Plug-in Rule An Artifact Based Rule.

Now that you have a template, you are going to need to configure the rule to populate your template.

To configure your rule:

  1. Select the Rules tab in the editor for the plug-in project.
  2. Select the Artifact Rules section, and click Add to add a new rule.
     For this tutorial, name your rule Simplerule.
  3. Click OK.
  4. Define your rule. A set of options for defining your rule will display. Some options are self-explanantory, while others are beyond the scope of this tutorial. The ones you need to look at are:
         * Template - Click Browse button and select the template you created.
         * Output File - Select the directory to where you want the output file created. The file name must be unique for each artifact that you process. The following file format will acheive this:
           ${ppProp.directoryName}/${artifact.Name}.out
           Where ${xxx} signals the plug-in to replace text, ppProp signals the plug-in that a plug-in property should be used, and similarly for the artifact.
         * ArtifactType - Select the type of artifact that the rule applies to from the drop-down list. An Artifact Based Rule only processes one type of artifact.  For this tutorial, use Managed Entity Artifact.
           Note: You can have several rules that use the same template.
  5. Click Save to save your plug-in.

Test the Plug-in In your local Environment.

Before distributing your plug-in, you should perform some testing to make sure you obtain the output you want.

To test your plug-in:

  1. Click Package and deploy this plugin within the Testing section on the Overview tab of the editor. Your plug-in is now available to all projects in your workspace!
  2. Run your plug-in from a Tigerstripe project.
  3. Select a Tigerstripe project and open the editor for that project by double clicking on tigerstripe.xml file.
  4. Open the Generation tab and a new section for the plug-in you just deployed will appear. At this stage, your plug-in is disabled. 
  5. Open your plug-in and click Enable to enable your plug-in on the Generation tab. Enabling your plug-in will also enable all of the other controls for that plug-in.  You can override the defaults specified during definition of your plug-in however, don't change these values.
  6. Click Save to save the Tigerstripe project.
     Note: You may wish to disable all other plug-ins when testing your new plug-in.


  7. Make sure you have the project in scope and click Generate (generateIcon).
  8. Review your generated code. 

If you used the settings as described above, you should find a new directory in the target directory of your project. This new directory is named default and contains a file called Order.out.

Note: Your default directory may contain additional files if you have more than one entity in your project.

The content of the file should look similar to the below image:


Further Testing

Note: Tigerstripe does not delete files in your target directory; therefore you may want to delete the default directory before re-testing your plug-in.

Add more entities to your project, and change the value of the directoryName property.

Changes to your model (artifacts) and property values are specific to the Tigerstripe Project so they will automatically be picked up by your plug-in, however if you change the associated template, add new rules, or change property definitions, don't forget to re-deploy your plug-in before running it again.

You are now ready to package your plug-in for others to use. Distribute your Plug-in To other users.

To package and distribute your plug-in:

  1. Navigate to your plug-in editor and locate the Package up this plugin link in the Packaging section on the Overview tab.
  2. Click the packaging link and name your plug-in.
  3. Navigate to where you want to save your plug-in and click Open.
  4. A message box appears upon successfully packaging your plug-in. Click OK to close the message box.

You can then distribute the resultant .zip file to other Tigerstripe users who can deploy your plug-in by placing the .zip file in their Tigerstripe plug-ins directory. (ECLIPSE_HOME\tigerstripe\plugins)

Complete the following procedure to see a list of deployed plug-ins in your Tigerstripe plug-ins directory.

To view a list of deployed plug-ins:

   * Click the Tigerstripe menu and click Plugins. The Deployed Tigerstripe Plugins dialog box opens.

To un-deploy a previously deployed plug-in:

  1. Open the Deployed Tigerstripe Plugins dialog box.
  2. Right-click on the plug-in and select Un-deploy.

Note: Remember that you will need to enable this plug-in manually in your Tigerstripe project if you wish to utilize it in another project.

Everyone in your organization will now be able to apply the same rules to their model and you can be sure of generating consistent results for all projects.

Back to the top