Search in sources :

Example 56 with IProjectDescription

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);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Workspace(aQute.bnd.build.Workspace)

Example 57 with IProjectDescription

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);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 58 with IProjectDescription

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;
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) TimeoutException(java.util.concurrent.TimeoutException) CoreException(org.eclipse.core.runtime.CoreException)

Example 59 with IProjectDescription

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);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Example 60 with IProjectDescription

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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TreeSet(java.util.TreeSet) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Aggregations

IProjectDescription (org.eclipse.core.resources.IProjectDescription)68 IProject (org.eclipse.core.resources.IProject)35 CoreException (org.eclipse.core.runtime.CoreException)18 IWorkspace (org.eclipse.core.resources.IWorkspace)16 IPath (org.eclipse.core.runtime.IPath)13 ICommand (org.eclipse.core.resources.ICommand)12 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)11 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Path (org.eclipse.core.runtime.Path)8 Status (org.eclipse.core.runtime.Status)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 URI (java.net.URI)5 IResource (org.eclipse.core.resources.IResource)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 InputStream (java.io.InputStream)3 IFile (org.eclipse.core.resources.IFile)3 Resource (org.eclipse.emf.ecore.resource.Resource)3