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);
}
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;
}
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);
}
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");
}
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();
}
}
Aggregations