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 192074 - Add Project Name to File Template Keywords
Summary: Add Project Name to File Template Keywords
Status: NEW
Alias: None
Product: cnd
Classification: Unclassified
Component: Project (show other bugs)
Version: 6.x
Hardware: All All
: P4 normal (vote)
Assignee: issues@cnd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-17 21:22 UTC by jcrada
Modified: 2015-07-26 13:40 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jcrada 2010-11-17 21:22:55 UTC
Hi,

I have two separate C++ library projects A and B, where A uses B. In both projects there is a file named Example.h created using the default C++ header template, so they both look like this:

#ifndef EXAMPLE_H
#define	EXAMPLE_H


#endif	/* EXAMPLE_H */

This represents a problem when building A, since A defines first EXAMPLE_H and when building B it would become a compiling error since it will not compile whatever it is in B:Example.h. 

In order to overcome this, you guys could improve the template by adding the project name to the #ifndef, so that way you ensure uniqueness to the definition. Sadly, the file templates do not have (or at least I cannot find) a keyword for the project name.

The idea would be to have a template C++ header file as:

/* 
 * File:   %<%NAME%>%.%<%EXTENSION%>%
 * Author: %<%USER%>%
 *
 * Created on %<%DATE%>%, %<%TIME%>%
 */

#ifndef %<%PROJECT_NAME%>%_%<%GUARD_NAME%>%
#define	%<%PROJECT_NAME%>%_%<%GUARD_NAME%>%


#endif	/* %<%PROJECT_NAME%>%_%<%GUARD_NAME%>% */

Is there a way I could do this in NetBeans 6.9.1?
Comment 1 Quality Engineering 2015-04-27 05:09:26 UTC
Integrated into 'main-silver', will be available in build *201504270341* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/da4cb91c0c54
User: Alexander Simon <alexvsimon@netbeans.org>
Log: fixing bugs:
- Bug #192074 Add Project Name to File Template Keywords
- Bug #198793 No File-templates variables for C++ documentation available
Migrate c/c++/fortran templates on FreeMarker:
- use FreeMarker variables syntax ${var}
- add license
- change login meme to user name

Avaliable containing project variables:
- project.name
- project.displayName
- project.encoding
- project.license
- project.licensePath

To compatibility old variable "USER" has a previous meaning (login name).

New variable "user" contains login or user name specified in template properties (Tools->Templates-Settings)

If property "project.licensePath" or "project.license" is specified in project properties (nbproject/project.properties or nbproject/private/project.properties),
it is used for licence generating. Othewvise the default licence will be inserted in the created file.
Comment 2 capricious 2015-07-26 13:40:25 UTC
Hi,

wouldn't it make more sense to support project.properties as replacement variables?

So everybody can define on project level what they want to get replaced in the file templates.

At the moment you have to use many different file templates for this purpose.

Also it would make it much easier in project management to change the replacements for multiple file templates in one time.
Currently you have to edit each template by itself.

For example, if you need an OrganisationUnit in the header guard.
Each OU needs its own file templates.

Although it would be quite easy to edit a project.properties and put in a custom 
PRODUCT_NAME=XYZ
PROJECT_OU=IT101.

In file template you could use:

#ifndef %<%PROJECT_OU%>%_%<%PRODUCT_NAME%>%_%<%GUARD_NAME%>%
#define	%<%PROJECT_OU%>%_%<%PRODUCT_NAME%>%_%<%GUARD_NAME%>%


#endif	/* %<%PROJECT_OU%>%_%<%PRODUCT_NAME%>%_%<%GUARD_NAME%>% */

br