Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 256942 - Using file_prompt for Ant script produces confusing results
Summary: Using file_prompt for Ant script produces confusing results
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows 2000
: P3 minor (vote)
Target Milestone: 3.5.1   Edit
Assignee: Platform-Ant-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-28 16:13 EST by Dmytro Stepanchuk CLA
Modified: 2010-05-27 17:43 EDT (History)
8 users (show)

See Also:
daniel_megert: pmc_approved+
Michael_Rennie: review+
Michael_Rennie: review+


Attachments
Sample ant task (833 bytes, text/xml)
2008-11-28 16:13 EST, Dmytro Stepanchuk CLA
no flags Details
Patch_1.0 (3.95 KB, patch)
2009-08-05 07:56 EDT, Natalia Bartol CLA
no flags Details | Diff
AntPrompts_v.1.0 (1023 bytes, patch)
2009-08-24 10:40 EDT, Natalia Bartol CLA
no flags Details | Diff
patch (4.89 KB, patch)
2009-08-27 10:54 EDT, Darin Wright CLA
no flags Details | Diff
patch with copyright updates (5.71 KB, patch)
2009-08-27 10:56 EDT, Darin Wright CLA
no flags Details | Diff
AntPrompts_v.2.0 (7.80 KB, patch)
2009-08-28 04:51 EDT, Natalia Bartol CLA
john.arthorne: iplog+
Details | Diff
patch (2.40 KB, patch)
2009-09-01 14:49 EDT, Darin Wright CLA
no flags Details | Diff
combined patch for 3.5.1 (8.95 KB, patch)
2009-09-01 15:45 EDT, Darin Wright CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmytro Stepanchuk CLA 2008-11-28 16:13:20 EST
Build ID: I20081030-1917
Running on Windows XP 64

Steps To Reproduce:
1. Create any kind of ant script (use attached for example)
2. Right-click on it, go to External Tools Configurations, create new
3. In the Arguments section click on Variables and select file_prompt
4. Click apply - you will be prompted for file name. This is a bug, it shouldn't ask for a file name, what for???
4. Save your configuration.
5. Right-click on your ant script and select Run as -> Ant Build...
Notice that you get prompted for a file name, then dialog appears. 
6. In the dialog click Run and you will be prompted for a file name - again? So it shows file prompt twice - this is a BUG.
7. Now, right-click on your ant script and go to Run As -> External Tools Configurations. Again it shows a file selection dialog - why? Bug too.

Looks like it is all related to usage of $file_prompt in the run configuration - it pops up this dialog when it isn't even running your script.


More information:
This bug was originally observed in Rational Application Developer 7.5 (which uses Eclipse 3.4 runtime). Verified on Eclipse 3.5 M3 and bug is still there.
Comment 1 Dmytro Stepanchuk CLA 2008-11-28 16:13:54 EST
Created attachment 119057 [details]
Sample ant task
Comment 2 Henry Cui CLA 2009-07-31 10:38:52 EDT
Customer reported this issue through  PMR 38704,047,649. 

There actually are side effects. Later, when you try to edit the launch configuration, it will prompt you for a file as soon as you focus on the Launch Configuration. If you happen to hit "escape" at that point, your launch configuration will get corrupted (all targets will be unselected). 

Please fix this issue if possible. Thanks.
Comment 3 Natalia Bartol CLA 2009-08-05 07:56:18 EDT
Created attachment 143496 [details]
Patch_1.0

User was prompted for a filename whenever variable in configuration was being resolved. Usage of ExternalToolUtil#getArguments always causes variables resolving and should be used only while running script, not in case of opening external tool dialog or performing apply after changes in configuration. I removed variables resolving in methods that are not used while launching script.
Comment 4 Krzysztof Daniel CLA 2009-08-05 09:02:38 EDT
Darin,

The patch and the diagnosis looks fine. Could you please review the patch by yourself and release it? The diagnosis is in comment 3, business impact in comment 2.
Comment 5 Darin Wright CLA 2009-08-12 14:51:20 EDT
The attached patch does avoid the prompts, but could have other side effects. For example, variables that do not prompt will no longer be resolved when computing arguments during non-launch processing. I wonder if we can do better and just avoid the *_prompt variables when not launching.
Comment 6 Krzysztof Daniel CLA 2009-08-13 02:19:02 EDT
Darin,

I do understand your concerns, but what is the point of resolving any variables before launching? Is there anything that we should check?

Actually it is possible to resolve only non-prompting variables but:
(1) it leads to inconsistent state (some variables are resolved, some are not)
(2) it requires API change

Other launch configuration resolve variables on launch time.
Comment 7 Darin Wright CLA 2009-08-20 12:16:07 EDT
Perhaps Darin(S) can comment here. My concern was effecting the context the Ant model uses for target resolution (i.e. by not resolving variables, does it potentially change the Ant model in an important way?). If not, then avoiding variable resolution until launch is probably fine.

Darin (S)?
Comment 8 Darin Swanson CLA 2009-08-20 19:15:31 EDT
By changing to not resolve any Ant properties you can potentially lose the Ant model's ability to resolve some of the targets. 
For example: <import file="${importFileName}" />
None of the targets from the imported build file could be resolved.

This has been an unfortunate long standing bug with the current implementation.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=175676 for more details and pointer to https://bugs.eclipse.org/bugs/show_bug.cgi?id=76226 which contains test cases for target resolution based on property resolution.

The past argument was that with the relatively low usage of string_prompt or file_prompt in production buildfiles this bug was deemed not worth the investment to fix.
Comment 9 Natalia Bartol CLA 2009-08-21 06:51:29 EDT
Darin(S),

This problem is not only about annoying prompts. If user clicks "Cancel" at that point (because he is not launching script), launch configuration will get corrupted and all targets will dissapear form Targets tab. And that is really confusing. 

Comment 10 Natalia Bartol CLA 2009-08-21 08:39:38 EDT
...and what about not resolving just *_prompt variables when not launching? 
Comment 11 Natalia Bartol CLA 2009-08-24 10:40:26 EDT
Created attachment 145431 [details]
AntPrompts_v.1.0

There is simple fix to avoid corruption of launch configuration after user chooses Cancel on prompt dialog. I added 

try {
    model.setProperties(getAllProperties(config));
} catch (CoreException ex){}

The same is done in AntModel#setExtraProperties and AntJRETab#applySeparateVMAttributes. 

Looking on AntJRETab#applySeparateVMAttributes I am wondering if resolving variables is really needed here? This method is only used to set the logger - we are searching for "-logger" parameter. Is it possible that one of resolved variables will have such value? Can such value be given via prompt dialog? If we will remove resolving of prompt variables from this method, then we can avoid prompting while "Apply" and while switching to JRE tab. And that will be much improvement for the client!
Comment 12 Darin Wright CLA 2009-08-27 10:54:03 EDT
Created attachment 145797 [details]
patch

This patch

(1) uses the suggestion from comment#11 to avoid resolution when looking for the existence of the "-logger" argument.
(2) avoids resolution of *_prompt variables when processing -D args for target resolution
Comment 13 Darin Wright CLA 2009-08-27 10:54:55 EDT
Natalia, can you verify if this patch meets your needs?
Comment 14 Darin Wright CLA 2009-08-27 10:56:22 EDT
Created attachment 145798 [details]
patch with copyright updates

updated copyrights to 2009
Comment 15 Natalia Bartol CLA 2009-08-28 04:51:45 EDT
Created attachment 145906 [details]
AntPrompts_v.2.0

(In reply to comment #13)
> Natalia, can you verify if this patch meets your needs?
> 

Yes Darin, this patch works as is needed. However I believe that we should also avoid resolving *_prompt variables in AntModel#setExtraProperties. This method process changes on  Properties tab in External Tool Dialog. I include this change in this patch. Now Ant External Tool Dialog will work correctly with prompts. The prompt variables are resolved correctly during launch process. I am waiting for this patch to be commited.
Comment 16 Darin Wright CLA 2009-08-31 13:52:54 EDT
Applied patch. Please verify, Mike.
Comment 17 Michael Rennie CLA 2009-09-01 09:43:39 EDT
looks fine, although the fix will cause anyone who provides a variable with _prompt in it to no longer be evaluated - in the off chance that someone does name their variable *_prompt* and it does not prompt...
Comment 18 Natalia Bartol CLA 2009-09-01 10:19:42 EDT
(In reply to comment #17)
> looks fine, although the fix will cause anyone who provides a variable with
> _prompt in it to no longer be evaluated - in the off chance that someone does
> name their variable *_prompt* and it does not prompt...

Michael,

Why do we need *_propmt variable to prompt if we are not launching script but just changing launch config? All prompts will appear during launch.
Comment 19 Darin Wright CLA 2009-09-01 10:38:26 EDT
(In reply to comment #18)

> Why do we need *_propmt variable to prompt if we are not launching script but
> just changing launch config? All prompts will appear during launch.

Mike is just pointing out that we are using the '*_prompt' pattern as a heuristic for identifying prompting variables. There's nothing that prevents someone from contirbuting a variable with this sort of name that does not actually prompt. We don't know of any such variables, it's just a note.
Comment 20 Darin Wright CLA 2009-09-01 10:39:09 EDT
Re-opening to mark as 3.5.1 candidate.
Comment 21 Darin Wright CLA 2009-09-01 10:39:48 EDT
Adding Dani for PMC approval.
Comment 22 Dani Megert CLA 2009-09-01 12:22:27 EDT
Looked at the patch. The whole story is still pretty scary not to say broken but the patch fixes the most common issues. There's only one change that I'd like to see changed: there's a small risk that someone contributes a variable that resolves to "-logger". This is now doomed because the changes to AntJRETab don't use the string pattern like its done at the other places.

+1 for 3.5.1 if the above mentioned change is made.
Comment 23 Darin Wright CLA 2009-09-01 14:49:19 EDT
Created attachment 146224 [details]
patch

Additional patch for HEAD that uses pattern matching when searching for the -logger argument.
Comment 24 Darin Wright CLA 2009-09-01 15:45:01 EDT
Created attachment 146227 [details]
combined patch for 3.5.1
Comment 25 Darin Wright CLA 2009-09-01 15:51:54 EDT
Fixed in HEAD and 3.5.x. Please verify again, Mike.
Comment 26 Michael Rennie CLA 2009-09-01 16:26:24 EDT
looks good again.
Comment 27 Markus Keller CLA 2009-09-01 20:23:51 EDT
The regex looks a bit scary. ".*" matches really any sequence of characters. That's OK for a quick manual search, but should not be used in production code, because it's too easy to have it match more than expected.

In this case, it would e.g. also match the following argument:

${system:NL} \"do_prompt\" ${workspace_loc}
  .*-------------       .*----------------

A better regex would use an excluded character set containing the terminating character "}", i.e.:
"\\$\\{[^}]*_prompt[^}]*\\}"
Comment 28 Darin Wright CLA 2009-09-01 22:23:58 EDT
I agree, the suggested regex would be safer. But, keep in mind that the arguments are first parsed into separate arguments before the matching is done. So the case mentioned would not be an issue since we would do the matching on 3 separate cases - and none would match.

${system:NL}
\"do_prompt\"
${workspace_loc}
Comment 29 Darin Wright CLA 2009-09-03 12:20:50 EDT
Verified in M20090902-1400. I don't plan on further changes in 3.5.1. I will open a new bug for 3.6 to address improving the regular expression.