将 OSGi Bundle 中的文件转换为 IFile

发布于 2025-01-03 21:53:03 字数 328 浏览 0 评论 0原文

我在运行的 eclipse 中安装了一个包(org.osgi.framework.Bundle)。这个包里有一个文件。我有文件的路径,并且可以使用 URL url = bundle.getEntry("/folder/file") 通过 URL (java.net.URL) 表示该文件。

有没有办法获取 IFile 类型的文件(org.eclipse.core.resources.IFile)的句柄?

我需要位于已安装的 IFile 类型的 osgi 包中的文件的引用。但我不想将文件临时复制到本地磁盘(如工作区)上。

提前致谢!

I have an installed bundle (org.osgi.framework.Bundle) in my running eclipse. There is a file in this bundle. I have the path to the file and i can represent this file by an URL (java.net.URL) by using URL url = bundle.getEntry("/folder/file").

Is there a way to get a handle of this file of type IFile (org.eclipse.core.resources.IFile)?

I need a reference of the file located in the installed osgi bundle of type IFile. But I don't want to copy the file temporary on my local disk (like workspace).

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬心 2025-01-10 21:53:03

它很难。 IFile 表示实际文件而不是存档中的条目。您需要为存档构建 Eclipse 文件系统 (EFS) 表示形式,但这可能需要大量工作。

你想达到什么目的?您可能可以做一些更简单的事情。

It's difficult. An IFile represents an actual file rather than an entry in an archive. You would need to build an Eclipse FileSystem (EFS) representation for the archive, but that's likely to be a lot of work.

What are you trying to achieve? There's probably something you can do that is much simpler.

似狗非友 2025-01-10 21:53:03

如果您有 Eclipse 插件/编辑器或类似的东西,请尝试:

//get the workspace
IWorkspace workspace= ResourcesPlugin.getWorkspace();

//create the path to the file
IPath location= new Path(yourURL.getPath());

//try to get the IFile (returns null if it could not be found in the workspace)
IFile file= workspace.getRoot().getFileForLocation(location);

if (file == null) {
    //not found in the workspace, get the IFileStore (external files)
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(location);
    return fileStore;
} else {
    // file found, return it
    return file;
}

Helpfull 也可以是:

url = FileLocator.toFileURL(yourURL);

和/或

URL resolvedUrl = FileLocator.resolve(url);

之后您可以为您的编辑器创建输入(我想您想在那里使用它?)

Object file = myGetFile();
IEditorInput input;
if (file instanceof IFile) {
    input = new FileEditorInput((IFile)file);
else {
    if (file instanceof IFileStore) {
        input = new FileStoreEditorInput((IFileStore)file);
    } else {
       throw new MyException("file is null, not found");
    }
}

我希望这会对您有所帮助。

问候,
阿德里莫斯

If you have an eclipse plugin / editor or something like this try:

//get the workspace
IWorkspace workspace= ResourcesPlugin.getWorkspace();

//create the path to the file
IPath location= new Path(yourURL.getPath());

//try to get the IFile (returns null if it could not be found in the workspace)
IFile file= workspace.getRoot().getFileForLocation(location);

if (file == null) {
    //not found in the workspace, get the IFileStore (external files)
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(location);
    return fileStore;
} else {
    // file found, return it
    return file;
}

Helpfull could be also:

url = FileLocator.toFileURL(yourURL);

and/or

URL resolvedUrl = FileLocator.resolve(url);

After this you can create the input for your editor (I think you want to use it there?)

Object file = myGetFile();
IEditorInput input;
if (file instanceof IFile) {
    input = new FileEditorInput((IFile)file);
else {
    if (file instanceof IFileStore) {
        input = new FileStoreEditorInput((IFileStore)file);
    } else {
       throw new MyException("file is null, not found");
    }
}

I hope this will help you.

Greetz,
Adreamus

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文