Search in sources :

Example 6 with IWorkspaceRoot

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

the class JavaProject method computePackageFragmentRoots.

/**
     * Returns the package fragment roots identified by the given entry. In case it refers to
     * a project, it will follow its classpath so as to find exported roots as well.
     * Only works with resolved entry
     *
     * @param resolvedEntry
     *         IClasspathEntry
     * @param accumulatedRoots
     *         ObjectVector
     * @param rootIDs
     *         HashSet
     * @param referringEntry
     *         the CP entry (project) referring to this entry, or null if initial project
     * @param retrieveExportedRoots
     *         boolean
     * @throws JavaModelException
     */
public void computePackageFragmentRoots(IClasspathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, IClasspathEntry referringEntry, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException {
    String rootID = ((ClasspathEntry) resolvedEntry).rootID();
    if (rootIDs.contains(rootID))
        return;
    IPath projectPath = this.project.getFullPath();
    IPath entryPath = resolvedEntry.getPath();
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPackageFragmentRoot root = null;
    switch(resolvedEntry.getEntryKind()) {
        // source folder
        case IClasspathEntry.CPE_SOURCE:
            if (projectPath.isPrefixOf(entryPath)) {
                Object target = getTarget(entryPath, true);
                if (target == null)
                    return;
                if (target instanceof IFolder || target instanceof IProject) {
                    root = getPackageFragmentRoot((IResource) target);
                }
            }
            break;
        // internal/external JAR or folder
        case IClasspathEntry.CPE_LIBRARY:
            if (referringEntry != null && !resolvedEntry.isExported())
                return;
            Object target = getTarget(entryPath, true);
            if (target == null)
                return;
            if (target instanceof IResource) {
                //                    // internal target
                root = getPackageFragmentRoot((IResource) target, entryPath);
            } else if (target instanceof File) {
                // external target
                if (isFile(target)) {
                    root = new JarPackageFragmentRoot(entryPath, this);
                } else if (((File) target).isDirectory()) {
                    //                        root = new ExternalPackageFragmentRoot(entryPath, this);
                    throw new UnsupportedOperationException();
                }
            }
            break;
        // recurse into required project
        case IClasspathEntry.CPE_PROJECT:
            if (!retrieveExportedRoots)
                return;
            if (referringEntry != null && !resolvedEntry.isExported())
                return;
            IResource member = workspaceRoot.findMember(entryPath);
            if (member != null && member.getType() == IResource.PROJECT) {
                // double check if bound to project (23977)
                IProject requiredProjectRsc = (IProject) member;
                if (org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(requiredProjectRsc)) {
                    // special builder binary output
                    rootIDs.add(rootID);
                    org.eclipse.jdt.internal.core.JavaProject requiredProject = (org.eclipse.jdt.internal.core.JavaProject) JavaCore.create(requiredProjectRsc);
                    requiredProject.computePackageFragmentRoots(requiredProject.getResolvedClasspath(), accumulatedRoots, rootIDs, rootToResolvedEntries == null ? resolvedEntry : ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry), // only combine if need to build the reverse map
                    retrieveExportedRoots, rootToResolvedEntries);
                }
                break;
            }
    }
    if (root != null) {
        accumulatedRoots.add(root);
        rootIDs.add(rootID);
        if (rootToResolvedEntries != null)
            rootToResolvedEntries.put(root, ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry));
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JavaModelManager.isFile(org.eclipse.jdt.internal.core.JavaModelManager.isFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with IWorkspaceRoot

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

the class DeleteResourcesDescriptor method createRefactoring.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.RefactoringDescriptor#createRefactoring(org.eclipse.ltk.core.refactoring.RefactoringStatus)
	 */
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
    IResource[] resources = new IResource[fResourcePaths.length];
    for (int i = 0; i < fResourcePaths.length; i++) {
        IResource resource = wsRoot.findMember(fResourcePaths[i]);
        if (resource == null || !resource.exists()) {
            status.addFatalError(Messages.format(RefactoringCoreMessages.DeleteResourcesDescriptor_error_delete_not_exists, BasicElementLabels.getPathLabel(fResourcePaths[i], false)));
            return null;
        }
        resources[i] = resource;
    }
    DeleteResourcesProcessor processor = new DeleteResourcesProcessor(resources, fDeleteContents);
    return new DeleteRefactoring(processor);
}
Also used : DeleteResourcesProcessor(org.eclipse.ltk.internal.core.refactoring.resource.DeleteResourcesProcessor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) DeleteRefactoring(org.eclipse.ltk.core.refactoring.participants.DeleteRefactoring) IResource(org.eclipse.core.resources.IResource)

Example 8 with IWorkspaceRoot

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

the class ChangeDescription method createSourceResource.

private IResource createSourceResource(IResourceDelta delta) {
    IPath sourcePath = delta.getMovedFromPath();
    IResource resource = delta.getResource();
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
    switch(resource.getType()) {
        case IResource.PROJECT:
            return wsRoot.getProject(sourcePath.segment(0));
        case IResource.FOLDER:
            return wsRoot.getFolder(sourcePath);
        case IResource.FILE:
            return wsRoot.getFile(sourcePath);
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IResource(org.eclipse.core.resources.IResource)

Example 9 with IWorkspaceRoot

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

the class Activator method updateProjectConnections.

private void updateProjectConnections() throws CoreException {
    String[] projects = getConnectedProjectPreferences();
    for (String projectName : projects) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(projectName);
        if (project.exists()) {
            if (!project.isOpen()) {
                project.open(null);
            }
            Repository repository = org.eclipse.flux.core.Activator.getDefault().getRepository();
            repository.addProject(project);
        }
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject)

Example 10 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot 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)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)92 IPath (org.eclipse.core.runtime.IPath)41 IProject (org.eclipse.core.resources.IProject)31 IFile (org.eclipse.core.resources.IFile)30 IResource (org.eclipse.core.resources.IResource)29 CoreException (org.eclipse.core.runtime.CoreException)25 File (java.io.File)19 IWorkspace (org.eclipse.core.resources.IWorkspace)15 Path (org.eclipse.core.runtime.Path)14 IFolder (org.eclipse.core.resources.IFolder)12 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 ArrayList (java.util.ArrayList)10 IContainer (org.eclipse.core.resources.IContainer)10 IOException (java.io.IOException)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 URI (java.net.URI)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IStatus (org.eclipse.core.runtime.IStatus)5 Project (aQute.bnd.build.Project)4 Workspace (aQute.bnd.build.Workspace)4