P2.inf:根据位置引用更新站点

时间:2013-03-24 20:46:54

标签: eclipse-rcp p2

我开发了一个RCP应用程序,我正在提供p2更新功能。

在我的p2.inf中,我提供更新站点的URL。我不希望用户添加任何网站,因此我禁用了添加网站的选项。我的p2.inf看起来像:

instructions.configure=\
  addRepository(type:0,location:http${#58}//blrupdates.com/Updates);\
  addRepository(type:1,location:http${#58}//blrupdates.com/Updates);

如果用户位置是班加罗尔,RCP应用程序应该转到brlupdates.com,如果用户位置是chennai,那么RCP应用程序应该在chnupdates.com上查找更新。

如何在p2.inf中添加另一个存储库位置?

-Priyank

1 个答案:

答案 0 :(得分:2)

您需要以编程方式添加存储库。以下解决方案取自here。另一个我不确定它会起作用的解决方案是使用重定向。您定义一个p2存储库,然后将用户重定向到基于位置的存储库。

import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;

@SuppressWarnings("restriction")
public class P2Util {
  private static String UPDATE_SITE = "http://www.example.com/update_site";

  public static void setRepositories() throws InvocationTargetException {
    try {
      final MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(UPDATE_SITE), true);
      ElementUtils.updateRepositoryUsingElements(new MetadataRepositoryElement[] {element}, null);
    } catch (URISyntaxException e) {
      e.printStackTrace();
      throw new InvocationTargetException(e);
    }
  }
}
相关问题