Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Add -excludeApiList (-xal) option to GenAPI
Browse files Browse the repository at this point in the history
This allows folks to specify which APIs should be specifically excluded
in addition to other API selection parameters.
  • Loading branch information
ericstj committed Aug 27, 2015
1 parent 40455e2 commit e2a25b0
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 7 deletions.
24 changes: 21 additions & 3 deletions src/GenAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,30 @@ private static ICciWriter GetWriter(TextWriter output, IStyleSyntaxWriter syntax

private static ICciFilter GetFilter()
{
ICciFilter includeFilter = null;

if (string.IsNullOrWhiteSpace(s_apiList))
{
if (s_all)
return new IncludeAllFilter();
{
includeFilter = new IncludeAllFilter();
}
else
{
includeFilter = new PublicOnlyCciFilter(excludeAttributes: s_apiOnly);
}
}
else
{
includeFilter = new DocIdIncludeListFilter(s_apiList);
}

return new PublicOnlyCciFilter(excludeAttributes: s_apiOnly);
if (!string.IsNullOrWhiteSpace(s_excludeApiList))
{
includeFilter = new IntersectionFilter(includeFilter, new DocIdExcludeListFilter(s_excludeApiList));
}

return new DocIdWhitelistFilter(s_apiList);
return includeFilter;
}

private static IStyleSyntaxWriter GetSyntaxWriter(TextWriter output)
Expand Down Expand Up @@ -145,6 +160,7 @@ private enum SyntaxWriterType
private static WriterType s_writer = WriterType.CSDecl;
private static SyntaxWriterType s_syntaxWriter = SyntaxWriterType.Text;
private static string s_apiList;
private static string s_excludeApiList;
private static string s_headerFile;
private static string s_out;
private static string s_libPath;
Expand All @@ -161,6 +177,8 @@ private static void ParseCommandLine(string[] args)
parser.DefineOptionalQualifier("libPath", ref s_libPath, "Delimited (',' or ';') set of paths to use for resolving assembly references");
parser.DefineAliases("apiList", "al");
parser.DefineOptionalQualifier("apiList", ref s_apiList, "(-al) Specify a api list in the DocId format of which APIs to include.");
parser.DefineAliases("excludeApiList", "xal");
parser.DefineOptionalQualifier("excludeApiList", ref s_excludeApiList, "(-xal) Specify a api list in the DocId format of which APIs to exclude.");
parser.DefineAliases("writer", "w");
parser.DefineOptionalQualifier<WriterType>("writer", ref s_writer, "(-w) Specify the writer type to use.");
parser.DefineAliases("syntax", "s");
Expand Down
62 changes: 62 additions & 0 deletions src/Microsoft.Cci.Extensions/Filters/DocIdExcludeListFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Cci.Extensions;
using System.IO;

namespace Microsoft.Cci.Filters
{
public class DocIdExcludeListFilter : ICciFilter
{
private readonly HashSet<string> _docIds;

public DocIdExcludeListFilter(IEnumerable<string> docIds)
{
_docIds = new HashSet<string>(docIds);
}

public DocIdExcludeListFilter(string whiteListFilePath)
{
_docIds = DocIdExtensions.ReadDocIds(whiteListFilePath);
}

public bool Include(INamespaceDefinition ns)
{
// Only include non-empty namespaces
return ns.GetTypes().Any(Include);
}

public bool Include(ITypeDefinition type)
{
string typeId = type.DocId();

// include so long as it isn't in the exclude list.
return !_docIds.Contains(typeId);
}

public bool Include(ITypeDefinitionMember member)
{
string memberId = member.DocId();
// include so long as it isn't in the exclude list.
return !_docIds.Contains(memberId);
}

public bool Include(ICustomAttribute attribute)
{
string typeId = attribute.DocId();
string removeUsages = "RemoveUsages:" + typeId;

// special case: attribute usage can be removed without removing
// the attribute itself
if (_docIds.Contains(removeUsages))
return false;

// include so long as it isn't in the exclude list.
return !_docIds.Contains(typeId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

namespace Microsoft.Cci.Filters
{
public class DocIdWhitelistFilter : ICciFilter
public class DocIdIncludeListFilter : ICciFilter
{
private readonly HashSet<string> _docIds;

public DocIdWhitelistFilter(IEnumerable<string> docIds)
public DocIdIncludeListFilter(IEnumerable<string> docIds)
{
_docIds = new HashSet<string>(docIds);
}

public DocIdWhitelistFilter(string whiteListFilePath)
public DocIdIncludeListFilter(string whiteListFilePath)
{
_docIds = DocIdExtensions.ReadDocIds(whiteListFilePath);
}
Expand Down
44 changes: 44 additions & 0 deletions src/Microsoft.Cci.Extensions/Filters/IntersectionFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Cci.Filters
{
/// <summary>
/// Combines multiple filters together to only include if all filters include.
/// </summary>
public class IntersectionFilter : ICciFilter
{
public IntersectionFilter(params ICciFilter[] filters)
{
Filters = new List<ICciFilter>(filters);
}

public IList<ICciFilter> Filters { get; private set; }

public bool Include(ITypeDefinitionMember member)
{
return Filters.All(filter => filter.Include(member));
}

public bool Include(ICustomAttribute attribute)
{
return Filters.All(filter => filter.Include(attribute));
}

public bool Include(ITypeDefinition type)
{
return Filters.All(filter => filter.Include(type));
}

public bool Include(INamespaceDefinition ns)
{
return Filters.All(filter => filter.Include(ns));
}
}
}
4 changes: 3 additions & 1 deletion src/Microsoft.Cci.Extensions/Microsoft.Cci.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
<Compile Include="Filters\BaselineDifferenceFilter.cs" />
<Compile Include="Filters\CommonTypesMappingDifferenceFilter.cs" />
<Compile Include="Filters\DifferenceFilter.cs" />
<Compile Include="Filters\DocIdWhitelistFilter.cs" />
<Compile Include="Filters\DocIdExcludeListFilter.cs" />
<Compile Include="Filters\DocIdIncludeListFilter.cs" />
<Compile Include="Filters\ExcludeAttributesFilter.cs" />
<Compile Include="Filters\IDifferenceFilter.cs" />
<Compile Include="Filters\IncludeAllFilter.cs" />
<Compile Include="Filters\IntersectionFilter.cs" />
<Compile Include="Filters\MonoStubFilter.cs" />
<Compile Include="Filters\TypesOnlyMappingDifferenceFilter.cs" />
<Compile Include="Internal\DisposeAction.cs" />
Expand Down

0 comments on commit e2a25b0

Please sign in to comment.