From f3a380ae607a95c07773fecf0b802c77991cce51 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 11 Jul 2021 21:22:11 -0700 Subject: [PATCH 1/2] Add missing test for `packages[].platforms[].toolsDependencies[].version` type This test verifies that the package index JSON schema validation result for the type of `Add missing test for packages[].platforms[].toolsDependencies[].version type` is as expected. --- internal/project/packageindex/packageindexschemas_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/project/packageindex/packageindexschemas_test.go b/internal/project/packageindex/packageindexschemas_test.go index d1184f39..94509f4b 100644 --- a/internal/project/packageindex/packageindexschemas_test.go +++ b/internal/project/packageindex/packageindexschemas_test.go @@ -551,6 +551,7 @@ func TestType(t *testing.T) { {"/packages/0/platforms/0/boards/0/name", 42, assert.True}, {"/packages/0/platforms/0/toolsDependencies", 42, assert.True}, {"/packages/0/platforms/0/toolsDependencies/0/packager", 42, assert.True}, + {"/packages/0/platforms/0/toolsDependencies/0/version", 42, assert.True}, {"/packages/0/tools", 42, assert.True}, {"/packages/0/tools/0/name", 42, assert.True}, {"/packages/0/tools/0/version", 42, assert.True}, From 1ee41db9125bb2c4287126117887fa8f117bdf14 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Jul 2021 04:31:02 -0700 Subject: [PATCH 2/2] Add schema-based rules for discovery dependencies data of package index These are the JSON schema-based rules to check the `packages[].platforms[].discoveryDependencies[]`-level data of the Arduino Package Index. --- ...uino-package-index-definitions-schema.json | 86 ++++++++++ .../packageindex/packageindexschemas_test.go | 33 ++++ internal/project/projectdata/packageindex.go | 12 ++ .../project/projectdata/packageindex_test.go | 157 +++++++++++++++-- .../empty-ids/package_foo_index.json | 52 ++++++ .../missing-ids/package_foo_index.json | 52 ++++++ .../package_foo_index.json | 26 +++ .../ruleconfiguration/ruleconfiguration.go | 128 ++++++++++++++ internal/rule/rulefunction/packageindex.go | 160 ++++++++++++++++++ .../rule/rulefunction/packageindex_test.go | 80 +++++++++ .../package_foo_index.json | 38 +++++ .../package_foo_index.json | 32 ++++ .../package_foo_index.json | 37 ++++ .../package_foo_index.json | 37 ++++ .../package_foo_index.json | 36 ++++ .../package_foo_index.json | 37 ++++ .../package_foo_index.json | 37 ++++ .../package_foo_index.json | 36 ++++ internal/rule/schema/schemadata/bindata.go | 86 ++++++++++ 19 files changed, 1144 insertions(+), 18 deletions(-) create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-additional-properties/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-incorrect-type/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-incorrect-type/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-length-lt/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-missing/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-incorrect-type/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-length-lt/package_foo_index.json create mode 100644 internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-missing/package_foo_index.json diff --git a/etc/schemas/arduino-package-index-definitions-schema.json b/etc/schemas/arduino-package-index-definitions-schema.json index 9902fdee..98561789 100644 --- a/etc/schemas/arduino-package-index-definitions-schema.json +++ b/etc/schemas/arduino-package-index-definitions-schema.json @@ -451,6 +451,9 @@ }, "toolsDependencies": { "$ref": "#/definitions/propertiesObjects/toolsDependencies/permissive/object" + }, + "discoveryDependencies": { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/permissive/object" } }, "additionalProperties": false @@ -503,6 +506,9 @@ }, "toolsDependencies": { "$ref": "#/definitions/propertiesObjects/toolsDependencies/specification/object" + }, + "discoveryDependencies": { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/specification/object" } }, "additionalProperties": false @@ -555,6 +561,9 @@ }, "toolsDependencies": { "$ref": "#/definitions/propertiesObjects/toolsDependencies/strict/object" + }, + "discoveryDependencies": { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/strict/object" } }, "additionalProperties": false @@ -997,6 +1006,83 @@ } } }, + "discoveryDependencies": { + "base": { + "object": { + "type": "array", + "items": { + "type": "object", + "required": ["packager", "name"] + } + } + }, + "permissive": { + "object": { + "allOf": [ + { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object" + }, + { + "items": { + "properties": { + "packager": { + "$ref": "#/definitions/propertiesObjects/packager/permissive/object" + }, + "name": { + "$ref": "#/definitions/propertiesObjects/toolName/permissive/object" + } + }, + "additionalProperties": false + } + } + ] + } + }, + "specification": { + "object": { + "allOf": [ + { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object" + }, + { + "items": { + "properties": { + "packager": { + "$ref": "#/definitions/propertiesObjects/packager/specification/object" + }, + "name": { + "$ref": "#/definitions/propertiesObjects/toolName/specification/object" + } + }, + "additionalProperties": false + } + } + ] + } + }, + "strict": { + "object": { + "allOf": [ + { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object" + }, + { + "items": { + "properties": { + "packager": { + "$ref": "#/definitions/propertiesObjects/packager/strict/object" + }, + "name": { + "$ref": "#/definitions/propertiesObjects/toolName/strict/object" + } + }, + "additionalProperties": false + } + } + ] + } + } + }, "packager": { "base": { "object": { diff --git a/internal/project/packageindex/packageindexschemas_test.go b/internal/project/packageindex/packageindexschemas_test.go index 94509f4b..8a1fd91c 100644 --- a/internal/project/packageindex/packageindexschemas_test.go +++ b/internal/project/packageindex/packageindexschemas_test.go @@ -64,6 +64,12 @@ var validIndexRaw = []byte(` "name": "avr-gcc", "version": "7.3.0-atmel3.6.1-arduino7" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + } ] } ], @@ -137,6 +143,14 @@ func TestMinLength(t *testing.T) { {"/packages/0/platforms/0/toolsDependencies/0/name", 1, compliancelevel.Specification}, {"/packages/0/platforms/0/toolsDependencies/0/name", 1, compliancelevel.Strict}, + {"/packages/0/platforms/0/discoveryDependencies/0/packager", 1, compliancelevel.Permissive}, + {"/packages/0/platforms/0/discoveryDependencies/0/packager", 1, compliancelevel.Specification}, + {"/packages/0/platforms/0/discoveryDependencies/0/packager", 1, compliancelevel.Strict}, + + {"/packages/0/platforms/0/discoveryDependencies/0/name", 1, compliancelevel.Permissive}, + {"/packages/0/platforms/0/discoveryDependencies/0/name", 1, compliancelevel.Specification}, + {"/packages/0/platforms/0/discoveryDependencies/0/name", 1, compliancelevel.Strict}, + {"/packages/0/tools/0/systems/0/archiveFileName", 1, compliancelevel.Permissive}, {"/packages/0/tools/0/systems/0/archiveFileName", 1, compliancelevel.Specification}, {"/packages/0/tools/0/systems/0/archiveFileName", 1, compliancelevel.Strict}, @@ -276,6 +290,18 @@ func TestRequired(t *testing.T) { {"/packages/0/platforms/0/toolsDependencies/0/version", compliancelevel.Specification, assert.True}, {"/packages/0/platforms/0/toolsDependencies/0/version", compliancelevel.Strict, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies", compliancelevel.Permissive, assert.False}, + {"/packages/0/platforms/0/discoveryDependencies", compliancelevel.Specification, assert.False}, + {"/packages/0/platforms/0/discoveryDependencies", compliancelevel.Strict, assert.False}, + + {"/packages/0/platforms/0/discoveryDependencies/0/packager", compliancelevel.Permissive, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0/packager", compliancelevel.Specification, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0/packager", compliancelevel.Strict, assert.True}, + + {"/packages/0/platforms/0/discoveryDependencies/0/name", compliancelevel.Permissive, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0/name", compliancelevel.Specification, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0/name", compliancelevel.Strict, assert.True}, + {"/packages/0/tools/0/name", compliancelevel.Permissive, assert.True}, {"/packages/0/tools/0/name", compliancelevel.Specification, assert.True}, {"/packages/0/tools/0/name", compliancelevel.Strict, assert.True}, @@ -552,6 +578,9 @@ func TestType(t *testing.T) { {"/packages/0/platforms/0/toolsDependencies", 42, assert.True}, {"/packages/0/platforms/0/toolsDependencies/0/packager", 42, assert.True}, {"/packages/0/platforms/0/toolsDependencies/0/version", 42, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies", 42, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0/packager", 42, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0/name", 42, assert.True}, {"/packages/0/tools", 42, assert.True}, {"/packages/0/tools/0/name", 42, assert.True}, {"/packages/0/tools/0/version", 42, assert.True}, @@ -679,6 +708,10 @@ func TestAdditionalProperties(t *testing.T) { {"/packages/0/platforms/0/toolsDependencies/0", compliancelevel.Specification, assert.True}, {"/packages/0/platforms/0/toolsDependencies/0", compliancelevel.Strict, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0", compliancelevel.Permissive, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0", compliancelevel.Specification, assert.True}, + {"/packages/0/platforms/0/discoveryDependencies/0", compliancelevel.Strict, assert.True}, + {"/packages/0/tools/0", compliancelevel.Permissive, assert.True}, {"/packages/0/tools/0", compliancelevel.Specification, assert.True}, {"/packages/0/tools/0", compliancelevel.Strict, assert.True}, diff --git a/internal/project/projectdata/packageindex.go b/internal/project/projectdata/packageindex.go index 6a75cff2..16343e23 100644 --- a/internal/project/projectdata/packageindex.go +++ b/internal/project/projectdata/packageindex.go @@ -44,6 +44,7 @@ func InitializeForPackageIndex() { packageIndexPlatforms = nil packageIndexBoards = nil packageIndexToolsDependencies = nil + packageIndexDiscoveryDependencies = nil packageIndexTools = nil packageIndexSystems = nil packageIndexSchemaValidationResult = nil @@ -62,6 +63,10 @@ func InitializeForPackageIndex() { packageIndexToolsDependencies = append(packageIndexToolsDependencies, getPackageIndexData(platformData.Object, platformData.JSONPointer, "toolsDependencies", platformData.ID, " - {{index . 0}}:{{index . 1}}@{{index . 2}}", []string{"packager", "name", "version"})...) } + for _, platformData := range PackageIndexPlatforms() { + packageIndexDiscoveryDependencies = append(packageIndexDiscoveryDependencies, getPackageIndexData(platformData.Object, platformData.JSONPointer, "discoveryDependencies", platformData.ID, " - {{index . 0}}:{{index . 1}}", []string{"packager", "name"})...) + } + for _, packageData := range PackageIndexPackages() { packageIndexTools = append(packageIndexTools, getPackageIndexData(packageData.Object, packageData.JSONPointer, "tools", packageData.ID, ":{{index . 0}}@{{index . 1}}", []string{"name", "version"})...) } @@ -123,6 +128,13 @@ func PackageIndexToolsDependencies() []PackageIndexData { return packageIndexToolsDependencies } +var packageIndexDiscoveryDependencies []PackageIndexData + +// PackageIndexDiscoveryDependencies returns the slice of pluggable discovery tool dependency data for the package index. +func PackageIndexDiscoveryDependencies() []PackageIndexData { + return packageIndexDiscoveryDependencies +} + var packageIndexTools []PackageIndexData // PackageIndexTools returns the slice of tool data for the package index. diff --git a/internal/project/projectdata/packageindex_test.go b/internal/project/projectdata/packageindex_test.go index 86d4d1bf..33de679e 100644 --- a/internal/project/projectdata/packageindex_test.go +++ b/internal/project/projectdata/packageindex_test.go @@ -36,24 +36,26 @@ func init() { func TestInitializeForPackageIndex(t *testing.T) { testTables := []struct { - testName string - path *paths.Path - packageIndexAssertion assert.ValueAssertionFunc - packageIndexLoadErrorAssertion assert.ValueAssertionFunc - packageIndexCLILoadErrorAssertion assert.ValueAssertionFunc - packageIndexPackagesAssertion assert.ValueAssertionFunc - packageIndexPackagesDataAssertion []PackageIndexData - packageIndexPlatformsAssertion assert.ValueAssertionFunc - packageIndexPlatformsDataAssertion []PackageIndexData - packageIndexBoardsAssertion assert.ValueAssertionFunc - packageIndexBoardsDataAssertion []PackageIndexData - packageIndexToolsDependenciesAssertion assert.ValueAssertionFunc - packageIndexToolsDependenciesDataAssertion []PackageIndexData - packageIndexToolsAssertion assert.ValueAssertionFunc - packageIndexToolsDataAssertion []PackageIndexData - packageIndexSystemsAssertion assert.ValueAssertionFunc - packageIndexSystemsDataAssertion []PackageIndexData - packageIndexSchemaValidationResultAssertion assert.ValueAssertionFunc + testName string + path *paths.Path + packageIndexAssertion assert.ValueAssertionFunc + packageIndexLoadErrorAssertion assert.ValueAssertionFunc + packageIndexCLILoadErrorAssertion assert.ValueAssertionFunc + packageIndexPackagesAssertion assert.ValueAssertionFunc + packageIndexPackagesDataAssertion []PackageIndexData + packageIndexPlatformsAssertion assert.ValueAssertionFunc + packageIndexPlatformsDataAssertion []PackageIndexData + packageIndexBoardsAssertion assert.ValueAssertionFunc + packageIndexBoardsDataAssertion []PackageIndexData + packageIndexToolsDependenciesAssertion assert.ValueAssertionFunc + packageIndexToolsDependenciesDataAssertion []PackageIndexData + packageIndexDiscoveryDependenciesAssertion assert.ValueAssertionFunc + packageIndexDiscoveryDependenciesDataAssertion []PackageIndexData + packageIndexToolsAssertion assert.ValueAssertionFunc + packageIndexToolsDataAssertion []PackageIndexData + packageIndexSystemsAssertion assert.ValueAssertionFunc + packageIndexSystemsDataAssertion []PackageIndexData + packageIndexSchemaValidationResultAssertion assert.ValueAssertionFunc }{ { testName: "Valid", @@ -161,6 +163,29 @@ func TestInitializeForPackageIndex(t *testing.T) { JSONPointer: "/packages/1/platforms/1/toolsDependencies/1", }, }, + packageIndexDiscoveryDependenciesAssertion: assert.NotNil, + packageIndexDiscoveryDependenciesDataAssertion: []PackageIndexData{ + { + ID: "foopackager1:avr@1.0.1 - arduino:ble-discovery", + JSONPointer: "/packages/0/platforms/1/discoveryDependencies/0", + }, + { + ID: "foopackager1:avr@1.0.1 - barpackager:carrier-pigeon-discovery", + JSONPointer: "/packages/0/platforms/1/discoveryDependencies/1", + }, + { + ID: "foopackager2:samd@2.0.0 - arduino:ble-discovery", + JSONPointer: "/packages/1/platforms/0/discoveryDependencies/0", + }, + { + ID: "foopackager2:samd@2.0.0 - bazpackager:signal-flag-discovery", + JSONPointer: "/packages/1/platforms/0/discoveryDependencies/1", + }, + { + ID: "foopackager2:mbed@1.1.1 - quxpackager:sneakernet-discovery", + JSONPointer: "/packages/1/platforms/1/discoveryDependencies/0", + }, + }, packageIndexToolsAssertion: assert.NotNil, packageIndexToolsDataAssertion: []PackageIndexData{ { @@ -327,6 +352,53 @@ func TestInitializeForPackageIndex(t *testing.T) { JSONPointer: "/packages/1/platforms/2/toolsDependencies/3", }, }, + packageIndexDiscoveryDependenciesAssertion: assert.NotNil, + packageIndexDiscoveryDependenciesDataAssertion: []PackageIndexData{ + { + ID: "/packages/0/platforms/0/discoveryDependencies/0", + JSONPointer: "/packages/0/platforms/0/discoveryDependencies/0", + }, + { + ID: "/packages/0/platforms/0/discoveryDependencies/1", + JSONPointer: "/packages/0/platforms/0/discoveryDependencies/1", + }, + { + ID: "/packages/0/platforms/1/discoveryDependencies/0", + JSONPointer: "/packages/0/platforms/1/discoveryDependencies/0", + }, + { + ID: "/packages/0/platforms/1/discoveryDependencies/1", + JSONPointer: "/packages/0/platforms/1/discoveryDependencies/1", + }, + { + ID: "/packages/1/platforms/0/discoveryDependencies/0", + JSONPointer: "/packages/1/platforms/0/discoveryDependencies/0", + }, + { + ID: "/packages/1/platforms/0/discoveryDependencies/1", + JSONPointer: "/packages/1/platforms/0/discoveryDependencies/1", + }, + { + ID: "/packages/1/platforms/1/discoveryDependencies/0", + JSONPointer: "/packages/1/platforms/1/discoveryDependencies/0", + }, + { + ID: "/packages/1/platforms/1/discoveryDependencies/1", + JSONPointer: "/packages/1/platforms/1/discoveryDependencies/1", + }, + { + ID: "/packages/1/platforms/2/discoveryDependencies/0", + JSONPointer: "/packages/1/platforms/2/discoveryDependencies/0", + }, + { + ID: "/packages/1/platforms/2/discoveryDependencies/1", + JSONPointer: "/packages/1/platforms/2/discoveryDependencies/1", + }, + { + ID: "foopackager2:megaavr@1.0.0 - quxpackager:sneakernet-discovery", + JSONPointer: "/packages/1/platforms/2/discoveryDependencies/3", + }, + }, packageIndexToolsAssertion: assert.NotNil, packageIndexToolsDataAssertion: []PackageIndexData{ { @@ -501,6 +573,53 @@ func TestInitializeForPackageIndex(t *testing.T) { JSONPointer: "/packages/1/platforms/2/toolsDependencies/3", }, }, + packageIndexDiscoveryDependenciesAssertion: assert.NotNil, + packageIndexDiscoveryDependenciesDataAssertion: []PackageIndexData{ + { + ID: "/packages/0/platforms/0/discoveryDependencies/0", + JSONPointer: "/packages/0/platforms/0/discoveryDependencies/0", + }, + { + ID: "/packages/0/platforms/0/discoveryDependencies/1", + JSONPointer: "/packages/0/platforms/0/discoveryDependencies/1", + }, + { + ID: "/packages/0/platforms/1/discoveryDependencies/0", + JSONPointer: "/packages/0/platforms/1/discoveryDependencies/0", + }, + { + ID: "/packages/0/platforms/1/discoveryDependencies/1", + JSONPointer: "/packages/0/platforms/1/discoveryDependencies/1", + }, + { + ID: "/packages/1/platforms/0/discoveryDependencies/0", + JSONPointer: "/packages/1/platforms/0/discoveryDependencies/0", + }, + { + ID: "/packages/1/platforms/0/discoveryDependencies/1", + JSONPointer: "/packages/1/platforms/0/discoveryDependencies/1", + }, + { + ID: "/packages/1/platforms/1/discoveryDependencies/0", + JSONPointer: "/packages/1/platforms/1/discoveryDependencies/0", + }, + { + ID: "/packages/1/platforms/1/discoveryDependencies/1", + JSONPointer: "/packages/1/platforms/1/discoveryDependencies/1", + }, + { + ID: "/packages/1/platforms/2/discoveryDependencies/0", + JSONPointer: "/packages/1/platforms/2/discoveryDependencies/0", + }, + { + ID: "/packages/1/platforms/2/discoveryDependencies/1", + JSONPointer: "/packages/1/platforms/2/discoveryDependencies/1", + }, + { + ID: "foopackager2:megaavr@1.0.0 - quxpackager:sneakernet-discovery", + JSONPointer: "/packages/1/platforms/2/discoveryDependencies/3", + }, + }, packageIndexToolsAssertion: assert.NotNil, packageIndexToolsDataAssertion: []PackageIndexData{ { @@ -551,6 +670,7 @@ func TestInitializeForPackageIndex(t *testing.T) { packageIndexPlatformsAssertion: assert.Nil, packageIndexBoardsAssertion: assert.Nil, packageIndexToolsDependenciesAssertion: assert.Nil, + packageIndexDiscoveryDependenciesAssertion: assert.Nil, packageIndexToolsAssertion: assert.Nil, packageIndexSystemsAssertion: assert.Nil, packageIndexSchemaValidationResultAssertion: assert.Nil, @@ -565,6 +685,7 @@ func TestInitializeForPackageIndex(t *testing.T) { packageIndexPlatformsAssertion: assert.Nil, packageIndexBoardsAssertion: assert.Nil, packageIndexToolsDependenciesAssertion: assert.Nil, + packageIndexDiscoveryDependenciesAssertion: assert.Nil, packageIndexToolsAssertion: assert.Nil, packageIndexSystemsAssertion: assert.Nil, packageIndexSchemaValidationResultAssertion: assert.Nil, diff --git a/internal/project/projectdata/testdata/packageindexes/empty-ids/package_foo_index.json b/internal/project/projectdata/testdata/packageindexes/empty-ids/package_foo_index.json index 0d6e86c9..076738e3 100644 --- a/internal/project/projectdata/testdata/packageindexes/empty-ids/package_foo_index.json +++ b/internal/project/projectdata/testdata/packageindexes/empty-ids/package_foo_index.json @@ -33,6 +33,16 @@ "name": "avrdude", "version": "6.0.1-arduino5" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "barpackager", + "name": "carrier-pigeon-discovery" + } ] }, { @@ -59,6 +69,16 @@ "name": "avrdude", "version": "6.3.0-arduino17" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "barpackager", + "name": "carrier-pigeon-discovery" + } ] } ], @@ -97,6 +117,16 @@ "name": "bossac", "version": "1.7.0-arduino3" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "bazpackager", + "name": "signal-flag-discovery" + } ] }, { @@ -123,6 +153,16 @@ "name": "arm-none-eabi-gcc", "version": "7-2017q4" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "bazpackager", + "name": "signal-flag-discovery" + } ] }, { @@ -159,6 +199,18 @@ "name": "CMSIS", "version": "4.5.0" } + ], + "discoveryDependencies": [ + { + "name": "ble-discovery" + }, + { + "packager": "bazpackager" + }, + { + "packager": "quxpackager", + "name": "sneakernet-discovery" + } ] } ], diff --git a/internal/project/projectdata/testdata/packageindexes/missing-ids/package_foo_index.json b/internal/project/projectdata/testdata/packageindexes/missing-ids/package_foo_index.json index 05542649..ea1b5622 100644 --- a/internal/project/projectdata/testdata/packageindexes/missing-ids/package_foo_index.json +++ b/internal/project/projectdata/testdata/packageindexes/missing-ids/package_foo_index.json @@ -32,6 +32,16 @@ "name": "avrdude", "version": "6.0.1-arduino5" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "barpackager", + "name": "carrier-pigeon-discovery" + } ] }, { @@ -58,6 +68,16 @@ "name": "avrdude", "version": "6.3.0-arduino17" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "barpackager", + "name": "carrier-pigeon-discovery" + } ] } ], @@ -95,6 +115,16 @@ "name": "bossac", "version": "1.7.0-arduino3" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "bazpackager", + "name": "signal-flag-discovery" + } ] }, { @@ -120,6 +150,16 @@ "name": "arm-none-eabi-gcc", "version": "7-2017q4" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "bazpackager", + "name": "signal-flag-discovery" + } ] }, { @@ -153,6 +193,18 @@ "name": "CMSIS", "version": "4.5.0" } + ], + "discoveryDependencies": [ + { + "name": "ble-discovery" + }, + { + "packager": "bazpackager" + }, + { + "packager": "quxpackager", + "name": "sneakernet-discovery" + } ] } ], diff --git a/internal/project/projectdata/testdata/packageindexes/valid-package-index/package_foo_index.json b/internal/project/projectdata/testdata/packageindexes/valid-package-index/package_foo_index.json index 15203499..67181764 100644 --- a/internal/project/projectdata/testdata/packageindexes/valid-package-index/package_foo_index.json +++ b/internal/project/projectdata/testdata/packageindexes/valid-package-index/package_foo_index.json @@ -59,6 +59,16 @@ "name": "avrdude", "version": "6.3.0-arduino17" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "barpackager", + "name": "carrier-pigeon-discovery" + } ] } ], @@ -97,6 +107,16 @@ "name": "bossac", "version": "1.7.0-arduino3" } + ], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "ble-discovery" + }, + { + "packager": "bazpackager", + "name": "signal-flag-discovery" + } ] }, { @@ -123,6 +143,12 @@ "name": "arm-none-eabi-gcc", "version": "7-2017q4" } + ], + "discoveryDependencies": [ + { + "packager": "quxpackager", + "name": "sneakernet-discovery" + } ] } ], diff --git a/internal/rule/ruleconfiguration/ruleconfiguration.go b/internal/rule/ruleconfiguration/ruleconfiguration.go index 42f6717e..a512990f 100644 --- a/internal/rule/ruleconfiguration/ruleconfiguration.go +++ b/internal/rule/ruleconfiguration/ruleconfiguration.go @@ -4233,6 +4233,134 @@ var configurations = []Type{ ErrorModes: []rulemode.Type{rulemode.Strict}, RuleFunction: rulefunction.PackageIndexPackagesPlatformsToolsDependenciesVersionNonSemver, }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL059", + Brief: "incorrect packages[].platforms[].discoveryDependencies type", + Description: "Must be an array.", + MessageTemplate: "packages[].platforms[].discoveryDependencies property has incorrect type in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesIncorrectType, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL060", + Brief: "additional properties in packages[].platforms[].discoveryDependencies[]", + Description: "", + MessageTemplate: "Unknown properties under packages[].platforms[].discoveryDependencies[] found in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesAdditionalProperties, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL061", + Brief: "packages[].platforms[].discoveryDependencies[].packager missing", + Description: "", + MessageTemplate: "Missing packages[].platforms[].discoveryDependencies[].packager property in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerMissing, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL062", + Brief: "incorrect packages[].platforms[].discoveryDependencies[].packager type", + Description: "Must be a string.", + MessageTemplate: "packages[].platforms[].discoveryDependencies[].packager property has incorrect type in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerIncorrectType, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL063", + Brief: "packages[].platforms[].discoveryDependencies[].packager < min length", + Description: "", + MessageTemplate: "packages[].platforms[].discoveryDependencies[].packager value less than the minimum length in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerLTMinLength, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL064", + Brief: "packages[].platforms[].discoveryDependencies[].name missing", + Description: "", + MessageTemplate: "Missing packages[].platforms[].discoveryDependencies[].name property in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesNameMissing, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL065", + Brief: "incorrect packages[].platforms[].discoveryDependencies[].name type", + Description: "Must be a string.", + MessageTemplate: "packages[].platforms[].discoveryDependencies[].name property has incorrect type in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesNameIncorrectType, + }, + { + ProjectType: projecttype.PackageIndex, + SuperprojectType: projecttype.All, + Category: "data", + Subcategory: "platform", + ID: "IL066", + Brief: "packages[].platforms[].discoveryDependencies[].name < min length", + Description: "", + MessageTemplate: "packages[].platforms[].discoveryDependencies[].name value less than the minimum length in platform(s): {{.}}", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsDiscoveryDependenciesNameLTMinLength, + }, { ProjectType: projecttype.PackageIndex, SuperprojectType: projecttype.All, diff --git a/internal/rule/rulefunction/packageindex.go b/internal/rule/rulefunction/packageindex.go index cb380056..b455ecde 100644 --- a/internal/rule/rulefunction/packageindex.go +++ b/internal/rule/rulefunction/packageindex.go @@ -1775,6 +1775,166 @@ func PackageIndexPackagesPlatformsToolsDependenciesVersionNonSemver() (result ru return ruleresult.Pass, "" } +// PackageIndexPackagesPlatformsDiscoveryDependenciesIncorrectType checks for incorrect type of the packages[].platforms[].discoveryDependencies property. +func PackageIndexPackagesPlatformsDiscoveryDependenciesIncorrectType() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, platformData := range projectdata.PackageIndexPlatforms() { + if schema.PropertyTypeMismatch(platformData.JSONPointer+"/discoveryDependencies", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, platformData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesAdditionalProperties checks for additional properties in packages[].platforms[].discoveryDependencies[]. +func PackageIndexPackagesPlatformsDiscoveryDependenciesAdditionalProperties() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.ProhibitedAdditionalProperties(dependencyData.JSONPointer, projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerMissing checks for missing packages[].platforms[].discoveryDependencies[].packager property. +func PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerMissing() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.RequiredPropertyMissing(dependencyData.JSONPointer+"/packager", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerIncorrectType checks for incorrect type of the packages[].platforms[].discoveryDependencies[].packager property. +func PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerIncorrectType() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.PropertyTypeMismatch(dependencyData.JSONPointer+"/packager", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerLTMinLength checks for packages[].platforms[].discoveryDependencies[].packager property less than the minimum length. +func PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerLTMinLength() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.PropertyLessThanMinLength(dependencyData.JSONPointer+"/packager", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesNameMissing checks for missing packages[].platforms[].discoveryDependencies[].name property. +func PackageIndexPackagesPlatformsDiscoveryDependenciesNameMissing() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.RequiredPropertyMissing(dependencyData.JSONPointer+"/name", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesNameIncorrectType checks for incorrect type of the packages[].platforms[].discoveryDependencies[].name property. +func PackageIndexPackagesPlatformsDiscoveryDependenciesNameIncorrectType() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.PropertyTypeMismatch(dependencyData.JSONPointer+"/name", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + +// PackageIndexPackagesPlatformsDiscoveryDependenciesNameLTMinLength checks for packages[].platforms[].discoveryDependencies[].name property less than the minimum length. +func PackageIndexPackagesPlatformsDiscoveryDependenciesNameLTMinLength() (result ruleresult.Type, output string) { + if projectdata.PackageIndexLoadError() != nil { + return ruleresult.NotRun, "Error loading package index" + } + + nonCompliantIDs := []string{} + for _, dependencyData := range projectdata.PackageIndexDiscoveryDependencies() { + if schema.PropertyLessThanMinLength(dependencyData.JSONPointer+"/name", projectdata.PackageIndexSchemaValidationResult()[compliancelevel.Specification]) { + nonCompliantIDs = append(nonCompliantIDs, dependencyData.ID) + } + } + + if len(nonCompliantIDs) > 0 { + return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ") + } + + return ruleresult.Pass, "" +} + // PackageIndexPackagesToolsMissing checks for missing packages[].tools property. func PackageIndexPackagesToolsMissing() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { diff --git a/internal/rule/rulefunction/packageindex_test.go b/internal/rule/rulefunction/packageindex_test.go index 9bcbfdb3..442d6012 100644 --- a/internal/rule/rulefunction/packageindex_test.go +++ b/internal/rule/rulefunction/packageindex_test.go @@ -932,6 +932,86 @@ func TestPackageIndexPackagesPlatformsToolsDependenciesVersionNonSemver(t *testi checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsToolsDependenciesVersionNonSemver, testTables, t) } +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesIncorrectType(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"Incorrect packages[].platforms[].discoveryDependencies type", "packages-platforms-discoverydependencies-incorrect-type", ruleresult.Fail, "^foopackager:avr@1\\.0\\.0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesIncorrectType, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesAdditionalProperties(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"Additional packages[].platforms[].discoveryDependencies[] properties", "packages-platforms-discoverydependencies-additional-properties", ruleresult.Fail, "^foopackager:avr@1\\.0\\.0 - arduino:ble-discovery$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesAdditionalProperties, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesPackagerMissing(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"packages[].platforms[].discoveryDependencies[].packager missing", "packages-platforms-discoverydependencies-packager-missing", ruleresult.Fail, "^/packages/0/platforms/0/discoveryDependencies/0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerMissing, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesPackagerIncorrectType(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"Incorrect packages[].platforms[].discoveryDependencies[].packager type", "packages-platforms-discoverydependencies-packager-incorrect-type", ruleresult.Fail, "^/packages/0/platforms/0/discoveryDependencies/0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerIncorrectType, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesPackagerLTMinLength(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"packages[].platforms[].discoveryDependencies[].packager < min length", "packages-platforms-discoverydependencies-packager-length-lt", ruleresult.Fail, "^/packages/0/platforms/0/discoveryDependencies/0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesPackagerLTMinLength, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesNameMissing(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"packages[].platforms[].discoveryDependencies[].name missing", "packages-platforms-discoverydependencies-name-missing", ruleresult.Fail, "^/packages/0/platforms/0/discoveryDependencies/0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesNameMissing, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesNameIncorrectType(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"Incorrect packages[].platforms[].discoveryDependencies[].name type", "packages-platforms-discoverydependencies-name-incorrect-type", ruleresult.Fail, "^/packages/0/platforms/0/discoveryDependencies/0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesNameIncorrectType, testTables, t) +} + +func TestPackageIndexPackagesPlatformsDiscoveryDependenciesNameLTMinLength(t *testing.T) { + testTables := []packageIndexRuleFunctionTestTable{ + {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, + {"packages[].platforms[].discoveryDependencies[].name < min length", "packages-platforms-discoverydependencies-name-length-lt", ruleresult.Fail, "^/packages/0/platforms/0/discoveryDependencies/0$"}, + {"Valid", "valid-package-index", ruleresult.Pass, ""}, + } + + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsDiscoveryDependenciesNameLTMinLength, testTables, t) +} + func TestPackageIndexPackagesToolsMissing(t *testing.T) { testTables := []packageIndexRuleFunctionTestTable{ {"Invalid JSON", "invalid-JSON", ruleresult.NotRun, ""}, diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-additional-properties/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-additional-properties/package_foo_index.json new file mode 100644 index 00000000..61f2642a --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-additional-properties/package_foo_index.json @@ -0,0 +1,38 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "foo": "bar", + "packager": "arduino", + "name": "ble-discovery" + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-incorrect-type/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-incorrect-type/package_foo_index.json new file mode 100644 index 00000000..6ef418d8 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-incorrect-type/package_foo_index.json @@ -0,0 +1,32 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": 42 + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-incorrect-type/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-incorrect-type/package_foo_index.json new file mode 100644 index 00000000..f5c64682 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-incorrect-type/package_foo_index.json @@ -0,0 +1,37 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": 42 + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-length-lt/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-length-lt/package_foo_index.json new file mode 100644 index 00000000..de446446 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-length-lt/package_foo_index.json @@ -0,0 +1,37 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "packager": "arduino", + "name": "" + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-missing/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-missing/package_foo_index.json new file mode 100644 index 00000000..36313023 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-name-missing/package_foo_index.json @@ -0,0 +1,36 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "packager": "arduino" + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-incorrect-type/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-incorrect-type/package_foo_index.json new file mode 100644 index 00000000..1d1bb903 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-incorrect-type/package_foo_index.json @@ -0,0 +1,37 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "packager": 42, + "name": "ble-discovery" + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-length-lt/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-length-lt/package_foo_index.json new file mode 100644 index 00000000..7f509746 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-length-lt/package_foo_index.json @@ -0,0 +1,37 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "packager": "", + "name": "ble-discovery" + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-missing/package_foo_index.json b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-missing/package_foo_index.json new file mode 100644 index 00000000..b711ce68 --- /dev/null +++ b/internal/rule/rulefunction/testdata/packageindexes/packages-platforms-discoverydependencies-packager-missing/package_foo_index.json @@ -0,0 +1,36 @@ +{ + "packages": [ + { + "name": "foopackager", + "maintainer": "Jane Developer", + "websiteURL": "http://example.com", + "email": "jane@example.com", + "help": { + "online": "http://example.com" + }, + "platforms": [ + { + "name": "My Board", + "architecture": "avr", + "version": "1.0.0", + "category": "Contributed", + "help": { + "online": "http://example.com" + }, + "url": "http://example.com", + "archiveFileName": "myboard-1.0.0.zip", + "checksum": "MD5:6c0f556759894aa1a45e8af423a08ce8", + "size": "15005", + "boards": [], + "toolsDependencies": [], + "discoveryDependencies": [ + { + "name": "ble-discovery" + } + ] + } + ], + "tools": [] + } + ] +} diff --git a/internal/rule/schema/schemadata/bindata.go b/internal/rule/schema/schemadata/bindata.go index 805b8872..1ff2f050 100644 --- a/internal/rule/schema/schemadata/bindata.go +++ b/internal/rule/schema/schemadata/bindata.go @@ -2987,6 +2987,9 @@ var _arduinoPackageIndexDefinitionsSchemaJson = []byte(`{ }, "toolsDependencies": { "$ref": "#/definitions/propertiesObjects/toolsDependencies/permissive/object" + }, + "discoveryDependencies": { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/permissive/object" } }, "additionalProperties": false @@ -3039,6 +3042,9 @@ var _arduinoPackageIndexDefinitionsSchemaJson = []byte(`{ }, "toolsDependencies": { "$ref": "#/definitions/propertiesObjects/toolsDependencies/specification/object" + }, + "discoveryDependencies": { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/specification/object" } }, "additionalProperties": false @@ -3091,6 +3097,9 @@ var _arduinoPackageIndexDefinitionsSchemaJson = []byte(`{ }, "toolsDependencies": { "$ref": "#/definitions/propertiesObjects/toolsDependencies/strict/object" + }, + "discoveryDependencies": { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/strict/object" } }, "additionalProperties": false @@ -3533,6 +3542,83 @@ var _arduinoPackageIndexDefinitionsSchemaJson = []byte(`{ } } }, + "discoveryDependencies": { + "base": { + "object": { + "type": "array", + "items": { + "type": "object", + "required": ["packager", "name"] + } + } + }, + "permissive": { + "object": { + "allOf": [ + { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object" + }, + { + "items": { + "properties": { + "packager": { + "$ref": "#/definitions/propertiesObjects/packager/permissive/object" + }, + "name": { + "$ref": "#/definitions/propertiesObjects/toolName/permissive/object" + } + }, + "additionalProperties": false + } + } + ] + } + }, + "specification": { + "object": { + "allOf": [ + { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object" + }, + { + "items": { + "properties": { + "packager": { + "$ref": "#/definitions/propertiesObjects/packager/specification/object" + }, + "name": { + "$ref": "#/definitions/propertiesObjects/toolName/specification/object" + } + }, + "additionalProperties": false + } + } + ] + } + }, + "strict": { + "object": { + "allOf": [ + { + "$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object" + }, + { + "items": { + "properties": { + "packager": { + "$ref": "#/definitions/propertiesObjects/packager/strict/object" + }, + "name": { + "$ref": "#/definitions/propertiesObjects/toolName/strict/object" + } + }, + "additionalProperties": false + } + } + ] + } + } + }, "packager": { "base": { "object": {