Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/main/java/org/codehaus/mojo/clirr/AbstractClirrMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ public abstract class AbstractClirrMojo
*/
protected String[] excludes;

/**
* A list of annotations marking special classes and interfaces to be excluded from comparison.
* Classes annotated with these annotations are excluded from the list of classes that are included.
* Values are specified in class name notation, e.g. <code>java.lang.Deprecated</code>.
*
* @parameter
*/
protected String[] excludeAnnotated;

/**
* A list of differences reported by Clirr that should be ignored when producing the final report.
* Values specified here will be joined with the ones specified using the "ignoredDifferencesFile"
Expand Down Expand Up @@ -258,7 +267,7 @@ protected ClirrDiffListener executeClirr( Severity minSeverity )
{
ClirrDiffListener listener = new ClirrDiffListener();

ClassFilter classFilter = new ClirrClassFilter( includes, excludes );
ClassFilter classFilter = new ClirrClassFilter( includes, excludes, excludeAnnotated );

JavaType[] origClasses = resolvePreviousReleaseClasses( classFilter );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected ClirrDiffListener executeClirr( Severity minSeverity )
{
ClirrDiffListener listener = new ClirrDiffListener();

ClassFilter classFilter = new ClirrClassFilter( includes, excludes );
ClassFilter classFilter = new ClirrClassFilter( includes, excludes, excludeAnnotated );

JavaType[] origClasses = resolveClasses( oldComparisonArtifacts, classFilter );

Expand Down
43 changes: 42 additions & 1 deletion src/main/java/org/codehaus/mojo/clirr/ClirrClassFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* limitations under the License.
*/

import net.sf.clirr.core.ClassFilter;
import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.JavaClass;
import org.codehaus.plexus.util.SelectorUtils;

import net.sf.clirr.core.ClassFilter;

/**
* Filter classes by pattern sets.
*
Expand All @@ -32,9 +34,16 @@ public class ClirrClassFilter

private final String[] includes;

private final String[] excludeAnnotated;

private boolean alwaysTrue;

public ClirrClassFilter( String[] includes, String[] excludes )
{
this( includes, excludes, null );
}

public ClirrClassFilter( String[] includes, String[] excludes, String[] excludeAnnotated )
{
if ( excludes == null || excludes.length == 0 )
{
Expand All @@ -58,6 +67,18 @@ public ClirrClassFilter( String[] includes, String[] excludes )
{
this.includes = (String[]) includes.clone();
}

if ( excludeAnnotated == null || excludeAnnotated.length == 0 )
{
this.excludeAnnotated = null;
}
else {
this.excludeAnnotated = new String[excludeAnnotated.length];
for (int i = 0; i < excludeAnnotated.length; i++)
{
this.excludeAnnotated[i] = "L" + excludeAnnotated[i].replace( '.', '/' ) + ";";
}
}
}

public boolean isSelected( JavaClass javaClass )
Expand All @@ -82,6 +103,26 @@ public boolean isSelected( JavaClass javaClass )
result = !SelectorUtils.matchPath( excludes[i], path );
}
}

if (excludeAnnotated != null)
{
final AnnotationEntry[] annotationEntries = javaClass.getAnnotationEntries();
if (annotationEntries != null)
{
for (AnnotationEntry annotationEntry : annotationEntries)
{
final String annotationType = annotationEntry.getAnnotationType();
for ( String annotated: excludeAnnotated )
{
if ( annotationType.equals(annotated) )
{
return false;
}
}
}
}
}

}

return result;
Expand Down