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).
精彩评论