Eclipse RCP:如何构造专用配置目录(使用共享安装时在〜/ .eclipse中创建)的默认名称? [英] Eclipse RCP: How is the default name of the private configuration directory (created in ~/.eclipse when using a shared install) constructed?

查看:84
本文介绍了Eclipse RCP:如何构造专用配置目录(使用共享安装时在〜/ .eclipse中创建)的默认名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

我已经开发了Eclipse RCP应用程序。该应用程序可以安装在Windows和Linux系统上。

I have developed an Eclipse RCP application. This application may be installed on both Windows and Linux systems.

如果此应用是在管理员模式(Windows)或由超级用户(Linux)安装的,则该应用通常安装在受写保护的共享安装目录

If this application is installed in Administrator mode (Windows) or by a superuser (Linux), the application is typically installed in a write-protected shared install directory.


  • 在Windows上,我们的产品安装程序始终在 Administrator中运行 -mode。默认安装目录为(写保护) C:\Program Files\MyProduct

  • 在Linux上,安装程序可以由普通用户和超级用户运行。对于超级用户,默认安装目录为(也具有写保护) / opt / MyProduct

  • On Windows, our product installer is always run in Administrator-mode. The default installation directory is the (write-protected) C:\Program Files\MyProduct.
  • On Linux, the installer can be run by both a normal user and a superuser. For a superuser the default installation directory is the (also write-protected) /opt/MyProduct.

这就是Eclipse本身所说的共享安装

This is what Eclipse itself calls a shared install.

很显然,运行该应用程序的普通用户无权修改此目录。因此,运行时数据(例如更改的配置数据或自动更新的插件)将被写入用户专用的私有配置区域

Obviously, a normal user running the application does not have rights to modify this directory. Therefore, runtime data such as changed configuration data or auto-updated plug-ins are written to a user-specific private configuration area.


  • 在Windows上,该目录默认为 $ USERPROFILE\.eclipse\ 的子目录。

  • 在Linux上,它也默认为〜/ .eclipse /

  • On Windows this defaults to a subdirectory of $USERPROFILE\.eclipse\.
  • On Linux this also defaults to a subdirectory of ~/.eclipse/

问题

默认情况下, .eclipse 中的私有目录有一个貌似随机的名称:

By default the private directory within .eclipse has a seemingly random name:

.eclipse/1410846118

如果添加 .eclipseproduct 元数据文件,则默认行为会更改。该文件的内容在此论坛帖子中:

If I add an .eclipseproduct metadata file, the default behaviour changes. The content of the file is described in this forum post:

# FILE:
name=MyProduct
id=com.mycompany.myproduct.gui.product
version=1.8.17

这将产生一个具有以下名称的私有目录:

This results in a private directory with the following name:

.eclipse/com.mycompany.myproduct.gui.product_1.8.17_1410846118/

这意味着尽管现在使用了产品ID和版本,但仍存在相同的看似随机数作为后缀。

This means although the product ID and version are now used, the same seemingly random number is still present as a suffix.

我的问题很简单:这个数字是多少,如何计算?

My question is simple: what is this number and how can I calculate it?

Eclipse似乎能够在安装后进行计算。但是,我似乎在使用

Eclipse seems to be able to calculate it after installation. However, I don't seem to find it in any file of the shared installation using

sudo find /opt/MyProduct -name '*' | xargs grep -e '1410846118'


推荐答案

此代码似乎在 org.eclipse.core.runtime.adaptor.LocationManager 中。这将在安装目录中名为 .eclipseproduct 的文件中查找产品ID。如果该文件不存在,它将使用安装目录路径的哈希码,大概就是您所看到的。

The code for this seems to be in org.eclipse.core.runtime.adaptor.LocationManager. This looks for the product id in a file called .eclipseproduct in the installation directory. If the file does not exist it uses the hash code of the install directory path which is presumably what you are seeing.

所以我认为您需要一个 .eclipseproduct 文件。有关更多信息,请参见在构建期间定义.eclipseproduct

So I think you need an .eclipseproduct file. See Define .eclipseproduct during build for some more information.

编辑:

即使与产品文件一起,哈希代码仍会附加。哈希的计算方法如下:

Even with the product file the hash code is still appended. The hash is calculated using this:

File installDir = path of install directory from osgi.install.area
int hashCode;
try {
    hashCode = installDir.getCanonicalPath().hashCode();
} catch (IOException ioe) {
    // fall back to absolute path
    hashCode = installDir.getAbsolutePath().hashCode();
}
if (hashCode < 0)
    hashCode = -(hashCode);
String installDirHash = String.valueOf(hashCode);

这篇关于Eclipse RCP:如何构造专用配置目录(使用共享安装时在〜/ .eclipse中创建)的默认名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆