Skip to content

Commit

Permalink
Build files from output directories are now excluded by default
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisJehan committed Sep 6, 2024
1 parent c0e1243 commit d2b1994
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
### New features
- [[#5](https://github.com/AlexisJehan/MvnCheck/issues/5)] Generate an executable JAR as an extra release file (thanks
to [TobseF](https://github.com/TobseF))
- Add the `--include-output`/`-o` option to include build files from output directories (`target` for _Maven_ and
`build` for _Gradle_, note that this was the default behavior in previous releases)

### Bug fixes
- [[#3](https://github.com/AlexisJehan/MvnCheck/issues/3)] Fix parsing errors related to the BOM character of the UTF-8
with BOM encoding (thanks to [TobseF](https://github.com/TobseF))

### Improvements
- Improve the _Maven Artifact Resolver_ usage by migrating from `Eclipse Sisu` to `Supplier`
- Build files from output directories (`target` for _Maven_ and `build` for _Gradle_) are now excluded by default

### Notes
- Add the `maven-resolver-supplier` dependency
Expand Down
58 changes: 50 additions & 8 deletions src/main/java/com/github/alexisjehan/mvncheck/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,23 @@ public final class Application {
*/
static final String OPTION_HELP = "help";

/**
* <p>Ignore snapshots option long name.</p>
* @since 1.0.0
*/
static final String OPTION_IGNORE_SNAPSHOTS = "ignore-snapshots";

/**
* <p>Ignore inherited option long name.</p>
* @since 1.5.0
*/
static final String OPTION_IGNORE_INHERITED = "ignore-inherited";

/**
* <p>Ignore snapshots option long name.</p>
* @since 1.0.0
* <p>Include output option long name.</p>
* @since 1.7.0
*/
static final String OPTION_IGNORE_SNAPSHOTS = "ignore-snapshots";
static final String OPTION_INCLUDE_OUTPUT = "include-output";

/**
* <p>Short option long name.</p>
Expand Down Expand Up @@ -152,17 +158,23 @@ public final class Application {
false,
"Display help information"
);
options.addOption(
"i",
OPTION_IGNORE_SNAPSHOTS,
false,
"Ignore build file artifacts with a snapshot version"
);
options.addOption(
null,
OPTION_IGNORE_INHERITED,
false,
"Ignore build file artifacts with an inherited version"
);
options.addOption(
"i",
OPTION_IGNORE_SNAPSHOTS,
"o",
OPTION_INCLUDE_OUTPUT,
false,
"Ignore build file artifacts with a snapshot version"
"Include build files inside output directories"
);
options.addOption(
"s",
Expand Down Expand Up @@ -257,8 +269,9 @@ void run(final String... args) {
commandLine.hasOption(OPTION_MAX_DEPTH)
? Integer.parseUnsignedInt(commandLine.getOptionValue(OPTION_MAX_DEPTH))
: DEFAULT_MAX_DEPTH,
commandLine.hasOption(OPTION_IGNORE_INHERITED),
commandLine.hasOption(OPTION_IGNORE_SNAPSHOTS),
commandLine.hasOption(OPTION_IGNORE_INHERITED),
commandLine.hasOption(OPTION_INCLUDE_OUTPUT),
commandLine.hasOption(OPTION_SHORT)
);
}
Expand Down Expand Up @@ -318,19 +331,48 @@ void run(
* @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.7.0, use {@link #run(Path, int, boolean, boolean, boolean, boolean)} instead
* @since 1.5.0
*/
@Deprecated(since = "1.7.0")
void run(
final Path path,
final int maxDepth,
final boolean ignoreInherited,
final boolean ignoreSnapshots,
final boolean short0
) throws IOException {
run(path, maxDepth, ignoreSnapshots, ignoreInherited, true, short0);
}

/**
* <p>Run the program.</p>
* @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 ignoreInherited {@code true} if build file artifacts with an inherited version should be ignored
* @param includeOutput {@code true} if build files inside output directories should be included
* @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.7.0
*/
void run(
final Path path,
final int maxDepth,
final boolean ignoreSnapshots,
final boolean ignoreInherited,
final boolean includeOutput,
final boolean short0
) throws IOException {
Ensure.notNull("path", path);
Ensure.greaterThanOrEqualTo("maxDepth", maxDepth, 0);
final var service = createService();
final var buildFiles = service.findBuildFiles(path, maxDepth);
var buildFiles = service.findBuildFiles(path, maxDepth);
if (!includeOutput) {
buildFiles = service.filterBuildFiles(buildFiles);
}
if (buildFiles.isEmpty()) {
outputStream.println("No build file found");
return;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/github/alexisjehan/mvncheck/core/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ public List<BuildFile> findBuildFiles(final Path path, final int maxDepth) throw
}
}

/**
* <p>Filter a {@link List} of build files to ignore those inside output directories.</p>
* @param buildFiles a {@link List} of build files
* @return the {@link List} of build files
* @throws NullPointerException if the {@link List} of build files or any of them is {@code null}
* @since 1.7.0
*/
public List<BuildFile> filterBuildFiles(final List<BuildFile> buildFiles) {
Ensure.notNullAndNotNullElements("buildFiles", buildFiles);
final var outputDirectories = buildFiles.stream()
.map(buildFile -> buildFile.getFile().resolveSibling(buildFile.getType().getOutputDirectoryName()))
.collect(Collectors.toUnmodifiableList());
return buildFiles.stream()
.filter(buildFile -> outputDirectories.stream().noneMatch(buildFile.getFile()::startsWith))
.collect(Collectors.toUnmodifiableList());
}

/**
* <p>Find the build for the given build file.</p>
* @param buildFile a build file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,41 @@ public enum BuildFileType {
* <p>The <i>Maven</i> build file type.</p>
* @since 1.0.0
*/
MAVEN("pom.xml"),
MAVEN("pom.xml", "target"),

/**
* <p>The <i>Gradle Groovy</i> build file type.</p>
* @since 1.0.0
*/
GRADLE_GROOVY("build.gradle"),
GRADLE_GROOVY("build.gradle", "build"),

/**
* <p>The <i>Gradle Kotlin</i> build file type.</p>
* @since 1.0.0
*/
GRADLE_KOTLIN("build.gradle.kts");
GRADLE_KOTLIN("build.gradle.kts", "build");

/**
* <p>File name.</p>
* @since 1.0.0
*/
private final String fileName;

/**
* <p>Output directory name.</p>
* @since 1.7.0
*/
private final String outputDirectoryName;

/**
* <p>Constructor.</p>
* @param fileName a file name
* @since 1.0.0
* @param outputDirectoryName an output directory name
* @since 1.7.0
*/
BuildFileType(final String fileName) {
BuildFileType(final String fileName, final String outputDirectoryName) {
this.fileName = fileName;
this.outputDirectoryName = outputDirectoryName;
}

/**
Expand All @@ -76,6 +84,15 @@ public String getFileName() {
return fileName;
}

/**
* <p>Get the output directory name.</p>
* @return the output directory name
* @since 1.7.0
*/
public String getOutputDirectoryName() {
return outputDirectoryName;
}

/**
* <p>Return an {@link Optional} of the value for the given file name.</p>
* @param fileName a file name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ void testRun(@TempDir final Path tmpDirectory) throws IOException {
try (var outputStream = new ByteArrayOutputStream()) {
try (var printStream = new PrintStream(outputStream)) {
final var application = new Application(printStream);
application.run(tmpDirectory, 1, false, false, false);
application.run(
tmpDirectory,
1,
false,
false,
true,
false
);
}
assertThat(outputStream.toString()).matches(
"^"
Expand Down
Loading

0 comments on commit d2b1994

Please sign in to comment.