forked from jhunters/jprotobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gradle precompile plugin supports pattern match feature for package
filters
- Loading branch information
xiemalin
committed
Nov 17, 2020
1 parent
ed10550
commit 1d794d6
Showing
8 changed files
with
156 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...-precompile-plugin-gradle/src/main/java/com/baidu/jprotobuf/plugin/PatternMatchUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.baidu.jprotobuf.plugin; | ||
|
||
/** | ||
* Utility methods for simple pattern matching, in particular for Spring's typical "xxx*", "*xxx" and "*xxx*" pattern | ||
* styles. | ||
* | ||
* @author Juergen Hoeller | ||
* @since 2.0 | ||
*/ | ||
public abstract class PatternMatchUtils { | ||
|
||
/** | ||
* Match a String against the given pattern, supporting the following simple pattern styles: "xxx*", "*xxx", "*xxx*" | ||
* and "xxx*yyy" matches (with an arbitrary number of pattern parts), as well as direct equality. | ||
* | ||
* @param pattern the pattern to match against | ||
* @param str the String to match | ||
* @return whether the String matches the given pattern | ||
*/ | ||
public static boolean simpleMatch(String pattern, String str) { | ||
if (pattern == null || str == null) { | ||
return false; | ||
} | ||
int firstIndex = pattern.indexOf('*'); | ||
if (firstIndex == -1) { | ||
return pattern.equals(str); | ||
} | ||
if (firstIndex == 0) { | ||
if (pattern.length() == 1) { | ||
return true; | ||
} | ||
int nextIndex = pattern.indexOf('*', firstIndex + 1); | ||
if (nextIndex == -1) { | ||
return str.endsWith(pattern.substring(1)); | ||
} | ||
String part = pattern.substring(1, nextIndex); | ||
if ("".equals(part)) { | ||
return simpleMatch(pattern.substring(nextIndex), str); | ||
} | ||
int partIndex = str.indexOf(part); | ||
while (partIndex != -1) { | ||
if (simpleMatch(pattern.substring(nextIndex), str.substring(partIndex + part.length()))) { | ||
return true; | ||
} | ||
partIndex = str.indexOf(part, partIndex + 1); | ||
} | ||
return false; | ||
} | ||
return (str.length() >= firstIndex && pattern.substring(0, firstIndex).equals(str.substring(0, firstIndex)) | ||
&& simpleMatch(pattern.substring(firstIndex), str.substring(firstIndex))); | ||
} | ||
|
||
/** | ||
* Match a String against the given patterns, supporting the following simple pattern styles: "xxx*", "*xxx", | ||
* "*xxx*" and "xxx*yyy" matches (with an arbitrary number of pattern parts), as well as direct equality. | ||
* | ||
* @param patterns the patterns to match against | ||
* @param str the String to match | ||
* @return whether the String matches any of the given patterns | ||
*/ | ||
public static boolean simpleMatch(String[] patterns, String str) { | ||
if (patterns != null) { | ||
for (String pattern : patterns) { | ||
if (simpleMatch(pattern, str)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PatternMatchUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.baidu.jprotobuf.mojo; | ||
|
||
/** | ||
* Utility methods for simple pattern matching, in particular for Spring's typical "xxx*", "*xxx" and "*xxx*" pattern | ||
* styles. | ||
* | ||
* @author Juergen Hoeller | ||
* @since 2.0 | ||
*/ | ||
public abstract class PatternMatchUtils { | ||
|
||
/** | ||
* Match a String against the given pattern, supporting the following simple pattern styles: "xxx*", "*xxx", "*xxx*" | ||
* and "xxx*yyy" matches (with an arbitrary number of pattern parts), as well as direct equality. | ||
* | ||
* @param pattern the pattern to match against | ||
* @param str the String to match | ||
* @return whether the String matches the given pattern | ||
*/ | ||
public static boolean simpleMatch(String pattern, String str) { | ||
if (pattern == null || str == null) { | ||
return false; | ||
} | ||
int firstIndex = pattern.indexOf('*'); | ||
if (firstIndex == -1) { | ||
return pattern.equals(str); | ||
} | ||
if (firstIndex == 0) { | ||
if (pattern.length() == 1) { | ||
return true; | ||
} | ||
int nextIndex = pattern.indexOf('*', firstIndex + 1); | ||
if (nextIndex == -1) { | ||
return str.endsWith(pattern.substring(1)); | ||
} | ||
String part = pattern.substring(1, nextIndex); | ||
if ("".equals(part)) { | ||
return simpleMatch(pattern.substring(nextIndex), str); | ||
} | ||
int partIndex = str.indexOf(part); | ||
while (partIndex != -1) { | ||
if (simpleMatch(pattern.substring(nextIndex), str.substring(partIndex + part.length()))) { | ||
return true; | ||
} | ||
partIndex = str.indexOf(part, partIndex + 1); | ||
} | ||
return false; | ||
} | ||
return (str.length() >= firstIndex && pattern.substring(0, firstIndex).equals(str.substring(0, firstIndex)) | ||
&& simpleMatch(pattern.substring(firstIndex), str.substring(firstIndex))); | ||
} | ||
|
||
/** | ||
* Match a String against the given patterns, supporting the following simple pattern styles: "xxx*", "*xxx", | ||
* "*xxx*" and "xxx*yyy" matches (with an arbitrary number of pattern parts), as well as direct equality. | ||
* | ||
* @param patterns the patterns to match against | ||
* @param str the String to match | ||
* @return whether the String matches any of the given patterns | ||
*/ | ||
public static boolean simpleMatch(String[] patterns, String str) { | ||
if (patterns != null) { | ||
for (String pattern : patterns) { | ||
if (simpleMatch(pattern, str)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/test/java/com/baidu/bjf/remoting/protobuf/v3/any/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.baidu.bjf.remoting.protobuf.v3.any; |