Localize Migration
This commit is contained in:
parent
e7487cab97
commit
5cfed1a787
7 changed files with 103 additions and 33 deletions
|
@ -33,7 +33,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
{
|
||||
foreach (var rule in Rules)
|
||||
{
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(DefaultMigrationRuleSet)}: Executing migration rule {rule.GetType().Name}");
|
||||
MigrationTrace.Instance.WriteLine(string.Format(LocalizableStrings.ExecutingMigrationRule, nameof(DefaultMigrationRuleSet), rule.GetType().Name));
|
||||
rule.Apply(migrationSettings, migrationRuleInputs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
// 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.
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration
|
||||
{
|
||||
internal class LocalizableStrings
|
||||
{
|
||||
public const string DoubleMigrationError = "Detected double project migration: {0}";
|
||||
|
||||
public const string CannotMergeMetadataError = "Cannot merge metadata with the same name and different values";
|
||||
|
||||
public const string NoXprojFileGivenError = "{0}: No xproj file given.";
|
||||
|
||||
public const string MultipleXprojFilesError = "Multiple xproj files found in {0}, please specify which to use";
|
||||
|
||||
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 DiagnosticMessageTemplate = "{0} (line: {1}, file: {2})";
|
||||
|
||||
public const string MIGRATE1011 = "Deprecated Project";
|
||||
|
||||
public const string MIGRATE1012 = "Project not Restored";
|
||||
|
||||
public const string MIGRATE1013 = "No Project";
|
||||
|
||||
public const string MIGRATE1013Arg = "The project.json specifies no target frameworks in {0}";
|
||||
|
||||
public const string MIGRATE1014 = "Unresolved Dependency";
|
||||
|
||||
public const string MIGRATE1014Arg = "Unresolved project dependency ({0})";
|
||||
|
||||
public const string MIGRATE1015 = "File Overwrite";
|
||||
|
||||
public const string MIGRATE1016 = "Unsupported Script Variable";
|
||||
|
||||
public const string MIGRATE1017 = "Multiple Xproj Files";
|
||||
|
||||
public const string MIGRATE1018 = "Dependency Project not found";
|
||||
|
||||
public const string MIGRATE1018Arg = "Dependency project not found ({0})" ;
|
||||
|
||||
public const string MIGRATE1019 = "Unsupported Script Event Hook";
|
||||
|
||||
public const string MIGRATE20011 = "Multi-TFM";
|
||||
|
||||
public const string MIGRATE20012 = "Configuration Exclude";
|
||||
|
||||
public const string MIGRATE20013 = "Non-Csharp App";
|
||||
|
||||
public const string MIGRATE20018 = "Files specified under PackOptions";
|
||||
|
||||
public const string IncludesNotEquivalent = "{0}.{1} includes not equivalent.";
|
||||
|
||||
public const string ExcludesNotEquivalent = "{0}.{1} excludes not equivalent.";
|
||||
|
||||
public const string RemovesNotEquivalent = "{0}.{1} removes not equivalent.";
|
||||
|
||||
public const string MetadataDoesntExist = "{0}.{1} metadata doesn't exist {{ {2} {3} }}";
|
||||
|
||||
public const string MetadataHasAnotherValue = "{0}.{1} metadata has another value {{ {2} {3} {4} }}";
|
||||
|
||||
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.";
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (item.IntersectIncludes(otherItem).Count() != item.Includes().Count())
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} includes not equivalent.");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.IncludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (item.IntersectExcludes(otherItem).Count() != item.Excludes().Count())
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} excludes not equivalent.");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ExcludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (item.Remove != otherItem.Remove)
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} removes not equivalent.");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.RemovesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (otherMetadata == null)
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} metadata doesn't exist {{ {metadata.Name} {metadata.Value} }}");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataDoesntExist, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (!metadata.ValueEquals(otherMetadata))
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} metadata has another value {{ {metadata.Name} {metadata.Value} {otherMetadata.Value} }}");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataHasAnotherValue, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value, otherMetadata.Value));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -202,13 +202,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
|
||||
if (existingMetadata != default(ProjectMetadataElement) && !existingMetadata.ValueEquals(metadata))
|
||||
{
|
||||
throw new Exception("Cannot merge metadata with the same name and different values");
|
||||
throw new Exception(LocalizableStrings.CannotMergeMetadataError);
|
||||
}
|
||||
|
||||
if (existingMetadata == default(ProjectMetadataElement))
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(AddMetadata)}: Adding metadata to {item.ItemType} item: {{ {metadata.Name}, {metadata.Value}, {metadata.Condition} }}");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.AddingMetadataToItem, nameof(AddMetadata), item.ItemType, metadata.Name, metadata.Value, metadata.Condition));
|
||||
#endif
|
||||
var metametadata = item.AddMetadata(metadata.Name, metadata.Value);
|
||||
metametadata.Condition = metadata.Condition;
|
||||
|
|
|
@ -8,43 +8,43 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
internal static partial class MigrationErrorCodes
|
||||
{
|
||||
public static Func<string, MigrationError> MIGRATE1011
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1011), "Deprecated Project", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1011), LocalizableStrings.MIGRATE1011, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1012
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1012), "Project not Restored", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1012), LocalizableStrings.MIGRATE1012, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1013
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1013), "No Project", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1013), LocalizableStrings.MIGRATE1013, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1014
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1014), "Unresolved Dependency", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1014), LocalizableStrings.MIGRATE1014, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1015
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1015), "File Overwrite", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1015), LocalizableStrings.MIGRATE1015, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1016
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1016), "Unsupported Script Variable", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1016), LocalizableStrings.MIGRATE1016, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1017
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1017), "Multiple Xproj Files", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1017), LocalizableStrings.MIGRATE1017, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1018
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1018), "Dependency Project not found", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1018), LocalizableStrings.MIGRATE1018, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1019
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1019), "Unsupported Script Event Hook", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1019), LocalizableStrings.MIGRATE1019, message);
|
||||
|
||||
// Potentially Temporary (Point in Time) Errors
|
||||
public static Func<string, MigrationError> MIGRATE20011
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20011), "Multi-TFM", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20011), LocalizableStrings.MIGRATE20011, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE20012
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20012), "Configuration Exclude", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20012), LocalizableStrings.MIGRATE20012, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE20013
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20013), "Non-Csharp App", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20013), LocalizableStrings.MIGRATE20013, message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE20018
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20018), "Files specified under PackOptions", message);
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20018), LocalizableStrings.MIGRATE20018, message);
|
||||
}
|
||||
}
|
|
@ -66,7 +66,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (!File.Exists(project.ProjectFilePath))
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE1018($"Dependency project not found ({project.ProjectFilePath})").Throw();
|
||||
.MIGRATE1018(String.Format(LocalizableStrings.MIGRATE1018Arg, project.ProjectFilePath)).Throw();
|
||||
}
|
||||
|
||||
var projectContext =
|
||||
|
@ -140,7 +140,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (projectFileDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project)
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE1014($"Unresolved project dependency ({dependencyName})").Throw();
|
||||
.MIGRATE1014(String.Format(LocalizableStrings.MIGRATE1014Arg, dependencyName)).Throw();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -158,7 +158,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
{
|
||||
if (xproj == null)
|
||||
{
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(ProjectDependencyFinder)}: No xproj file given.");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.NoXprojFileGivenError, nameof(ProjectDependencyFinder)));
|
||||
return Enumerable.Empty<ProjectItemElement>();
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (allXprojFiles.Count() > 1)
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE1017($"Multiple xproj files found in {projectDirectory}, please specify which to use")
|
||||
.MIGRATE1017(String.Format(LocalizableStrings.MultipleXprojFilesError, projectDirectory))
|
||||
.Throw();
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (projectExport.Library.Identity.Type.Equals(LibraryType.Project))
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE1014($"Unresolved project dependency ({projectExportName})").Throw();
|
||||
.MIGRATE1014(String.Format(LocalizableStrings.MIGRATE1014Arg, projectExportName)).Throw();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
{
|
||||
if (IsMigrated(migrationSettings, migrationRuleInputs))
|
||||
{
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(ProjectMigrator)}: Skip migrating {migrationSettings.ProjectDirectory}, it is already migrated.");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.SkipMigrationAlreadyMigrated, nameof(ProjectMigrator), migrationSettings.ProjectDirectory));
|
||||
return new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, skipped: true);
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
var templateMSBuildProject = migrationSettings.MSBuildProjectTemplate;
|
||||
if (templateMSBuildProject == null)
|
||||
{
|
||||
throw new Exception("Expected non-null MSBuildProjectTemplate in MigrationSettings");
|
||||
throw new Exception(LocalizableStrings.NullMSBuildProjectTemplateError);
|
||||
}
|
||||
|
||||
var propertyGroup = templateMSBuildProject.AddPropertyGroup();
|
||||
|
@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
{
|
||||
if (!projectContexts.Any())
|
||||
{
|
||||
MigrationErrorCodes.MIGRATE1013($"The project.json specifies no target frameworks in {projectDirectory}").Throw();
|
||||
MigrationErrorCodes.MIGRATE1013(String.Format(LocalizableStrings.MIGRATE1013Arg, projectDirectory)).Throw();
|
||||
}
|
||||
|
||||
var defaultProjectContext = projectContexts.First();
|
||||
|
@ -202,7 +202,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (diagnostics.Any())
|
||||
{
|
||||
MigrationErrorCodes.MIGRATE1011(
|
||||
$"{projectDirectory}{Environment.NewLine}{string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))}")
|
||||
String.Format("{0}{1}{2}", projectDirectory, Environment.NewLine, string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))))
|
||||
.Throw();
|
||||
}
|
||||
|
||||
|
@ -212,13 +212,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
MigrationErrorCodes.MIGRATE20013(
|
||||
$"Cannot migrate project {defaultProjectContext.ProjectFile.ProjectFilePath} using compiler {compilerName}").Throw();
|
||||
String.Format(LocalizableStrings.CannotMigrateProjectWithCompilerError, defaultProjectContext.ProjectFile.ProjectFilePath, compilerName)).Throw();
|
||||
}
|
||||
}
|
||||
|
||||
private string FormatDiagnosticMessage(DiagnosticMessage d)
|
||||
{
|
||||
return $"{d.Message} (line: {d.StartLine}, file: {d.SourceFilePath})";
|
||||
return String.Format(LocalizableStrings.DiagnosticMessageTemplate, d.Message, d.StartLine, d.SourceFilePath);
|
||||
}
|
||||
|
||||
private void SetupOutputDirectory(string projectDirectory, string outputDirectory)
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
}
|
||||
else if (!report.Skipped)
|
||||
{
|
||||
MigrationTrace.Instance.WriteLine("Detected double project migration: {report.ProjectDirectory}");
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.DoubleMigrationError, report.ProjectDirectory));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue