001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.batch.fs;
021
022import java.io.File;
023import java.util.Collection;
024
025/**
026 * Factory of {@link org.sonar.api.batch.fs.FilePredicate}
027 *
028 * @since 4.2
029 */
030public interface FilePredicates {
031  /**
032   * Predicate that always evaluates to true
033   */
034  FilePredicate all();
035
036  /**
037   * Predicate that always evaluates to false
038   */
039  FilePredicate none();
040
041  /**
042   * Predicate that gets a file by its absolute path. The parameter
043   * accepts forward/back slashes as separator and non-normalized values
044   * (<code>/path/to/../foo.txt</code> is same as <code>/path/foo.txt</code>).
045   * <p>
046   * Warning - not efficient because absolute path is not indexed yet.
047   */
048  FilePredicate hasAbsolutePath(String s);
049
050  /**
051   * Predicate that gets a file by its relative path. The parameter
052   * accepts forward/back slashes as separator and non-normalized values
053   * (<code>foo/../bar.txt</code> is same as <code>bar.txt</code>). It must
054   * not be <code>null</code>.
055   */
056  FilePredicate hasRelativePath(String s);
057
058  /**
059   * Predicate that matches files by filename, in any directory.
060   * For example, the parameter <code>Foo.java</code> will match both
061   * <code>some/path/Foo.java</code> and <code>other/path/Foo.java</code>.
062   * The parameter must match exactly, no patterns are allowed,
063   * and it must not be <code>null</code>.
064   * 
065   * @since 6.3
066   */
067  FilePredicate hasFilename(String s);
068
069  /**
070   * Predicate that matches files by extension (case insensitive).
071   * For example, the parameter <code>java</code> will match
072   * <code>some/path/Foo.java</code> and <code>other/path/Foo.JAVA</code>
073   * but not <code>some/path/Foo.js</code>.
074   * The parameter must not be <code>null</code>.
075   * 
076   * @since 6.3
077   */
078  FilePredicate hasExtension(String s);
079
080  /**
081   * Predicate that gets the files which relative or absolute path matches a wildcard pattern.
082   * <br>
083   * If the parameter starts with <code>file:</code>, then absolute path is used, else relative path. Pattern
084   * is case-sensitive, except for file extension.
085   * <br>
086   * Supported wildcards are <code>&#42;</code> and <code>&#42;&#42;</code>, but not <code>?</code>.
087   * <br>
088   * Examples:
089   * <ul>
090   *   <li><code>&#42;&#42;/&#42;Foo.java</code> matches Foo.java, src/Foo.java and src/java/SuperFoo.java</li>
091   *   <li><code>&#42;&#42;/&#42;Foo&#42;.java</code> matches src/Foo.java, src/BarFoo.java, src/FooBar.java
092   *   and src/BarFooBaz.java</li>
093   *   <li><code>&#42;&#42;/&#42;FOO.JAVA</code> matches FOO.java and FOO.JAVA but not Foo.java</li>
094   *   <li><code>file:&#42;&#42;/src/&#42;Foo.java</code> matches /path/to/src/Foo.java on unix and c:\path\to\Foo.java on MSWindows</li>
095   * </ul>
096   */
097  FilePredicate matchesPathPattern(String inclusionPattern);
098
099  /**
100   * Predicate that gets the files matching at least one wildcard pattern. No filter is applied when
101   * zero wildcard patterns (similar to {@link #all()}.
102   * @see #matchesPathPattern(String)
103   */
104  FilePredicate matchesPathPatterns(String[] inclusionPatterns);
105
106  /**
107   * Predicate that gets the files that do not match the given wildcard pattern.
108   * @see #matchesPathPattern(String)
109   */
110  FilePredicate doesNotMatchPathPattern(String exclusionPattern);
111
112  /**
113   * Predicate that gets the files that do not match any of the given wildcard patterns. No filter is applied when
114   * zero wildcard patterns (similar to {@link #all()}.
115   * @see #matchesPathPattern(String)
116   */
117  FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns);
118
119  /**
120   * if the parameter represents an absolute path for the running environment, then
121   * returns {@link #hasAbsolutePath(String)}, else {@link #hasRelativePath(String)}
122   */
123  FilePredicate hasPath(String s);
124
125  FilePredicate is(File ioFile);
126
127  FilePredicate hasLanguage(String language);
128
129  FilePredicate hasLanguages(Collection<String> languages);
130
131  FilePredicate hasLanguages(String... languages);
132
133  FilePredicate hasType(InputFile.Type type);
134
135  FilePredicate not(FilePredicate p);
136
137  FilePredicate or(Collection<FilePredicate> or);
138
139  FilePredicate or(FilePredicate... or);
140
141  FilePredicate or(FilePredicate first, FilePredicate second);
142
143  FilePredicate and(Collection<FilePredicate> and);
144
145  FilePredicate and(FilePredicate... and);
146
147  FilePredicate and(FilePredicate first, FilePredicate second);
148
149}