org.sonar.api.batch.fs.FilePredicates Maven / Gradle / Ivy
Show all versions of sonar-plugin-api Show documentation
/*
* Sonar Plugin API
* Copyright (C) 2009-2022 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.batch.fs;
import java.io.File;
import java.net.URI;
import java.util.Collection;
/**
* Factory of {@link org.sonar.api.batch.fs.FilePredicate}
*
* @since 4.2
*/
public interface FilePredicates {
/**
* Predicate that always evaluates to true
*/
FilePredicate all();
/**
* Predicate that always evaluates to false
*/
FilePredicate none();
/**
* Predicate that find file by its absolute path. The parameter
* accepts forward/back slashes as separator and non-normalized values
* (/path/to/../foo.txt
is same as /path/foo.txt
).
*
* Warning - may not be supported in SonarLint
*/
FilePredicate hasAbsolutePath(String s);
/**
* Predicate that gets a file by its relative path. The parameter
* accepts forward/back slashes as separator and non-normalized values
* (foo/../bar.txt
is same as bar.txt
). It must
* not be null
.
*
* Warning - may not be supported in SonarLint
*/
FilePredicate hasRelativePath(String s);
/**
* Predicate that matches files by filename, in any directory.
* For example, the parameter Foo.java
will match both
* some/path/Foo.java
and other/path/Foo.java
.
* The parameter must match exactly, no patterns are allowed,
* and it must not be null
.
*
* @since 6.3
*/
FilePredicate hasFilename(String s);
/**
* Predicate that matches files by extension (case insensitive).
* For example, the parameter java
will match
* some/path/Foo.java
and other/path/Foo.JAVA
* but not some/path/Foo.js
.
* The parameter must not be null
.
*
* @since 6.3
*/
FilePredicate hasExtension(String s);
/**
* Predicate that gets a file by its {@link InputFile#uri()}.
*
* @since 6.6
*/
FilePredicate hasURI(URI uri);
/**
* Predicate that gets the files which "path" matches a wildcard pattern.
*
* The path is the path part of the {@link InputFile#uri()}. Pattern is case-sensitive, except for file extension.
*
* Supported wildcards are *
and **
, but not ?
.
*
* Examples:
*
* **/*Foo.java
matches Foo.java, src/Foo.java and src/java/SuperFoo.java
* **/*Foo*.java
matches src/Foo.java, src/BarFoo.java, src/FooBar.java
* and src/BarFooBaz.java
* **/*FOO.JAVA
matches FOO.java and FOO.JAVA but not Foo.java
*
*/
FilePredicate matchesPathPattern(String inclusionPattern);
/**
* Predicate that gets the files matching at least one wildcard pattern. No filter is applied when
* zero wildcard patterns (similar to {@link #all()}.
* @see #matchesPathPattern(String)
*/
FilePredicate matchesPathPatterns(String[] inclusionPatterns);
/**
* Predicate that gets the files that do not match the given wildcard pattern.
* @see #matchesPathPattern(String)
*/
FilePredicate doesNotMatchPathPattern(String exclusionPattern);
/**
* Predicate that gets the files that do not match any of the given wildcard patterns. No filter is applied when
* zero wildcard patterns (similar to {@link #all()}.
* @see #matchesPathPattern(String)
*/
FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns);
/**
* if the parameter represents an absolute path for the running environment, then
* returns {@link #hasAbsolutePath(String)}, else {@link #hasRelativePath(String)}
*
* Warning - may not be supported in SonarLint
*/
FilePredicate hasPath(String s);
/**
* Warning - may not be supported in SonarLint
*/
FilePredicate is(File ioFile);
FilePredicate hasLanguage(String language);
FilePredicate hasLanguages(Collection languages);
FilePredicate hasLanguages(String... languages);
FilePredicate hasType(InputFile.Type type);
FilePredicate not(FilePredicate p);
FilePredicate or(Collection or);
FilePredicate or(FilePredicate... or);
FilePredicate or(FilePredicate first, FilePredicate second);
FilePredicate and(Collection and);
FilePredicate and(FilePredicate... and);
FilePredicate and(FilePredicate first, FilePredicate second);
/**
* Look for InputFile having a specific {@link InputFile#status()}
* @since 6.6
*/
FilePredicate hasStatus(InputFile.Status status);
/**
* Explicitely look for InputFile having any {@link InputFile#status()}
* @since 6.6
*/
FilePredicate hasAnyStatus();
}