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.net.URI; 024import java.util.Collection; 025 026/** 027 * Factory of {@link org.sonar.api.batch.fs.FilePredicate} 028 * 029 * @since 4.2 030 */ 031public interface FilePredicates { 032 /** 033 * Predicate that always evaluates to true 034 */ 035 FilePredicate all(); 036 037 /** 038 * Predicate that always evaluates to false 039 */ 040 FilePredicate none(); 041 042 /** 043 * Predicate that find file by its absolute path. The parameter 044 * accepts forward/back slashes as separator and non-normalized values 045 * (<code>/path/to/../foo.txt</code> is same as <code>/path/foo.txt</code>). 046 * <p> 047 * Warning - may not be supported in SonarLint 048 */ 049 FilePredicate hasAbsolutePath(String s); 050 051 /** 052 * Predicate that gets a file by its relative path. The parameter 053 * accepts forward/back slashes as separator and non-normalized values 054 * (<code>foo/../bar.txt</code> is same as <code>bar.txt</code>). It must 055 * not be <code>null</code>. 056 * <p> 057 * Warning - may not be supported in SonarLint 058 */ 059 FilePredicate hasRelativePath(String s); 060 061 /** 062 * Predicate that matches files by filename, in any directory. 063 * For example, the parameter <code>Foo.java</code> will match both 064 * <code>some/path/Foo.java</code> and <code>other/path/Foo.java</code>. 065 * The parameter must match exactly, no patterns are allowed, 066 * and it must not be <code>null</code>. 067 * 068 * @since 6.3 069 */ 070 FilePredicate hasFilename(String s); 071 072 /** 073 * Predicate that matches files by extension (case insensitive). 074 * For example, the parameter <code>java</code> will match 075 * <code>some/path/Foo.java</code> and <code>other/path/Foo.JAVA</code> 076 * but not <code>some/path/Foo.js</code>. 077 * The parameter must not be <code>null</code>. 078 * 079 * @since 6.3 080 */ 081 FilePredicate hasExtension(String s); 082 083 /** 084 * Predicate that gets a file by its {@link InputFile#uri()}. 085 * 086 * @since 6.6 087 */ 088 FilePredicate hasURI(URI uri); 089 090 /** 091 * Predicate that gets the files which "path" matches a wildcard pattern. 092 * <p> 093 * The path is the path part of the {@link InputFile#uri()}. Pattern is case-sensitive, except for file extension. 094 * <p> 095 * Supported wildcards are <code>*</code> and <code>**</code>, but not <code>?</code>. 096 * <br> 097 * Examples: 098 * <ul> 099 * <li><code>**/*Foo.java</code> matches Foo.java, src/Foo.java and src/java/SuperFoo.java</li> 100 * <li><code>**/*Foo*.java</code> matches src/Foo.java, src/BarFoo.java, src/FooBar.java 101 * and src/BarFooBaz.java</li> 102 * <li><code>**/*FOO.JAVA</code> matches FOO.java and FOO.JAVA but not Foo.java</li> 103 * </ul> 104 */ 105 FilePredicate matchesPathPattern(String inclusionPattern); 106 107 /** 108 * Predicate that gets the files matching at least one wildcard pattern. No filter is applied when 109 * zero wildcard patterns (similar to {@link #all()}. 110 * @see #matchesPathPattern(String) 111 */ 112 FilePredicate matchesPathPatterns(String[] inclusionPatterns); 113 114 /** 115 * Predicate that gets the files that do not match the given wildcard pattern. 116 * @see #matchesPathPattern(String) 117 */ 118 FilePredicate doesNotMatchPathPattern(String exclusionPattern); 119 120 /** 121 * Predicate that gets the files that do not match any of the given wildcard patterns. No filter is applied when 122 * zero wildcard patterns (similar to {@link #all()}. 123 * @see #matchesPathPattern(String) 124 */ 125 FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns); 126 127 /** 128 * if the parameter represents an absolute path for the running environment, then 129 * returns {@link #hasAbsolutePath(String)}, else {@link #hasRelativePath(String)} 130 * <p> 131 * Warning - may not be supported in SonarLint 132 */ 133 FilePredicate hasPath(String s); 134 135 /** 136 * Warning - may not be supported in SonarLint 137 */ 138 FilePredicate is(File ioFile); 139 140 FilePredicate hasLanguage(String language); 141 142 FilePredicate hasLanguages(Collection<String> languages); 143 144 FilePredicate hasLanguages(String... languages); 145 146 FilePredicate hasType(InputFile.Type type); 147 148 FilePredicate not(FilePredicate p); 149 150 FilePredicate or(Collection<FilePredicate> or); 151 152 FilePredicate or(FilePredicate... or); 153 154 FilePredicate or(FilePredicate first, FilePredicate second); 155 156 FilePredicate and(Collection<FilePredicate> and); 157 158 FilePredicate and(FilePredicate... and); 159 160 FilePredicate and(FilePredicate first, FilePredicate second); 161 162 /** 163 * Look for InputFile having a specific {@link InputFile#status()} 164 * @since 6.6 165 */ 166 FilePredicate hasStatus(InputFile.Status status); 167 168 /** 169 * Explicitely look for InputFile having any {@link InputFile#status()} 170 * @since 6.6 171 */ 172 FilePredicate hasAnyStatus(); 173 174}