Search in sources :

Example 6 with ExternalProject

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

the class ProjectDescriptionLoadListener method updateProjectReferencesIfNecessary.

/**
 * We have to set dynamic dependencies in the project meta data to ensure that the builder is correctly triggered
 * according to the declared dependencies in the N4JS manifest files.
 *
 * @param project
 *            the project to update in respect of its dynamic references.
 */
public void updateProjectReferencesIfNecessary(final IProject project) {
    if (project instanceof ExternalProject) {
        // No need to adjust any dynamic references.
        return;
    }
    try {
        IProject[] eclipseRequired = project.getDescription().getDynamicReferences();
        Set<IProject> currentRequires = Sets.newHashSet(eclipseRequired);
        final Set<IProject> newRequires = getProjectDependenciesAsSet(project);
        if (currentRequires.equals(newRequires)) {
            return;
        }
        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                IProjectDescription description = project.getDescription();
                IProject[] array = newRequires.toArray(new IProject[newRequires.size()]);
                description.setDynamicReferences(array);
                project.setDescription(description, IResource.AVOID_NATURE_CONFIG, monitor);
            }
        };
        internalWorkspace.getWorkspace().getWorkspace().run(runnable, null, /* cannot use a scheduling rule here since this is triggered lazily by the linker */
        IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
    // ignore
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Example 7 with ExternalProject

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

the class EclipseExternalLibraryWorkspace method getLocation.

@Override
public URI getLocation(URI projectURI, ProjectReference reference, N4JSSourceContainerType expectedN4JSSourceContainerType) {
    if (PROJECT.equals(expectedN4JSSourceContainerType)) {
        String name = reference.getProject().getProjectId();
        ExternalProject project = projectProvider.getProject(name);
        if (null == project) {
            return null;
        }
        File referencedProject = new File(project.getLocationURI());
        URI refLocation = URI.createFileURI(referencedProject.getAbsolutePath());
        Pair<N4JSExternalProject, ProjectDescription> pair = projectProvider.getProjectWithDescription(refLocation);
        if (null != pair) {
            return refLocation;
        }
    }
    return null;
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription)

Example 8 with ExternalProject

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

the class NpmManager method getAllNpmProjectsMapping.

/**
 * A map of project (npm package) names to project location mappings.
 */
private Map<String, URI> getAllNpmProjectsMapping() {
    final URI nodeModulesLocation = locationProvider.getTargetPlatformNodeModulesLocation();
    final Map<String, URI> mappings = newHashMap();
    // Intentionally might include projects that are already in the workspace
    for (final IProject project : externalLibraryWorkspace.getProjectsIn(nodeModulesLocation)) {
        if (project.isAccessible() && project instanceof ExternalProject) {
            final URI location = ((ExternalProject) project).getExternalResource().toURI();
            mappings.put(project.getName(), location);
        }
    }
    return ImmutableMap.copyOf(mappings);
}
Also used : ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject)

Example 9 with ExternalProject

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

the class EclipseExternalLibraryWorkspace method getResource.

@Override
public IResource getResource(URI location) {
    String path = location.toFileString();
    if (null == path) {
        return null;
    }
    File nestedResource = new File(path);
    if (nestedResource.exists()) {
        URI projectLocation = findProjectWith(location);
        if (null != projectLocation) {
            String projectName = projectLocation.lastSegment();
            IProject project = getProject(projectName);
            if (project instanceof ExternalProject) {
                File projectResource = new File(project.getLocationURI());
                if (projectResource.exists() && projectResource.isDirectory()) {
                    Path projectPath = projectResource.toPath();
                    Path nestedPath = nestedResource.toPath();
                    if (projectPath.equals(nestedPath)) {
                        return project;
                    }
                    // TODO: project.getFile and project.getFolder don't check whether then given path is a file or
                    // a folder, and they should not?
                    Path relativePath = projectPath.relativize(nestedPath);
                    IFile file = project.getFile(relativePath.toString());
                    if (file.exists())
                        return file;
                    IFolder folder = project.getFolder(relativePath.toString());
                    if (folder.exists())
                        return folder;
                }
            }
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) IFile(org.eclipse.core.resources.IFile) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with ExternalProject

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

the class EclipseExternalLibraryWorkspace method getFolderIterator.

@Override
public Iterator<URI> getFolderIterator(URI folderLocation) {
    URI findProjectWith = findProjectWith(folderLocation);
    if (null != findProjectWith) {
        String projectName = findProjectWith.lastSegment();
        ExternalProject project = projectProvider.getProject(projectName);
        if (null != project) {
            String projectPath = new File(project.getLocationURI()).getAbsolutePath();
            String folderPath = folderLocation.toFileString();
            IContainer container = projectPath.equals(folderPath) ? project : project.getFolder(folderPath.substring(projectPath.length() + 1));
            Collection<URI> result = Lists.newLinkedList();
            try {
                container.accept(resource -> {
                    if (resource instanceof IFile) {
                        String path = new File(resource.getLocationURI()).getAbsolutePath();
                        result.add(URI.createFileURI(path));
                    }
                    return true;
                });
                return unmodifiableIterator(result.iterator());
            } catch (CoreException e) {
                return unmodifiableIterator(result.iterator());
            }
        }
    }
    return emptyIterator();
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IContainer(org.eclipse.core.resources.IContainer) URI(org.eclipse.emf.common.util.URI) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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