more migration loc

This commit is contained in:
Piotr Puszkiewicz 2016-12-16 20:47:54 -08:00 committed by Livar Cunha
parent 5cfed1a787
commit 91061c2296
7 changed files with 84 additions and 30 deletions

View file

@ -15,12 +15,20 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string NullMSBuildProjectTemplateError = "Expected non-null MSBuildProjectTemplate in MigrationSettings";
public const string ExecutingMigrationRule = "{0}: Executing migration rule {1}";
public const string CannotMigrateProjectWithCompilerError = "Cannot migrate project {0} using compiler {1}";
public const string ExpectedElementToBeOfTypeNotTypeError = "Expected element to be of type {0}, but got {1}";
public const string ProjAlreadyExistsError = "{0} already exists. Has migration already been run?";
public const string NullDestinationElementError = "expected destinationElement to not be null";
public const string DiagnosticMessageTemplate = "{0} (line: {1}, file: {2})";
public const string CannotMergeItemsOfDifferentTypesError = "Cannot merge items of different types.";
public const string CannotMergeItemsWithoutCommonIncludeError = "Cannot merge items without a common include.";
public const string MIGRATE1011 = "Deprecated Project";
public const string MIGRATE1012 = "Project not Restored";
@ -37,6 +45,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string MIGRATE1016 = "Unsupported Script Variable";
public const string MIGRATE1016Arg = "{0} is currently an unsupported script variable for project migration";
public const string MIGRATE1017 = "Multiple Xproj Files";
public const string MIGRATE1018 = "Dependency Project not found";
@ -45,6 +55,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string MIGRATE1019 = "Unsupported Script Event Hook";
public const string MIGRATE1019Arg = "{0} is an unsupported script event hook for project migration";
public const string MIGRATE20011 = "Multi-TFM";
public const string MIGRATE20012 = "Configuration Exclude";
@ -66,5 +78,39 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string AddingMetadataToItem = "{0}: Adding metadata to {1} item: {{ {2}, {3}, {4} }}";
public const string SkipMigrationAlreadyMigrated = "{0}: Skip migrating {1}, it is already migrated.";
public const string ExecutingRule = "Executing rule: {0}";
public const string NoConfigurationOrFrameworkFoundInProject = "{0}: No configuration or framework build options found in project";
public const string MigratingCountTargetFrameworks = "Migrating {0} target frameworks";
public const string MigratingFramework = "Migrating framework {0}";
public const string ImportsTransformNullFor = "{0}: imports transform null for {1}";
public const string MigratingCountXprojToCsprojReferences = "{0}: Migrating {1} xproj to csproj references";
public const string ExecutingMigrationRule = "{0}: Executing migration rule {1}";
public const string ItemTransformApplicatorHeader = "{0}: Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4}, Update: {5} }}";
public const string ItemTransformApplicatorItemGroup = "{0}: ItemGroup {{ Condition: {1} }}";
public const string ItemTransformAppliatorItemCompletelyMerged = "{0}: Item completely merged";
public const string ItemTransformApplicatorAddItemHeader = "{0}: AddItemToItemGroup {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4}, Update: {5} }}";
public const string ItemTransformApplicatorMergingItemWithExistingItems = "{0}: Merging Item with {1} existing items with a different condition chain.";
public const string ItemTransformApplicatorEncompassedIncludes = "{0}: encompassed includes {1}";
public const string ItemTransformApplicatorRemovingItem = "{0}: Removing Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4} }}";
public const string ItemTransformApplicatorIgnoringItem = "{0}: Ignoring Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4} }}";
public const string ItemTransformApplicatorMergingItemWithExistingItemsSameChain = "{0}: Merging Item with {1} existing items with the same condition chain.";
public const string ItemTransformApplicatorAddingMergedItem = "{0}: Adding Merged Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4} }}";
}
}

View file

@ -1,6 +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 System.Linq;
using Microsoft.Build.Construction;
@ -13,7 +14,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
{
MigrationTrace.Instance.WriteLine($"Executing rule: {nameof(MigrateConfigurationsRule)}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ExecutingRule, nameof(MigrateConfigurationsRule)));
var projectContext = migrationRuleInputs.DefaultProjectContext;
var configurations = projectContext.ProjectFile.GetConfigurations().ToList();
@ -22,7 +23,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if (!configurations.Any() && !frameworks.Any())
{
MigrationTrace.Instance.WriteLine($"{nameof(MigrateConfigurationsRule)}: No configuration or framework build options found in project");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.NoConfigurationOrFrameworkFoundInProject, nameof(MigrateConfigurationsRule)));
return;
}

View file

@ -55,10 +55,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
migrationSettings.SolutionFile,
itemGroup: noFrameworkPackageReferenceItemGroup);
MigrationTrace.Instance.WriteLine($"Migrating {targetFrameworks.Count()} target frameworks");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingCountTargetFrameworks, targetFrameworks.Count()));
foreach (var targetFramework in targetFrameworks)
{
MigrationTrace.Instance.WriteLine($"Migrating framework {targetFramework.FrameworkName.GetShortFolderName()}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingFramework, targetFramework.FrameworkName.GetShortFolderName()));
MigrateImports(migrationRuleInputs.CommonPropertyGroup, targetFramework);
@ -172,7 +172,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
}
else
{
MigrationTrace.Instance.WriteLine($"{nameof(MigratePackageDependenciesAndToolsRule)}: imports transform null for {targetFramework.FrameworkName.GetShortFolderName()}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ImportsTransformNullFor, nameof(MigratePackageDependenciesAndToolsRule), targetFramework.FrameworkName.GetShortFolderName()));
}
}

View file

@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
csprojTransformedReferences.Add(transformItem);
}
MigrationTrace.Instance.WriteLine($"{nameof(MigrateProjectDependenciesRule)}: Migrating {csprojTransformedReferences.Count()} xproj to csproj references");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingCountXprojToCsprojReferences, nameof(MigrateProjectDependenciesRule), csprojTransformedReferences.Count()));
foreach (var csprojTransformedReference in csprojTransformedReferences)
{

View file

@ -1,6 +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.IO;
namespace Microsoft.DotNet.ProjectJsonMigration.Rules
@ -20,7 +21,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if (File.Exists(outputRuntimeOptionsFile))
{
MigrationErrorCodes.MIGRATE1015(
$"{outputRuntimeOptionsFile} already exists. Has migration already been run?").Throw();
String.Format(LocalizableStrings.ProjAlreadyExistsError, outputRuntimeOptionsFile)).Throw();
}
File.WriteAllText(outputRuntimeOptionsFile, raw);

View file

@ -65,7 +65,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if (ScriptVariableToMSBuildMap[key] == null)
{
MigrationErrorCodes.MIGRATE1016(
$"{key} is currently an unsupported script variable for project migration")
String.Format(LocalizableStrings.MIGRATE1016Arg, key))
.Throw();
}
@ -102,7 +102,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if(!ScriptSetToMSBuildHookTargetMap.TryGetValue(scriptSetName, out targetHookInfo))
{
MigrationErrorCodes.MIGRATE1019(
$"{scriptSetName} is an unsupported script event hook for project migration")
String.Format(LocalizableStrings.MIGRATE1019Arg, scriptSetName))
.Throw();
}

View file

@ -19,12 +19,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{
if (typeof(T) != typeof(ProjectItemElement))
{
throw new ArgumentException($"Expected element to be of type {nameof(ProjectItemElement)}, but got {typeof(T)}");
throw new ArgumentException(String.Format(LocalizableStrings.ExpectedElementToBeOfTypeNotTypeError, nameof(ProjectItemElement), typeof(T)));
}
if (typeof(U) != typeof(ProjectItemGroupElement))
{
throw new ArgumentException($"Expected destinationElement to be of type {nameof(ProjectItemGroupElement)}, but got {typeof(U)}");
throw new ArgumentException(String.Format(LocalizableStrings.ExpectedElementToBeOfTypeNotTypeError, nameof(ProjectItemGroupElement), typeof(U)));
}
if (element == null)
@ -34,14 +34,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
if (destinationElement == null)
{
throw new ArgumentException("expected destinationElement to not be null");
throw new ArgumentException(LocalizableStrings.NullDestinationElementError);
}
var item = element as ProjectItemElement;
var destinationItemGroup = destinationElement as ProjectItemGroupElement;
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item {{ ItemType: {item.ItemType}, Condition: {item.Condition}, Include: {item.Include}, Exclude: {item.Exclude}, Update: {item.Update} }}");
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: ItemGroup {{ Condition: {destinationItemGroup.Condition} }}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorHeader, nameof(ItemTransformApplicator), item.ItemType, item.Condition, item.Include, item.Exclude, item.Update));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorItemGroup, nameof(ItemTransformApplicator), destinationItemGroup.Condition));
if (mergeExisting)
{
@ -49,7 +49,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
item = MergeWithExistingItemsWithSameCondition(item, destinationItemGroup);
if (item == null)
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item completely merged");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformAppliatorItemCompletelyMerged, nameof(ItemTransformApplicator)));
return;
}
@ -57,14 +57,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
item = MergeWithExistingItemsWithNoCondition(item, destinationItemGroup);
if (item == null)
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item completely merged");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformAppliatorItemCompletelyMerged, nameof(ItemTransformApplicator)));
return;
}
item = MergeWithExistingItemsWithACondition(item, destinationItemGroup);
if (item == null)
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item completely merged");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformAppliatorItemCompletelyMerged, nameof(ItemTransformApplicator)));
return;
}
}
@ -88,7 +88,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var outputItem = itemGroup.ContainingProject.CreateItemElement("___TEMP___");
outputItem.CopyFrom(item);
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: AddItemToItemGroup {{ ItemType: {outputItem.ItemType}, Condition: {outputItem.Condition}, Include: {outputItem.Include}, Exclude: {outputItem.Exclude}, Update: {outputItem.Update} }}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorAddItemHeader, nameof(ItemTransformApplicator), outputItem.ItemType, outputItem.Condition, outputItem.Include, outputItem.Exclude, outputItem.Update));
itemGroup.AppendChild(outputItem);
outputItem.AddMetadata(item.Metadata);
@ -105,7 +105,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var existingItemsWithACondition =
FindExistingItemsWithACondition(item, destinationItemGroup.ContainingProject, destinationItemGroup);
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Merging Item with {existingItemsWithACondition.Count()} existing items with a different condition chain.");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorMergingItemWithExistingItems, nameof(ItemTransformApplicator), existingItemsWithACondition.Count()));
foreach (var existingItem in existingItemsWithACondition)
{
@ -113,14 +113,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var encompassedIncludes = item.GetEncompassedIncludes(existingItem);
if (encompassedIncludes.Any())
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: encompassed includes {string.Join(", ", encompassedIncludes)}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes)));
existingItem.RemoveIncludes(encompassedIncludes);
}
// continue if the existing item is now empty
if (!existingItem.Includes().Any())
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Removing Item {{ ItemType: {existingItem.ItemType}, Condition: {existingItem.Condition}, Include: {existingItem.Include}, Exclude: {existingItem.Exclude} }}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorRemovingItem, nameof(ItemTransformApplicator), existingItem.ItemType, existingItem.Condition, existingItem.Include, existingItem.Exclude));
existingItem.Parent.RemoveChild(existingItem);
continue;
}
@ -172,7 +172,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var existingItemsWithNoCondition =
FindExistingItemsWithNoCondition(item, destinationItemGroup.ContainingProject, destinationItemGroup);
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Merging Item with {existingItemsWithNoCondition.Count()} existing items with a different condition chain.");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorMergingItemWithExistingItems, nameof(ItemTransformApplicator), existingItemsWithNoCondition.Count()));
// Handle the item being placed inside of a condition, when it is overlapping with a conditionless item
// If it is not definining new metadata or excludes, the conditioned item can be merged with the
@ -182,11 +182,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var encompassedIncludes = existingItem.GetEncompassedIncludes(item);
if (encompassedIncludes.Any())
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: encompassed includes {string.Join(", ", encompassedIncludes)}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes)));
item.RemoveIncludes(encompassedIncludes);
if (!item.Includes().Any())
{
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Ignoring Item {{ ItemType: {existingItem.ItemType}, Condition: {existingItem.Condition}, Include: {existingItem.Include}, Exclude: {existingItem.Exclude} }}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorIgnoringItem, nameof(ItemTransformApplicator), existingItem.ItemType, existingItem.Condition, existingItem.Include, existingItem.Exclude));
return null;
}
}
@ -225,7 +225,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var existingItemsWithSameCondition =
FindExistingItemsWithSameCondition(item, destinationItemGroup.ContainingProject, destinationItemGroup);
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: Merging Item with {existingItemsWithSameCondition.Count()} existing items with the same condition chain.");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorMergingItemWithExistingItemsSameChain, nameof(TransformApplicator), existingItemsWithSameCondition.Count()));
foreach (var existingItem in existingItemsWithSameCondition)
{
@ -238,7 +238,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
existingItem.Parent.RemoveChild(existingItem);
}
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: Adding Merged Item {{ ItemType: {mergeResult.MergedItem.ItemType}, Condition: {mergeResult.MergedItem.Condition}, Include: {mergeResult.MergedItem.Include}, Exclude: {mergeResult.MergedItem.Exclude} }}");
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorAddingMergedItem,
nameof(TransformApplicator),
mergeResult.MergedItem.ItemType,
mergeResult.MergedItem.Condition,
mergeResult.MergedItem.Include,
mergeResult.MergedItem.Exclude));
AddItemToItemGroup(mergeResult.MergedItem, destinationItemGroup);
}
@ -261,12 +266,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{
if (!string.Equals(item.ItemType, existingItem.ItemType, StringComparison.Ordinal))
{
throw new InvalidOperationException("Cannot merge items of different types.");
throw new InvalidOperationException(LocalizableStrings.CannotMergeItemsOfDifferentTypesError);
}
if (!item.IntersectIncludes(existingItem).Any())
{
throw new InvalidOperationException("Cannot merge items without a common include.");
throw new InvalidOperationException(LocalizableStrings.CannotMergeItemsWithoutCommonIncludeError);
}
var commonIncludes = item.IntersectIncludes(existingItem).ToList();