Search in sources :

Example 86 with IResource

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource)

Example 87 with IResource

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);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IResource(org.eclipse.core.resources.IResource)

Example 88 with IResource

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;
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 89 with IResource

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
        ;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) XMLParserException(org.mybatis.generator.exception.XMLParserException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) IResource(org.eclipse.core.resources.IResource)

Example 90 with IResource

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());
}
Also used : Path(org.eclipse.core.runtime.Path) IResourceProxyVisitor(org.eclipse.core.resources.IResourceProxyVisitor) IResourceProxy(org.eclipse.core.resources.IResourceProxy) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) Test(org.testng.annotations.Test) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest)

Aggregations

IResource (org.eclipse.core.resources.IResource)559 CoreException (org.eclipse.core.runtime.CoreException)141 IFile (org.eclipse.core.resources.IFile)140 IPath (org.eclipse.core.runtime.IPath)119 IProject (org.eclipse.core.resources.IProject)104 IContainer (org.eclipse.core.resources.IContainer)88 ArrayList (java.util.ArrayList)84 IFolder (org.eclipse.core.resources.IFolder)64 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IStatus (org.eclipse.core.runtime.IStatus)47 IOException (java.io.IOException)46 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)44 Path (org.eclipse.core.runtime.Path)42 File (java.io.File)39 Status (org.eclipse.core.runtime.Status)38 IJavaProject (org.eclipse.jdt.core.IJavaProject)31 IJavaElement (org.eclipse.jdt.core.IJavaElement)30 ISelection (org.eclipse.jface.viewers.ISelection)26 List (java.util.List)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22