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

Summary: Permit POM properties to be used from Freemarker templates
Product: projects Reporter: christianlerch
Component: MavenAssignee: Milos Kleint <mkleint>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 7.1   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: Generic license header

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.