Skip to content

Commit 252f4d8

Browse files
authored
Merge pull request #413 from Microsoft/users/tihuang/moneysaver
remove extra loc strings.
2 parents 5009d0a + d2399cc commit 252f4d8

File tree

3 files changed

+72
-24
lines changed

3 files changed

+72
-24
lines changed

src/Agent.Worker/TaskCommandExtension.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private void ProcessTaskUploadFileCommand(IExecutionContext context, string data
248248
}
249249
else
250250
{
251-
throw new Exception("CannotUploadFile");
251+
throw new Exception(StringUtil.Loc("CannotUploadFile"));
252252
}
253253
}
254254

src/Misc/layoutbin/en-US/strings.json

-18
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@
2727
"BuildTagRequired": "Build tag is required.",
2828
"BuildTagsForBuild": "Build '{0}' has following tags now: {1}",
2929
"CannotChangeParentTimelineRecord": "Can't change parent timeline record of an existing timeline record.",
30-
"CannotChangePermission": "Cannot change permission of configuration store, report this error. You can still run the agent in interactive mode",
31-
"CanNotFindLoginUserName": "Cannot find logged in username",
3230
"CanNotFindService": "Cannot find service {0}",
3331
"CanNotFindSystemd": "Cannot find if systemd is installed",
3432
"CanNotGrantPermission": "Cannot grant LogonAsService permission to the user {0}",
35-
"CanNotInstallService": "Cannot install the service, check the logs for more details ",
36-
"CanNotRunAgent": "Cannot run. Must configure first.",
37-
"CanNotSetPermissionForAccount": "Cannot set permission for service account. Check the logs for more details.",
3833
"CanNotStartService": "Cannot start the service. Check the logs for more details.",
3934
"CanNotStopService": "Cannot stop the service {0} in a timely fashion. Please stop the service and reconfigure again.",
4035
"CannotUploadFile": "Cannot upload file because file location is not specified.",
@@ -72,7 +67,6 @@
7267
"EulasSectionHeader": "End User License Agreements",
7368
"Failed": "Failed: ",
7469
"FailedDeletingTempDirectory0Message1": "Failed to delete temporary directory '{0}'. {1}",
75-
"FailedToConfigureService": "Service configuration failed, try configuring again after resolving the error",
7670
"FailedToConnect": "Failed to connect. Try again or ctrl-c to quit",
7771
"FailedToDeleteTempScript": "Failed to delete temporary inline script file '{0}'. {1}",
7872
"FailedToFindPool": "Failed to find pool name. Try again or ctrl-c to quit",
@@ -81,7 +75,6 @@
8175
"FailedToOpenSCManager": "Failed to Open Service Control Manager",
8276
"FailedToPublishTestResults": "Failed to publish test results: {0}",
8377
"FailedToReadFile": "Failed to read {0}. Error : {1}.",
84-
"FailedToRemoveService": "Cannot remove the service, remove the service manually and configure again",
8578
"FailedToReplaceAgent": "Failed to replace the agent. Try again or ctrl-c to quit",
8679
"FileContainerUploadFailed": "Unable to copy file to server StatusCode={0}: {1}. Source file path: {2}. Target server path: {3}",
8780
"FileDoesNotExist": "File '{0}' does not exist or is not accessible.",
@@ -90,7 +83,6 @@
9083
"FileUploadProgress": "Total file: {0} ---- Uploaded file: {1}",
9184
"GetSources": "Get Sources",
9285
"GroupDoesNotExists": "Group: {0} does not Exist",
93-
"InstalledGitNotSupport": "The version of the installed Git is less than min-supported Git version {0}.",
9486
"InvalidBuildOrCoverageTool": "An internal error occurred. Details: Invalid build or code coverage tool provided. Build tool = '{0}'. Coverage tool = '{1}'. ",
9587
"InvalidBuildXml": "Invalid build xml '{0}'. Error '{1}' occured while parsing the file. Ensure the file provided is well-formed and try again.",
9688
"InvalidClassFilesDirectory": "Invalid input for 'Class Files Directory' field. It should not be a regular expression or a file path. 'Class Files Directory' accepts comma seperated list of class directories.",
@@ -108,8 +100,6 @@
108100
"InvalidWindowsCredential": "Invalid windows credentials entered. Try again or ctrl-c to quit",
109101
"IsMultiModuleParameterNotAvailable": "Parameter IsMultiModule is not available. Considering the project as a single module project.",
110102
"JobCompleted": "{0:u}: Job {1} completed with result: {2}",
111-
"LinuxServiceConfigured": "Service {0} successfully configured",
112-
"LinuxServiceStartFailed": "Could not start the service. Start the service manually",
113103
"ListenerHelp": [
114104
"Visual Studio Team Services Agent",
115105
"Copyright (c) Microsoft Corporation",
@@ -252,13 +242,11 @@
252242
"RenameIndexFileCoberturaFailed": "Renaming '{0}' to '{1}' failed while publishing code coverage files for '{2}'. Inner Exception: '{3}'",
253243
"Replace": "replace? (Y/N)",
254244
"ResultsCommandNotFound": "##vso[results.{0}] is not a recognized command for Task command extension. TODO: DOC aka link",
255-
"RMAgentVariableInfo": "ReleaseId={0}, TeamProjectId={1}, ReleaseDefinitionName={2}",
256245
"RMArtifactDetailsIncomplete": "Cannot find the required information to download the artifact",
257246
"RMArtifactDirectoryNotFoundError": "The artifact directory does not exist: {0}",
258247
"RMArtifactDownloadBegin": "Downloading linked artifact {0} of type {1}...",
259248
"RMArtifactDownloadFinished": "Downloaded linked artifact {0}",
260249
"RMArtifactFolderCreated": "Created artifact folder {0}",
261-
"RMArtifactIsNotContainerType": "The following is not a server drop artifact: {0}",
262250
"RMArtifactMatchNotFound": "The build artifact '{0}' does not match any naming patterns, skipping download",
263251
"RMArtifactNameDirectoryNotFound": "Directory '{0}' does not exist. Falling back to parent directory: {1}",
264252
"RMArtifactsDownloadFinished": "Finished artifacts download",
@@ -273,7 +261,6 @@
273261
"RMGitEndpointNotFound": "Cannot find required information in the job to download the Team Foundation Git artifact.",
274262
"RMGitHubEndpointNotFound": "Cannot find required information in the job to download the GitHub artifact: {0}",
275263
"RMGotJenkinsArtifactDetails": "Received Jenkins Artifact Details",
276-
"RMInitializeTask": "Initialize",
277264
"RMJenkinsBuildId": "BuildId: {0}",
278265
"RMJenkinsEndpointNotFound": "Cannot find required information in the job to download the Jenkins artifact: {0}",
279266
"RMJenkinsJobName": "Job Name: {0}",
@@ -291,7 +278,6 @@
291278
"RunAgentAsServiceDescription": "run agent as service? (Y/N)",
292279
"RunningJob": "{0:u}: Running job: {1}",
293280
"SavedSettings": "{0:u}: Settings Saved.",
294-
"SavingCredential": "Saving credentials...",
295281
"ScanToolCapabilities": "Scanning for tool capabilities.",
296282
"SelfManageGitCreds": "You are in self manage git creds mode. Make sure your agent host machine can bypass any git authentication challenge.",
297283
"ServerUrl": "server URL",
@@ -322,8 +308,6 @@
322308
"SvnMappingIgnored": "The entire mapping set is ignored. Proceeding with the full branch mapping.",
323309
"SvnNotInstalled": "Can't find installed svn command line utility",
324310
"SvnSyncingRepo": "Syncing repository: {0} (Svn)",
325-
"SystemdCannotReload": "Cannot reload systemd daemon",
326-
"SystemdDoesNotExists": "Systemd does not exist, if you are having init.d or any other init system you can manually configure it",
327311
"TaskCommandNotFound": "##vso[task.{0}] is not a recognized command for Task command extension. Please reference documentaion (http://go.microsoft.com/fwlink/?LinkId=817296)",
328312
"TeeEula": [
329313
"Building sources from a TFVC repository requires accepting the Team Explorer Everywhere End User License Agreement. This step is not required for building sources from Git repositories.",
@@ -333,13 +317,11 @@
333317
],
334318
"TestAgentConnection": "Testing agent connection.",
335319
"TestResultsRemaining": "Test results remaining: {0}. Test run id: {1}",
336-
"TFSConnectionDownRetrying": "The TFS service is currently unavailable. Error: '{1}'. Retrying to establing a connection - attempt '{0}'.",
337320
"TotalUploadFiles": "Uploading {0} files",
338321
"TypeRequiredForTimelineRecord": "Type is required for this new timeline record.",
339322
"UnableResolveArtifactType": "Can't infer artifact type from artifact location: {0}.",
340323
"UnableToArchiveResults": "Unable to archive the test results: {0}",
341324
"UnableToParseBuildTrackingConfig0": "Unable to parse the legacy build tracking configuration. A new build directory will be created instead. The previous directory may be left in an unreclaimed state. Legacy configuration contents: {0}",
342-
"UnauthorizedAccess": "You do not have access to {0} to create systemd unit file. Did you forget to run with sudo permission?",
343325
"UninstallingService": "Removing service",
344326
"UnknownCodeCoverageTool": "Code coverage tool '{0}' is not supported.",
345327
"UnregisteringAgent": "Removing agent from the server",

src/Test/L0/LocStringsL0.cs

+71-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using Microsoft.VisualStudio.Services.Agent;
21
using Microsoft.VisualStudio.Services.Agent.Util;
3-
using System;
42
using System.Collections.Generic;
5-
using System.Diagnostics;
6-
using System.Globalization;
73
using System.IO;
84
using System.Linq;
95
using System.Text.RegularExpressions;
106
using Xunit;
7+
using System;
118

129
namespace Microsoft.VisualStudio.Services.Agent.Tests
1310
{
@@ -61,11 +58,80 @@ public void IsLocStringsPrettyPrint()
6158
IOUtil.SaveObject(sortedResourceDictionary, prettyStringsFile);
6259

6360
Assert.True(string.Equals(File.ReadAllText(stringsFile), File.ReadAllText(prettyStringsFile)), $"Orginal string.json file: {stringsFile} is not pretty printed, replace it with: {prettyStringsFile}");
64-
61+
6562
// delete file on succeed
6663
File.Delete(prettyStringsFile);
6764
}
6865

66+
[Fact]
67+
[Trait("Level", "L0")]
68+
[Trait("Category", "LocString")]
69+
public void FindExtraLocStrings()
70+
{
71+
// Load the strings.
72+
string stringsFile = Path.Combine(TestUtil.GetSrcPath(), "Misc", "layoutbin", "en-US", "strings.json");
73+
Assert.True(File.Exists(stringsFile), $"File does not exist: {stringsFile}");
74+
var resourceDictionary = IOUtil.LoadObject<Dictionary<string, object>>(stringsFile);
75+
76+
// find all loc string key in source file
77+
var keys = new List<string>();
78+
string[] sourceFiles = Directory.GetFiles(
79+
TestUtil.GetSrcPath(),
80+
"*.cs",
81+
SearchOption.AllDirectories);
82+
foreach (string sourceFile in sourceFiles)
83+
{
84+
// Skip files in the obj directory.
85+
if (sourceFile.Contains(StringUtil.Format("{0}obj{0}", Path.DirectorySeparatorChar)))
86+
{
87+
continue;
88+
}
89+
90+
foreach (string line in File.ReadAllLines(sourceFile))
91+
{
92+
// Search for calls to the StringUtil.Loc method within the line.
93+
const string Pattern = "StringUtil.Loc(";
94+
int searchIndex = 0;
95+
int patternIndex;
96+
while (searchIndex < line.Length &&
97+
(patternIndex = line.IndexOf(Pattern, searchIndex)) >= 0)
98+
{
99+
// Bump the search index in preparation for the for the next iteration within the same line.
100+
searchIndex = patternIndex + Pattern.Length;
101+
102+
// Extract the resource key.
103+
int keyStartIndex = patternIndex + Pattern.Length;
104+
int keyEndIndex;
105+
if (keyStartIndex + 2 < line.Length && // Key should start with a ", be followed by at least
106+
line[keyStartIndex] == '"' && // one character, and end with a ".
107+
(keyEndIndex = line.IndexOf('"', keyStartIndex + 1)) > 0)
108+
{
109+
// Remove the first and last double quotes.
110+
keyStartIndex++;
111+
keyEndIndex--;
112+
string key = line.Substring(
113+
startIndex: keyStartIndex,
114+
length: keyEndIndex - keyStartIndex + 1);
115+
if (ValidKeyRegex.IsMatch(key))
116+
{
117+
// A valid key was extracted.
118+
keys.Add(key);
119+
continue;
120+
}
121+
}
122+
}
123+
}
124+
}
125+
126+
// find extra loc strings.
127+
var extraKeys = resourceDictionary.Keys.Where(x => !keys.Contains(x))?.ToList();
128+
129+
if (extraKeys != null)
130+
{
131+
Assert.True(extraKeys.Count == 0, $"Please save company's money by removing extra loc strings:{Environment.NewLine}{string.Join(Environment.NewLine, extraKeys)}");
132+
}
133+
}
134+
69135
private void ValidateLocStrings(TestHostContext hc, string project)
70136
{
71137
using (hc)

0 commit comments

Comments
 (0)