Search in sources :

Example 16 with N4JSProjectConfigSnapshot

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();
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)

Example 17 with N4JSProjectConfigSnapshot

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;
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)

Example 18 with N4JSProjectConfigSnapshot

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);
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 19 with N4JSProjectConfigSnapshot

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);
}
Also used : BuildOrderInfo(org.eclipse.n4js.xtext.workspace.BuildOrderInfo) N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI) ProjectSet(org.eclipse.n4js.xtext.workspace.ProjectSet)

Example 20 with N4JSProjectConfigSnapshot

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());
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

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