Skip to content

Commit

Permalink
Added method EqualsIgnoreCase (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorfire authored Jun 5, 2019
1 parent fdf88c3 commit 2822c44
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Oryx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedCodeGenerator", "buil
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{2AA826A1-5647-46B2-9885-20E89050653F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oryx.Common.Test", "tests\Oryx.Common.Test\Oryx.Common.Test.csproj", "{48391B54-0D43-4E49-94C6-727B47F7C416}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oryx.Common.Tests", "tests\Oryx.Common.Tests\Oryx.Common.Tests.csproj", "{48391B54-0D43-4E49-94C6-727B47F7C416}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 2 additions & 2 deletions src/BuildScriptGenerator/BuildPropertiesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license.
// --------------------------------------------------------------------------------------------

using System;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator
{
Expand All @@ -19,7 +19,7 @@ public static bool IsTrue(string propertyKeyName, BuildScriptGeneratorContext co
return true;
}

if (string.Equals("true", value, StringComparison.InvariantCultureIgnoreCase))
if (value.EqualsIgnoreCase("true"))
{
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/BuildScriptGenerator/DefaultBuildScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Oryx.BuildScriptGenerator.Exceptions;
using Microsoft.Oryx.Common;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator
{
Expand Down Expand Up @@ -133,7 +134,7 @@ public IList<Tuple<IProgrammingPlatform, string>> GetCompatiblePlatforms(BuildSc
if (!string.IsNullOrEmpty(ctx.Language))
{
var selectedPlatform = enabledPlatforms
.Where(p => string.Equals(ctx.Language, p.Name, StringComparison.OrdinalIgnoreCase))
.Where(p => ctx.Language.EqualsIgnoreCase(p.Name))
.FirstOrDefault();

if (selectedPlatform == null)
Expand Down
16 changes: 7 additions & 9 deletions src/BuildScriptGenerator/DefaultEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Oryx.Common;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator
{
Expand Down Expand Up @@ -40,16 +41,13 @@ public EnvironmentType Type
public bool? GetBoolEnvironmentVariable(string name)
{
var variable = GetEnvironmentVariable(name);
if (!string.IsNullOrEmpty(variable))
if (variable.EqualsIgnoreCase("true"))
{
if (variable.Equals("true", StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
else if (variable.Equals("false", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
return true;
}
else if (variable.EqualsIgnoreCase("false"))
{
return false;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Oryx.BuildScriptGenerator.Exceptions;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
{
Expand Down Expand Up @@ -166,7 +167,7 @@ internal static bool IsAspNetCoreWebApplicationProject(XDocument projectFileDoc)
DotNetCoreConstants.ProjectSdkElementNameAttributeValueXPathExpression);
sdkName = sdkNameAttributeValue as string;

return string.Equals(sdkName, expectedWebSdkName, StringComparison.OrdinalIgnoreCase);
return sdkName.EqualsIgnoreCase(expectedWebSdkName);
}

// To enable unit testing
Expand Down
7 changes: 4 additions & 3 deletions src/BuildScriptGenerator/Node/NodePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Oryx.BuildScriptGenerator.SourceRepo;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator.Node
{
Expand Down Expand Up @@ -368,7 +369,7 @@ private static bool ShouldPruneDevDependencies(BuildScriptGeneratorContext conte
if (context.Properties != null &&
context.Properties.TryGetValue(PruneDevDependenciesPropertyKey, out string value))
{
if (string.IsNullOrWhiteSpace(value) || string.Equals("true", value, StringComparison.InvariantCultureIgnoreCase))
if (string.IsNullOrWhiteSpace(value) || value.EqualsIgnoreCase("true"))
{
ret = true;
}
Expand Down Expand Up @@ -428,13 +429,13 @@ private static bool GetNodeModulesPackOptions(
{
// default to tar.gz if the property was provided with no value.
if (string.IsNullOrEmpty(compressNodeModulesOption) ||
string.Equals(compressNodeModulesOption, TarGzNodeModulesOption, StringComparison.InvariantCultureIgnoreCase))
compressNodeModulesOption.EqualsIgnoreCase(TarGzNodeModulesOption))
{
compressedNodeModulesFileName = NodeConstants.NodeModulesTarGzFileName;
compressNodeModulesCommand = $"tar -zcf";
isNodeModulesPackaged = true;
}
else if (string.Equals(compressNodeModulesOption, ZipNodeModulesOption, StringComparison.InvariantCultureIgnoreCase))
else if (compressNodeModulesOption.EqualsIgnoreCase(ZipNodeModulesOption))
{
compressedNodeModulesFileName = NodeConstants.NodeModulesZippedFileName;
compressNodeModulesCommand = $"zip -y -q -r";
Expand Down
9 changes: 4 additions & 5 deletions src/BuildScriptGenerator/Python/PythonPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Oryx.BuildScriptGenerator.Exceptions;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator.Python
{
Expand Down Expand Up @@ -260,17 +261,15 @@ private static bool GetVirtualEnvPackOptions(
{
// default to tar.gz if the property was provided with no value.
if (string.IsNullOrEmpty(compressVirtualEnvOption) ||
string.Equals(
compressVirtualEnvOption, TarGzOption, StringComparison.InvariantCultureIgnoreCase))
compressVirtualEnvOption.EqualsIgnoreCase(TarGzOption))
{
compressedVirtualEnvFileName = string.Format(
PythonConstants.TarGzVirtualEnvFileNameFormat,
virtualEnvName);
compressVirtualEnvCommand = $"tar -zcf";
isVirtualEnvPackaged = true;
}
else if (string.Equals(
compressVirtualEnvOption, ZipOption, StringComparison.InvariantCultureIgnoreCase))
else if (compressVirtualEnvOption.EqualsIgnoreCase(ZipOption))
{
compressedVirtualEnvFileName = string.Format(
PythonConstants.ZipVirtualEnvFileNameFormat,
Expand All @@ -289,7 +288,7 @@ private bool IsCollectStaticEnabled()
var enableCollectStatic = true;
var disableCollectStaticEnvValue = _environment.GetEnvironmentVariable(
EnvironmentSettingsKeys.DisableCollectStatic);
if (string.Equals(disableCollectStaticEnvValue, "true", StringComparison.OrdinalIgnoreCase))
if (disableCollectStaticEnvValue.EqualsIgnoreCase("true"))
{
enableCollectStatic = false;
}
Expand Down
9 changes: 4 additions & 5 deletions src/BuildScriptGenerator/RunScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Oryx.BuildScriptGenerator.Exceptions;
using Microsoft.Oryx.Common.Extensions;

namespace Microsoft.Oryx.BuildScriptGenerator
{
Expand All @@ -21,11 +22,9 @@ public RunScriptGenerator(IEnumerable<IProgrammingPlatform> programmingPlatforms

public string GenerateBashScript(string targetPlatformName, RunScriptGeneratorOptions options)
{
var targetPlatform = _programmingPlatforms.Where(
p => string.Equals(
p.Name,
targetPlatformName,
StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
var targetPlatform = _programmingPlatforms
.Where(p => p.Name.EqualsIgnoreCase(targetPlatformName))
.FirstOrDefault();

if (targetPlatform == null)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static class StringExtensions

private static readonly string UrlUserInfoReplacement = "***";

public static bool EqualsIgnoreCase(this string a, string b)
{
return string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Replaces the userinfo subcomponent of URLs in a string with asterisks.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.Oryx.Tests.Common;
using Xunit;

namespace Microsoft.Oryx.Common.Test
namespace Microsoft.Oryx.Common.Tests
{
public class OryxDirectoryStructureHelperTest : IClassFixture<TestTempDirTestFixture>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ namespace Microsoft.Oryx.Common.Extensions
{
public class StringExtensionsTest
{
[Fact]
public void EqualsIgnoreCase_Sanity()
{
Assert.True("abc".EqualsIgnoreCase("aBc"));

Assert.True("abc".EqualsIgnoreCase("ABC"));

Assert.False("bl".EqualsIgnoreCase("bla"));

string s = null;
Assert.False(s.EqualsIgnoreCase("bla"));
Assert.False("bla".EqualsIgnoreCase(s));
}

[Fact]
public void Chunkify_Sanity()
{
Expand Down

0 comments on commit 2822c44

Please sign in to comment.