2011-01-19 2 views

답변

0

프로그래밍 방식으로 확장 프로그램을 추가하거나 제거 할 수 있습니다. 다음 예제 방법 (요구에 적응) 참조 :

public void addExtension() throws UnsupportedEncodingException { 
    String pluginXmlAsString = "<a string with the content of plugin.xml"; 
    InputStream pluginXmlIs = new ByteArrayInputStream(pluginXmlAsString.getBytes(StandardCharsets.UTF_8.name())); 

    IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); 
    Object token = ((ExtensionRegistry) extensionRegistry).getTemporaryUserToken(); 
    IContributor contributor = ContributorFactoryOSGi.createContributor(Platform.getBundle("org.acme.mybundle")); 

    extensionRegistry.addContribution(pluginXmlIs, contributor, false, null, null, token); 
} 

public static void removeExtensionsContributedByMe() { 
    String extensionPointId = "<ID of the extension point for remove an extension of"; 
    String extensionContributor = "org.acme.mybundle"; 

    ExtensionRegistry extensionRegistry = (ExtensionRegistry) Platform.getExtensionRegistry(); 
    IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(extensionPointId); 
    IExtension[] extensions = extensionPoint.getExtensions(); 
    Object token = extensionRegistry.getTemporaryUserToken(); 

    for (IExtension extension : extensions) { 
     if (extensionContributor.equals(extension.getContributor().getName())) { 
      extensionRegistry.removeExtension(extension, token); 
     } 
    } 
} 

우리는 준비로 확장을 추가하고 정리하는 확장자를 제거하는 단위 테스트를 위해 이것을 사용합니다. 이렇게하면 테스트가 서로 영향을 미치지 않습니다 (확장이 plugin.xml 또는 fragment.xml에서 "하드 코딩 됨"인 경우).

관련 문제