Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333537 - [Template Engine] Macro expansion in conditional process groups does not work
Summary: [Template Engine] Macro expansion in conditional process groups does not work
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 7.0.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 7.0.2   Edit
Assignee: James Blackburn CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-05 04:30 EST by Christian Walther CLA
Modified: 2014-01-29 22:46 EST (History)
2 users (show)

See Also:


Attachments
test case (3.47 KB, application/zip)
2011-01-05 04:31 EST, Christian Walther CLA
no flags Details
replace.patch (1.26 KB, patch)
2011-01-05 04:33 EST, Christian Walther CLA
cdtdoug: iplog+
Details | Diff
processhelper.patch (1.33 KB, patch)
2011-01-05 04:33 EST, Christian Walther CLA
jamesblackburn+eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Walther CLA 2011-01-05 04:30:59 EST
Build Identifier: M20100909-0800

I am creating new project templates for the CDT template engine. Some of my template creation processes in template.xml are optional depending on what the user entered in the project creation wizard, therefore I enclose them in an <if condition="$(myBoolean)==true"> tag. This condition however always evaluates to false, no matter what the value of myBoolean in the value store is. Closer examination reveals that the macro $(myBoolean) is not actually expanded, so the condition compares the literal strings "$(myBoolean)" and "true", which are always different.

The reason is that ConditionalProcessGroup.isConditionValueTrue() mistakenly uses String.replaceAll() to expand the macros, which does a regular expression replace. Characters "$()" have special meanings in regular expressions, so nothing is matched and replaced. It should be using String.replace(), which does a plain string replace. This is what the attached patch "replace.patch" does.

A more elegant solution would be to use the centralized macro expansion facility, ProcessHelper.getValueAfterExpandingMacros(), instead of reimplementing it using replace(). This is what "processhelper.patch" does.

Patches are against (and tested with) git://dev.eclipse.org/org.eclipse.cdt/org.eclipse.cdt.git 0549e1d13de88a9a762d57c21b70906184dbeeb5, which I assume corresponds to CVS HEAD.

Reproducible: Always

Steps to Reproduce:
1. Install plugin ch.indel.templateenginetest_1.0.0.201101051017.jar from the attached testplugin.zip or build it from the included source.
2. Create a new C++ project using the template provided by this plugin (Executable > Test Template). In the "Properties" wizard page, check or uncheck the "Perform optional step" checkbox.

Actual result:
A source folder named "False" is created in the new project, no matter whether the checkbox was checked or not.

Expected result:
A source folder named "True" should be created when the checkbox was checked, one named "False" when it was not.
Comment 1 Christian Walther CLA 2011-01-05 04:31:55 EST
Created attachment 186074 [details]
test case
Comment 2 Christian Walther CLA 2011-01-05 04:33:17 EST
Created attachment 186075 [details]
replace.patch
Comment 3 Christian Walther CLA 2011-01-05 04:33:58 EST
Created attachment 186076 [details]
processhelper.patch
Comment 4 James Blackburn CLA 2011-01-18 04:50:54 EST
I'm working in this area right now, so will take this...
Comment 5 James Blackburn CLA 2011-01-20 13:16:40 EST
Thanks for the patch and simple test case!
Patch applied to HEAD and 7.0.x.
Comment 7 Christian Walther CLA 2011-01-21 02:00:01 EST
Thanks!