Skip to content

Commit

Permalink
Fixed issue when processing code file for metapackage (#8892)
Browse files Browse the repository at this point in the history
* Fixed issue when processing code file for metapackage
  • Loading branch information
praveenkuttappan authored Aug 27, 2024
1 parent 7b333b1 commit 2afc9d4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ private static void InsertCodePanelRowData(CodePanelData codePanelData, CodePane

private static void AddDiagnosticRow(CodePanelData codePanelData, CodeFile codeFile, string nodeId, string nodeIdHashed)
{
if (codeFile.Diagnostics == null || codeFile.Diagnostics.Length == 0)
return;

var diagnostics = codeFile.Diagnostics.Where(d => d.TargetId == nodeId);
foreach (var diagnostic in diagnostics)
{
Expand Down
12 changes: 6 additions & 6 deletions src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,12 @@ public async Task UpdateAPIRevisionAsync(APIRevisionListItemModel revision, Lang
try
{
var fileOriginal = await _originalsRepository.GetOriginalAsync(file.FileId);
// file.Name property has been repurposed to store package name and version string
// This is causing issue when updating review using latest parser since it expects Name field as file name
// We have added a new property FileName which is only set for new reviews
// All older reviews needs to be handled by checking review name field
var fileName = file.FileName ?? file.FileId;
var codeFile = await languageService.GetCodeFileAsync(fileName, fileOriginal, false);
if (string.IsNullOrEmpty(file.FileName))
{
_telemetryClient.TrackTrace($"Revision does not have original file name to update API revision. Revision Id: {revision.Id}");
continue;
}
var codeFile = await languageService.GetCodeFileAsync(file.FileName, fileOriginal, false);
if (!verifyUpgradabilityOnly)
{
await _codeFileRepository.UpsertCodeFileAsync(revision.Id, file.FileId, codeFile);
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/APIView/apiview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
default: 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json'
- name: CSharpAPIParserVersion
type: string
default: '1.0.0-dev.20240723.1'
default: '1.0.0-dev.20240826.7'

trigger:
branches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ public static void BuildInternalsVisibleToAttributes(List<ReviewLine> reviewLine
!a.ConstructorArguments[0].Value?.ToString()?.Contains("DynamicProxyGenAssembly2") == true);
if (assemblyAttributes != null && assemblyAttributes.Any())
{
reviewLines.Add(new ReviewLine()
var internalVisibleLine = new ReviewLine()
{
LineId = "InternalsVisibleTo",
Tokens = [
ReviewToken.CreateStringLiteralToken("Exposes internals to:")
]
});
};
reviewLines.Add(internalVisibleLine);

foreach (AttributeData attribute in assemblyAttributes)
{
Expand All @@ -146,6 +147,8 @@ public static void BuildInternalsVisibleToAttributes(List<ReviewLine> reviewLine
}
}
}
// Add an empty line after internals visible to section
reviewLines.Add(new ReviewLine() { RelatedToLine = internalVisibleLine.LineId });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.42.0" />
<PackageReference Include="Azure.Security.Attestation" Version="1.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageReference Include="Azure.Template" Version="1.0.3-beta.4055065" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ static CodeFileTests()

public static IEnumerable<object[]> CodeFiles => new List<object[]>
{
new object[] { templateCodeFile, "Azure.Template" , "1.0.3.0", 8},
new object[] { storageCodeFile , "Azure.Storage.Blobs", "12.21.2.0", 14},
new object[] { coreCodeFile, "Azure.Core", "1.42.0.0", 26},
new object[] { templateCodeFile, "Azure.Template" , "1.0.3.0", 9},
new object[] { storageCodeFile , "Azure.Storage.Blobs", "12.21.2.0", 15},
new object[] { coreCodeFile, "Azure.Core", "1.42.0.0", 27},
};

[Theory]
Expand Down Expand Up @@ -103,6 +103,7 @@ public void TestApiReviewLine()
var classLine = namespaceLine.Children.Where(lines => lines.LineId == "Azure.Storage.Blobs.BlobServiceClient").FirstOrDefault();
Assert.NotNull(classLine);
var methodLine = classLine.Children.Where(lines => lines.LineId == "Azure.Storage.Blobs.BlobServiceClient.BlobServiceClient(System.String)").FirstOrDefault();
Assert.NotNull(methodLine);
Assert.Equal(7, methodLine.Tokens.Count());
Assert.Equal("public BlobServiceClient(string connectionString);", methodLine.ToString().Trim());
}
Expand Down Expand Up @@ -224,7 +225,7 @@ public static class TemplateClientBuilderExtensions {
public void TestCodeFileJsonSchema(CodeFile codeFile)
{
//Verify JSON file generated for Azure.Template
var isValid = validateSchema(templateCodeFile);
var isValid = validateSchema(codeFile);
Assert.True(isValid);
}

Expand Down Expand Up @@ -261,6 +262,7 @@ public void TestNavigationNodeHasRenderingClass()
{
var jsonString = JsonSerializer.Serialize(templateCodeFile);
var parsedCodeFile = JsonSerializer.Deserialize<CodeFile>(jsonString);
Assert.NotNull(parsedCodeFile);
Assert.Equal(8, CountNavigationNodes(parsedCodeFile.ReviewLines));
}

Expand Down Expand Up @@ -317,5 +319,31 @@ private int CountHiddenApiInBlobDownloadInfo(List<ReviewLine> lines)
}
return count;
}

[Fact]
public void VerifyObsoleteMemberIsHidden()
{
var attestationAssembly = Assembly.Load("Azure.Security.Attestation");
var dllStream = attestationAssembly.GetFile("Azure.Security.Attestation.dll");
var assemblySymbol = CompilationFactory.GetCompilation(dllStream, null);
var codeFile = new CSharpAPIParser.TreeToken.CodeFileBuilder().Build(assemblySymbol, true, null);

var lines = codeFile.ReviewLines;
var namespaceLine = lines.Where(lines => lines.LineId == "Azure.Security.Attestation").FirstOrDefault();
Assert.NotNull(namespaceLine);
var classLine = namespaceLine.Children.Where(lines => lines.LineId == "Azure.Security.Attestation.AttestationResult").FirstOrDefault();
Assert.NotNull(classLine);

var obsoleteMethods = classLine.Children.Where(line => line.ToString().StartsWith("[Obsolete("));
Assert.NotEmpty(obsoleteMethods);
//Make sure member lines are marked as hidden if it has obsolete attribute
foreach (var method in obsoleteMethods)
{
Assert.True(method.IsHidden);
Assert.NotNull(method.RelatedToLine);
var relatedLine = classLine.Children.Where(line => line.LineId == method.RelatedToLine).FirstOrDefault();
Assert.True(relatedLine?.IsHidden);
}
}
}
}

0 comments on commit 2afc9d4

Please sign in to comment.