use of org.eclipse.n4js.cli.helper.N4jsLibsAccess 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("probands"), "TestProject", 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;
}
Aggregations