Search in sources :

Example 1 with TestWorkspaceManager

use of org.eclipse.n4js.ide.tests.helper.server.TestWorkspaceManager in project n4js by eclipse.

the class ConvertedIdeTest method importProband.

/**
 * Creates an empty yarn workspace project with
 * {@link TestWorkspaceManager#createTestOnDisk(org.eclipse.xtext.xbase.lib.Pair...) the test workspace manager},
 * starts the LSP server, and then imports all projects in the given proband folder. Each sub-folder of the given
 * proband folder is assumed to be a project and will be imported.
 */
protected List<N4JSPackageName> importProband(File probandFolder, Collection<N4JSPackageName> n4jsLibs) {
    if (testWorkspaceManager.isCreated()) {
        throw new IllegalStateException("the test workspace has already been created");
    }
    // this will create an empty yarn workspace
    testWorkspaceManager.createTestOnDisk();
    startAndWaitForLspServer();
    // import the projects
    final List<N4JSPackageName> importedProjects = new ArrayList<>();
    boolean needToCopyLibs = true;
    for (final File child : probandFolder.listFiles()) {
        if (child.isDirectory()) {
            if (child.getName().startsWith(ProjectDescriptionUtils.NPM_SCOPE_PREFIX)) {
                for (final File grandChild : child.listFiles()) {
                    if (grandChild.isDirectory()) {
                        final N4JSPackageName name = new N4JSPackageName(child.getName(), grandChild.getName());
                        importProject(probandFolder, name, needToCopyLibs ? n4jsLibs : Collections.emptyList());
                        importedProjects.add(name);
                        needToCopyLibs = false;
                    }
                }
            } else {
                final N4JSPackageName name = new N4JSPackageName(child.getName());
                importProject(probandFolder, name, needToCopyLibs ? n4jsLibs : Collections.emptyList());
                importedProjects.add(name);
                needToCopyLibs = false;
            }
        }
    }
    cleanBuildAndWait();
    // ensure that all projects have been imported properly
    final Set<String> expectedProjects = importedProjects.stream().map(pn -> "yarn-test-project/packages/" + pn.getRawName()).collect(Collectors.toSet());
    final Set<String> actualProjects = concurrentIndex.entries().stream().map(Entry::getKey).collect(Collectors.toSet());
    final Set<String> missingProjects = new HashSet<>(Sets.difference(expectedProjects, actualProjects));
    Assert.assertTrue("some projects were not correctly imported: " + missingProjects, missingProjects.isEmpty());
    return importedProjects;
}
Also used : UserDataMapper(org.eclipse.n4js.resource.UserDataMapper) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) IssueCodes(org.eclipse.n4js.validation.IssueCodes) CliTools(org.eclipse.n4js.cli.helper.CliTools) FileTime(java.nio.file.attribute.FileTime) AbstractIdeTest(org.eclipse.n4js.ide.tests.helper.server.AbstractIdeTest) Diagnostic(org.eclipse.lsp4j.Diagnostic) Multimap(com.google.common.collect.Multimap) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) TestWorkspaceManager(org.eclipse.n4js.ide.tests.helper.server.TestWorkspaceManager) URIUtils(org.eclipse.n4js.utils.URIUtils) ArrayList(java.util.ArrayList) FileEvent(org.eclipse.lsp4j.FileEvent) HashSet(java.util.HashSet) FileChangeType(org.eclipse.lsp4j.FileChangeType) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) FluentIterable(com.google.common.collect.FluentIterable) Optional(com.google.common.base.Optional) Path(java.nio.file.Path) ProjectDescriptionUtils(org.eclipse.n4js.utils.ProjectDescriptionUtils) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Files(java.nio.file.Files) FileCopier(org.eclipse.n4js.utils.io.FileCopier) Collection(java.util.Collection) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) Set(java.util.Set) IOException(java.io.IOException) WrappedException(org.eclipse.emf.common.util.WrappedException) Collectors(java.util.stream.Collectors) File(java.io.File) Sets(com.google.common.collect.Sets) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject) ConcurrentIndex(org.eclipse.n4js.xtext.ide.server.build.ConcurrentIndex) List(java.util.List) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) N4jsLibsAccess(org.eclipse.n4js.cli.helper.N4jsLibsAccess) TypesPackage(org.eclipse.n4js.ts.types.TypesPackage) Entry(java.util.Map.Entry) Assert(org.junit.Assert) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) ArrayList(java.util.ArrayList) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

Optional (com.google.common.base.Optional)1 FluentIterable (com.google.common.collect.FluentIterable)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 FileTime (java.nio.file.attribute.FileTime)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 DidChangeWatchedFilesParams (org.eclipse.lsp4j.DidChangeWatchedFilesParams)1