Search in sources :

Example 61 with IContainer

use of org.eclipse.core.resources.IContainer in project xtext-xtend by eclipse.

the class XtendParallelBuilderParticipant method getGeneratorMarkers.

@Override
protected Map<OutputConfiguration, Iterable<IMarker>> getGeneratorMarkers(IProject builtProject, Collection<OutputConfiguration> outputConfigurations) throws CoreException {
    Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = newHashMap();
    List<IPath> sourcePath = getSourceFolderPathes(builtProject);
    for (OutputConfiguration config : outputConfigurations) {
        if (config.isCleanUpDerivedResources()) {
            List<IContainer> containerToSearchIn = Lists.newArrayList();
            for (IPath sourceFolder : sourcePath) {
                if (sourceFolder.segmentCount() == 1) {
                    containerToSearchIn.add(builtProject);
                } else {
                    IContainer sourcePathBasedContainer = builtProject.getWorkspace().getRoot().getFolder(sourceFolder);
                    containerToSearchIn.add(sourcePathBasedContainer);
                }
            }
            Collection<IMarker> markers = Lists.newArrayList();
            for (IContainer container : containerToSearchIn) {
                Iterables.addAll(markers, getDerivedResourceMarkers().findDerivedResourceMarkers(container, getGeneratorIdProvider().getGeneratorIdentifier()));
            }
            generatorMarkers.put(config, markers);
        }
    }
    return buildGeneratorMarkersReverseLookupMap(generatorMarkers);
}
Also used : IPath(org.eclipse.core.runtime.IPath) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) IMarker(org.eclipse.core.resources.IMarker) IContainer(org.eclipse.core.resources.IContainer)

Example 62 with IContainer

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

the class STLink2SourceSupport method getFileForPathImpl.

private static IFile getFileForPathImpl(IPath path, IProject project) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    if (path.isAbsolute()) {
        return root.getFileForLocation(path);
    }
    if (project != null && project.exists()) {
        ICProject cproject = CoreModel.getDefault().create(project);
        if (cproject != null) {
            try {
                ISourceRoot[] roots = cproject.getAllSourceRoots();
                for (ISourceRoot sourceRoot : roots) {
                    IContainer r = sourceRoot.getResource();
                    IResource res = r.findMember(path);
                    if (res != null && res.exists() && res instanceof IFile) {
                        return (IFile) res;
                    }
                }
                IOutputEntry[] entries = cproject.getOutputEntries();
                for (IOutputEntry pathEntry : entries) {
                    IPath p = pathEntry.getPath();
                    IResource r = root.findMember(p);
                    if (r instanceof IContainer) {
                        IContainer parent = (IContainer) r;
                        IResource res = parent.findMember(path);
                        if (res != null && res.exists() && res instanceof IFile) {
                            return (IFile) res;
                        }
                    }
                }
            } catch (CModelException e) {
                Activator.getDefault().getLog().log(e.getStatus());
            }
        }
    }
    // no match found...try and see if we are dealing with a link
    IPath realPath = project.getLocation().append(path).makeAbsolute();
    URI realURI = URIUtil.toURI(realPath.toString());
    try {
        FindLinkedResourceVisitor visitor = new STLink2SourceSupport.FindLinkedResourceVisitor(realURI);
        project.accept(visitor, IResource.DEPTH_INFINITE);
        // If we find a match, make note of the target and the real C project.
        if (visitor.foundElement()) {
            return (IFile) visitor.getResource();
        }
    } catch (CoreException e) {
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) IPath(org.eclipse.core.runtime.IPath) CModelException(org.eclipse.cdt.core.model.CModelException) URI(java.net.URI) ISourceRoot(org.eclipse.cdt.core.model.ISourceRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IOutputEntry(org.eclipse.cdt.core.model.IOutputEntry) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 63 with IContainer

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

the class StapNewWizard method doFinish.

/**
 * The worker method. It will find the container, create the
 * file if missing or just replace its contents, and open
 * the editor on the newly created file.
 */
private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException {
    // create a .stp file
    // $NON-NLS-1$
    monitor.beginTask(resourceBundle.getString("StapNewWizard.BeginTask") + fileName, 2);
    final IContainer newResource = (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(containerName);
    final IFile newFile = newResource.getFile(new Path(fileName));
    // $NON-NLS-1$
    String envString = "#!/usr/bin/env stap";
    newFile.create(new ByteArrayInputStream(envString.getBytes()), true, monitor);
    monitor.worked(1);
    // $NON-NLS-1$
    monitor.setTaskName(resourceBundle.getString("StapNewWizard.SetTask"));
    getShell().getDisplay().asyncExec(() -> {
        try {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
            IDE.openEditor(page, newFile);
        } catch (WorkbenchException e1) {
        // ignore, the file is created but opening the editor failed
        }
    });
    monitor.worked(1);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IContainer(org.eclipse.core.resources.IContainer) WorkbenchException(org.eclipse.ui.WorkbenchException)

Example 64 with IContainer

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

the class StapNewWizardPage method initialize.

/**
 * Tests if the current workbench selection is a suitable container to use.
 */
private void initialize() {
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1) {
            return;
        }
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer) {
                container = (IContainer) obj;
            } else {
                container = ((IResource) obj).getParent();
            }
            containerText.setText(container.getFullPath().toString());
        }
    }
    // $NON-NLS-1$
    fileText.setText(".stp");
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 65 with IContainer

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

the class SourcesFileDownloadHyperlink method open.

/**
 * Tries to open the given file name looking for it in the current directory
 * and in ../SOURCES.
 *
 * @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
 */
@Override
public void open() {
    IContainer container = original.getParent();
    IResource saveFolder = container.getParent().findMember(IRPMConstants.SOURCES_FOLDER);
    if (saveFolder == null) {
        saveFolder = container.findMember(original.getFullPath().removeLastSegments(1));
    }
    if (saveFolder == null) {
        // $NON-NLS-1$
        saveFolder = container.findMember("/");
    }
    try {
        URL url = new URL(fileName);
        URLConnection connection = url.openConnection();
        String savedFileName = fileName.substring(fileName.lastIndexOf('/') + 1);
        IFile savedFile = original.getProject().getFile(saveFolder.getProjectRelativePath().append(savedFileName));
        if (savedFile.exists()) {
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
            mb.setText(Messages.SourcesFileDownloadHyperlink_0);
            mb.setMessage(NLS.bind(Messages.SourcesFileDownloadHyperlink_1, savedFileName));
            int rc = mb.open();
            if (rc == SWT.OK) {
                new DownloadJob(savedFile, connection).schedule();
            }
        } else {
            new DownloadJob(savedFile, connection).schedule();
        }
    } catch (IOException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
        mb.setMessage(Messages.SourcesFileDownloadHyperlink_2);
        mb.setText(Messages.SourcesFileDownloadHyperlink_3);
        mb.open();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException) IContainer(org.eclipse.core.resources.IContainer) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) IResource(org.eclipse.core.resources.IResource) URL(java.net.URL) URLConnection(java.net.URLConnection) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9