Skip to content

Commit

Permalink
Fix parser compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan committed Aug 18, 2024
1 parent 2fa9b75 commit 0d5db1d
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tools/apiview/parsers/csharp-api-parser/CSharpAPIParser/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.CommandLine;
using System.IO.Compression;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using ApiView;
using APIView.Model.V2;
Expand All @@ -13,6 +14,8 @@

public static class Program
{
private static Regex _packageNameParser = new Regex("([A-Za-z.]*[a-z]).([\\S]*)", RegexOptions.Compiled);

public static int Main(string[] args)
{
var inputOption = new Option<FileInfo>("--packageFilePath", "C# Package (.nupkg) file").ExistingOnly();
Expand Down Expand Up @@ -70,7 +73,7 @@ static async Task HandlePackageFileParsing(Stream stream, FileInfo packageFilePa
if (dllEntries.Length == 0)
{
Console.Error.WriteLine($"PackageFile {packageFilePath.FullName} contains no dll. Creating a meta package API review file.");
var codeFile = CodeFile.CreateDummyCodeFile(packageFilePath.FullName, $"Package {packageFilePath.Name} does not contain any dll to create API review.");
var codeFile = CreateDummyCodeFile(packageFilePath.FullName, $"Package {packageFilePath.Name} does not contain any dll to create API review.");
outputFileName = string.IsNullOrEmpty(outputFileName) ? nuspecEntry.Name : outputFileName;
await CreateOutPutFile(OutputDirectory.FullName, outputFileName, codeFile);
return;
Expand Down Expand Up @@ -123,7 +126,7 @@ static async Task HandlePackageFileParsing(Stream stream, FileInfo packageFilePa
if (assemblySymbol == null)
{
Console.Error.WriteLine($"PackageFile {packageFilePath.FullName} contains no Assembly Symbol.");
var codeFile = CodeFile.CreateDummyCodeFile(packageFilePath.FullName, $"Package {packageFilePath.Name} does not contain any assembly symbol to create API review.");
var codeFile = CreateDummyCodeFile(packageFilePath.FullName, $"Package {packageFilePath.Name} does not contain any assembly symbol to create API review.");
outputFileName = string.IsNullOrEmpty(outputFileName) ? packageFilePath.Name : outputFileName;
await CreateOutPutFile(OutputDirectory.FullName, outputFileName, codeFile);
return;
Expand Down Expand Up @@ -157,6 +160,31 @@ static async Task CreateOutPutFile(string outputPath, string outputFileNamePrefi
Console.WriteLine();
}

/*** Creates dummy API review file to support meta packages.*/
static CodeFile CreateDummyCodeFile(string originalName, string text)
{
var packageName = Path.GetFileNameWithoutExtension(originalName);
var packageNameMatch = _packageNameParser.Match(packageName);
var packageVersion = "";
if (packageNameMatch.Success)
{
packageName = packageNameMatch.Groups[1].Value;
packageVersion = $"{packageNameMatch.Groups[2].Value}";
}

var codeFile = new CodeFile();
codeFile.PackageName = packageName;
codeFile.PackageVersion = packageVersion;
codeFile.ReviewLines.Add(new ReviewLine
{
Tokens = new List<ReviewToken>
{
ReviewToken.CreateTextToken(text)
}
});
return codeFile;
}

static bool IsNuget(string name)
{
return name.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase);
Expand Down

0 comments on commit 0d5db1d

Please sign in to comment.