use of org.eclipse.core.resources.IResource in project che by eclipse.
the class RefactoringFileBuffers method acquire.
/**
* Connects to and acquires a text file buffer for the specified compilation unit.
* <p>
* All text file buffers acquired by a call to {@link RefactoringFileBuffers#acquire(ICompilationUnit)}
* must be released using {@link RefactoringFileBuffers#release(ICompilationUnit)}.
* </p>
*
* @param unit the compilation unit to acquire a text file buffer for
* @return the text file buffer, or <code>null</code> if no buffer could be acquired
* @throws CoreException if no buffer could be acquired
*/
public static ITextFileBuffer acquire(final ICompilationUnit unit) throws CoreException {
Assert.isNotNull(unit);
final IResource resource = unit.getResource();
if (resource != null && resource.getType() == IResource.FILE) {
final IPath path = resource.getFullPath();
FileBuffers.getTextFileBufferManager().connect(path, LocationKind.IFILE, new NullProgressMonitor());
return FileBuffers.getTextFileBufferManager().getTextFileBuffer(path, LocationKind.IFILE);
}
return null;
}
use of org.eclipse.core.resources.IResource in project generator by mybatis.
the class AbstractGeneratorComposite method createFileNameBrowseButtons.
private void createFileNameBrowseButtons(Composite parent) {
new Label(parent, SWT.NONE);
Composite buttonComposite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
buttonComposite.setLayout(layout);
GridData gd = new GridData(SWT.END, SWT.CENTER, false, false);
buttonComposite.setLayoutData(gd);
buttonComposite.setFont(parent.getFont());
btnBrowseWorkplace = new Button(buttonComposite, SWT.NONE);
btnBrowseWorkplace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IResource chosenFile = chooseFileFromWorkspace();
if (chosenFile != null) {
IPath path = chosenFile.getFullPath();
//$NON-NLS-1$ //$NON-NLS-2$
txtFileName.setText("${workspace_loc:" + path.toString() + "}");
javaProjectName = GeneratorLaunchShortcut.getJavaProjectNameFromResource(chosenFile);
}
}
});
btnBrowseWorkplace.setText(Messages.FILE_PICKER_BROWSE_WORKSPACE);
btnBrowseFileSystem = new Button(buttonComposite, SWT.NONE);
btnBrowseFileSystem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chooseFileFromFileSystem();
}
});
btnBrowseFileSystem.setText(Messages.FILE_PICKER_BROWSE_FILE_SYSTEM);
}
use of org.eclipse.core.resources.IResource in project generator by mybatis.
the class AbstractGeneratorComposite method chooseFileFromWorkspace.
protected IResource chooseFileFromWorkspace() {
ElementTreeSelectionDialog esd = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
esd.setTitle(getDialogTitle());
esd.setMessage(getDialogMessage());
esd.setAllowMultiple(false);
esd.setValidator(selectionStatusVerifier);
esd.addFilter(getViewerFilter());
esd.setInput(ResourcesPlugin.getWorkspace().getRoot());
esd.setInitialSelection(getWorkspaceResource());
int rc = esd.open();
if (rc == 0) {
Object[] elements = esd.getResult();
if (elements.length > 0) {
return (IResource) elements[0];
}
}
return null;
}
use of org.eclipse.core.resources.IResource in project generator by mybatis.
the class RunGeneratorThread method setClassLoader.
private void setClassLoader() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IJavaProject javaProject = getJavaProject();
try {
if (javaProject != null) {
List<URL> entries = new ArrayList<URL>();
IPath path = javaProject.getOutputLocation();
IResource iResource = root.findMember(path);
path = iResource.getLocation();
path = path.addTrailingSeparator();
entries.add(path.toFile().toURI().toURL());
IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
for (IClasspathEntry cpEntry : cpEntries) {
switch(cpEntry.getEntryKind()) {
case IClasspathEntry.CPE_SOURCE:
path = cpEntry.getOutputLocation();
if (path != null) {
iResource = root.findMember(path);
path = iResource.getLocation();
path = path.addTrailingSeparator();
entries.add(path.toFile().toURI().toURL());
}
break;
case IClasspathEntry.CPE_LIBRARY:
iResource = root.findMember(cpEntry.getPath());
if (iResource == null) {
// resource is not in workspace, must be an external JAR
path = cpEntry.getPath();
} else {
path = iResource.getLocation();
}
entries.add(path.toFile().toURI().toURL());
break;
}
}
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
URL[] entryArray = new URL[entries.size()];
entries.toArray(entryArray);
ClassLoader newCl = new URLClassLoader(entryArray, oldCl);
Thread.currentThread().setContextClassLoader(newCl);
oldClassLoader = oldCl;
}
} catch (Exception e) {
// ignore - something too complex is wrong
;
}
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class ClasspathBuilderTest method elementShouldBeAddedAsLibToClasspathFromLibFolder.
@Test
public void elementShouldBeAddedAsLibToClasspathFromLibFolder() throws Exception {
Path jarPath = new Path(LIBRARY + "/a.jar");
library.add(LIBRARY);
IFolder libraryFolder1 = mock(IFolder.class);
IResourceProxy iResourceProxy = mock(IResourceProxy.class);
IResource iResource = mock(IResource.class);
when(iProject.getFolder(LIBRARY)).thenReturn(libraryFolder1);
when(libraryFolder1.exists()).thenReturn(true);
when(iResourceProxy.getType()).thenReturn(IResource.FILE);
when(iResourceProxy.requestFullPath()).thenReturn(jarPath);
when(iResourceProxy.requestResource()).thenReturn(iResource);
when(iResource.getLocation()).thenReturn(jarPath);
classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
ArgumentCaptor<IResourceProxyVisitor> resourceProxyVisitorArgumentCaptor = ArgumentCaptor.forClass(IResourceProxyVisitor.class);
verify(libraryFolder1).accept(resourceProxyVisitorArgumentCaptor.capture(), eq(IContainer.INCLUDE_PHANTOMS));
resourceProxyVisitorArgumentCaptor.getValue().visit(iResourceProxy);
verify(iResourceProxy).getType();
assertEquals(jarPath, iResource.getLocation());
}
Aggregations