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 34730 - Provide API for finding file relatively to another file
Summary: Provide API for finding file relatively to another file
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Filesystems (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker (vote)
Assignee: rmatous
URL:
Keywords: API
: 22865 (view as bug list)
Depends on: 37445
Blocks:
  Show dependency tree
 
Reported: 2003-07-02 14:35 UTC by Petr Jiricka
Modified: 2008-12-22 22:13 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
is it OK for you ? (1.23 KB, patch)
2003-11-19 09:43 UTC, rmatous
Details | Diff
relative path (1.08 KB, patch)
2003-11-24 09:58 UTC, rmatous
Details | Diff
added test (1.79 KB, patch)
2003-12-03 13:43 UTC, rmatous
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Jiricka 2003-07-02 14:35:40 UTC
Provide a method for acquiring a FileObject for
another FileObject, and a relative path as
discussed at:

http://www.netbeans.org/servlets/BrowseList?listName=nbdev&by=thread&from=19026

So far module authors used methods
FileSystem.find(...) and
FileSystem.findResource(...) for this, but since
now IDE filesystems are the machine filesystems
(not explicitly mounted filesystems), these
methods are much less useful now.
Comment 1 Petr Jiricka 2003-11-18 15:27:51 UTC
I just found the method that finds a relative path between two
fileobjects duplicated in three places in the WebApps code. Would it
be possible to reevaluate this request? I believe a method like this
will be useful more generally.

Also, I think this API:

String findRelativePath(FileObject rootFolder, FileObject relativeObject)

should also work in the case that the two files that are sent in as a
parameter are the same, in that case it should return "". Unlike
currently FileUtil.isParentOf(...), which does not accept such a case,
which I think is wrong.
Comment 2 Jesse Glick 2003-11-18 20:39:12 UTC
I would very much appreciate this also.
Comment 3 rmatous 2003-11-19 09:43:29 UTC
Created attachment 12207 [details]
is it OK for you ?
Comment 4 rmatous 2003-11-19 09:49:06 UTC
Please see attachment: should be compatible API change just in
javadoc. Is it OK and is it enough ? Or do you really need method
findRelativePath which is basically specialized substring method that
fires IllegalArgumentException. The same could be requested also for
Registry API. 
Comment 5 Petr Jiricka 2003-11-19 10:20:44 UTC
This sounds good for the first part of the request, i.e. finding a
file from another file based on a relative path. I am only a little
bit confused by the Javadoc for method FileObject.getFileObject(String
name, String ext), particularly by the part which says:

* @param ext extension of the file; <CODE>null</CODE> or <code>""</code>
*    if the file should have no extension or if folder is requested

This sounds like name can not be of the form "MyClass.java" - but in
reality it can. I think the Javadoc here should be changed to say that
extension can be specified either in the 'ext' parameter, or as a part
of the name in the usual syntax (i.e. "name.ext").


Regarding the second part of the request (finding a relative path
between two fileobjects), it would still be useful to have such a
general API method to me, but this really depends on whether other
people need it as well. CC'ing Tomas, so he can also express his
opinion on whether this is needed or not.

If I am the only one, then I will not push for it.
Comment 6 rmatous 2003-11-19 10:39:56 UTC
You are right this javadoc is confusing. I still hasitate whether this
method shouldn't be deprecated at all(the same for all methods that
take extension).
Comment 7 Jesse Glick 2003-11-19 15:34:39 UTC
+1 from me for deprecating methods taking extension... :-)

The proposed diff looks OK to me, and findRelativePath would be nice
sometimes too (in FileUtil I suppose). Good candidate for devrev
fast-track.
Comment 8 rmatous 2003-11-24 09:58:36 UTC
Created attachment 12272 [details]
relative path
Comment 9 Petr Jiricka 2003-11-24 10:25:03 UTC
Excellent, I like this. I would only clarify the Javadoc to make it
super clear that folder and fo may be the same, e.g.:

@param fo arbitrary FileObject in folder's tree (including folder itself)
@return relative path between folder and fo. The returned path never
starts with a '/'. It never ends with a '/'. Specifically, if
folder==fo, returns "". Returns <code>null</code> if fo is not in
folder's tree.

Comment 10 Jesse Glick 2003-11-24 14:20:57 UTC
Looks OK to me.

BTW please remember to always use the -u flag to cvs diff. Most
easily, add to ~/.cvsrc or the Win32 equivalent:

diff -u
Comment 11 Jaroslav Tulach 2003-11-25 08:45:34 UTC
I do not see any tests. Especially 

>         if (result.startsWith("/")) {
>             result = result.substring(1);
>         }

looks suspicious to me. Probably something you want to ensure. No
comments otherwise.
Comment 12 rmatous 2003-12-03 13:43:46 UTC
Created attachment 12400 [details]
added test
Comment 13 rmatous 2003-12-03 13:46:20 UTC
Incorporated all comments, added test. Tommorow will be commited.
Comment 14 rmatous 2003-12-09 09:54:09 UTC
In trunk: 

/cvs/openide/test/unit/src/org/openide/filesystems/FileObjectTestHid.java,v
 <-- FileObjectTestHid.java
new revision: 1.22; previous revision: 1.21

/cvs/openide/src/org/openide/filesystems/FileObject.java,v  <-- 
FileObject.java
new revision: 1.80; previous revision: 1.79

/cvs/openide/src/org/openide/filesystems/FileUtil.java,v  <-- 
FileUtil.java
new revision: 1.71; previous revision: 1.70

/cvs/openide/api/doc/changes/apichanges.xml,v  <--  apichanges.xml
new revision: 1.174; previous revision: 1.173
Comment 15 Jesse Glick 2004-02-04 04:49:02 UTC
*** Issue 22865 has been marked as a duplicate of this issue. ***