This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 206321 - Permit POM properties to be used from Freemarker templates
Summary: Permit POM properties to be used from Freemarker templates
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.1
Hardware: All All
: P3 normal (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-13 10:22 UTC by christianlerch
Modified: 2012-07-26 02:17 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Generic license header (1.07 KB, text/plain)
2011-12-13 20:25 UTC, christianlerch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description christianlerch 2011-12-13 10:22:15 UTC
Product Version = NetBeans IDE 7.1 RC2 (Build 201111302200)
Operating System = Windows XP version 5.1 running on x86
Java; VM; Vendor = 1.6.0_29
Runtime = Java HotSpot(TM) Client VM 20.4-b02
Comment 1 christianlerch 2011-12-13 10:27:49 UTC
Example:

pom.xml
  <properties>
    <copyrightyear>2011</copyrightyear>
  </properties>

Template Class.java
<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

// ${copyrightyear}

<#if package?? && package != "">
package ${package};
...
Comment 2 christianlerch 2011-12-13 10:29:21 UTC
Result:

// Expression copyrightyear is undefined on line 6, column 6 in Templates/Classes/Class.java.
Comment 3 Jesse Glick 2011-12-13 15:34:15 UTC
Might be useful. Never heard of anyone trying this before. http://wiki.netbeans.org/NetFIX candidate I think.
Comment 4 christianlerch 2011-12-13 20:25:11 UTC
Created attachment 114107 [details]
Generic license header

A example for the intended use of custom properties in FreeMarker templates is illustrated in the attached license template file. By using this scheme you dont need a separate license file anymore for each and every project. A single file per license type together with an appropriate set of properties in the pom (or nbproject/project.properties) is then sufficient.
Comment 5 Milos Kleint 2012-02-13 15:14:41 UTC
my personal preference would be to have all such properties prefixed with "netbeans.template" or similar to avoid unintended replacements and to have optionally a way to create a UI in netbeans for these props.
Comment 6 Milos Kleint 2012-07-24 08:54:11 UTC
project.property prefix is used for properties coming from MavenProject.getProperties()

please note that properties containing a dot cannot be nested. eg. you cannot have  both maven.test and maven.test.skip property. even if just one of them is used in the template, during preparing of the data, the created freemarker object tree will only contain one of the and give error for the second one when used (most likely randomly.
Comment 7 Quality Engineering 2012-07-26 02:17:47 UTC
Integrated into 'main-golden', will be available in build *201207260002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/5b5d997d1607
User: Milos Kleint <mkleint@netbeans.org>
Log: #206321 maven project's properties are available in new file templates via project.property.<name> expressions.