Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333537

Summary: [Template Engine] Macro expansion in conditional process groups does not work
Product: [Tools] CDT Reporter: Christian Walther <walther>
Component: cdt-coreAssignee: James Blackburn <jamesblackburn+eclipse>
Status: RESOLVED FIXED QA Contact: Doug Schaefer <cdtdoug>
Severity: normal    
Priority: P3 CC: jamesblackburn+eclipse, yevshif
Version: 7.0.1   
Target Milestone: 7.0.2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
test case
none
replace.patch
cdtdoug: iplog+
processhelper.patch jamesblackburn+eclipse: iplog+

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!