Monday November 26, 2007
Project-Level License Settings in NetBeans IDE 6.0
In my earlier series on FreeMarker support (especially this one), I discussed the many flexible ways in which templating support in NetBeans IDE 6.0 can be of benefit to you. Importantly, the flexibility can be made use of either by the developer providing the templates or by the user of those templates. (That series discusses this, and the differences, in some detail.) One point that I hadn't discussed yet relates to licensing. The short story is: in NetBeans IDE 6.0 you can define a license for your project and then all files within that project will be created with that license embedded in the code. OK, that's the short story.
The long story makes sense in the context of a step-by-step procedure:
- Go to the Tools menu. Choose Templates. Open the Java|Java Class template in the editor:
- In general, the template above, and the ramifications of defining it in FreeMarker, have been discussed in the earlier blog entries (starting here). However, lets look (this time) at the first four lines:
<#assign licenseFirst = "/*"> <#assign licensePrefix = " * "> <#assign licenseLast = " */"> <#include "../Licenses/license-${project.license}.txt">What do these lines mean? They all have to do with licensing. The last line determines the license that will be used, per project. The first three determine the characters in front of and behind each line in the license. Above are the four lines for Java source files. Here's the same set of definitions you'll find for the Properties file template:
<#assign licensePrefix = "# "> <#include "../Licenses/license-${project.license}.txt">What's the difference? Nothing in the second line (which we'll look at later). The first line, however, tells us that each line in the license will be prefixed with a "# ", instead of with a " * ", which is the prefix for Java source files (with "/*" for the first line and " */" for the last line). To verify this, create a Java source file and then create a Properties file. You'll see a license in both cases. However, the characters prefixing and postfixing each line is different. Now you know why.
- Next, let's look at the license itself. Notice this line in the templates above:
<#include "../Licenses/license-${project.license}.txt">In particular, notice this bit:
${project.license}Put that, as a key, in your application's nbproject/project.properties file. Now add a value. For example:
project.license=apache
Now look in the Template Manager again, in the Licenses folder. You see some templates there. Create a new one called "license-apache.txt". For now, you can just copy an existing one and paste it in the same category in the Template Manager. Then, next time that you create a file that is defined by a FreeMarker template that includes this line:
<#include "../Licenses/license-${project.license}.txt">...you will have the specified license embedded within the newly created file.
What's the purpose of all this? Simple: NetBeans IDE 6.0 lets you define, per project, the license that each of its files should display. Plus, imagine if you need to create a new project with a different license. Assuming you have all your licenses defined in the Template Manager, using a new license is as simple as adding that one key/value pair to the nbproject/project.properties file. That was not possible before but, thanks to FreeMarker support in NetBeans IDE 6.0, is possible now.
Nov 26 2007, 09:01:54 AM PST Permalink


