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);
}
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());
}
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());
}
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);
}
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));
}
}
}
}
}
Aggregations