Generated .bat file calls endlocal twice in error case
------------------------------------------------------
Key: MAPPASM-120
URL: http://jira.codehaus.org/browse/MAPPASM-120
Project: Mojo AppAssembler Plugin
Issue Type: Bug
Affects Versions: 1.1.1
Environment: Various versions of Windows 2003, Windows 2008, and
Windows 7
Reporter: Andreas Kohn
Attachments: bug-call.bat, bug-direct.bat, pom.xml
The generated .bat file handles the case of an error code incorrectly, and will
invoke 'endlocal' twice in this case.
In the best case this means variables like ERROR_CODE are leaked into the
parent environment, but it can also lead to errors if the generated script is
in turn invoked by another bat script that uses setlocal/endlocal as well.
See the attached example maven project which generates a bug.bat and includes
two wrapper scripts around that.
If bug.bat is invoked directly everything seems to work fine, although the
variable ERROR_CODE will now be visible in the environment:
{noformat}
C:\appassembler>echo %ERROR_CODE%
%ERROR_CODE%
C:\appassembler>bin\bug.bat
C:\appassembler>echo %ERROR_CODE%
1
{noformat}
If bug.bat is invoked via bug-call.bat everything looks fine (no leaking, no
odd messages).
The same happens if bug.bat is invoked via the bug-call.bat script.
But, if one invokes using bug-direct.bat (calls bug.bat, without call, but with
setlocal) one sees the following:cd
{noformat}
C:\appassembler>bug-direct.bat
C:\appassembler>setlocal
C:\appassembler>bin\bug.bat
0 was unexpected at this time.
C:\appassembler>echo %ERROR_CODE%
%ERROR_CODE%
{noformat}
This is caused by endlocal being called twice if the %OS% is Windows_NT: the
first time after the :error label (correct, ERROR_CODE was defined to 1 before
the matching setlocal call), and then right after that after the :endNT label
(incorrect, already left local scope, and now it is in the parent scope.
Attached patch should fix this.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email