Search in sources :

Example 21 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.

the class ProjectSetTest method testRemoveAndRecreate.

/**
 * Tests the special cases described in {@link ProjectSet#update(Iterable, Iterable)}.
 */
@Test
public void testRemoveAndRecreate() {
    String projectName = "TestProject";
    URI rootA = URI.createFileURI("///some/folder");
    URI rootB = URI.createFileURI("///another/folder");
    N4JSProjectConfigSnapshot projectBelowRootA = createProjectConfig(rootA.appendSegment(projectName));
    N4JSProjectConfigSnapshot projectBelowRootB = createProjectConfig(rootB.appendSegment(projectName));
    ProjectSet set1 = new ProjectSet(Collections.singleton(projectBelowRootA));
    ProjectSet set2 = set1.update(Collections.singleton(projectBelowRootB), Collections.singleton(projectName));
    assertEquals(1, set2.size());
    ProjectConfigSnapshot projectInSet2 = IterableExtensions.head(set2.getProjects());
    assertEquals(rootB.appendSegment(projectName), projectInSet2.getPath());
    assertEquals(projectBelowRootB, projectInSet2);
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) URI(org.eclipse.emf.common.util.URI) ProjectSet(org.eclipse.n4js.xtext.workspace.ProjectSet) Test(org.junit.Test)

Example 22 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.

the class ProjectSetTest method createProjectConfig.

private N4JSProjectConfigSnapshot createProjectConfig(URI path) {
    String name = ProjectDescriptionUtils.deriveN4JSPackageNameFromURI(path);
    ProjectDescription pd = ProjectDescription.builder().setPackageName(name).setType(ProjectType.LIBRARY).setVersion(SemverUtils.createVersionNumber(0, 0, 1)).build();
    N4JSSourceFolderSnapshot srcFolder = new N4JSSourceFolderSnapshot("src", path.appendSegment("src"), SourceContainerType.SOURCE, "src");
    return new N4JSProjectConfigSnapshot(pd, path, false, true, Collections.emptyList(), Collections.singleton(srcFolder), Map.of());
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 23 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.

the class N4JSConfigSnapshotFactory method createProjectConfigSnapshot.

@Override
public N4JSProjectConfigSnapshot createProjectConfigSnapshot(XIProjectConfig projectConfig) {
    N4JSProjectConfig projectConfigCasted = (N4JSProjectConfig) projectConfig;
    List<String> semanticDependencies = Lists.transform(projectConfigCasted.getSemanticDependencies(), ProjectDependency::getPackageName);
    return new N4JSProjectConfigSnapshot(projectConfigCasted.getProjectDescription(), projectConfig.getPath(), projectConfig.indexOnly(), projectConfig.isGeneratorEnabled(), semanticDependencies, Iterables.transform(projectConfig.getSourceFolders(), this::createSourceFolderSnapshot), projectConfigCasted.getPackageNameForProjectIdMap());
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) N4JSProjectConfig(org.eclipse.n4js.workspace.N4JSProjectConfig)

Example 24 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.

the class RepoRelativePath method compute.

/**
 * Creates the RepoRelativePath from a given resource. Returns null, if resource is not contained in a repository.
 * If a repository is found, the simple name of the origin is used.
 */
public static RepoRelativePath compute(FileURI uriOfResource, WorkspaceAccess workspaceAccess, Notifier context) {
    N4JSProjectConfigSnapshot project = workspaceAccess.findProjectByNestedLocation(context, uriOfResource.toURI());
    if (project == null) {
        return null;
    }
    Path pathOfResource = uriOfResource.toFileSystemPath();
    Path pathOfProject = project.getPathAsFileURI().toFileSystemPath();
    String fileOfResourceInsideProject = pathOfProject.relativize(pathOfResource).toString();
    // strip anchor part if present, i.e. path to type within the resource
    int anchorIndex = fileOfResourceInsideProject.indexOf("#");
    if (anchorIndex >= 0)
        fileOfResourceInsideProject = fileOfResourceInsideProject.substring(0, anchorIndex);
    File absolutePathOfResource = pathOfProject.toAbsolutePath().resolve(fileOfResourceInsideProject).toFile();
    if (!absolutePathOfResource.exists()) {
        return null;
    }
    // note: for retrieving the repo relative folder name, we must not rely on single path segments as they
    // may appear more than once. E.g. "n4js" maybe the folder of the oomph installation, the simple name of the
    // repository folder and a folder representing the package n4js.
    File repoFolder = getRepoFolder(absolutePathOfResource);
    // for resolving the repo relative path,
    // we only care about the repo folder name, since the folder may be named differently
    String pathOfProjectInRepo = getRepoPath(repoFolder, pathOfProject.getParent().toFile());
    if (pathOfProjectInRepo == null) {
        return null;
    }
    String pathOfResourceInProject = '/' + fileOfResourceInsideProject;
    // ensure slashes
    if (File.separatorChar != '/') {
        pathOfResourceInProject = pathOfResourceInProject.replace(File.separatorChar, '/');
        pathOfProjectInRepo = pathOfProjectInRepo.replace(File.separatorChar, '/');
    }
    N4JSPackageName projName = project.getN4JSPackageName();
    String repoName = getRepoName(repoFolder);
    return new // repo relative
    RepoRelativePath(// repo relative
    repoName, // repo relative
    pathOfProjectInRepo, // project relative
    projName, // project relative
    pathOfResourceInProject, -1);
}
Also used : Path(java.nio.file.Path) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) File(java.io.File)

Example 25 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.

the class JSONIdeContentProposalProvider method proposeLocalPackages.

private void proposeLocalPackages(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) {
    if (!namePath.isEmpty()) {
        // somewhat poor heuristic: propose all projects that are known in the current workspace
        String last = namePath.get(namePath.size() - 1);
        if (PackageJsonProperties.DEPENDENCIES.name.equals(last) || PackageJsonProperties.DEV_DEPENDENCIES.name.equals(last)) {
            for (N4JSProjectConfigSnapshot project : workspaceAccess.findAllProjects(context.getResource())) {
                N4JSPackageName projectName = project.getN4JSPackageName();
                ContentAssistEntry entryForModule = getProposalCreator().createProposal('"' + projectName.getRawName() + '"', context, ContentAssistEntry.KIND_MODULE, null);
                if (entryForModule != null) {
                    acceptor.accept(entryForModule, getProposalPriorities().getDefaultPriority(entryForModule));
                }
            }
        }
    }
}
Also used : ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)

Aggregations

N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)50 URI (org.eclipse.emf.common.util.URI)15 N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)9 N4JSSourceFolderSnapshot (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)8 Path (java.nio.file.Path)7 Resource (org.eclipse.emf.ecore.resource.Resource)7 N4JSWorkspaceConfigSnapshot (org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot)7 FileURI (org.eclipse.n4js.workspace.locations.FileURI)7 ArrayList (java.util.ArrayList)6 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)6 File (java.io.File)5 HashMap (java.util.HashMap)5 N4JSResource (org.eclipse.n4js.resource.N4JSResource)5 LinkedHashMap (java.util.LinkedHashMap)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)4 TModule (org.eclipse.n4js.ts.types.TModule)4 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)4