use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class TestDiscoveryHelper method collectTestLocations.
/**
* Low-level method to collect all test modules, i.e. N4JS files containing classes containing at least one method
* annotated with @Test, as {@link IResourceDescription}s.
*/
private Stream<URI> collectTestLocations(N4JSWorkspaceConfigSnapshot ws, final IResourceDescriptions index, final ResourceSet resSet, URI location) {
if (null == location) {
return Stream.empty();
}
// does location point to an N4JS project?
if (isProject(ws, location)) {
// yes
// --> collect all test modules (files containing test classes) located in source containers of type "test"
final N4JSProjectConfigSnapshot p = ws.findProjectByPath(location);
return p.getSourceFolders().stream().filter(N4JSSourceFolderSnapshot::isTest).map(N4JSSourceFolderSnapshot::getContents).flatMap(TestDiscoveryHelper::stream).filter(uri -> isTestFile(uri) && isTestModule(resSet, index.getResourceDescription(uri)));
}
// does location point to an n4js file?
final IResourceDescription resDesc = index.getResourceDescription(location.trimFragment());
if (resDesc != null) {
// yes --> is it a test module? (i.e. does it contain test classes and the class is not abstract?)
if (isTestModule(resSet, resDesc)) {
// yes --> is it contained in a source container of type "test"?
final N4JSSourceFolderSnapshot srcContainer = ws.findSourceFolderContaining(location.trimFragment());
if (srcContainer != null && srcContainer.isTest()) {
// return location with fragment! (if any)
return Stream.of(location);
}
}
return Stream.empty();
}
// does location point to a source container (or sub-folder)?
final N4JSSourceFolderSnapshot srcContainer = ws.findSourceFolderContaining(location);
if (srcContainer != null) {
// yes --> is this a source container of type "test"?
if (srcContainer.isTest()) {
// yes --> collect all test modules (files containing test classes) in this source container
final String locationStr = location.toString();
return stream(srcContainer.getContents()).filter(uri -> uri.toString().startsWith(locationStr) && isTestModule(resSet, index.getResourceDescription(uri)));
}
return Stream.empty();
}
// invalid location URI
return Stream.empty();
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class TestDiscoveryHelper method getTestCatalogNameFor.
/**
* Returns the name to be used in the test catalog for the given {@link TClass}. We use the fully qualified name for
* this purpose.
*/
private String getTestCatalogNameFor(N4JSWorkspaceConfigSnapshot ws, TClass clazz) {
String classStr = "";
classStr = resourceNameComputer.getFullyQualifiedTypeName(clazz);
N4JSProjectConfigSnapshot project = ws.findProjectContaining(clazz.eResource().getURI());
if (project != null) {
String output = project.getOutputPath();
if (Strings.isNullOrEmpty(output) == false && output != ".") {
if (output.endsWith("/")) {
classStr = output + classStr;
} else {
classStr = output + "/" + classStr;
}
}
}
return classStr;
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class AbstractPackageJSONValidatorExtension method isResponsible.
@Override
protected boolean isResponsible(Map<Object, Object> context, EObject eObject) {
if (eObject.eClass().getEPackage() != JSONPackage.eINSTANCE) {
return false;
}
// this validator extension only applies to package.json files located in the root of a project
Resource resource = eObject.eResource();
URI pckjsonUri = resource.getURI();
String fileName = fileExtensionCalculator.getFilenameWithoutXpectExtension(pckjsonUri);
if (!fileName.equals(N4JSGlobals.PACKAGE_JSON)) {
return false;
}
N4JSProjectConfigSnapshot project = workspaceAccess.findProjectContaining(resource);
if (project == null) {
// LOGGER.error("no containing project found for package.json URI:" + pckjsonUri);
return false;
}
URI expectedLocation = project.getPathAsFileURI().appendSegment(N4JSGlobals.PACKAGE_JSON).toURI();
// In test Xpect scenarios (see bundle packagejson.xpect.tests) package.json files can be named package.json.xt
URI pckjsonUriWithoutXpectExtension = fileExtensionCalculator.getUriWithoutXpectExtension(pckjsonUri);
return expectedLocation.equals(pckjsonUriWithoutXpectExtension);
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class MockWorkspaceSupplier method createWorkspaceConfig.
/**
* Creates the configuration of the mocked test workspace.
* <p>
* The returned workspace configuration is expected to contain at least one project with at least one source folder
* that isn't a {@link N4JSSourceFolderSnapshotForPackageJson}. The corresponding folders and files are not expected
* to exist on disk.
* <p>
* Only invoked on demand and never more than once.
*/
protected N4JSWorkspaceConfigSnapshot createWorkspaceConfig() {
N4JSProjectConfigSnapshot projectConfig = createProjectConfig();
URI workspacePath = URIUtils.trimTrailingPathSeparator(projectConfig.getPath()).trimSegments(1);
ProjectSet projects = new ProjectSet(Collections.singleton(projectConfig));
BuildOrderInfo buildOrderInfo = new BuildOrderInfo(Collections.emptyList(), Collections.emptySet());
return new N4JSWorkspaceConfigSnapshot(workspacePath, projects, buildOrderInfo);
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class MockWorkspaceSupplier method createProjectConfig.
/**
* See {@link #createWorkspaceConfig()}.
*/
protected N4JSProjectConfigSnapshot createProjectConfig() {
// try to load a test package.json from disk, otherwise create a project configuration from default values
Pair<FileURI, ProjectDescription> loadedOrCreated = loadProjectDescription().or(this::createProjectDescription);
FileURI projectPath = loadedOrCreated.getKey();
ProjectDescription pd = loadedOrCreated.getValue();
List<N4JSSourceFolderSnapshot> sourceFolders = createSourceFolders(projectPath, pd);
return new N4JSProjectConfigSnapshot(pd, projectPath.withTrailingPathDelimiter().toURI(), false, true, Collections.emptyList(), sourceFolders, Map.of());
}
Aggregations