2011-08-18 94 views
1

我嘗試加載的工件和元數據存儲庫管理如下神器和元數據倉庫管理器是空的

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總是返回null。是否有另一種方法來獲取存儲庫管理器?我使用的是Eclipse/RCP 3.7(Indigo)。

我用束從之前的Eclipse 3.5和一切工作正常使用此代碼:

private IMetadataRepositoryManager getMetadataRepositoryManager() { 
    //Load repository manager 
    IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) context.getService(
     context.getServiceReference(IMetadataRepositoryManager.class.getName())); 
    return metadataManager; 
} 

回答

0

我找到了一個解決方案通過閱讀「可用軟件站點」首選項頁面的源代碼。這很容易,但你找不到任何有關它的文檔:

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); 

這適用於Eclipse 3.7。對於ProvUIProvisioningUI你必須輸入束org.eclipse.equinox.p2.uiorg.eclipse.equinox.p2.operations(等等)。

2

我認爲解決方案是確保p2插件在插件啓動之前啓動。相應地在產品配置中設置自動啓動級別。

<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>