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
}
}
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;
}
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);
}
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;
}
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();
}
Aggregations