use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method importConfigurationProject.
private void importConfigurationProject(final ImportSettings importSettings, IProgressMonitor monitor) throws Exception {
monitor.subTask("Import configuration project 'cnf'.");
final IWorkspace eclipseWorkspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot eclipseWorkspaceRoot = eclipseWorkspace.getRoot();
final Workspace bndWorkspace = Workspace.getWorkspace(importSettings.rootImportPath);
// Prepare Eclipse Workspace
updateEclipseWorkspaceSettings(bndWorkspace);
// create generic project
final IProjectDescription cnfProjectDescription = eclipseWorkspace.newProjectDescription(Workspace.CNFDIR);
final IProject project = eclipseWorkspaceRoot.getProject(Workspace.CNFDIR);
if (importSettings.deleteSettings) {
deleteOldProjectFiles(Paths.get(bndWorkspace.getBase().toURI()).resolve(Workspace.CNFDIR));
}
// create JavaProject
IPath path = URIUtil.toPath(bndWorkspace.getBuildDir().toURI());
if (Platform.getLocation().isPrefixOf(path)) {
cnfProjectDescription.setLocation(null);
} else {
cnfProjectDescription.setLocation(path);
}
if (!project.exists()) {
project.create(cnfProjectDescription, monitor);
}
if (!project.isOpen()) {
project.open(monitor);
}
monitor.worked(1);
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method setNatures.
private void setNatures(IProject project, IProgressMonitor monitor, String... natureIds) throws CoreException {
IProjectDescription updatingDescription = project.getDescription();
updatingDescription.setNatureIds(natureIds);
project.setDescription(updatingDescription, monitor);
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class BndtoolsBuilder method setBuildOrder.
/*
* Set the project's dependencies to influence the build order for Eclipse.
*/
private boolean setBuildOrder(IProgressMonitor monitor) throws Exception {
try {
IProjectDescription projectDescription = getProject().getDescription();
IProject[] older = projectDescription.getDynamicReferences();
if (Arrays.equals(dependsOn, older))
return false;
projectDescription.setDynamicReferences(dependsOn);
getProject().setDescription(projectDescription, monitor);
buildLog.full("Changed the build order to %s", Arrays.toString(dependsOn));
} catch (Exception e) {
logger.logError("Failed to set build order", e);
}
return true;
}
use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method importBndProject.
private void importBndProject(final Project bndProject, final Workspace bndWorkspace, final ImportSettings importSettings, IProgressMonitor monitor) throws IOException, CoreException, Exception {
monitor.subTask("Import Bnd project '" + bndProject.getName() + "'.");
final IWorkspace eclipseWorkspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot eclipseWorkspaceRoot = eclipseWorkspace.getRoot();
if (importSettings.deleteSettings) {
deleteOldProjectFiles(Paths.get(bndWorkspace.getBaseURI()).resolve(bndProject.getName()));
}
// create generic project
final IProjectDescription projectDescription = eclipseWorkspace.newProjectDescription(bndProject.getName());
final IProject project = eclipseWorkspaceRoot.getProject(bndProject.getName());
IPath path = URIUtil.toPath(bndProject.getBaseURI());
if (Platform.getLocation().isPrefixOf(path)) {
projectDescription.setLocation(null);
} else {
projectDescription.setLocation(path);
}
if (!project.exists()) {
project.create(projectDescription, monitor);
}
project.open(monitor);
setNatures(project, monitor, JavaCore.NATURE_ID, Plugin.BNDTOOLS_NATURE);
IJavaProject javaProject = JavaCore.create(project);
if (!javaProject.isOpen()) {
javaProject.open(monitor);
}
updateJavaProjectSettings(bndProject, javaProject, importSettings, monitor);
importSourceAndOutputFolders(bndProject, project, javaProject, monitor);
}
use of org.eclipse.core.resources.IProjectDescription in project sling by apache.
the class ContentPackageProjectConfigurator method addNatures.
/**
* Adds the given natures to the project
* @param project
* @param natureIdsToAdd
* @param progressMonitor
* @throws CoreException
* @see <a href="http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_natures.htm">Eclipse Help: Project Natures</a>
*/
private void addNatures(IProject project, String[] natureIdsToAdd, IProgressMonitor progressMonitor, IResource pomResource) throws CoreException {
trace("Adding natures {0} to project {1} ", Arrays.toString(natureIdsToAdd), project);
IProjectDescription description = project.getDescription();
String[] oldNatureIds = description.getNatureIds();
Set<String> newNatureIdSet = new TreeSet<String>();
newNatureIdSet.addAll(Arrays.asList(oldNatureIds));
newNatureIdSet.addAll(Arrays.asList(natureIdsToAdd));
String[] newNatureIds = newNatureIdSet.toArray(new String[newNatureIdSet.size()]);
IStatus status = project.getWorkspace().validateNatureSet(newNatureIds);
// check the status and decide what to do
if (status.getCode() == IStatus.OK) {
description.setNatureIds(newNatureIds);
project.setDescription(description, IResource.KEEP_HISTORY, progressMonitor);
} else {
// add marker
addMarker(pomResource, "Could not add all necessary WTP natures: " + status.getMessage(), IMarker.SEVERITY_ERROR);
}
}
Aggregations