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