Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ComponentDetection.Contracts.BcdeModels;
using Microsoft.ComponentDetection.Contracts.BcdeModels;

namespace Microsoft.ComponentDetection.Common
{
/// <summary>
/// Merges dependnecy Scope in their order of Priority.
/// Higher priority scope, as indicated by its lower enum value is given precendence.
/// Merges dependnecy Scope in their order of Priority.
/// Higher priority scope, as indicated by its lower enum value is given precendence.
/// </summary>
public class DependencyScopeComparer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.ComponentDetection.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

// transcribed from https://github.com/containers/image/blob/c1a5f92d0ebbf9e0bf187b3353dd400472b388eb/docker/reference/reference.go
Expand Down Expand Up @@ -67,7 +64,7 @@ public static DockerReference ParseQualifiedName(string qualifiedName)
}

Reference reference = new Reference();

var nameMatch = DockerRegex.AnchoredNameRegexp.Match(name).Groups;
if (nameMatch.Count == 3)
{
Expand Down Expand Up @@ -172,4 +169,4 @@ private static DockerReference CreateDockerReference(Reference options)
return DockerReference.CreateDockerReference(options.Repository, options.Domain, options.Digest, options.Tag);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -71,10 +69,10 @@ public static Regex Capture(params Regex[] regexps)
DomainComponentRegexp,
Optional(
Repeated(
new Regex(@"\."),
new Regex(@"\."),
DomainComponentRegexp)),
Optional(
new Regex(":"),
new Regex(":"),
new Regex("[0-9]+")));

public static Regex AnchoredDigestRegexp = Anchored(DigestRegexp);
Expand Down Expand Up @@ -107,4 +105,4 @@ public static Regex Capture(params Regex[] regexps)

public static Regex AnchoredIdentifierRegexp = Anchored(IdentifierRegexp);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Net;

namespace Microsoft.ComponentDetection.Common.Telemetry.Records
namespace Microsoft.ComponentDetection.Common.Telemetry.Records
{
public class PypiCacheTelemetryRecord : BaseDetectionTelemetryRecord
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.ComponentDetection.Contracts.BcdeModels
namespace Microsoft.ComponentDetection.Contracts.BcdeModels
{
/// <summary>Used to communicate Dependency Scope of Component.
/// Currently only populated for Maven component.
/// <summary>Used to communicate Dependency Scope of Component.
/// Currently only populated for Maven component.
/// The values are ordered in terms of priority, which is used to resolve the scope for duplicate component while merging them.
/// </summary>
public enum DependencyScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Composition;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.ComponentDetection.Common.Telemetry.Records;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Contracts.BcdeModels;
Expand All @@ -10,7 +9,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
{
public static class MavenParsingUtilities
{
private static readonly Dictionary<string, DependencyScope> MavenScopeToDependencyScopeMapping = new Dictionary<string, DependencyScope>()
private static readonly Dictionary<string, DependencyScope> MavenScopeToDependencyScopeMapping = new Dictionary<string, DependencyScope>()
{
{ "compile", DependencyScope.MavenCompile },
{ "provided", DependencyScope.MavenProvided },
Expand Down Expand Up @@ -60,8 +59,8 @@ private static (string groupId, string artifactId, string version, bool? isDevel
{
dependencyScope = MavenScopeToDependencyScopeMapping.TryGetValue(
Regex.Match(results[4], @"^([\w]+)").Value,
out dependencyScope)
? dependencyScope
out dependencyScope)
? dependencyScope
: throw new InvalidOperationException($"Invalid scope ('{results[4]}') found for '{mavenComponentString}' found in generated dependency graph.");
isDevDependency = dependencyScope == DependencyScope.MavenTest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
using System.Composition;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.ComponentDetection.Common;
using Microsoft.ComponentDetection.Common.Telemetry.Records;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Contracts.Internal;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using FluentAssertions;
using FluentAssertions.Primitives;
using Microsoft.ComponentDetection.Contracts.BcdeModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Faker;
using static Microsoft.ComponentDetection.Common.DependencyScopeComparer;
using System.Linq;

namespace Microsoft.ComponentDetection.Common.Tests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.ComponentDetection.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System;

Expand All @@ -26,14 +25,14 @@ public void TestCleanup()

[TestMethod]
public void DoesEnvironmentVariableExist_ChecksAreCaseInsensitive()
{
{
Assert.IsFalse(testSubject.DoesEnvironmentVariableExist("THIS_ENVIRONMENT_VARIABLE_DOES_NOT_EXIST"));

Assert.IsTrue(testSubject.DoesEnvironmentVariableExist(MyEnvVar));
Assert.IsTrue(testSubject.DoesEnvironmentVariableExist(MyEnvVar.ToLower()));
Assert.IsTrue(testSubject.DoesEnvironmentVariableExist(MyEnvVar.ToUpper()));
}

[TestMethod]
public void GetEnvironmentVariable_returnNullIfVariableDoesNotExist()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.ComponentDetection.Detectors.Maven;
using System;
using System.Collections.Generic;
using System.Text;
using static Microsoft.ComponentDetection.Detectors.Maven.MavenParsingUtilities;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using FluentAssertions.Collections;
using Microsoft.ComponentDetection.Contracts.BcdeModels;
using Microsoft.ComponentDetection.Contracts;

namespace Microsoft.ComponentDetection.Detectors.Tests
{
Expand All @@ -26,12 +21,12 @@ public void GenerateDetectedComponentAndIsDeveDependencyAndDependencyScope_Happy
Assert.IsNotNull(componentAndMetaData.Component);
Assert.IsNotNull(componentAndMetaData.IsDevelopmentDependency);
Assert.IsNotNull(componentAndMetaData.dependencyScope);

var actualComponent = (MavenComponent)componentAndMetaData.Component.Component;
Assert.IsInstanceOfType(actualComponent, typeof(MavenComponent));

var expectedComponent = new MavenComponent("org.apache.maven", "maven-artifact", "3.6.1-SNAPSHOT");

Assert.AreEqual(expectedComponent.ArtifactId, actualComponent.ArtifactId);
Assert.AreEqual(expectedComponent.GroupId, actualComponent.GroupId);
Assert.AreEqual(expectedComponent.Version, actualComponent.Version);
Expand Down