use of org.eclipse.n4js.packagejson.projectDescription.SourceContainerDescription in project n4js by eclipse.
the class PackageJsonUtils method asSourceContainerDescriptionOrNull.
/**
* Converts given name/value pair to a {@link SourceContainerDescription}; returns <code>null</code> if not
* possible.
* <p>
* Expected format of argument:
*
* <pre>
* "source": [
* "src1",
* "src2"
* ]
*
* // or:
*
* "external": [
* "src-ext"
* ]
* </pre>
*/
public static SourceContainerDescription asSourceContainerDescriptionOrNull(NameValuePair pair) {
SourceContainerType type = parseSourceContainerType(pair.getName());
List<String> paths = asNonEmptyStringsInArrayOrEmpty(pair.getValue());
if (type != null && !paths.isEmpty()) {
return new SourceContainerDescription(type, paths);
}
return null;
}
use of org.eclipse.n4js.packagejson.projectDescription.SourceContainerDescription in project n4js by eclipse.
the class PackageJsonHelper method applyDefaults.
/**
* Apply default values to the given project description. This should be performed right after loading and
* converting the project description from JSON.
*/
private void applyDefaults(ProjectDescriptionBuilder target, String defaultProjectName) {
if (!target.hasN4JSNature() || target.getType() == null) {
// for non-N4JS projects, and if the project type is unset, enforce the default project type, i.e.
// project type 'PLAINJS':
target.setType(parseProjectType((String) PROJECT_TYPE.defaultValue));
}
if (target.getPackageName() == null) {
target.setPackageName(defaultProjectName);
}
if (target.getVersion() == null) {
target.setVersion(createDefaultVersionNumber());
}
if (target.getVendorId() == null) {
target.setVendorId((String) VENDOR_ID.defaultValue);
}
if (target.getMainModule() == null) {
target.setMainModule((String) MAIN_MODULE.defaultValue);
}
if (target.getOutputPath() == null) {
// note that in case the project is a yarn workspace project and there is a 'clean build' running
// the entire contents will be deleted.
target.setOutputPath((String) OUTPUT.defaultValue);
}
if (target.isGeneratorEnabledSourceMaps() == null) {
target.setGeneratorEnabledSourceMaps((Boolean) GENERATOR_SOURCE_MAPS.defaultValue);
}
if (target.isGeneratorEnabledDts() == null) {
target.setGeneratorEnabledDts((Boolean) GENERATOR_DTS.defaultValue);
}
if (target.isGeneratorEnabledRewriteCjsImports() == null) {
target.setGeneratorEnabledRewriteCjsImports((Boolean) GENERATOR_REWRITE_CJS_IMPORTS.defaultValue);
}
if (target.isYarnWorkspaceRoot()) {
return;
}
List<SourceContainerDescription> sourceContainers = target.getSourceContainers();
SourceContainerDescription sourceContainerOfTypeSource = null;
for (SourceContainerDescription sourceContainer : sourceContainers) {
if (!sourceContainer.getPaths().isEmpty()) {
return;
}
if (sourceContainerOfTypeSource == null && sourceContainer.getType() == SourceContainerType.SOURCE) {
sourceContainerOfTypeSource = sourceContainer;
}
}
if (sourceContainerOfTypeSource != null) {
sourceContainers.remove(sourceContainerOfTypeSource);
}
sourceContainers.add(new SourceContainerDescription(SourceContainerType.SOURCE, Collections.singleton((String) OUTPUT.defaultValue)));
}
use of org.eclipse.n4js.packagejson.projectDescription.SourceContainerDescription in project n4js by eclipse.
the class N4JSProjectConfig method createSourceFolders.
/**
* Create source folders from the information in the given project description. Does not update the state of this
* project configuration.
*/
protected Set<? extends IN4JSSourceFolder> createSourceFolders(ProjectDescription pd) {
Set<IN4JSSourceFolder> result = new LinkedHashSet<>();
for (SourceContainerDescription scd : pd.getSourceContainers()) {
SourceContainerType type = scd.getType();
for (String relPath : ProjectDescriptionUtils.getPathsNormalized(scd)) {
result.add(new N4JSSourceFolder(this, type, relPath));
}
}
result.add(new N4JSSourceFolderForPackageJson(this));
return result;
}
use of org.eclipse.n4js.packagejson.projectDescription.SourceContainerDescription in project n4js by eclipse.
the class MockWorkspaceSupplier method createProjectDescription.
/**
* See {@link #createWorkspaceConfig()}. Only invoked if {@link #loadProjectDescription()} returns absent value.
*/
protected Pair<FileURI, ProjectDescription> createProjectDescription() {
VersionNumber versionNumber = SemverUtils.createVersionNumber(0, 0, 1);
Iterable<SourceContainerDescription> sourceContainers = createSourceContainerDescriptions();
ProjectDescription pd = ProjectDescription.builder().setPackageName(TEST_PROJECT__NAME).setVersion(versionNumber).setType(TEST_PROJECT__TYPE).setVendorId(TEST_PROJECT__VENDOR_ID).setVendorName(TEST_PROJECT__VENDOR_NAME).addSourceContainers(sourceContainers).build();
return Pair.of(TEST_PROJECT__PATH, pd);
}
Aggregations