Search in sources :

Example 1 with SOURCES

use of org.eclipse.n4js.packagejson.PackageJsonProperties.SOURCES in project n4js by eclipse.

the class PackageJsonValidatorExtension method checkSourceContainers.

/**
 * Validates the source container section of N4JS package.json files
 */
@CheckProperty(property = SOURCES)
public void checkSourceContainers() {
    // obtain source-container-related content of the section and validate its structure
    Multimap<SourceContainerType, List<JSONStringLiteral>> sourceContainers = getSourceContainers();
    final List<JSONStringLiteral> allDeclaredSourceContainers = sourceContainers.entries().stream().flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList());
    // check each source container sub-section (e.g. sources, external, etc.)
    final List<JSONStringLiteral> validSourceContainerLiterals = allDeclaredSourceContainers.stream().filter(l -> internalCheckSourceContainerLiteral(l)).collect(Collectors.toList());
    // find all groups of duplicate paths
    final List<List<JSONStringLiteral>> containerDuplicates = findPathDuplicates(allDeclaredSourceContainers);
    for (List<JSONStringLiteral> duplicateGroup : containerDuplicates) {
        // indicates whether the duplicates are spread across multiple container types (e.g. external, sources)
        final String normalizedPath = FileUtils.normalize(duplicateGroup.get(0).getValue());
        for (JSONStringLiteral duplicate : duplicateGroup) {
            final String inClause = createInSourceContainerTypeClause(duplicate, duplicateGroup);
            addIssue(IssueCodes.getMessageForPKGJ_DUPLICATE_SOURCE_CONTAINER(normalizedPath, inClause), duplicate, IssueCodes.PKGJ_DUPLICATE_SOURCE_CONTAINER);
        }
    }
    // check for nested source containers (within valid source container literals)
    internalCheckNoNestedSourceContainers(validSourceContainerLiterals);
}
Also used : REQUIRED_RUNTIME_LIBRARIES(org.eclipse.n4js.packagejson.PackageJsonProperties.REQUIRED_RUNTIME_LIBRARIES) IssueCodes(org.eclipse.n4js.validation.IssueCodes) JSONStringLiteral(org.eclipse.n4js.json.JSON.JSONStringLiteral) Inject(com.google.inject.Inject) NV_SOURCE_CONTAINER(org.eclipse.n4js.packagejson.PackageJsonProperties.NV_SOURCE_CONTAINER) NAME(org.eclipse.n4js.packagejson.PackageJsonProperties.NAME) FileUtils(org.eclipse.n4js.utils.io.FileUtils) ProjectNameInfo(org.eclipse.n4js.utils.ProjectDescriptionUtils.ProjectNameInfo) URLVersionRequirement(org.eclipse.n4js.semver.Semver.URLVersionRequirement) VENDOR_NAME(org.eclipse.n4js.packagejson.PackageJsonProperties.VENDOR_NAME) HashMultimap(com.google.common.collect.HashMultimap) PackageJsonUtils(org.eclipse.n4js.packagejson.PackageJsonUtils) DEPENDENCIES(org.eclipse.n4js.packagejson.PackageJsonProperties.DEPENDENCIES) ModuleFilterType(org.eclipse.n4js.packagejson.projectDescription.ModuleFilterType) Optional(com.google.common.base.Optional) Map(java.util.Map) SourceContainerType(org.eclipse.n4js.packagejson.projectDescription.SourceContainerType) VersionRangeSetRequirement(org.eclipse.n4js.semver.Semver.VersionRangeSetRequirement) INode(org.eclipse.xtext.nodemodel.INode) Check(org.eclipse.xtext.validation.Check) Path(java.nio.file.Path) PackageJsonProperties(org.eclipse.n4js.packagejson.PackageJsonProperties) JSONPackage(org.eclipse.n4js.json.JSON.JSONPackage) ProjectType(org.eclipse.n4js.packagejson.projectDescription.ProjectType) IParseResult(org.eclipse.xtext.parser.IParseResult) FileURI(org.eclipse.n4js.workspace.locations.FileURI) DEFINES_PACKAGE(org.eclipse.n4js.packagejson.PackageJsonProperties.DEFINES_PACKAGE) N4JS(org.eclipse.n4js.packagejson.PackageJsonProperties.N4JS) Collection(java.util.Collection) IMPLEMENTATION_ID(org.eclipse.n4js.packagejson.PackageJsonProperties.IMPLEMENTATION_ID) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) TagVersionRequirement(org.eclipse.n4js.semver.Semver.TagVersionRequirement) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Collectors(java.util.stream.Collectors) GitHubVersionRequirement(org.eclipse.n4js.semver.Semver.GitHubVersionRequirement) JSONArray(org.eclipse.n4js.json.JSON.JSONArray) List(java.util.List) Stream(java.util.stream.Stream) NPMVersionRequirement(org.eclipse.n4js.semver.Semver.NPMVersionRequirement) SimpleVersion(org.eclipse.n4js.semver.Semver.SimpleVersion) GENERATOR_REWRITE_MODULE_SPECIFIERS(org.eclipse.n4js.packagejson.PackageJsonProperties.GENERATOR_REWRITE_MODULE_SPECIFIERS) IMPLEMENTED_PROJECTS(org.eclipse.n4js.packagejson.PackageJsonProperties.IMPLEMENTED_PROJECTS) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) Singleton(com.google.inject.Singleton) DEV_DEPENDENCIES(org.eclipse.n4js.packagejson.PackageJsonProperties.DEV_DEPENDENCIES) URI(org.eclipse.emf.common.util.URI) VersionRangeConstraint(org.eclipse.n4js.semver.Semver.VersionRangeConstraint) JSONValue(org.eclipse.n4js.json.JSON.JSONValue) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) Multimap(com.google.common.collect.Multimap) VERSION(org.eclipse.n4js.packagejson.PackageJsonProperties.VERSION) NodeModelUtils(org.eclipse.xtext.nodemodel.util.NodeModelUtils) PROVIDED_RUNTIME_LIBRARIES(org.eclipse.n4js.packagejson.PackageJsonProperties.PROVIDED_RUNTIME_LIBRARIES) TESTED_PROJECTS(org.eclipse.n4js.packagejson.PackageJsonProperties.TESTED_PROJECTS) VENDOR_ID(org.eclipse.n4js.packagejson.PackageJsonProperties.VENDOR_ID) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InvalidPathException(java.nio.file.InvalidPathException) EClass(org.eclipse.emf.ecore.EClass) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) WorkspaceAccess(org.eclipse.n4js.workspace.WorkspaceAccess) PROJECT_TYPE(org.eclipse.n4js.packagejson.PackageJsonProperties.PROJECT_TYPE) JSONDocument(org.eclipse.n4js.json.JSON.JSONDocument) MAIN_MODULE(org.eclipse.n4js.packagejson.PackageJsonProperties.MAIN_MODULE) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) JSONModelUtils.asNonEmptyStringOrNull(org.eclipse.n4js.json.model.utils.JSONModelUtils.asNonEmptyStringOrNull) ProjectDescriptionUtils(org.eclipse.n4js.utils.ProjectDescriptionUtils) MODULE_FILTERS(org.eclipse.n4js.packagejson.PackageJsonProperties.MODULE_FILTERS) NV_MODULE(org.eclipse.n4js.packagejson.PackageJsonProperties.NV_MODULE) OUTPUT(org.eclipse.n4js.packagejson.PackageJsonProperties.OUTPUT) Iterator(java.util.Iterator) EXTENDED_RUNTIME_ENVIRONMENT(org.eclipse.n4js.packagejson.PackageJsonProperties.EXTENDED_RUNTIME_ENVIRONMENT) SOURCES(org.eclipse.n4js.packagejson.PackageJsonProperties.SOURCES) File(java.io.File) LocalPathVersionRequirement(org.eclipse.n4js.semver.Semver.LocalPathVersionRequirement) SemverHelper(org.eclipse.n4js.semver.SemverHelper) JSONObject(org.eclipse.n4js.json.JSON.JSONObject) Issue(org.eclipse.xtext.validation.Issue) Paths(java.nio.file.Paths) SemverSerializer(org.eclipse.n4js.semver.model.SemverSerializer) NameValuePair(org.eclipse.n4js.json.JSON.NameValuePair) List(java.util.List) ArrayList(java.util.ArrayList) SourceContainerType(org.eclipse.n4js.packagejson.projectDescription.SourceContainerType) JSONStringLiteral(org.eclipse.n4js.json.JSON.JSONStringLiteral)

Aggregations

Optional (com.google.common.base.Optional)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Multimap (com.google.common.collect.Multimap)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 File (java.io.File)1 InvalidPathException (java.nio.file.InvalidPathException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1