1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3 * SPDX-License-Identifier: MIT
4 */
5 package com.qulice.spi;
6
7 import java.util.List;
8
9 /**
10 * A file Qulice leaves alone, wherever the project keeps it.
11 *
12 * <p>Three directories of a Maven project hold Java files that are not
13 * sources of the product, and Checkstyle, PMD and ErrorProne have
14 * nothing useful to say about any of them:</p>
15 *
16 * <ul>
17 * <li>{@code src/test/resources} holds fixtures: inputs to the tests,
18 * which Maven never compiles and which quite often are broken on
19 * purpose, because that is exactly what the test needs them to be;</li>
20 * <li>{@code src/site} holds the sources of the Maven site, where a
21 * {@code .java} file is an illustration in the documentation rather
22 * than code that ships;</li>
23 * <li>{@code src/it} holds whole projects of their own, the ones
24 * {@code maven-invoker-plugin} builds, each with its own POM and its
25 * own idea of what good code looks like.</li>
26 * </ul>
27 *
28 * <p>All three are skipped by default, without the project having to
29 * say so through an {@code <exclude>} of its own.</p>
30 *
31 * <p>The path handed to the constructor is the one {@link Relative}
32 * makes: forward slashes, relative to the base directory of the project
33 * and starting with a slash, or absolute when the file lies outside of
34 * it. Both forms are recognised, and so is a file of a nested Maven
35 * module, whose own {@code src/site} the path merely contains. The
36 * trailing slash of each directory is part of the match, so a
37 * {@code src/itest} of someone else's making stays in.</p>
38 *
39 * @since 1.0
40 */
41 public final class Ignored {
42
43 /**
44 * The directories left alone, by Maven convention.
45 */
46 private static final List<String> DIRS = List.of(
47 "/src/test/resources/",
48 "/src/site/",
49 "/src/it/"
50 );
51
52 /**
53 * The path of the file.
54 */
55 private final String path;
56
57 /**
58 * Ctor.
59 *
60 * @param file Path of the file, the way {@link Relative} makes it
61 */
62 public Ignored(final String file) {
63 this.path = file;
64 }
65
66 /**
67 * Is this file ignored?
68 *
69 * @return TRUE if the file is inside one of the ignored directories
70 */
71 public boolean yes() {
72 return Ignored.DIRS.stream().anyMatch(this.path::contains);
73 }
74 }