IProject project = targetResource.getProject();
File projectDir = project.getLocation().toFile();
if (targetResource.getType() == IResource.FILE && targetResource.getName().endsWith(LaunchConstants.EXT_BNDRUN)) {
if (!targetResource.getName().endsWith(LaunchConstants.EXT_BNDRUN))
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Bnd launch target file \"{0}\" is not a .bndrun file.", targetResource.getFullPath().toString()), null));
// Get the synthetic "run" project (based on a .bndrun file)
File runFile = targetResource.getLocation().toFile();
File bndbnd = new File(runFile.getParentFile(), Project.BNDFILE);
try {
Project parent = new Project(Central.getWorkspace(), projectDir, bndbnd);
result = new Project(Central.getWorkspace(), projectDir, runFile);
result.setParent(parent);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Failed to create synthetic project for run file {0} in project {1}.", targetResource.getProjectRelativePath().toString(),
project.getName()), e));
}
} else if (targetResource.getType() == IResource.PROJECT || targetResource.getName().equals(Project.BNDFILE)) {
// Use the main project (i.e. bnd.bnd)
if (!project.hasNature(BndtoolsConstants.NATURE_ID))
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("The configured run project \"{0}\"is not a Bnd project.", project.getName()), null));
try {
result = Central.getProject(projectDir);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Failed to retrieve Bnd project model for project \"{0}\".", project.getName()), null));
}
} else {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("The specified launch target \"{0}\" is not recognised as a bnd project, bnd.bnd or .bndrun file.", targetResource.getFullPath()
.toString()), null));
}
return result;
}