Search in sources :

Example 21 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class ExcludePckJson_IdeTest method checkProblemMarkers.

/**
 * Checks that there is exactly one error marker in the problems view. This single marker must be from the
 * package.json of the project root folder.
 */
@Test
public void checkProblemMarkers() {
    File project = getProjectRootForImportedProject(PROJECT_NAME);
    assertTrue("Test project is not a directory.", project.isDirectory());
    Set<FileURI> urisWithIssues = getIssues().keySet();
    assertEquals(1, urisWithIssues.size());
    assertTrue(urisWithIssues.iterator().next().toString().endsWith("test-workspace/yarn-test-project/packages/ExcludePckJson/package.json"));
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) File(java.io.File) ConvertedIdeTest(org.eclipse.n4js.tests.utils.ConvertedIdeTest) Test(org.junit.Test)

Example 22 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class ConvertedIdeTest method importProject.

/**
 * Imports a project into the running JUnit test workspace. Usage:
 *
 * <pre>
 * IProject project = ProjectTestsUtils.importProject(new File(&quot;probands&quot;), &quot;TestProject&quot;, n4jsLibs);
 * </pre>
 *
 * @param probandsFolder
 *            the parent folder in which the test project is found
 * @param projectName
 *            the name of the test project, must be folder contained in probandsFolder
 * @param n4jsLibs
 *            names of N4JS libraries to install from the local <code>n4js-libs</code> top-level folder (see
 *            {@link N4jsLibsAccess#installN4jsLibs(Path, boolean, boolean, boolean, N4JSPackageName...)}).
 * @return the imported project
 * @see <a href=
 *      "http://stackoverflow.com/questions/12484128/how-do-i-import-an-eclipse-project-from-a-zip-file-programmatically">
 *      stackoverflow: from zip</a>
 */
protected File importProject(File probandsFolder, N4JSPackageName projectName, Collection<N4JSPackageName> n4jsLibs) {
    if (!testWorkspaceManager.isCreated()) {
        throw new IllegalStateException("the test workspace is not yet created");
    }
    Path projectNameAsRelativePath = projectName.getProjectNameAsRelativePath();
    File projectSourceFolder = probandsFolder.toPath().resolve(projectNameAsRelativePath).toFile();
    if (!projectSourceFolder.exists()) {
        throw new IllegalArgumentException("proband not found in " + projectSourceFolder);
    }
    File projectFolder = projectName.getLocation(getProjectLocation().toPath());
    installN4jsLibs(projectName, n4jsLibs.toArray(new N4JSPackageName[0]));
    // copy project into workspace
    // (need to do that manually to properly handle NPM scopes, because the Eclipse import functionality won't put
    // those projects into an "@myScope" subfolder)
    final List<Path> filesCopied = new ArrayList<>();
    try {
        projectFolder.mkdirs();
        FileCopier.copy(projectSourceFolder.toPath(), projectFolder.toPath(), path -> filesCopied.add(path));
    } catch (IOException e) {
        throw new WrappedException("exception while copying project into workspace", e);
    }
    // create symbolic link in node_modules folder of root project (if necessary)
    if (isYarnWorkspace()) {
        try {
            File nodeModulesFolder = getNodeModulesFolder(projectName);
            Path from = nodeModulesFolder.toPath().resolve(projectNameAsRelativePath);
            Files.createDirectories(from.getParent());
            Files.createSymbolicLink(from, projectFolder.toPath());
        } catch (IOException e) {
            throw new WrappedException("exception while creating symbolic link from node_modules folder to project folder", e);
        }
    }
    // notify LSP server
    DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(FluentIterable.from(filesCopied).transform(path -> new FileURI(path.toFile())).transform(fileURI -> new FileEvent(fileURI.toString(), FileChangeType.Created)).toList());
    languageServer.didChangeWatchedFiles(params);
    joinServerRequests();
    return projectFolder;
}
Also used : Path(java.nio.file.Path) 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) WrappedException(org.eclipse.emf.common.util.WrappedException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileEvent(org.eclipse.lsp4j.FileEvent) FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) File(java.io.File) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams)

Example 23 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class ConvertedIdeTest method assertDuplicateModuleIssue.

/**
 * Asserts that the file denoted by the given {@link FileURI} contains an issue of code
 * {@link IssueCodes#CLF_DUP_MODULE CLF_DUP_MODULE}.
 */
protected void assertDuplicateModuleIssue(FileURI fileURI, String duplicateProjectName, String duplicateModulePathAndNameWithExt) {
    Multimap<FileURI, Diagnostic> issues = getIssues();
    Collection<Diagnostic> issuesInFile = issues.get(fileURI);
    for (Diagnostic d : issuesInFile) {
        String msg = d.getMessage();
        boolean isDuplicateModuleIssue = msg.startsWith("A duplicate module C is also defined in ") && msg.endsWith(duplicateProjectName + "/" + duplicateModulePathAndNameWithExt + ".");
        if (isDuplicateModuleIssue) {
            // success!
            return;
        }
    }
    Assert.fail("expected duplicate module issue not found in module: " + fileURI);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 24 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class SpecInfosByName method computeRRP.

private RepoRelativePath computeRRP(FullMemberReference ref, TMember testMember) {
    Resource resource = testMember.eResource();
    IScope scope = globalScopeProvider.getScope(resource, N4JSPackage.Literals.IMPORT_DECLARATION__MODULE);
    QualifiedName qn = QualifiedName.create(ref.getModuleName().split("/"));
    IEObjectDescription eod = scope.getSingleElement(qn);
    if (eod != null) {
        FileURI uri = new FileURI(eod.getEObjectURI());
        RepoRelativePath rrp = RepoRelativePath.compute(uri, workspaceAccess, resource);
        return rrp;
    } else {
        issueAcceptor.addWarning("Cannot resolve testee " + ref, testMember);
        return null;
    }
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 25 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class N4JSLanguageHelper method isDirectoryWithPackageJson.

private boolean isDirectoryWithPackageJson(IResourceDescriptions index, TModule targetModule, QualifiedName targetQN) {
    // NOTE: the following approach would be a more elegant implementation of this method, but would require a
    // different computation of FQNs for package.json files in source folders (in N4JSQualifiedNameProvider):
    // @formatter:off
    // Iterable<IEObjectDescription> matchingPackageJsonDesc = index.getExportedObjects(
    // JSONPackage.Literals.JSON_DOCUMENT,
    // targetQN.append(N4JSQualifiedNameProvider.PACKAGE_JSON_SEGMENT), false);
    // if (matchingPackageJsonDesc.iterator().hasNext()) {
    // return true;
    // }
    // @formatter:on
    N4JSProjectConfigSnapshot targetProject = replaceDefinitionProjectByDefinedProject(targetModule, workspaceAccess.findProjectContaining(targetModule), true);
    if (targetProject == null) {
        return false;
    }
    int segCount = targetQN.getSegments().size();
    String[] segments = new String[segCount + 1];
    for (int i = 0; i < segCount; i++) {
        segments[i] = targetQN.getSegments().get(i);
    }
    segments[segCount] = N4JSGlobals.PACKAGE_JSON;
    for (N4JSSourceFolderSnapshot srcFolder : targetProject.getSourceFolders()) {
        if (srcFolder instanceof N4JSSourceFolderSnapshotForPackageJson) {
            continue;
        }
        FileURI packageJsonURI = srcFolder.getPathAsFileURI().appendSegments(segments);
        if (index.getResourceDescription(packageJsonURI.toURI()) != null) {
            return true;
        }
    }
    return false;
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSSourceFolderSnapshotForPackageJson(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)

Aggregations

FileURI (org.eclipse.n4js.workspace.locations.FileURI)49 List (java.util.List)13 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Position (org.eclipse.lsp4j.Position)9 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)9 IOException (java.io.IOException)7 CompletionList (org.eclipse.lsp4j.CompletionList)7 Collections (java.util.Collections)6 Range (org.eclipse.lsp4j.Range)6 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Files (java.nio.file.Files)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 URI (org.eclipse.emf.common.util.URI)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)5 Diagnostic (org.eclipse.lsp4j.Diagnostic)5