Merge pull request #4233 from livarcocc/migrate_packOptions
Adding migrate PackOptions capabilities.
This commit is contained in:
commit
a0aa51777f
4 changed files with 324 additions and 9 deletions
|
|
@ -1,16 +1,7 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Build.Evaluation;
|
||||
using Microsoft.Build.Construction;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration
|
||||
{
|
||||
|
|
@ -21,6 +12,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
new MigrateRootOptionsRule(),
|
||||
new MigrateTFMRule(),
|
||||
new MigrateBuildOptionsRule(),
|
||||
new MigratePackOptionsRule(),
|
||||
new MigrateRuntimeOptionsRule(),
|
||||
new MigratePublishOptionsRule(),
|
||||
new MigrateProjectDependenciesRule(),
|
||||
|
|
|
|||
|
|
@ -31,5 +31,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
|
||||
public static Func<string, MigrationError> MIGRATE20013
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20013), "Non-Csharp App", message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE20018
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20018), "Files specified under PackOptions", message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.ProjectJsonMigration;
|
||||
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||
{
|
||||
public class MigratePackOptionsRule : IMigrationRule
|
||||
{
|
||||
private AddPropertyTransform<PackOptions> TagsTransform => new AddPropertyTransform<PackOptions>(
|
||||
"PackageTags",
|
||||
packOptions => string.Join(";", packOptions.Tags),
|
||||
packOptions => packOptions.Tags != null && packOptions.Tags.Any());
|
||||
|
||||
private AddPropertyTransform<PackOptions> ReleaseNotesTransform => new AddPropertyTransform<PackOptions>(
|
||||
"PackageReleaseNotes",
|
||||
packOptions => packOptions.ReleaseNotes,
|
||||
packOptions => !string.IsNullOrEmpty(packOptions.ReleaseNotes));
|
||||
|
||||
private AddPropertyTransform<PackOptions> IconUrlTransform => new AddPropertyTransform<PackOptions>(
|
||||
"PackageIconUrl",
|
||||
packOptions => packOptions.IconUrl,
|
||||
packOptions => !string.IsNullOrEmpty(packOptions.IconUrl));
|
||||
|
||||
private AddPropertyTransform<PackOptions> ProjectUrlTransform => new AddPropertyTransform<PackOptions>(
|
||||
"PackageProjectUrl",
|
||||
packOptions => packOptions.ProjectUrl,
|
||||
packOptions => !string.IsNullOrEmpty(packOptions.ProjectUrl));
|
||||
|
||||
private AddPropertyTransform<PackOptions> LicenseUrlTransform => new AddPropertyTransform<PackOptions>(
|
||||
"PackageLicenseUrl",
|
||||
packOptions => packOptions.LicenseUrl,
|
||||
packOptions => !string.IsNullOrEmpty(packOptions.LicenseUrl));
|
||||
|
||||
private AddPropertyTransform<PackOptions> RequireLicenseAcceptanceTransform => new AddPropertyTransform<PackOptions>(
|
||||
"PackageRequireLicenseAcceptance",
|
||||
packOptions => packOptions.RequireLicenseAcceptance.ToString().ToLower(),
|
||||
packOptions => true);
|
||||
|
||||
private AddPropertyTransform<PackOptions> RepositoryTypeTransform => new AddPropertyTransform<PackOptions>(
|
||||
"RepositoryType",
|
||||
packOptions => packOptions.RepositoryType,
|
||||
packOptions => !string.IsNullOrEmpty(packOptions.RepositoryType));
|
||||
|
||||
private AddPropertyTransform<PackOptions> RepositoryUrlTransform => new AddPropertyTransform<PackOptions>(
|
||||
"RepositoryUrl",
|
||||
packOptions => packOptions.RepositoryUrl,
|
||||
packOptions => !string.IsNullOrEmpty(packOptions.RepositoryUrl));
|
||||
|
||||
private readonly ITransformApplicator _transformApplicator;
|
||||
|
||||
private List<AddPropertyTransform<PackOptions>> _propertyTransforms;
|
||||
|
||||
public MigratePackOptionsRule(ITransformApplicator transformApplicator = null)
|
||||
{
|
||||
_transformApplicator = transformApplicator ?? new TransformApplicator();
|
||||
|
||||
ConstructTransformLists();
|
||||
}
|
||||
|
||||
private void ConstructTransformLists()
|
||||
{
|
||||
_propertyTransforms = new List<AddPropertyTransform<PackOptions>>()
|
||||
{
|
||||
TagsTransform,
|
||||
ReleaseNotesTransform,
|
||||
IconUrlTransform,
|
||||
ProjectUrlTransform,
|
||||
LicenseUrlTransform,
|
||||
RequireLicenseAcceptanceTransform,
|
||||
RepositoryTypeTransform,
|
||||
RepositoryUrlTransform
|
||||
};
|
||||
}
|
||||
|
||||
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
|
||||
{
|
||||
var propertyGroup = migrationRuleInputs.CommonPropertyGroup;
|
||||
|
||||
var projectContext = migrationRuleInputs.DefaultProjectContext;
|
||||
var packOptions = projectContext.ProjectFile.PackOptions;
|
||||
|
||||
if(packOptions.PackInclude != null)
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE20018("Migrating projects with Files specified in PackOptions is not supported.").Throw();
|
||||
}
|
||||
|
||||
foreach (var propertyTransfrom in _propertyTransforms)
|
||||
{
|
||||
_transformApplicator.Execute(propertyTransfrom.Transform(packOptions), propertyGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue