adding project templates: documentation and/or tutorials/examples?

234 views
Skip to first unread message

Scott Lewis

unread,
Feb 22, 2018, 7:45:46 PM2/22/18
to bndtools-users
Howdy,

It looks as though bndtools exposes the project templates as an extension point.   Is there any docs, tutorials, or examples of adding one's own project templates?

Thanksinadvance,

Scott

Frank Rosenberger

unread,
Feb 27, 2018, 10:41:25 AM2/27/18
to bndtools-users
Older Bndtools releases had an option to create a bnd template project. Theses included a readme.txt explaining the template creation process. Ican't find that in my current Bndtools installation (4.0) any more. :(

Here's said readme though:

Bndtools Template README
========================

Welcome to your new Bndtools template! Here are some notes on how to make your
template do what you want.

bnd.bnd
-------

The bnd.bnd file declares a Provide-Capability in the 'org.bndtools.template'
namespace. This enables Bndtools to find your template bundle in the
repository. The attributes on the capability are as follows:

 * 'org.bndtools.template': either 'project' or 'bndrun'
 * 'name': the name of the template
 * 'category': the category of the template (optional)
 * 'dir': the base dir of the template resources within your bundle; defaults
   to 'template'
 * 'help': path to a document within your bundle that will be displayed in
   the template selection dialog (optional)
 * 'icon': the URL of an icon for the template (optional)

For performance, is it strongly recommended to use the "data" URL scheme for
the icon, as defined in RFC 2397 of the IETF. The Base64 encoding of a file
can be embedded using a bnd macro (be careful about the file size!). For example:

    icon="data:image/gif;base64,${base64;icons/mytemplate.gif}"


Template Files
--------------

Within your template directory, create a folder structure that matches what you
want the template to generate. For example to generate the following layout:

    bnd.bnd
    src/Main.java

Then just create the same layout inside your template directory:

    bnd.bnd
    src/Main.java

Unless the file name is a recognized binary format, or has been explicitly
ignored (see below), it will be processed through StringTemplate before being
written out.

The default delimiter character used with StringTemplate is '$', so you can put
template expressions in the file as follows:

    Bundle-SybolicName: $projectName$

See below for a list of the parameter names passed into the template by Bndtools.

The output file names can also be processed by template. For example:

    $srcDir$/$basePackageDir$/Main.java

When the expected output is a single file (e.g. a bndrun file), that filename will be
supplied as the parameter 'fileName'. Therefore the template sources should contain a
file named '$fileName$'.


Parameter Names
---------------

Project templates can use any of the following parameter names:

    projectName -- name of the project
    version -- version of the project
    srcDir -- Java source directory
    basePackageName -- base Java package name
    basePackageDir -- base package dir (=basePackageName, with dots replaced by slashes)
    binDir -- output classes directory
    testSrcDir -- Java source directory for tests
    testBinDir -- output classes directory for tests
    targetDir -- bnd's target directory

Bndrun templates can use any of the following parameter names:

    fileName -- the name of the output file, as selected by the user
    fileBaseName -- the name of the output file, minus any extension
    projectName -- the name of the enclosing Eclipse project, if any

     
Customizing the Template Processor
----------------------------------

The processor can be customized by including a special file named
'_template.properties' in the template directory. For example this can be used
to use a different pair of delimiter characters:

    leftDelim: <
    rightDelim: >

These alternative delimiters will be used for filenames and templates.

You can also add instructions to process (or not process) certain filetypes
(this will be in addition to the recognised file types in bnd):

    # don't process .img files
    process.extra: !*.img

    # don't process OR copy readme.* files
    ignore: readme.*

Version Information
-------------------

This project was generated by the Bndtools Template-Template, version 3.1.0.201512181404
(git commit ffa01d94f8e6fc54c221ec696679eeceb93d916b).

BJ Hargrave

unread,
Feb 27, 2018, 10:50:30 AM2/27/18
to bndtool...@googlegroups.com
The org.bndtools.templates.osgi project is a project which defines a set of OSGi templates. The org.bndtools.templates.template project is a project which defines a set of template templates.

These project do not produce bundles which are installed in Eclipse along side the Bndtools plugins. Instead these projects produce bundles which are to be placed in an OSGi repository and indexed so that Bndtools can locate them by their org.bndtools.template capabilities. Your Bnd Workspace repositories can include these bundles so that each workspace can define the appropriate template for that workspace. You can also configure repositories to search for template in the Bndtools preferences of the Eclipse installation.

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
BJ

Scott Lewis

unread,
Apr 17, 2018, 1:45:12 PM4/17/18
to bndtools-users
Thanks for the info.

With bnd project templates is it possible to:

1) Add wizard pages to let the user choose some configuration upon project creation?

2) Create more than one bundle project (e.g. api + impl/provider) with a single wizard?

Thanksinadvance for any info and/or pointers.

Scott

Neil Bartlett

unread,
Apr 17, 2018, 3:49:43 PM4/17/18
to bndtool...@googlegroups.com

On 17 Apr 2018, at 18:45, Scott Lewis <scott...@gmail.com> wrote:

Thanks for the info.

With bnd project templates is it possible to:

1) Add wizard pages to let the user choose some configuration upon project creation?

Yes and no. You can define required properties for the template using OSGi MetaType format. The wizard will present a page for the user to populate those fields, skipping that page if there are no properties defined.

You do not have full flexibility to create an SWT WizardPage with programmatic validation etc. This is because the templates are 100% declarative.


2) Create more than one bundle project (e.g. api + impl/provider) with a single wizard?

No this is not currently possible.

- Neil

Tim Ward

unread,
Apr 18, 2018, 1:06:40 AM4/18/18
to bndtool...@googlegroups.com
Note that the answer to question 2 is unlikely to change in future. Eclipse is very focussed on creating one project at a time, and that’s where we hook in our templates. 

Tim

Sent from my iPhone

Scott Lewis

unread,
Apr 18, 2018, 11:46:19 AM4/18/18
to bndtools-users
Hi Neil,

Thanks for the answers.


On Tuesday, April 17, 2018 at 12:49:43 PM UTC-7, Neil Bartlett wrote:


On 17 Apr 2018, at 18:45, Scott Lewis <scott...@gmail.com> wrote:

Thanks for the info.

With bnd project templates is it possible to:

1) Add wizard pages to let the user choose some configuration upon project creation?

Yes and no. You can define required properties for the template using OSGi MetaType format. The wizard will present a page for the user to populate those fields, skipping that page if there are no properties defined.


I would like to use this.   Are there examples, docs, or source somewhere that describe how this can be done for a template?  (I know the metatype format, but I'm not sure what is expected from bndtools to use it in a template).

 

You do not have full flexibility to create an SWT WizardPage with programmatic validation etc. This is because the templates are 100% declarative.


2) Create more than one bundle project (e.g. api + impl/provider) with a single wizard?

No this is not currently possible.

Ok, thanks.

Scott

 

Scott Lewis

unread,
Apr 18, 2018, 11:49:59 AM4/18/18
to bndtools-users


On Tuesday, April 17, 2018 at 10:06:40 PM UTC-7, Tim Ward wrote:
Note that the answer to question 2 is unlikely to change in future. Eclipse is very focused on creating one project at a time, and that’s where we hook in our templates. 


I understand your point.   Unfortunately IMHO this makes some use cases (e.g. remote services and to some degree OSGi services in general) more complicated...particularly for new users.

Scott

Neil Bartlett

unread,
Apr 18, 2018, 12:36:27 PM4/18/18
to bndtool...@googlegroups.com
On Wed, Apr 18, 2018 at 4:46 PM, Scott Lewis <scott...@gmail.com> wrote:
Hi Neil,

Thanks for the answers.

On Tuesday, April 17, 2018 at 12:49:43 PM UTC-7, Neil Bartlett wrote:


On 17 Apr 2018, at 18:45, Scott Lewis <scott...@gmail.com> wrote:

Thanks for the info.

With bnd project templates is it possible to:

1) Add wizard pages to let the user choose some configuration upon project creation?

Yes and no. You can define required properties for the template using OSGi MetaType format. The wizard will present a page for the user to populate those fields, skipping that page if there are no properties defined.


I would like to use this.   Are there examples, docs, or source somewhere that describe how this can be done for a template?  (I know the metatype format, but I'm not sure what is expected from bndtools to use it in a template).

The annotation type ApplTemplateMeta.java defines the metatype information... this is processed into metatype XML by bnd (you wouldn't want to write this XML by hand!).

The bnd.bnd for the bundle defines three templates via its Provide-Capability header. The one labelled "Application" consumes the metatype declarations by setting a `metaType` attribute.

Regards,
Neil

 

 

You do not have full flexibility to create an SWT WizardPage with programmatic validation etc. This is because the templates are 100% declarative.


2) Create more than one bundle project (e.g. api + impl/provider) with a single wizard?

No this is not currently possible.

Ok, thanks.

Scott

 

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.

Scott Lewis

unread,
Apr 18, 2018, 1:03:33 PM4/18/18
to bndtools-users


The annotation type ApplTemplateMeta.java defines the metatype information... this is processed into metatype XML by bnd (you wouldn't want to write this XML by hand!).

Done it before...but happy not to.
 

The bnd.bnd for the bundle defines three templates via its Provide-Capability header. The one labelled "Application" consumes the metatype declarations by setting a `metaType` attribute.

Ok, thanks.

While I have a bit of your attention:   I would also like to create a couple of workspace templates that point to github locations.   I've found the workspace template meta-data for the "Minimal Workspace" in org.bndtools.templates.osgi, but that one doesn't seem to point to a github location.   I can't seem to find the metadata for the github workspaces listed in the new bndtools workspace. wizard..i.e. the  bndtools/workspace and osgi/enroute.workspace...these two obviously point to the associated github repo and this is what I would like to do also.

Where can I find the metadata for these two GitHub-based workspace templates?

Once again...thanksinadvance,

Scott



Regards,
Neil

 

 

You do not have full flexibility to create an SWT WizardPage with programmatic validation etc. This is because the templates are 100% declarative.


2) Create more than one bundle project (e.g. api + impl/provider) with a single wizard?

No this is not currently possible.

Ok, thanks.

Scott

 

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.

Scott Lewis

unread,
Apr 18, 2018, 1:25:05 PM4/18/18
to bndtools-users
<stuff deleted>
 
While I have a bit of your attention:   I would also like to create a couple of workspace templates that point to github locations.   I've found the workspace template meta-data for the "Minimal Workspace" in org.bndtools.templates.osgi, but that one doesn't seem to point to a github location.   I can't seem to find the metadata for the github workspaces listed in the new bndtools workspace. wizard..i.e. the  bndtools/workspace and osgi/enroute.workspace...these two obviously point to the associated github repo and this is what I would like to do also.

Where can I find the metadata for these two GitHub-based workspace templates?


I found them in the bndtools/Workspace Templates preferences.   Obviously, this can be amended either by the preference UI...or programmatically via an Eclipse plugin, true?   

Scott



Reply all
Reply to author
Forward
0 new messages