Search code examples
javaeclipsepdetarget-platform

Add a directory to a Target Platform dynamically on Eclipse


I was using Eclipse 3.7 (Indigo) and had a plugin which was adding a defined directory to the active Target Platform.

ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
ITargetDefinition target = service.getWorkspaceTargetHandle().getTargetDefinition();
IBundleContainer[] bundles = target.getBundleContainers();
String myDirectory = "C:\\directory";
boolean containsMyDirectory = false;

for (IBundleContainer bundle : bundles) {
    if (bundle.toString().contains(myDirectory.toString())) {
        containsMyDirectory = true;
        break;
    }
}

if (!containsMyDirectory) {
    bundles = Arrays.copyOf(bundles, bundles.length + 1);
    bundles[bundles.length - 1] = service.newDirectoryContainer(myDirectory.toString());
    target.setBundleContainers(bundles);
    service.saveTargetDefinition(target);
    LoadTargetDefinitionJob.load(target);
}

But now, we're migrating to Eclipse 4.4 (Luna) and the code doesn't compile anymore, showing the following message: The import org.eclipse.pde.internal.core.target.provisional cannot be resolved

The imports that couldn't be resolved were:

import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
import org.eclipse.pde.internal.core.target.provisional.LoadTargetDefinitionJob;

The jar used in Eclipse 3.7 is org.eclipse.pde.core_3.7.1.v20120103_r372.jar and in Eclipse 4.4 is org.eclipse.pde.core_3.10.0.v20140519-1409.jar

I couldn't find the classes that replace the old ones.

Does anybody know what to do?


Solution

  • These classes were internal so you should not have been using them.

    They have now all been moved to the org.eclipse.pde.target package in the org.eclipse.pde.core plugin so they are now part of the official API.

    However PDECore is still internal so should not be used. Since ITargetPlatformService is an OSGi service you should be able to get it in your plugin using a ServiceReference.