Search in sources :

Example 61 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.

the class RPMProjectCreator method create.

/**
 * Creates a project with the given name in the given location.
 *
 * @param projectName
 *            The name of the project.
 * @param projectPath
 *            The parent location of the project.
 * @param monitor
 *            Progress monitor to report back status.
 * @return The newly created project.
 * @throws CoreException If the location is wrong.
 */
public IProject create(String projectName, IPath projectPath, IProgressMonitor monitor) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
    String parsedIPathString = null;
    if (!Platform.getLocation().equals(projectPath)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        parsedIPathString = projectPath.toString().replaceFirst(":/", "://");
        try {
            description.setLocationURI(new URI(parsedIPathString));
        } catch (URISyntaxException e) {
            throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID, e.getMessage(), e));
        }
    }
    description.setNatureIds(new String[] { IRPMConstants.RPM_NATURE_ID });
    project.create(description, monitor);
    monitor.worked(10);
    project.open(monitor);
    new RPMProject(project, layout);
    return project;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject)

Example 62 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.

the class ChangeLogAction method createChangeLog.

protected IFile createChangeLog(IPath changelog) {
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IWorkbench ws = PlatformUI.getWorkbench();
    final IFile changelog_File = myWorkspaceRoot.getFile(changelog);
    final InputStream initialContents = new ByteArrayInputStream(new byte[0]);
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            try {
                // $NON-NLS-1$
                monitor.beginTask(Messages.getString("ChangeLog.AddingChangeLog"), 2000);
                changelog_File.create(initialContents, false, monitor);
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
            } finally {
                monitor.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(ws.getActiveWorkbenchWindow().getShell()).run(true, true, operation);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInterrupted"), e);
        return null;
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInvocation"), e);
        return null;
    }
    // FIXME:  we should put this refreshLocal call into a thread (filed as bug #256180)
    try {
        IContainer changelogContainer = myWorkspaceRoot.getContainerForLocation(changelog);
        if (changelogContainer != null)
            changelogContainer.refreshLocal(2, null);
    } catch (CoreException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrRefresh"), e);
        return null;
    }
    return changelog_File;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IContainer(org.eclipse.core.resources.IContainer)

Example 63 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.

the class ChangeLogAction method getChangelogForRemovePath.

/**
 * Find the ChangeLog for a file that is being removed.  It can't be found and
 * it is possible that the directory it is in has also been removed.
 *
 * @param path Path of removed file
 * @return ChangeLog editor part that must be used to report removed file
 */
protected IEditorPart getChangelogForRemovePath(IPath path) {
    IResource parent_resource = null;
    IPath loc_path = path;
    // Look from current loc up to find first folder that is still existing
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    while (loc_path.segmentCount() > 0) {
        parent_resource = myWorkspaceRoot.findMember(loc_path);
        if (parent_resource != null)
            break;
        loc_path = loc_path.removeLastSegments(1);
    }
    if (parent_resource != null) {
        IResource parent_dec = parent_resource;
        while (parent_dec != null) {
            String parent_node = parent_dec.getFullPath().toOSString();
            parent_node = parent_node + System.getProperty("file.separator") + // $NON-NLS-1$
            pref_ChangeLogName;
            IResource change_log_res = myWorkspaceRoot.findMember(parent_node);
            if (change_log_res != null) {
                IProject proj_loc = parent_resource.getProject();
                IPath modified_changelog_path = change_log_res.getFullPath().removeFirstSegments(1);
                IFile change_log_file = proj_loc.getFile(modified_changelog_path);
                return openEditor(change_log_file);
            }
            parent_dec = parent_dec.getParent();
            if (parent_dec == null) {
                break;
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 64 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.

the class ChangeLogAction method askChangeLogLocation.

protected IEditorPart askChangeLogLocation(String editorLoc) {
    IWorkbench ws = PlatformUI.getWorkbench();
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IResource given_resource = myWorkspaceRoot.findMember(editorLoc);
    if (given_resource == null)
        return null;
    ChangeLogContainerSelectionDialog dialog = new ChangeLogContainerSelectionDialog(ws.getActiveWorkbenchWindow().getShell(), given_resource.getParent(), false, Messages.getString(// $NON-NLS-1$
    "AddAction.str_ChangeLog_Location"));
    dialog.showClosedProjects(false);
    dialog.open();
    Object[] result = dialog.getResult();
    if (result == null)
        return null;
    final IPath result_path = new Path(result[0] + System.getProperty("file.separator") + // $NON-NLS-1$ //$NON-NLS-2$
    pref_ChangeLogName);
    IFile newChangeLog = createChangeLog(result_path);
    return openEditor(newChangeLog);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource)

Example 65 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.

the class ChangeLogAction method getChangelogFile.

protected IFile getChangelogFile(String currentEditorloc) {
    // Scenario 1: The Changelog is in in the current project file
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IResource given_resource = myWorkspaceRoot.findMember(currentEditorloc);
    if (given_resource != null) {
        IResource parent_dec = given_resource;
        while (parent_dec != null) {
            String parent_node = parent_dec.getFullPath().removeLastSegments(1).toOSString();
            parent_node = parent_node + System.getProperty("file.separator") + // $NON-NLS-1$
            pref_ChangeLogName;
            IResource change_log_res = myWorkspaceRoot.findMember(parent_node);
            if (change_log_res != null) {
                IProject proj_loc = given_resource.getProject();
                IPath modified_changelog_path = change_log_res.getFullPath().removeFirstSegments(1);
                IFile change_log_file = proj_loc.getFile(modified_changelog_path);
                return change_log_file;
            }
            parent_dec = parent_dec.getParent();
            if (parent_dec == null) {
                break;
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)172 IProject (org.eclipse.core.resources.IProject)69 IPath (org.eclipse.core.runtime.IPath)60 IResource (org.eclipse.core.resources.IResource)57 IFile (org.eclipse.core.resources.IFile)53 CoreException (org.eclipse.core.runtime.CoreException)50 IWorkspace (org.eclipse.core.resources.IWorkspace)34 File (java.io.File)30 Path (org.eclipse.core.runtime.Path)29 IContainer (org.eclipse.core.resources.IContainer)26 URI (java.net.URI)18 IFolder (org.eclipse.core.resources.IFolder)17 IOException (java.io.IOException)15 IProjectDescription (org.eclipse.core.resources.IProjectDescription)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 IStatus (org.eclipse.core.runtime.IStatus)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 Location (ch.acanda.eclipse.pmd.domain.Location)10