开发者

Artifact and metadata repository manager are null

开发者 https://www.devze.com 2023-03-28 19:40 出处:网络
I try to load an artifact and metadata repository manager as follows private IArtifactRepositoryManager getArtifactRepositoryManager() {

I try to load an artifact and metadata repository manager as follows

private IArtifactRepositoryManager getArtifactRepositoryManager() {
  IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) 
     ServiceHelper.getService(ProvUIActivator.getContext(),
     IArtifactRepositoryManager.class.getName());
  if(artifactManager == null) {
    LOG.error("ArtifactRepositoryManager service nor found");
  }
  return artifactManager;
}

ServiceHelper always returns null. Is there another way to get the repository managers? I'm using Eclipse/RCP 3.7 (Indigo).

I used bundles from Eclipse 3.5 before and everything works fine with this code:

private IMetadataRepositoryManager getMetadataRepositoryManager() {
  //Load repository manager
  IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) context.getService(
     开发者_C百科 context.getServiceReference(IMetadataRepositoryManager.class.getName()));
  return metadataManager;
}


I think the solution is to make sure the p2 plug-ins start before your plug-in starts. Set the auto-start levels in your product configuration accordingly.

<configurations>
  <plugin id="my.plugin" autoStart="false" startLevel="7" />
  <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="6" />
  <plugin id="org.eclipse.equinox.p2.core" autoStart="true" startLevel="5" />
</configurations>


I found a solution by reading the source code of the "Available Software Sites" preference page. It's easy but you can't find any documentation about it:

final ProvisioningUI ui = ProvUIActivator.getDefault().getProvisioningUI();
IArtifactRepositoryManager artifactManager = ProvUI.getArtifactRepositoryManager(ui.getSession());
artifactManager.addRepository(new URI(UPDATE_SITE_URL);

IMetadataRepositoryManager metadataManager = ProvUI.getMetadataRepositoryManager(ui.getSession());
metadataManager.addRepository(new URI(UPDATE_SITE_URL);

This works with Eclipse 3.7. For ProvUI and ProvisioningUI you have to import bundles org.eclipse.equinox.p2.ui and org.eclipse.equinox.p2.operations (among others).

0

精彩评论

暂无评论...
验证码 换一张
取 消