Search in sources :

Example 6 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class N4JSModel method getDependencies.

private ImmutableList<? extends IN4JSProject> getDependencies(N4JSProject project, boolean includeApis) {
    ImmutableList.Builder<IN4JSProject> result = ImmutableList.builder();
    URI location = project.getLocation();
    ProjectDescription description = getProjectDescription(location);
    if (description != null) {
        result.addAll(resolveProjectReferences(project, description.getAllRequiredRuntimeLibraries()));
        result.addAll(resolveProjectReferences(project, description.getAllProjectDependencies()));
        result.addAll(getTestedProjects(project));
        if (includeApis) {
            result.addAll(resolveProjectReferences(project, description.getImplementedProjects()));
        }
    }
    return result.build();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) ImmutableList(com.google.common.collect.ImmutableList) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) SimpleProjectDescription(org.eclipse.n4js.n4mf.SimpleProjectDescription)

Example 7 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class N4JSModel method getExtendedRuntimeEnvironment.

public Optional<IN4JSProject> getExtendedRuntimeEnvironment(N4JSProject project) {
    final URI location = project.getLocation();
    final ProjectDescription description = getProjectDescription(location);
    if (null == description) {
        return absent();
    }
    final ExtendedRuntimeEnvironment re = description.getExtendedRuntimeEnvironment();
    if (null == re) {
        return absent();
    }
    final ProjectReference ref = re.getExtendedRuntimeEnvironment();
    return resolveProjectReference(project, ref);
}
Also used : ExtendedRuntimeEnvironment(org.eclipse.n4js.n4mf.ExtendedRuntimeEnvironment) ProjectReference(org.eclipse.n4js.n4mf.ProjectReference) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) SimpleProjectDescription(org.eclipse.n4js.n4mf.SimpleProjectDescription)

Example 8 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class FileBasedExternalPackageManager method loadManifest.

@Override
public ProjectDescription loadManifest(URI manifest) {
    ResourceSet resourceSet = resourceSetProvider.get();
    Resource resource = null;
    try {
        // in case the manifest does not exist, a (wrapped) FileNotFound is thrown
        resource = resourceSet.getResource(manifest, true);
    } catch (RuntimeException e) {
        return null;
    }
    List<EObject> contents = resource.getContents();
    if (contents.isEmpty() || !(contents.get(0) instanceof ProjectDescription)) {
        return null;
    }
    // do some error handling:
    if (!resource.getErrors().isEmpty()) {
        throw new N4JSBrokenProjectException("Reading project description from " + manifest + " raised the following errors: " + Joiner.on('\n').join(resource.getErrors().stream().map(error -> error.getMessage() + " at line " + error.getLine()).iterator()));
    }
    ProjectDescription result = (ProjectDescription) contents.get(0);
    contents.clear();
    return result;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription)

Example 9 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class ExternalProjectProvider method getProjectsDescriptions.

Collection<ProjectDescription> getProjectsDescriptions(java.net.URI rootLocation) {
    ensureInitialized();
    File rootFolder = new File(rootLocation);
    Set<ProjectDescription> projectsMapping = newHashSet();
    URI rootUri = URI.createFileURI(rootFolder.getAbsolutePath());
    for (Entry<URI, Optional<Pair<N4JSExternalProject, ProjectDescription>>> entry : projectCache.asMap().entrySet()) {
        URI projectLocation = entry.getKey();
        if (rootUri.equals(projectLocation.trimSegments(1))) {
            Pair<N4JSExternalProject, ProjectDescription> pair = entry.getValue().orNull();
            if (null != pair && null != pair.getFirst()) {
                ProjectDescription description = pair.getSecond();
                if (description != null) {
                    projectsMapping.add(description);
                }
            }
        }
    }
    return unmodifiableCollection(projectsMapping);
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) Optional(com.google.common.base.Optional) File(java.io.File) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) URI(org.eclipse.emf.common.util.URI)

Example 10 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class ExternalProjectProvider method getProjectsIn.

Collection<N4JSExternalProject> getProjectsIn(java.net.URI rootLocation) {
    ensureInitialized();
    File rootFolder = new File(rootLocation);
    Map<String, N4JSExternalProject> projectsMapping = newTreeMap();
    URI rootUri = URI.createFileURI(rootFolder.getAbsolutePath());
    for (Entry<URI, Optional<Pair<N4JSExternalProject, ProjectDescription>>> entry : projectCache.asMap().entrySet()) {
        URI projectLocation = entry.getKey();
        if (rootUri.equals(projectLocation.trimSegments(1))) {
            Pair<N4JSExternalProject, ProjectDescription> pair = entry.getValue().orNull();
            if (null != pair && null != pair.getFirst()) {
                N4JSExternalProject project = pair.getFirst();
                projectsMapping.put(project.getName(), project);
            }
        }
    }
    return unmodifiableCollection(projectsMapping.values());
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) Optional(com.google.common.base.Optional) File(java.io.File) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription)

Aggregations

ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)37 URI (org.eclipse.emf.common.util.URI)19 SimpleProjectDescription (org.eclipse.n4js.n4mf.SimpleProjectDescription)11 Test (org.junit.Test)9 ImmutableList (com.google.common.collect.ImmutableList)7 File (java.io.File)6 EObject (org.eclipse.emf.ecore.EObject)6 ProjectDependency (org.eclipse.n4js.n4mf.ProjectDependency)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 SourceFragment (org.eclipse.n4js.n4mf.SourceFragment)5 N4JSExternalProject (org.eclipse.n4js.external.N4JSExternalProject)4 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)4 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 ExtendedRuntimeEnvironment (org.eclipse.n4js.n4mf.ExtendedRuntimeEnvironment)3 ProjectReference (org.eclipse.n4js.n4mf.ProjectReference)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 Optional (com.google.common.base.Optional)2 IResource (org.eclipse.core.resources.IResource)2