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 50092 - Foreign project cannot set dependency on freeform project artifact if build.xml not inside projdir
Summary: Foreign project cannot set dependency on freeform project artifact if build.x...
Status: CLOSED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker (vote)
Assignee: David Konecny
URL:
Keywords: API
Depends on: 51151 52886
Blocks: 41535
  Show dependency tree
 
Reported: 2004-10-07 13:12 UTC by navneet
Modified: 2008-04-22 23:03 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 navneet 2004-10-07 13:12:07 UTC
Steps:
1. Created one free form project that generates 2+
jar files in the build command.
2. Created a web project with existing sources.
3. Try to add the free form project as the
compilation classpath using the "Add Project" button.
4. Exception ( as below ).
5. Project settings are not saved after this
exception.

java.lang.IllegalArgumentException: Cannot use an
absolute URI file:/D:/tiger/build.xml for script
location
	at
org.netbeans.spi.project.support.ant.ReferenceHelper$RawReference.<init>(ReferenceHelper.java:863)
	at
org.netbeans.spi.project.support.ant.ReferenceHelper$1.run(ReferenceHelper.java:191)
	at org.openide.util.Mutex.writeAccess(Mutex.java:271)
	at
org.netbeans.spi.project.support.ant.ReferenceHelper.addReference(ReferenceHelper.java:175)
	at
org.netbeans.spi.project.support.ant.ReferenceHelper.createForeignFileReference(ReferenceHelper.java:740)
	at
org.netbeans.modules.web.project.ui.customizer.WebProjectProperties$PathParser.getPathItem(WebProjectProperties.java:892)
	at
org.netbeans.modules.web.project.ui.customizer.WebProjectProperties$PathParser.encode(WebProjectProperties.java:779)
	at
org.netbeans.modules.web.project.ui.customizer.WebProjectProperties$PropertyInfo.encode(WebProjectProperties.java:607)
	at
org.netbeans.modules.web.project.ui.customizer.WebProjectProperties$1.run(WebProjectProperties.java:347)
	at org.openide.util.Mutex.writeAccess(Mutex.java:307)
	at
org.netbeans.modules.web.project.ui.customizer.WebProjectProperties.store(WebProjectProperties.java:335)
	at
org.netbeans.modules.web.project.ui.WebCustomizerProvider$OptionListener.actionPerformed(WebCustomizerProvider.java:149)
	at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
	at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
	at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
	at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
	at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
	at
java.awt.Component.processMouseEvent(Component.java:5100)
	at
java.awt.Component.processEvent(Component.java:4897)
	at
java.awt.Container.processEvent(Container.java:1569)
	at
java.awt.Component.dispatchEventImpl(Component.java:3615)
	at
java.awt.Container.dispatchEventImpl(Container.java:1627)
	at
java.awt.Component.dispatchEvent(Component.java:3477)
	at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
	at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
	at
java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
	at
java.awt.Container.dispatchEventImpl(Container.java:1613)
	at
java.awt.Window.dispatchEventImpl(Window.java:1606)
	at
java.awt.Component.dispatchEvent(Component.java:3477)
[catch] at
java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
	at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
	at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
	at
java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Comment 1 Jesse Glick 2004-10-07 14:55:56 UTC
Navneet: please use the attachment facility in Issuezilla. Do not
paste large stack traces etc. into the body of an issue.

Workaround available: do not use "Add Project". Use "Add JAR" instead.
The freeform project will not be considered a subproject of the web
project, but otherwise things will work.

For David: there are several problems here. The immediate problem is
that the current semantics of ReferenceHelper forbids you to have a
build script for an artifact which is not under the project directory
(or at least located relative to it). I think it is too risky to
change this for D. Therefore I recommend that for now,
FreeformProjectGenerator simply not generate an <export> element at
all if the build.xml is not located within the project directory. With
that changed, this could be downgraded to P3 I think.

The full fix is more complicated. ReferenceHelper would need to accept
an absolute URI for scriptLocation. But just storing a full file name
(or file: URI) in <script> is not acceptable - needs to load file
paths from project.properties or private.properties (acc. to
CollocationQ) for proper VCS interaction.

Consider dirs:

~/src/myapp/web [original web app src dir]
~/src/myapp/lib [original lib src dir, w/ build.xml]
~/src/nbprj/web [web/project project dir]
~/src/nbprj/lib [freeform project dir]

Assume for example that ~/src is a CVS root.

Probably the RH would need to store something like this:

<reference>
  <foreign-project>myfreeform</>
  <artifact-type>jar</>
  <script qualified="true">${basedir.reference.lib}/build.xml</>
  <target>jar</>
  <clean-target>clean</>
  <id>jar</>
</>

Note the added attribute to <script> - will require a schema change.

At the same time, it would need to have in
~/src/nbprj/web/nbproject/project.properties:

# Unused, actually... but as now
project.lib=../lib
# Location of build.xml... ADDED
basedir.reference.lib=../../myapp/lib
# Location of artifact... as now
file.reference.lib.jar=../../myapp/lib/build/lib.jar

Now build-impl.xsl in both java/j2seproject and web/project (and
whatever else) would need to change to accommodate the new references
schema: if qualified="false" (or unspecified), should generate as now e.g.

<ant dir="${project.lib}" .../>

but if qualified="true" it should use the basedir as given, without a
project location prefix:

<ant dir="${basedir.reference.lib}" .../>

Note that the above makes <script> include at least one slash, so that
the actual build script file name is specified distinctly from the
containing dir. This is for consistency with the current XSLT, which
produces different Ant code depending on the format; either

<ant dir="something" target="x"/>

or

<ant dir="something" antfile="build.xml" target="x"/>

since

<ant antfile="something/build.xml" target="x"/>

does *not* work - fails to ${basedir} to "something".

An alternative would be to keep the complete file path in <script>:

<script qualified="true">${build.script.reference.lib}</>
build.script.reference.lib=../../myapp/lib/build.xml

and make the XSLT simpler by doing more work at runtime in Ant:

<dirname property="sub.dir" file="${build.script.reference.lib}"/>
<basename property="sub.file" file="${build.script.reference.lib}"/>
<ant dir="${sub.dir}" antfile="${sub.file}" target="x"/>

which is a little uglier in the build-impl.xml but a bit more robust
since you can change the build script name in project.properties too.
Comment 2 Jesse Glick 2004-10-07 15:42:54 UTC
Re. the last long note here - unnecessary after all, cf. issue #50072.
Should be fine to keep complete path to script in a property.

We could also consider making an incompatible schema change for
<references> (would just upgrade existing project.xml's quietly before
regenerating build-impl.xml; use a new namespace, /2): rather than a
qualified="true" attr, assume it is always true, so the choices would be

<script>${project.lib}/build.xml</>

for the normal case of build.xml inside the project dir, or

<script>${build.script.reference.lib}</>

for the case of some other location. Then build-impl.xsl would just
use the raw value from <script> directly in the 'antfile' attribute
without further interpretation.
Comment 3 navneet 2004-10-07 19:39:17 UTC
Why keep track of how to build a project ? Isn't it more logical for a
procect to just keep track of the "project" it is dependent on. And
whenever you need more info, just ask the other project for it, realtime.

This way everything goes smooth. I think this is what a "dependent" or
"sub" project would mean.
Comment 4 Jesse Glick 2004-10-07 21:19:27 UTC
"Why keep track of how to build a project ? Isn't it more logical for a
procect [sic] to just keep track of the "project" it is dependent on.
And whenever you need more info, just ask the other project for it,
realtime." - can't; we need to generate an Ant script for the
superproject that calls <ant> on the subproject. Look at the
build-impl.xml for your superproject to see what is going on.
Comment 5 David Konecny 2004-10-11 15:53:42 UTC
Agreed with Jesse. The exports are not generated if build script lies
outside of project folder. There is also workaround suggested.
Lowering to P3.

src/org/netbeans/modules/ant/freeform/FreeformProjectGenerator.java;
new revision: 1.29; previous revision: 1.28
test/unit/src/org/netbeans/modules/ant/freeform/FreeformProjectGeneratorTest.java;
new revision: 1.15; previous revision: 1.14
Comment 6 David Konecny 2004-10-11 16:41:51 UTC
I just realized that my change is not correct. I'm going to fix it.
Comment 7 David Konecny 2004-10-11 18:02:26 UTC
Improved now:
src/org/netbeans/modules/ant/freeform/FreeformProjectGenerator.java;
new revision: 1.30; previous revision: 1.29
src/org/netbeans/modules/ant/freeform/ui/ProjectModel.java;
new revision: 1.7; previous revision: 1.6
test/unit/src/org/netbeans/modules/ant/freeform/FreeformProjectGeneratorTest.java;
new revision: 1.16; previous revision: 1.15
Comment 8 David Konecny 2004-10-18 18:21:53 UTC
One more change. If script file is relative do not call URI.relativize
which would make it absolute.

Fixed in:
src/org/netbeans/spi/project/support/ant/ReferenceHelper.java
new revision: 1.19; previous revision: 1.18
Comment 9 David Konecny 2005-01-13 13:51:12 UTC
Implemented as part of the issue 52886.