public void AndroidStudioConverter_GetShortDescription_UsesProblemClassIfDescriptionNotPresent() { var uut = AndroidStudioProblemTests.GetDefaultProblem(); string result = AndroidStudioConverter.GetShortDescriptionForProblem(uut); result.Should().Contain("A Problematic Problem"); }
public Result ConvertProblemToSarifResult(AndroidStudioProblem problem) { var result = new Result(); result.RuleId = problem.ProblemClass; string description = AndroidStudioConverter.GetShortDescriptionForProblem(problem); if (problem.Hints.IsEmpty) { result.Message = new Message { Text = description }; } else { result.Message = new Message { Text = GenerateFullMessage(description, problem.Hints) }; } SetSarifResultPropertiesForProblem(result, problem); var location = new Location { LogicalLocation = new LogicalLocation { FullyQualifiedName = AddLogicalLocationEntriesForProblem(problem, out int logicalLocationIndex), Index = logicalLocationIndex } }; Uri uri; string file = problem.File; if (!String.IsNullOrEmpty(file)) { location.PhysicalLocation = new PhysicalLocation { ArtifactLocation = new ArtifactLocation(), Region = problem.Line <= 0 ? null : Extensions.CreateRegion(problem.Line) }; bool foundUriBaseId = RemoveBadRoot(file, out uri); location.PhysicalLocation.ArtifactLocation.Uri = uri; // TODO enable this change after current work // https://github.com/Microsoft/sarif-sdk/issues/1168 // //if (foundUriBaseId) //{ // location.PhysicalLocation.FileLocation.UriBaseId = PROJECT_DIR; //} } result.Locations = new List <Location> { location }; return(result); }
public void AndroidStudioConverter_GetShortDescription_UsesDescriptionIfPresent() { var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder(); builder.Description = "Cute fluffy kittens"; var uut = new AndroidStudioProblem(builder); string result = AndroidStudioConverter.GetShortDescriptionForProblem(uut); Assert.AreEqual("Cute fluffy kittens", result); }
public Result ConvertProblemToSarifResult(AndroidStudioProblem problem) { var result = new Result(); result.RuleId = problem.ProblemClass; string description = AndroidStudioConverter.GetShortDescriptionForProblem(problem); if (problem.Hints.IsEmpty) { result.Message = new Message { Text = description }; } else { result.Message = new Message { Text = GenerateFullMessage(description, problem.Hints) }; } SetSarifResultPropertiesForProblem(result, problem); var location = new Location(); location.FullyQualifiedLogicalName = CreateFullyQualifiedLogicalName(problem); Uri uri; string file = problem.File; if (!String.IsNullOrEmpty(file)) { location.PhysicalLocation = new PhysicalLocation { FileLocation = new FileLocation(), Region = problem.Line <= 0 ? null : Extensions.CreateRegion(problem.Line) }; if (RemoveBadRoot(file, out uri)) { location.PhysicalLocation.FileLocation.UriBaseId = PROJECT_DIR; } location.PhysicalLocation.FileLocation.Uri = uri; } result.Locations = new List <Location> { location }; return(result); }
public Result ConvertProblemToSarifResult(AndroidStudioProblem problem) { var result = new Result(); result.RuleId = problem.ProblemClass; string description = AndroidStudioConverter.GetShortDescriptionForProblem(problem); if (problem.Hints.IsEmpty) { result.Message = description; } else { result.Message = GenerateFullMessage(description, problem.Hints); } SetSarifResultPropertiesForProblem(result, problem); var location = new Location(); location.FullyQualifiedLogicalName = CreateSignature(problem); string logicalLocationKey = CreateLogicalLocation(problem); if (logicalLocationKey != location.FullyQualifiedLogicalName) { location.LogicalLocationKey = logicalLocationKey; } Uri uri; string file = problem.File; if (!String.IsNullOrEmpty(file)) { location.ResultFile = new PhysicalLocation { Region = problem.Line <= 0 ? null : Extensions.CreateRegion(problem.Line) }; if (RemoveBadRoot(file, out uri)) { location.ResultFile.UriBaseId = PROJECT_DIR; } location.ResultFile.Uri = uri; } if ("file".Equals(problem.EntryPointType, StringComparison.OrdinalIgnoreCase)) { if (location.AnalysisTarget != null) { location.ResultFile = location.AnalysisTarget; } location.AnalysisTarget = new PhysicalLocation(); if (RemoveBadRoot(problem.EntryPointName, out uri)) { location.AnalysisTarget.UriBaseId = PROJECT_DIR; } location.AnalysisTarget.Uri = uri; } result.Locations = new List <Location> { location }; return(result); }
public static Result ConvertProblemToSarifIssue(AndroidStudioProblem problem) { var result = new Result(); result.RuleId = problem.ProblemClass; string description = AndroidStudioConverter.GetShortDescriptionForProblem(problem); if (problem.Hints.IsEmpty) { result.FullMessage = description; } else { result.ShortMessage = description; result.FullMessage = GenerateFullMessage(description, problem.Hints); } result.Properties = GetSarifIssuePropertiesForProblem(problem); var location = new Location(); result.Locations = new[] { location }; var logicalLocation = new List <LogicalLocationComponent>(); if (!String.IsNullOrWhiteSpace(problem.Module)) { logicalLocation.Add(new LogicalLocationComponent { Name = problem.Module, Kind = LogicalLocationKind.AndroidModule }); } if (!String.IsNullOrWhiteSpace(problem.Package)) { logicalLocation.Add(new LogicalLocationComponent { Name = problem.Package, Kind = LogicalLocationKind.JvmPackage }); } if ("class".Equals(problem.EntryPointType, StringComparison.OrdinalIgnoreCase)) { logicalLocation.Add(new LogicalLocationComponent { Name = problem.EntryPointName, Kind = LogicalLocationKind.JvmType }); } if ("method".Equals(problem.EntryPointType, StringComparison.OrdinalIgnoreCase)) { logicalLocation.Add(new LogicalLocationComponent { Name = problem.EntryPointName, Kind = LogicalLocationKind.JvmFunction }); } if (logicalLocation.Count != 0) { location.LogicalLocation = logicalLocation; location.FullyQualifiedLogicalName = String.Join("\\", location.LogicalLocation.Select(x => x.Name)); } string file = problem.File; if (!String.IsNullOrEmpty(file)) { location.ResultFile = new[] { new PhysicalLocationComponent { Uri = RemoveBadRoot(file), MimeType = MimeType.Java, Region = problem.Line <= 0 ? null : Extensions.CreateRegion(problem.Line) } }; } if ("file".Equals(problem.EntryPointType, StringComparison.OrdinalIgnoreCase)) { if (location.AnalysisTarget != null) { location.ResultFile = location.AnalysisTarget; } location.AnalysisTarget = new[] { new PhysicalLocationComponent { Uri = RemoveBadRoot(problem.EntryPointName), MimeType = MimeType.Java } }; } return(result); }