Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 287622

Summary: Autogenerate plugin.xml entries using Groovy's MarkupBuilder
Product: Community Reporter: Antóin Óg Ó Cuinneagáin <anthony.cunningham>
Component: ArticlesAssignee: community.articles-inbox <community.articles-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: anthony.cunningham
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug
Attachments:
Description Flags
Basic article with same text as initial comment
none
Screenshot none

Description Antóin Óg Ó Cuinneagáin CLA 2009-08-25 18:28:41 EDT
Created attachment 145607 [details]
Basic article with same text as initial comment

Groovy has an XML Builder called MarkupBuilder
http://groovy.codehaus.org/Creating+XML+using+Groovy%27s+MarkupBuilder

code like this:
def xml = new MarkupBuilder(writer)
xml.records() {
  car(name:'HSV Maloo', make:'Holden', year:2006) {
    country('Australia')
    record(type:'speed', 'Production Pickup Truck with speed of 271kph')
  }

Produces XML like this:
 <records>
      <car name='HSV Maloo' make='Holden' year='2006'>
        <country>Australia</country>
        <record type='speed'>Production Pickup Truck with speed of 271kph</record>
      </car>


This could be useful for autogenerating extensions like commands, which also need corresponding handlers, menu entries, and commandImages.  The list of commands could also come from a Use Case document.

An example:
This groovy code:
def UseCases=[
              "CreateProject":"Create a new Project",
              "CreateBusinessObject":"Create a new Business Object",
              "GenerateDocumention":"Generate Documentation"
              ]

def pluginXMLFile=new  FileWriter(workspaceRoot+"/"+pkgSuffix+"/plugin.xml");
def pluginXML=new MarkupBuilder(pluginXMLFile);
pluginXML.setDoubleQuotes true

pluginXML.plugin(){
	extension(point:"org.eclipse.ui.commands"){
		UseCases.each {
			command(id:pkgSuffix+"."+it.key,name:it.value)
			}
	}
	extension(point:"org.eclipse.ui.commandImages"){
		UseCases.each {
			image(commandId:pkgSuffix+"."+it.key,icon:"icons/sample.gif")
			}
	}
	extension(point:"org.eclipse.ui.handlers"){
		UseCases.each {
			handler(commandId:pkgSuffix+"."+it.key,class:pkgSuffix+".handler.CommonHandler")
			}
	}
	extension(point:"org.eclipse.ui.menus"){
		menuContribution(locationURI:"menu:org.eclipse.ui.main.menu?after=additions"){
			menu(id:pkgSuffix+".menus.sampleMenu",label:"Sample Menu"){
				UseCases.each {
					command(commandId:pkgSuffix+"."+it.key)
					}				
			}
		}
	}
}

Produces this xml:
<plugin>
  <extension point="org.eclipse.ui.commands">
    <command id="com.companyname.groovygen.CreateProject" name="Create a new Project" />
    <command id="com.companyname.groovygen.CreateBusinessObject" name="Create a new Business Object" />
    <command id="com.companyname.groovygen.GenerateDocumention" name="Generate Documentation" />
  </extension>
  <extension point="org.eclipse.ui.commandImages">
    <image commandId="com.companyname.groovygen.CreateProject" icon="icons/sample.gif" />
    <image commandId="com.companyname.groovygen.CreateBusinessObject" icon="icons/sample.gif" />
    <image commandId="com.companyname.groovygen.GenerateDocumention" icon="icons/sample.gif" />
  </extension>
  <extension point="org.eclipse.ui.handlers">
    <handler commandId="com.companyname.groovygen.CreateProject" class="com.companyname.groovygen.handler.CommonHandler" />
    <handler commandId="com.companyname.groovygen.CreateBusinessObject" class="com.companyname.groovygen.handler.CommonHandler" />
    <handler commandId="com.companyname.groovygen.GenerateDocumention" class="com.companyname.groovygen.handler.CommonHandler" />
  </extension>
  <extension point="org.eclipse.ui.menus">
    <menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
      <menu id="com.companyname.groovygen.menus.sampleMenu" label="Sample Menu">
        <command commandId="com.companyname.groovygen.CreateProject" />
        <command commandId="com.companyname.groovygen.CreateBusinessObject" />
        <command commandId="com.companyname.groovygen.GenerateDocumention" />
      </menu>
    </menuContribution>
  </extension>
</plugin>
Comment 1 Antóin Óg Ó Cuinneagáin CLA 2009-08-25 18:30:45 EDT
UseCases.each could also be used to auto generate cheat sheets for commands
Comment 2 Antóin Óg Ó Cuinneagáin CLA 2009-08-25 18:54:43 EDT
Created attachment 145610 [details]
Screenshot

Added a screenshot

Plan to add menu/toolbar/popup contributions for all commands and create composite screenshot of all activated at once
Comment 3 Antóin Óg Ó Cuinneagáin CLA 2009-09-04 08:01:11 EDT
Could use a fragment plugin to keep generated plugin.xml separate to manually edited one
Comment 4 Eclipse Genie CLA 2014-06-15 14:17:19 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Wayne Beaton CLA 2014-10-06 15:59:39 EDT
We're no longer taking articles for Eclipse Corner. Further, this bug has been in the system with little activity for some time. Feel free to reopen.