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 34802 - Ant build target shortcut loses basedir
Summary: Ant build target shortcut loses basedir
Status: VERIFIED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Ant (show other bugs)
Version: 3.x
Hardware: All All
: P4 blocker with 1 vote (vote)
Assignee: Jesse Glick
URL:
Keywords: SIMPLEFIX
Depends on:
Blocks:
 
Reported: 2003-07-08 20:08 UTC by Mike Cepek
Modified: 2005-07-13 13:23 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Cepek 2003-07-08 20:08:34 UTC
The basedir setting of an Ant build script seems to be 
ignored when a target in that script is invoked from a 
shortcut key (rather than by right-clicking on the script 
file in the Explorer and using "Run Target").

To reproduce, create two files:

------- mydir/build.xml -------
<project name="Specific" default="one" basedir="..">
    <target name="one" description="run me">
        <ant antfile="build.xml" target="two"/>
    </target>
</project>

------- build.xml -------
<project name="Shared" default="two" basedir=".">
    <target name="two">
        <echo message="It Worked"/>
    </target>
</project>

Be sure that the Specific build file is one directory level 
deeper than the Shared build file.  The directory name does 
not matter.

Everything works fine using right-click in the Explorer:

1) Right-click on the Specific build file, and under "Run 
Target" select the only target, "one".

2) The output will be:

one:
two:
It Worked
BUILD SUCCESSFUL
Total time: 0 seconds

Now create a shortcut key to run that same target:

1) "File" -> "New" -> "Ant Build Scripts" -> "ShortCut to 
Target"
2) Check only "Add a keyboard shortcut" in the next screen
3) Specify the "one" target of the Specific Ant build file
4) In the next screen specify a shortcut key combination 
(e.g. Ctrl-B) and remember it
5) Finish the "New Wizard - Shortcut to Target" dialog

Press Ctrl-B to execute the new shortcut.  I get this error 
message:

run:
one:
dir1\build.xml [3] Target `two' does not exist in this 
project.
BUILD FAILED
Total time: 0 seconds

Note that the Specific build file sets basedir="..".  This 
means the execution directory of the Specific build file 
should be the same directory in which the Shared build file 
resides.  Thus, the <ant> task in the Specific build file 
should reference the Shared build file, which contains 
the "two" target.

Using "Options" -> "Ant Settings" -> "Verbose" didn't help; 
it only confirmed the erroneous basedir:

   Project base dir set to: C:\mike\dev\playground\dir1

BTW, this all works fine from the command line, both under 
Win2k and unix.

This item sounds a lot like closed issue 8992.
Comment 1 Jesse Glick 2003-07-08 21:09:54 UTC
The mini Ant script which is the shortcut - you can see this in the
Menu area of the Options dialog, e.g., or in the Customize Generated
Code wizard panel - just calls <ant dir="wherever"/> on the selected
Ant script.

For historical reasons, this sets ${basedir} to "wherever" regardless
of the basedir attr on wherever/build.xml's <project> - fine if
basedir=".", wrong otherwise as you found. Just using
antfile="wherever/build.xml" won't work at all because that will
*leave* ${base.dir} as some bogus directory like
~/nbdev/system/Menu/Build, wherever the shortcut script was.

Fortunately recent versions of Ant have a workaround (added I think
partially at my request, IIRC). You can just write:

<ant antfile="wherever/build.xml" inheritall="false"/>

and wherever/build.xml's basedir should be used.

Lowering priority due to existence of a workaround - just edit your
shortcut.
Comment 2 Jesse Glick 2003-07-08 21:32:43 UTC
Have untested patch.
Comment 3 Mike Cepek 2003-07-09 12:59:14 UTC
Thanks for the info, Jesse.  Unfortunately I cannot get the 
suggested workaround to work.

Adding:  inheritAll="false"
to the <ant> task in the shortcut script didn't help.  Same 
error.

I tried a variation on your idea (which I thought was 
clever, but apparently not clever enough).  Assuming the 
two build files are in the following locations:

   abspath/mypath/build.xml
   abspath/build.xml

I added:  basedir="abspath"
to the <project> tag, and used:  dir="mypath"
in the <ant> task (both in the shortcut script).  That 
didn't work either (same error), regardless of the 
inheritAll setting.  Seemed like it should have, though, 
don't you think?

So I haven't found a workaround that works for me yet.  :-(

I did appreciate your "Default Filesystem" setting 
suggestion.  It made it very easy to do the above tests.

But I noticed that the "Hidden=False" setting is not 
remembered across NetBeans restarts.  Is that as expected?  
It surprised me.
Comment 4 Jesse Glick 2003-07-09 15:08:12 UTC
Re. inheritall="false" not working: OK, I haven't tried it yet in NB;
I just confirmed that it works as documented on the command-line. Will
look into it.

Re. Hidden on Default System not being persistent - I agree; so if you
agree (and care) please reopen issue #26289.
Comment 5 Jesse Glick 2003-07-09 16:38:44 UTC
Working fine for me with the patch.

1. In mount point ~/nbdev/sampledir, create subfolder test34802, with
a build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="subdir" default="all">
    <target name="all">
        <ant antfile="build.xml"/>
    </target>
</project>

and a subdir 'subdir' of test34802 with a build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all">
    <target name="all">
        <echo>here I am: ${someprop}</echo>
    </target>
</project>

Set someprop=someval in Ant Settings -> Properties to make sure these
are still passed along.

Invoke shortcut wizard, select 'all' target of first build.xml, add a
menu item. It creates in my menu:

<?xml version="1.0" encoding="UTF-8"?>
<project default="run" name="34802">
    <target name="run">
        <ant
antfile="/home/jglick/nbdev/sampledir/test34802/build.xml"
inheritall="false" target="all"/>
    </target>
</project>

When this menu item is run, it correctly prints:

run:
all:
all:
here I am: someval

BUILD SUCCESSFUL

Total time: 0 seconds


So I will commit the patch as I have it. Perhaps you mistyped
something in your version of the shortcut, it is not clear. You write:

"Adding:  inheritAll="false" to the <ant> task in the shortcut script
didn't help.  Same error."

but you must not only add the 'inheritall' attr, you must delete the
'dir' attr (which forcibly sets the basedir in all cases) and instead
fully qualify the 'antfile' attr.
Comment 6 Jesse Glick 2003-07-09 16:46:18 UTC
committed     Up-To-Date  1.13       
ant/src/org/apache/tools/ant/module/wizards/shortcut/SelectTargetPanel.java
Comment 7 Marian Mirilovic 2005-07-13 13:23:34 UTC
closed