Search in sources :

Example 51 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.

the class ImportProjectsUtilities method importProject.

public static void importProject(String path) throws CoreException {
    IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(path + File.separator + ".project"));
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
    if (!project.isOpen() && !project.isLinked()) {
        project.create(description, null);
        project.open(null);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Example 52 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.

the class ComponentProjectManager method createNewProject.

/**
     * Creates a new project resource with the selected name.
     * <p>
     * In normal usage, this method is invoked after the user has pressed Finish on the wizard; the enablement of the
     * Finish button implies that all controls on the pages currently contain valid values.
     * </p>
     * <p>
     * Note that this wizard caches the new project once it has been successfully created; subsequent invocations of
     * this method will answer the same project resource without attempting to create it again.
     * </p>
     * 
     * @return the created project resource, or <code>null</code> if the project was not created
     */
public IProject createNewProject(String directroy, String projectName, Shell shell) {
    if (projDir.equals(directroy)) {
        return project;
    }
    final Shell currentShell = shell;
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (newProjectHandle.getRawLocation() != null) {
        if (newProjectHandle.getRawLocation().equals(directroy)) {
            return newProjectHandle;
        } else {
            try {
                newProjectHandle.delete(false, true, null);
            } catch (CoreException e) {
                // e.printStackTrace();
                org.talend.componentdesigner.exception.ExceptionHandler.process(e);
            }
        }
    }
    // final IJavaProject javaProjHandle = JavaCore.create(newProjectHandle);
    // get a project descriptor
    URI location = null;
    if (directroy == null || directroy.equals(PluginConstant.EMPTY_STRING)) {
        return null;
    } else {
        location = new File(directroy).toURI();
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    description.setLocationURI(location);
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(description, //$NON-NLS-1$
            Messages.getString("ComponentProjectManager.NewProject"));
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(currentShell));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // run the new project creation o`peration
    try {
        ProgressUI.popProgressDialog(op, shell);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("ComponentProjectManager.WarningMsg", //$NON-NLS-1$
                newProjectHandle.getName()), cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ComponentDesigenerPlugin.PLUGIN_ID, cause.getStatus().getSeverity(), Messages.getString("ComponentProjectManager.CreationProblems"), //$NON-NLS-1$
                cause));
            }
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, 0, Messages.getString("ComponentProjectManager.InternalErrorMsg", t.getMessage()), //$NON-NLS-1$
            t));
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
        return null;
    }
    project = newProjectHandle;
    return project;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) StatusAdapter(org.eclipse.ui.statushandlers.StatusAdapter) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) File(java.io.File)

Example 53 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.

the class ProjectNatureChange method perform.

@Override
public final Change perform(IProgressMonitor pm) throws CoreException {
    final IProjectDescription desc = project.getDescription();
    Set<String> natures = new HashSet<String>(Arrays.asList(desc.getNatureIds()));
    boolean changed = modifyNatures(natures);
    if (changed) {
        desc.setNatureIds(natures.toArray(new String[0]));
        project.setDescription(desc, pm);
    }
    return createInverse();
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription) HashSet(java.util.HashSet)

Example 54 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project bndtools by bndtools.

the class ToggleNatureAction method toggleNature.

/**
     * Toggles sample nature on a project
     *
     * @param project
     *            to have sample nature added or removed
     */
private static IStatus toggleNature(IJavaProject project) {
    try {
        /* Version control ignores */
        VersionControlIgnoresManager versionControlIgnoresManager = Plugin.getDefault().getVersionControlIgnoresManager();
        Set<String> enabledIgnorePlugins = new BndPreferences().getVersionControlIgnoresPluginsEnabled(versionControlIgnoresManager, project, null);
        /* Headless build files */
        HeadlessBuildManager headlessBuildManager = Plugin.getDefault().getHeadlessBuildManager();
        Set<String> enabledPlugins = new BndPreferences().getHeadlessBuildPluginsEnabled(headlessBuildManager, null);
        IProject iProject = project.getProject();
        IProjectDescription description = iProject.getDescription();
        String[] natures = description.getNatureIds();
        List<String> headlessBuildWarnings = new LinkedList<>();
        for (int i = 0; i < natures.length; ++i) {
            if (BndtoolsConstants.NATURE_ID.equals(natures[i])) {
                // Remove the nature
                String[] newNatures = new String[natures.length - 1];
                System.arraycopy(natures, 0, newNatures, 0, i);
                System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                description.setNatureIds(newNatures);
                iProject.setDescription(description, null);
                /* Remove the headless build files */
                headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), false, enabledIgnorePlugins, headlessBuildWarnings);
                /* refresh the project; files were created outside of Eclipse API */
                iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
                return createStatus("Obsolete build files may remain in the project. Please review the messages below.", Collections.<String>emptyList(), headlessBuildWarnings);
            }
        }
        /* Add the headless build files */
        headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), true, enabledIgnorePlugins, headlessBuildWarnings);
        // Add the nature
        ensureBndBndExists(iProject);
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = BndtoolsConstants.NATURE_ID;
        description.setNatureIds(newNatures);
        iProject.setDescription(description, null);
        /* refresh the project; files were created outside of Eclipse API */
        iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
        return createStatus("Some build files could not be generated. Please review the messages below.", Collections.<String>emptyList(), headlessBuildWarnings);
    } catch (CoreException e) {
        return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error occurred while toggling Bnd project nature", e);
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) BndPreferences(bndtools.preferences.BndPreferences) VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager) HeadlessBuildManager(org.bndtools.headless.build.manager.api.HeadlessBuildManager) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 55 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project sling by apache.

the class ProjectAdapter method addNatures.

public void addNatures(String... naturesToAdd) throws CoreException {
    IProjectDescription desc = project.getDescription();
    String[] natures = desc.getNatureIds();
    String[] newNatures = new String[natures.length + naturesToAdd.length];
    System.arraycopy(natures, 0, newNatures, 0, natures.length);
    for (int i = 0; i < naturesToAdd.length; i++) {
        newNatures[natures.length + i] = naturesToAdd[i];
    }
    desc.setNatureIds(newNatures);
    project.setDescription(desc, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) 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