aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java')
-rwxr-xr-xapi/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java67
1 files changed, 42 insertions, 25 deletions
diff --git a/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java b/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java
index 53b2c54..edfedbb 100755
--- a/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java
+++ b/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java
@@ -45,7 +45,9 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler {
private static final boolean DEBUG = false;
private String currentClassName;
private final Set<String> includes;
+ private final boolean includesAreRegExp;
private final Set<String> excludes;
+ private final boolean excludesAreRegExp;
private final Set<Difference> differences = new HashSet<Difference>();
public DifferenceAccumulatingHandler() {
@@ -53,14 +55,20 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler {
}
public DifferenceAccumulatingHandler(@Nonnull final Set<String> includes, @Nonnull final Set<String> excludes) {
+ this(includes, false, excludes, false);
+ }
+ public DifferenceAccumulatingHandler(@Nonnull final Set<String> includes, final boolean includesAreRegExp,
+ @Nonnull final Set<String> excludes, final boolean excludesAreRegExp) {
this.includes = includes;
+ this.includesAreRegExp = includesAreRegExp;
this.excludes = excludes;
+ this.excludesAreRegExp = excludesAreRegExp;
}
public String getCurrentClassName() {
return this.currentClassName;
}
-
+
@Override
public void startDiff(final String previous, final String current) throws DiffException {
}
@@ -252,46 +260,55 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler {
}
protected boolean isClassConsideredImpl( final String className ) {
for ( String exclude : this.excludes ) {
- if ( exclude.contains( "/**/" ) ) {
- exclude = exclude.replaceAll( "/\\*\\*/", "{0,1}**/" );
- }
- if ( exclude.contains( "/*/" ) ) {
- exclude = exclude.replaceAll( "/\\*/", "{0,1}*/{0,1}" );
+ final Pattern excludePattern;
+ if( !excludesAreRegExp ) {
+ if ( exclude.contains( "/**/" ) ) {
+ exclude = exclude.replaceAll( "/\\*\\*/", "{0,1}**/" );
+ }
+ if ( exclude.contains( "/*/" ) ) {
+ exclude = exclude.replaceAll( "/\\*/", "{0,1}*/{0,1}" );
+ }
+ excludePattern = simplifyRegularExpression( exclude, false );
+ } else {
+ excludePattern = Pattern.compile( exclude );
}
- Pattern excludePattern = simplifyRegularExpression( exclude, false );
-
- Matcher excludeMatcher = excludePattern.matcher( className );
-
+ final Matcher excludeMatcher = excludePattern.matcher( className );
+
while ( excludeMatcher.find() ) {
return false;
- }
- }
+ }
+ }
if ( !this.includes.isEmpty() ) {
for ( String include : this.includes ) {
- if ( include.contains( "/**/" ) ) {
- include = include.replaceAll( "/\\*\\*/", "{0,1}**/" );
- }
- if ( include.contains( "/*/" ) ) {
- include = include.replaceAll( "/\\*/", "{0,1}*/{0,1}" );
+ final Pattern includePattern;
+ if( !includesAreRegExp ) {
+ if ( include.contains( "/**/" ) ) {
+ include = include.replaceAll( "/\\*\\*/", "{0,1}**/" );
+ }
+ if ( include.contains( "/*/" ) ) {
+ include = include.replaceAll( "/\\*/", "{0,1}*/{0,1}" );
+ }
+ includePattern = simplifyRegularExpression( include, false );
+ } else {
+ includePattern = Pattern.compile( include );
}
- Pattern includePattern = simplifyRegularExpression( include, false );
- Matcher includeMatcher = includePattern.matcher( className );
-
+ final Matcher includeMatcher = includePattern.matcher( className );
+
while ( includeMatcher.find() ) {
return false;
- }
+ }
}
}
return true;
}
-
+
/**
- *
+ *
* Simplifies the given regular expression by the following pattern:<br>
* All substrings not containing "{0,1}", "*" and "?" get surrounded by "\\Q" and "\\E". Then all occurrences of
* "**" are replaced by ".*", "*" with "[^/]*" and all occurrences of "?" are replaced by "." In the end a "$" will
* be appended.
- *
+ *
* @param regEx the regular expression which is in a simple form.
* @return the simple regular expression converted to a normal regular expression.
*/
@@ -299,7 +316,7 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler {
final StringBuilder strBuild = new StringBuilder();
final Pattern p = Pattern.compile( "\\{0,1\\}|\\*|\\?|[[^*^?^{^}]|^]+", Pattern.CASE_INSENSITIVE );
final Matcher m = p.matcher( regEx );
-
+
while ( m.find() ) {
final String token = m.group();
if ( token.equals( "*" ) || token.equals( "?" ) ) { //$NON-NLS-1$ //$NON-NLS-2$