001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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 */
020 package org.sonar.api.batch.fs;
021
022 import java.io.File;
023 import java.util.Collection;
024
025 /**
026 * Factory of {@link org.sonar.api.batch.fs.FilePredicate}
027 *
028 * @since 4.2
029 */
030 public 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 gets the files which relative or absolute path matches a wildcard pattern.
060 * <p/>
061 * If the parameter starts with <code>file:</code>, then absolute path is used, else relative path. Pattern
062 * is case-sensitive, except for file extension.
063 * <p/>
064 * Supported wildcards are <code>*</code> and <code>**</code>, but not <code>?</code>.
065 * <p/>
066 * Examples:
067 * <ul>
068 * <li><code>**/*Foo.java</code> matches Foo.java, src/Foo.java and src/java/SuperFoo.java</li>
069 * <li><code>**/*Foo*.java</code> matches src/Foo.java, src/BarFoo.java, src/FooBar.java
070 * and src/BarFooBaz.java</li>
071 * <li><code>**/*FOO.JAVA</code> matches FOO.java and FOO.JAVA but not Foo.java</li>
072 * <li><code>file:**/src/*Foo.java</code> matches /path/to/src/Foo.java on unix and c:\path\to\Foo.java on MSWindows</li>
073 * </ul>
074 */
075 FilePredicate matchesPathPattern(String inclusionPattern);
076
077 /**
078 * Predicate that gets the files matching at least one wildcard pattern. No filter is applied when
079 * zero wildcard patterns (similar to {@link #all()}.
080 * @see #matchesPathPattern(String)
081 */
082 FilePredicate matchesPathPatterns(String[] inclusionPatterns);
083
084 /**
085 * Predicate that gets the files that do not match the given wildcard pattern.
086 * @see #matchesPathPattern(String)
087 */
088 FilePredicate doesNotMatchPathPattern(String exclusionPattern);
089
090 /**
091 * Predicate that gets the files that do not match any of the given wildcard patterns. No filter is applied when
092 * zero wildcard patterns (similar to {@link #all()}.
093 * @see #matchesPathPattern(String)
094 */
095 FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns);
096
097 /**
098 * if the parameter represents an absolute path for the running environment, then
099 * returns {@link #hasAbsolutePath(String)}, else {@link #hasRelativePath(String)}
100 */
101 FilePredicate hasPath(String s);
102
103 FilePredicate is(File ioFile);
104
105 FilePredicate hasLanguage(String language);
106
107 FilePredicate hasLanguages(Collection<String> languages);
108
109 FilePredicate hasLanguages(String... languages);
110
111 FilePredicate hasStatus(InputFile.Status status);
112
113 FilePredicate hasType(InputFile.Type type);
114
115 FilePredicate not(FilePredicate p);
116
117 FilePredicate or(Collection<FilePredicate> or);
118
119 FilePredicate or(FilePredicate... or);
120
121 FilePredicate or(FilePredicate first, FilePredicate second);
122
123 FilePredicate and(Collection<FilePredicate> and);
124
125 FilePredicate and(FilePredicate... and);
126
127 FilePredicate and(FilePredicate first, FilePredicate second);
128
129 }