Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for group name #2

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ usage: mvnchk [<path>] [-d <arg>] [-h] [-i] [--ignore-inherited] [-s] [-v]
version
--ignore-inherited Ignore build file artifacts with an inherited
version
-f,--filter RegEx to filter out build file artifacts
with a non mathing group name
-s,--short Only show build files with at least one artifact
update
-v,--version Display version information
Expand All @@ -111,6 +113,16 @@ com.google.guava:guava:*-android
com.google.guava:guava:30.?-android
```

## Filter
_MvnCheck_ allows to ignore artifacts based on a regular expression pattern for the group name.
This allows to search only for artifact update with the given group pattern.

Here is an example of how to only search for artifact
with the group name suffix `com.github.alexisjehan`:
```
- filter com.github.alexisjehan.*
```

## Compatibility matrix
The table below shows which version of _Maven_ and _Gradle_ is used by each _MvnCheck_ release. However, a higher
version of a build tool may still be compatible.
Expand Down
77 changes: 63 additions & 14 deletions src/main/java/com/github/alexisjehan/mvncheck/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import static org.apache.commons.lang3.StringUtils.isNotEmpty;

/**
* <p>Class that describes the application.</p>
Expand Down Expand Up @@ -92,6 +96,12 @@ public final class Application {
*/
static final String OPTION_VERSION = "version";

/**
* <p>Short option long name.</p>
* @since 1.7.0
*/
static final String OPTION_FILTER = "filter";

/**
* <p>Title.</p>
* @since 1.4.0
Expand Down Expand Up @@ -164,6 +174,12 @@ public final class Application {
false,
"Ignore build file artifacts with a snapshot version"
);
options.addOption(
"f",
OPTION_FILTER,
true,
"Filter packages by group name with a regular expression"
);
options.addOption(
"s",
OPTION_SHORT,
Expand Down Expand Up @@ -259,7 +275,8 @@ void run(final String... args) {
: DEFAULT_MAX_DEPTH,
commandLine.hasOption(OPTION_IGNORE_INHERITED),
commandLine.hasOption(OPTION_IGNORE_SNAPSHOTS),
commandLine.hasOption(OPTION_SHORT)
commandLine.hasOption(OPTION_SHORT),
commandLine.getOptionValue(OPTION_FILTER)
);
}
} catch (final Exception e) {
Expand All @@ -269,13 +286,14 @@ void run(final String... args) {

/**
* <p>Run the program.</p>
* @param path a path
*
* @param path a path
* @param ignoreSnapshots {@code true} if build file artifacts with a snapshot version should be ignored
* @param short0 {@code true} if only build files with at least one artifact update should be shown
* @throws IOException might occur with input/output operations
* @param short0 {@code true} if only build files with at least one artifact update should be shown
* @throws IOException might occur with input/output operations
* @throws NullPointerException if the path is {@code null}
* @deprecated since 1.1.0, use {@link #run(Path, int, boolean, boolean)} instead
* @since 1.0.0
* @deprecated since 1.1.0, use {@link #run(Path, int, boolean, boolean)} instead
*/
@Deprecated(since = "1.1.0")
void run(
Expand All @@ -288,15 +306,16 @@ void run(

/**
* <p>Run the program.</p>
* @param path a path
* @param maxDepth a maximum depth
*
* @param path a path
* @param maxDepth a maximum depth
* @param ignoreSnapshots {@code true} if build file artifacts with a snapshot version should be ignored
* @param short0 {@code true} if only build files with at least one artifact update should be shown
* @throws IOException might occur with input/output operations
* @throws NullPointerException if the path is {@code null}
* @param short0 {@code true} if only build files with at least one artifact update should be shown
* @throws IOException might occur with input/output operations
* @throws NullPointerException if the path is {@code null}
* @throws IllegalArgumentException if the maximum depth is lower than {@code 0}
* @deprecated since 1.5.0, use {@link #run(Path, int, boolean, boolean, boolean)} instead
* @since 1.1.0
* @deprecated since 1.5.0, use {@link #run(Path, int, boolean, boolean, boolean)} instead
*/
@Deprecated(since = "1.5.0")
void run(
Expand All @@ -308,27 +327,57 @@ void run(
run(path, maxDepth, false, ignoreSnapshots, short0);
}

/**
* <p>Run the program.</p>
*
* @param path a path
* @param maxDepth a maximum depth
* @param ignoreInherited {@code true} if build file artifacts with an inherited version should be ignored
* @param ignoreSnapshots {@code true} if build file artifacts with a snapshot version should be ignored
* @param short0 {@code true} if only build files with at least one artifact update should be shown
* @throws IOException might occur with input/output operations
* @throws NullPointerException if the path is {@code null}
* @throws IllegalArgumentException if the maximum depth is lower than {@code 0}
* @since 1.5.0
*/
void run(
final Path path,
final int maxDepth,
final boolean ignoreInherited,
final boolean ignoreSnapshots,
final boolean short0)
throws IOException {
run(path, maxDepth, false, ignoreSnapshots, short0, null);
}

/**
* <p>Run the program.</p>
* @param path a path
* @param maxDepth a maximum depth
* @param ignoreInherited {@code true} if build file artifacts with an inherited version should be ignored
* @param ignoreSnapshots {@code true} if build file artifacts with a snapshot version should be ignored
* @param short0 {@code true} if only build files with at least one artifact update should be shown
*
* @throws IOException might occur with input/output operations
* @throws NullPointerException if the path is {@code null}
* @throws IllegalArgumentException if the maximum depth is lower than {@code 0}
* @since 1.5.0
* @throws PatternSyntaxException if the specified filter regex is invalid
* @since 1.7.0
*/
void run(
final Path path,
final int maxDepth,
final boolean ignoreInherited,
final boolean ignoreSnapshots,
final boolean short0
final boolean short0,
final String groupFilter
) throws IOException {
Ensure.notNull("path", path);
Ensure.greaterThanOrEqualTo("maxDepth", maxDepth, 0);
Pattern filter = null;
if(isNotEmpty(groupFilter)){
filter = Pattern.compile(groupFilter, Pattern.CASE_INSENSITIVE);
}
final var service = createService();
final var buildFiles = service.findBuildFiles(path, maxDepth);
if (buildFiles.isEmpty()) {
Expand All @@ -344,7 +393,7 @@ void run(
final List<ArtifactUpdateVersion> artifactUpdateVersions;
try {
final var build = service.findBuild(buildFile);
artifactUpdateVersions = service.findArtifactUpdateVersions(build, ignoreInherited, ignoreSnapshots);
artifactUpdateVersions = service.findArtifactUpdateVersions(build, ignoreInherited, ignoreSnapshots, filter);
} catch (final BuildResolveException | ArtifactAvailableVersionsResolveException e) {
outputStream.println(Ansi.ansi().fgBrightRed().a(toString(file)).reset());
outputStream.println(Ansi.ansi().fgBrightRed().a(toString(e)).reset());
Expand Down
Loading