Search in sources :

Example 11 with ExternalProject

use of org.eclipse.n4js.utils.resources.ExternalProject in project n4js by eclipse.

the class N4JSEclipseModel method findN4JSSourceContainer.

@Override
public Optional<? extends IN4JSSourceContainer> findN4JSSourceContainer(URI location) {
    Optional<? extends IN4JSSourceContainer> n4jsContainer = Optional.absent();
    if (!location.isArchive()) {
        if (N4Scheme.isN4Scheme(location)) {
            return n4jsContainer;
        }
        if (!location.isPlatformResource()) {
            // just do not throw exception then, but continue with null:
            if ("revision".equals(location.scheme())) {
                if (LOGGER.isDebugEnabled()) {
                    final String message = "Got revision-scheme request, but refuse to find source-container for that:" + location;
                    LOGGER.debug(message);
                }
                return n4jsContainer;
            }
            if (location.isFile()) {
                final IN4JSEclipseProject eclipseProject = findProjectWith(location);
                if (null != eclipseProject && eclipseProject.exists()) {
                    if (eclipseProject.getProject() instanceof ExternalProject) {
                        final IResource resource = externalLibraryWorkspace.getResource(location);
                        if (null != resource) {
                            n4jsContainer = getN4JSSourceContainer(resource);
                        }
                    }
                }
            }
            return n4jsContainer;
        }
        final IN4JSEclipseProject project = findProjectWith(location);
        if (null != project && project.exists()) {
            final Path path = new Path(location.toPlatformString(true));
            final IResource resource;
            if (1 == path.segmentCount()) {
                resource = workspace.getProject(path.segment(0));
            } else {
                resource = workspace.getFile(path);
            }
            n4jsContainer = getN4JSSourceContainer(resource);
        }
    } else {
        String archiveFilePath = location.authority();
        URI archiveURI = URI.createURI(archiveFilePath.substring(0, archiveFilePath.length() - 1));
        N4JSEclipseProject containingProject = findProjectWith(archiveURI);
        N4JSEclipseArchive archive = getN4JSArchive(containingProject, workspace.getFile(new Path(archiveURI.toPlatformString(true))));
        n4jsContainer = findN4JSSourceContainerInArchive(location, archive);
    }
    return n4jsContainer;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IN4JSEclipseArchive(org.eclipse.n4js.ui.projectModel.IN4JSEclipseArchive) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Aggregations

ExternalProject (org.eclipse.n4js.utils.resources.ExternalProject)11 IProject (org.eclipse.core.resources.IProject)5 File (java.io.File)4 URI (org.eclipse.emf.common.util.URI)4 N4JSExternalProject (org.eclipse.n4js.external.N4JSExternalProject)4 IFile (org.eclipse.core.resources.IFile)3 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)3 FluentIterable.from (com.google.common.collect.FluentIterable.from)2 Inject (com.google.inject.Inject)2 URI (java.net.URI)2 Collection (java.util.Collection)2 IContainer (org.eclipse.core.resources.IContainer)2 IFolder (org.eclipse.core.resources.IFolder)2 CoreException (org.eclipse.core.runtime.CoreException)2 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 Maps.uniqueIndex (com.google.common.collect.Maps.uniqueIndex)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Singleton (com.google.inject.Singleton)1