use of org.eclipse.pde.core.target.ITargetHandle in project dsl-devkit by dsldevkit.
the class TargetDefinitionSetup method initializeTargetPlatform.
/**
* If necessary, creates and loads a new target platform. Waits until the new platform has been loaded.
*
* @throws IOException
* if locating bundle file fails
*/
public static void initializeTargetPlatform() throws IOException {
// The work-around is creating a new target platform adding the parent folders of the bundles
try {
final ITargetPlatformService targetPlatformService = TargetPlatformService.getDefault();
final ITargetHandle workspaceTargetHandle = targetPlatformService.getWorkspaceTargetHandle();
if (workspaceTargetHandle == null || !TARGET_PLATFORM_NAME.equals(workspaceTargetHandle.getTargetDefinition().getName())) {
final ITargetDefinition targetDefinition = targetPlatformService.newTarget();
targetDefinition.setName(TARGET_PLATFORM_NAME);
final List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
final Set<String> dirs = new HashSet<String>();
for (final Bundle bundle : Platform.getBundle("org.eclipse.core.runtime").getBundleContext().getBundles()) {
// $NON-NLS-1$
final File file = FileLocator.getBundleFile(bundle);
final File folder = file.getParentFile();
final String path = folder.getAbsolutePath();
if (dirs.add(path)) {
ITargetLocation newDirectoryLocation = targetPlatformService.newDirectoryLocation(path);
bundleContainers.add(newDirectoryLocation);
}
}
targetDefinition.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
targetDefinition.setArch(Platform.getOSArch());
targetDefinition.setOS(Platform.getOS());
targetDefinition.setWS(Platform.getWS());
targetDefinition.setNL(Platform.getNL());
targetPlatformService.saveTargetDefinition(targetDefinition);
final CountDownLatch platformLoaded = new CountDownLatch(1);
LoadTargetDefinitionJob.load(targetDefinition, new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
platformLoaded.countDown();
}
});
platformLoaded.await();
}
} catch (final CoreException coreException) {
// Nothing
} catch (InterruptedException e) {
// Restore interrupted status
Thread.currentThread().interrupt();
}
}
Aggregations