Search in sources :

Example 1 with ProjectReference

use of org.eclipse.n4js.packagejson.projectDescription.ProjectReference in project n4js by eclipse.

the class DtsAfterBuildListener method createLibValue.

private String createLibValue() {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    sb.append("\"es2019\", \"es2020\"");
    for (ProjectReference requiredLibRef : projectConfig.getProjectDescription().getRequiredRuntimeLibraries()) {
        N4JSPackageName requiredLibName = requiredLibRef.getN4JSProjectName();
        ImmutableSet<String> dtsLibNames = N4JSGlobals.N4JS_DTS_LIB_CORRESPONDENCE.get(requiredLibName);
        for (String dtsLibName : dtsLibNames) {
            sb.append(", \"");
            sb.append(dtsLibName);
            sb.append('"');
        }
    }
    sb.append("]");
    return sb.toString();
}
Also used : ProjectReference(org.eclipse.n4js.packagejson.projectDescription.ProjectReference) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName)

Example 2 with ProjectReference

use of org.eclipse.n4js.packagejson.projectDescription.ProjectReference in project n4js by eclipse.

the class ProjectCompareHelper method compareModules.

/**
 * Get the comparison for a module in a specific implementation specified by it's ID.
 *
 * @param module
 *            can be either Implementation or API
 * @param implementationID
 *            the current implementation to compare with
 *
 * @param includePolyfills
 *            {@code true} if polyfills should be considered as the part of the API and the implementation.
 *            Otherwise {@code false}.
 * @return a comparison between API and implementation with implementationID, or <code>null</code> if no project
 *         could be found, the module is not part of an API/IMPL ...
 */
public ProjectComparisonEntry compareModules(TModule module, N4JSPackageName implementationID, final boolean includePolyfills) {
    Resource resource = module.eResource();
    N4JSWorkspaceConfigSnapshot wc = workspaceAccess.getWorkspaceConfig(resource);
    N4JSProjectConfigSnapshot project = workspaceAccess.findProjectContaining(resource);
    if (project == null) {
        return null;
    }
    N4JSProjectConfigSnapshot implProject = null;
    N4JSProjectConfigSnapshot apiProject = null;
    TModule apiModule = null;
    TModule apiImplModule = null;
    if (project.getImplementationId() == null) {
        // this is NOT an implementation project, so assume we have the api
        // need to load the correct implementation. Since there might be multiple implementors
        ApiImplMapping mapping = ApiImplMapping.of(wc);
        implProject = mapping.getImpl(project.getN4JSPackageName(), implementationID);
        if (implProject == null) {
            // no implementation found.
            return null;
        }
        apiProject = project;
        apiModule = module;
        URI impUri = artifactHelper.findArtifact(implProject, apiModule.getQualifiedName(), Optional.of(N4JSGlobals.N4JS_FILE_EXTENSION));
        if (impUri != null) {
            IResourceDescriptions xtextIndex = workspaceAccess.getXtextIndex(module).orNull();
            IResourceDescription resourceDescription = xtextIndex != null ? xtextIndex.getResourceDescription(impUri) : null;
            if (resourceDescription != null) {
                apiImplModule = workspaceAccess.loadModuleFromIndex(module.eResource().getResourceSet(), resourceDescription, false);
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("...ouch nothing in index for " + impUri);
                }
                Resource implResource = module.eResource().getResourceSet().getResource(impUri, true);
                apiImplModule = (TModule) implResource.getContents().get(1);
                // .get(1);
                if (logger.isDebugEnabled()) {
                    logger.debug("TModule loaded from Resource: " + apiImplModule);
                }
            }
        } else {
            // No implementation present.
            if (logger.isDebugEnabled()) {
                logger.debug("No implementation given. For " + apiModule.getQualifiedName());
            }
        }
    } else {
        // check that the implementation ID matches.
        if (implementationID.equals(new N4JSPackageName(project.getImplementationId()))) {
            implProject = project;
            apiImplModule = module;
            List<N4JSProjectConfigSnapshot> apiProjects = new ArrayList<>();
            for (ProjectReference apiProjectRef : implProject.getProjectDescription().getImplementedProjects()) {
                N4JSProjectConfigSnapshot currApiProject = wc.findProjectByID(apiProjectRef.getPackageName());
                if (currApiProject != null) {
                    apiProjects.add(currApiProject);
                }
            }
            labelA: for (N4JSProjectConfigSnapshot ap : apiProjects) {
                URI apiURI = artifactHelper.findArtifact(ap, apiImplModule.getQualifiedName(), Optional.of(N4JSGlobals.N4JSD_FILE_EXTENSION));
                if (apiURI != null) {
                    IResourceDescriptions xtextIndex = workspaceAccess.getXtextIndex(apiImplModule).orNull();
                    IResourceDescription resourceDescription = xtextIndex.getResourceDescription(apiURI);
                    if (resourceDescription != null) {
                        apiModule = workspaceAccess.loadModuleFromIndex(apiImplModule.eResource().getResourceSet(), resourceDescription, false);
                        if (apiModule != null)
                            break labelA;
                    }
                }
            }
        } else {
            return null;
        }
    }
    if (apiModule != null) {
        return compareModules(apiProject, apiModule, implProject, apiImplModule, includePolyfills);
    } else {
        // no apiModule --> this is not an implementation of API.
        return null;
    }
}
Also used : ProjectReference(org.eclipse.n4js.packagejson.projectDescription.ProjectReference) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI)

Aggregations

ProjectReference (org.eclipse.n4js.packagejson.projectDescription.ProjectReference)2 N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)2 ArrayList (java.util.ArrayList)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 TModule (org.eclipse.n4js.ts.types.TModule)1 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)1 N4JSWorkspaceConfigSnapshot (org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1