forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chocolatey#3000) Move unsupported element rules to rule classes
This commit moves the existing rules that was added previously for unsupported metadata to their own classes that hooks into the rule service to make the validation.
- Loading branch information
1 parent
fbe4c0f
commit e9e180e
Showing
10 changed files
with
258 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/chocolatey/infrastructure.app/rules/FrameWorkReferencesMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System.Collections.Generic; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class FrameWorkReferencesMetadataRule : MetadataRuleBase | ||
{ | ||
public override IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
if (has_element(reader, "frameworkReferences")) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<frameworkReferences> elements are not supported in Chocolatey CLI."); | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/chocolatey/infrastructure.app/rules/IconMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System.Collections.Generic; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class IconMetadataRule : IMetadataRule | ||
{ | ||
public IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
if (!(reader.GetIcon() is null)) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<icon> elements are not supported in Chocolatey CLI, use <iconUrl> instead."); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/chocolatey/infrastructure.app/rules/LicenseMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class LicenseMetadataRule : IMetadataRule | ||
{ | ||
public IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
if (!(reader.GetLicenseMetadata() is null)) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<license> elements are not supported in Chocolatey CLI, use <licenseUrl> instead."); | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/chocolatey/infrastructure.app/rules/PackageTypesMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System.Collections.Generic; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class PackageTypesMetadataRule : MetadataRuleBase | ||
{ | ||
public override IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
if (has_element(reader, "packageTypes")) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<packageTypes> elements are not supported in Chocolatey CLI."); | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/chocolatey/infrastructure.app/rules/ReadmeMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System.Collections.Generic; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class ReadmeMetadataRule : IMetadataRule | ||
{ | ||
public IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
if (!(reader.GetReadme() is null)) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<readme> elements are not supported in Chocolatey CLI."); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/chocolatey/infrastructure.app/rules/RepositoryMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class RepositoryMetadataRule : MetadataRuleBase | ||
{ | ||
public override IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
var metadataNode = reader.Xml.Root.Elements().FirstOrDefault(e => StringComparer.Ordinal.Equals(e.Name.LocalName, "metadata")); | ||
|
||
if (has_element(reader, "repository")) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<repository> elements are not supported in Chocolatey CLI, use <packageSourceUrl> instead."); | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/chocolatey/infrastructure.app/rules/ServicableMetadataRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2023-Present Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.rules | ||
{ | ||
using System.Collections.Generic; | ||
using chocolatey.infrastructure.rules; | ||
using NuGet.Packaging; | ||
|
||
internal sealed class ServicableMetadataRule : MetadataRuleBase | ||
{ | ||
public override IEnumerable<RuleResult> validate(NuspecReader reader) | ||
{ | ||
if (has_element(reader, "serviceable")) | ||
{ | ||
yield return new RuleResult(RuleType.Error, "<serviceable> elements are not supported in Chocolatey CLI."); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.