Search in sources :

Example 6 with IN4JSSourceContainer

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

the class NFARExportOperation method countSelectedResources.

private int countSelectedResources() {
    // manifest
    int result = 1;
    for (IN4JSSourceContainer container : project.getSourceContainers()) {
        int numberOfURIs = Iterators.size(container.iterator());
        // compiled variants
        numberOfURIs *= 2;
        result += numberOfURIs;
    }
    return result;
}
Also used : IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 7 with IN4JSSourceContainer

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

the class N4HeadlessCompiler method collectResources.

/**
 * Collects all resources belonging to the given project and adds them to the given resource set.
 *
 * @param markedProject
 *            the project being loaded
 * @param resourceSet
 *            the resource set to load the resources into
 * @param recorder
 *            the progress recorder
 */
private void collectResources(MarkedProject markedProject, ResourceSet resourceSet, N4ProgressStateRecorder recorder) {
    markedProject.clearResources();
    for (IN4JSSourceContainer container : markedProject.project.getSourceContainers()) {
        // Conditionally filter test resources if not desired
        if (shouldLoadSourceContainer(container)) {
            if (logger.isCreateDebugOutput()) {
                logger.debug("Collecting resources from source container " + container.getLocation());
            }
            Iterables.filter(container, uri -> shouldLoadResource(uri)).forEach(uri -> {
                Resource resource = resourceSet.createResource(uri);
                if (resource != null) {
                    if (logger.isCreateDebugOutput()) {
                        logger.debug("  Creating resource " + resource.getURI());
                    }
                    markedProject.resources.add(resource);
                    if (container.isExternal()) {
                        markedProject.externalResources.add(resource);
                    }
                    if (container.isTest()) {
                        markedProject.testResources.add(resource);
                    }
                } else {
                    recorder.markFailedCreateResource(uri);
                    logger.warn("  Could not create resource for " + uri);
                }
            });
        }
    }
}
Also used : Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) ListIterator(java.util.ListIterator) Inject(com.google.inject.Inject) FileUtils(org.eclipse.n4js.utils.io.FileUtils) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer) HashMultimap(com.google.common.collect.HashMultimap) TreeMultimap(com.google.common.collect.TreeMultimap) Optional(com.google.common.base.Optional) Map(java.util.Map) Path(java.nio.file.Path) Collections2(org.eclipse.n4js.utils.collections.Collections2) N4JSModel(org.eclipse.n4js.internal.N4JSModel) BiMap(com.google.common.collect.BiMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Set(java.util.Set) IHeadlessLogger(org.eclipse.n4js.generator.headless.logging.IHeadlessLogger) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DelegatingIAllContainerAdapter(org.eclipse.xtext.resource.containers.DelegatingIAllContainerAdapter) List(java.util.List) FileBasedWorkspace(org.eclipse.n4js.internal.FileBasedWorkspace) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceType(org.eclipse.n4js.utils.ResourceType) CheckMode(org.eclipse.xtext.validation.CheckMode) Joiner(com.google.common.base.Joiner) Iterables(com.google.common.collect.Iterables) URI(org.eclipse.emf.common.util.URI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) N4JSProject(org.eclipse.n4js.internal.N4JSProject) TreeSet(java.util.TreeSet) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) HashSet(java.util.HashSet) JavaIoFileSystemAccess(org.eclipse.xtext.generator.JavaIoFileSystemAccess) ImmutableList(com.google.common.collect.ImmutableList) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) LinkedList(java.util.LinkedList) GeneratorException(org.eclipse.n4js.generator.GeneratorException) XtextResource(org.eclipse.xtext.resource.XtextResource) Severity(org.eclipse.xtext.diagnostics.Severity) N4FilebasedWorkspaceResourceSetContainerState(org.eclipse.n4js.internal.N4FilebasedWorkspaceResourceSetContainerState) DecimalFormat(java.text.DecimalFormat) Lazy(org.eclipse.n4js.utils.Lazy) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) IOException(java.io.IOException) File(java.io.File) N4JSResource(org.eclipse.n4js.resource.N4JSResource) HashBiMap(com.google.common.collect.HashBiMap) Provider(com.google.inject.Provider) Issue(org.eclipse.xtext.validation.Issue) OrderedResourceDescriptionsData(org.eclipse.n4js.resource.OrderedResourceDescriptionsData) Collections(java.util.Collections) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 8 with IN4JSSourceContainer

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

the class N4JSModel method getN4JSSourceContainers.

public ImmutableList<? extends IN4JSSourceContainer> getN4JSSourceContainers(N4JSProject project) {
    ImmutableList.Builder<IN4JSSourceContainer> result = ImmutableList.builder();
    URI location = project.getLocation();
    ProjectDescription description = getProjectDescription(location);
    if (description != null) {
        List<SourceFragment> sourceFragments = newArrayList(from(description.getSourceFragment()));
        sourceFragments.sort((f1, fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT) -> f1.compareByFragmentType(fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT));
        for (SourceFragment sourceFragment : sourceFragments) {
            List<String> paths = sourceFragment.getPaths();
            for (String path : paths) {
                // XXX poor man's canonical path conversion. Consider headless compiler with npm projects.
                final String relativeLocation = ".".equals(path) ? "" : path;
                IN4JSSourceContainer sourceContainer = this.createProjectN4JSSourceContainer(project, sourceFragment.getSourceFragmentType(), relativeLocation);
                result.add(sourceContainer);
            }
        }
    }
    return result.build();
}
Also used : 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) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer) SourceFragment(org.eclipse.n4js.n4mf.SourceFragment)

Example 9 with IN4JSSourceContainer

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

the class N4JSModel method getSourceContainers.

public ImmutableList<IN4JSSourceContainer> getSourceContainers(N4JSArchive archive) {
    ImmutableList.Builder<IN4JSSourceContainer> result = ImmutableList.builder();
    URI location = archive.getLocation();
    ProjectDescription description = getProjectDescription(location);
    if (description != null) {
        List<SourceFragment> sourceFragments = newArrayList(from(description.getSourceFragment()));
        sourceFragments.sort((f1, fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT) -> f1.compareByFragmentType(fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT));
        for (SourceFragment sourceFragment : sourceFragments) {
            List<String> paths = sourceFragment.getPaths();
            for (String path : paths) {
                result.add(createArchiveN4JSSourceContainer(archive, sourceFragment.getSourceFragmentType(), path));
            }
        }
    }
    return result.build();
}
Also used : 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) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer) SourceFragment(org.eclipse.n4js.n4mf.SourceFragment)

Example 10 with IN4JSSourceContainer

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

the class AbstractN4JSCore method getPaths.

private List<String> getPaths(URI location, ModuleFilter moduleFilter) {
    Optional<? extends IN4JSSourceContainer> sourceContainerOpt = findN4JSSourceContainer(location);
    if (sourceContainerOpt.isPresent()) {
        IN4JSSourceContainer sourceContainer = sourceContainerOpt.get();
        IN4JSProject project = sourceContainer.getProject();
        String projectLocation = getLocationPath(project.getLocation());
        return handleWildcardsAndRelativeNavigation(projectLocation, sourceContainer.getRelativeLocation(), moduleFilter);
    }
    return new ArrayList<>();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) ArrayList(java.util.ArrayList) 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