Search in sources :

Example 11 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class TestDiscoveryHelper method isTestable.

/**
 * Checks if the resource at the given location can be executed as a test. The location may point to an N4JS project
 * or a folder or file within an N4JS project.
 * <p>
 * This method is intended as a very first check to decide if the user should be given the option to launch a test
 * or not; for example, to enable or disable a "Run as test" context menu item). This method does not check all
 * details because many checks are better handled at later stages when meaningful error messages can be provided to
 * the user.
 */
public boolean isTestable(final URI location) {
    if (null == location) {
        return false;
    }
    if (isProject(location)) {
        // location points an N4JS project
        // --> must contain at least 1 source container of type "test"
        // (do *not* check if the folder contains test classes (for performance reasons and
        // to show better error messages; same behavior as in JUnit support in Eclipse))
        final IN4JSProject p = n4jsCore.create(location);
        return p.getSourceContainers().stream().anyMatch(IN4JSSourceContainer::isTest);
    } else {
        // then extract the fragment and check the location for the module.
        if (location.hasFragment()) {
            return isTestable(location.trimFragment());
        }
        // (2) location must lie in a source container of type "test"
        final IN4JSSourceContainer c = n4jsCore.findN4JSSourceContainer(location).orNull();
        if (c == null || !c.isTest())
            return false;
        // (3) if the location points to an n4js-file, it must contain at least one test class
        final ResourceSet resourceSet = n4jsCore.createResourceSet(Optional.of(c.getProject()));
        final IResourceDescriptions index = n4jsCore.getXtextIndex(resourceSet);
        final IResourceDescription rdesc = index.getResourceDescription(location);
        if (rdesc != null) {
            return stream(rdesc.getExportedObjectsByType(T_CLASS)).anyMatch(desc -> hasTestMethods(resourceSet, desc));
        } else {
            // to show better error messages; same behavior as in JUnit support in Eclipse))
            return true;
        }
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 12 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class NFARExportOperation method exportResources.

private void exportResources() throws InterruptedException {
    boolean hasCompiledFiles = true;
    for (IN4JSSourceContainer sourceContainer : project.getSourceContainers()) {
        Iterator<URI> iterator = sourceContainer.iterator();
        while (iterator.hasNext()) {
            exportResource(iterator.next(), hasCompiledFiles);
        }
    }
    exportResource(project.getLocation().appendSegment(IN4JSProject.N4MF_MANIFEST), false);
}
Also used : URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 13 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class N4JSProjectsStateHelper method initVisibleHandles.

public List<String> initVisibleHandles(String handle) {
    if (handle.startsWith(PROJECT_CONTAINER_PREFIX)) {
        // similar to source-container-prefix but we are only interested in the project/archive and
        // don't have an actual file of the source-locations.
        URI uri = URI.createURI(handle.substring(PROJECT_CONTAINER_PREFIX.length()));
        List<String> result = Lists.newArrayList();
        // Project.
        Optional<? extends IN4JSEclipseProject> containerProjectOpt = core.findProject(uri);
        if (containerProjectOpt.isPresent()) {
            fullCollectLocationHandles(result, containerProjectOpt.get());
        } else {
            // archive
            Optional<? extends IN4JSArchive> containerArchiveOpt = core.findArchive(uri);
            if (containerArchiveOpt.isPresent()) {
                // out of archive
                IN4JSArchive archive = containerArchiveOpt.get();
                fullCollectLocationHandles(result, archive);
            } else {
                // Nothing found.
                return Collections.emptyList();
            }
        }
        return result;
    }
    URI uri = URI.createURI(handle.substring(SOURCE_CONTAINER_PREFIX.length()));
    Optional<? extends IN4JSSourceContainer> containerOpt = core.findN4JSSourceContainer(uri);
    List<String> result = Lists.newArrayList();
    if (containerOpt.isPresent()) {
        IN4JSSourceContainer container = containerOpt.get();
        if (container.isLibrary()) {
            IN4JSArchive archive = container.getLibrary();
            fullCollectLocationHandles(result, archive);
        } else {
            IN4JSProject project = container.getProject();
            fullCollectLocationHandles(result, project);
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IN4JSArchive(org.eclipse.n4js.projectModel.IN4JSArchive) URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 14 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class ProjectCompareHelper method createEntries.

// may be made public later
private ProjectComparisonEntry createEntries(ProjectComparison root, IN4JSProject api, IN4JSProject[] impls, ResourceSet resourceSet, IResourceDescriptions index) {
    final ProjectComparisonEntry entry = new ProjectComparisonEntry(root, api, impls);
    for (IN4JSSourceContainer currSrcConti : api.getSourceContainers()) {
        for (URI uri : currSrcConti) {
            final String uriStr = uri.toString();
            if (uriStr.endsWith("." + N4JSGlobals.N4JS_FILE_EXTENSION) || uriStr.endsWith("." + N4JSGlobals.N4JSD_FILE_EXTENSION)) {
                final IResourceDescription resDesc = index.getResourceDescription(uri);
                final TModule moduleApi = getModuleFrom(resourceSet, resDesc);
                if (moduleApi != null) {
                    final TModule[] moduleImpls = new TModule[impls.length];
                    for (int idx = 0; idx < impls.length; idx++) {
                        final IN4JSProject projectImpl = impls[idx];
                        if (projectImpl != null)
                            moduleImpls[idx] = findImplementation(moduleApi, projectImpl, resourceSet, index);
                        else
                            moduleImpls[idx] = null;
                    }
                    createEntries(entry, -1, moduleApi, moduleImpls, false);
                }
            }
        }
    }
    return entry;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 15 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class N4HeadlessCompiler method configureResourceSetContainerState.

private void configureResourceSetContainerState(final List<N4JSProject> allProjects) {
    // a container is a project.
    List<String> containers = new LinkedList<>();
    BiMap<String, N4JSProject> container2project = HashBiMap.create();
    // the URIs of all resources directly contained in a project/container.
    Multimap<String, URI> container2Uris = HashMultimap.create();
    for (N4JSProject project : allProjects) {
        String container = FileBasedWorkspace.N4FBPRJ + project.getLocation();
        container2project.put(container, project);
        containers.add(container);
        for (IN4JSSourceContainer sourceContainer : project.getSourceContainers()) {
            Iterables.addAll(container2Uris.get(container), sourceContainer);
        }
    }
    // Define the Mapping of Resources (URIs to Container === Projects),
    rsbAcs.configure(containers, container2Uris);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) N4JSProject(org.eclipse.n4js.internal.N4JSProject) URI(org.eclipse.emf.common.util.URI) LinkedList(java.util.LinkedList) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Aggregations

IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)18 URI (org.eclipse.emf.common.util.URI)15 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)9 N4JSResource (org.eclipse.n4js.resource.N4JSResource)5 LinkedList (java.util.LinkedList)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 ImmutableList (com.google.common.collect.ImmutableList)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 Optional (com.google.common.base.Optional)2 HashMultimap (com.google.common.collect.HashMultimap)2 Inject (com.google.inject.Inject)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Script (org.eclipse.n4js.n4JS.Script)2 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)2