本文整理汇总了Java中org.sonar.api.batch.fs.FilePredicate类的典型用法代码示例。如果您正苦于以下问题:Java FilePredicate类的具体用法?Java FilePredicate怎么用?Java FilePredicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilePredicate类属于org.sonar.api.batch.fs包,在下文中一共展示了FilePredicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
public static FilePredicate create(Collection<FilePredicate> predicates) {
if (predicates.isEmpty()) {
return TruePredicate.TRUE;
}
AndPredicate result = new AndPredicate();
for (FilePredicate filePredicate : predicates) {
if (filePredicate == TruePredicate.TRUE) {
continue;
} else if (filePredicate == FalsePredicate.FALSE) {
return FalsePredicate.FALSE;
} else if (filePredicate instanceof AndPredicate) {
result.predicates.addAll(((AndPredicate) filePredicate).predicates);
} else {
result.predicates.add(OptimizedFilePredicateAdapter.create(filePredicate));
}
}
Collections.sort(result.predicates);
return result;
}
示例2: create
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
public static FilePredicate create(Collection<FilePredicate> predicates) {
if (predicates.isEmpty()) {
return TruePredicate.TRUE;
}
OrPredicate result = new OrPredicate();
for (FilePredicate filePredicate : predicates) {
if (filePredicate == TruePredicate.TRUE) {
return TruePredicate.TRUE;
} else if (filePredicate == FalsePredicate.FALSE) {
continue;
} else if (filePredicate instanceof OrPredicate) {
result.predicates.addAll(((OrPredicate) filePredicate).predicates);
} else {
result.predicates.add(filePredicate);
}
}
return result;
}
示例3: key
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Test
public void key() {
FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");
DefaultInputFile inputFile = new TestInputFileBuilder("struts", "Action.java").build();
assertThat(predicate.apply(inputFile)).isTrue();
inputFile = new TestInputFileBuilder("struts", "Filter.java").build();
assertThat(predicate.apply(inputFile)).isFalse();
}
示例4: and
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Test
public void and() {
// empty
assertThat(predicates.and().apply(javaFile)).isTrue();
assertThat(predicates.and(new FilePredicate[0]).apply(javaFile)).isTrue();
assertThat(predicates.and(Collections.<FilePredicate>emptyList()).apply(javaFile)).isTrue();
// two arguments
assertThat(predicates.and(predicates.all(), predicates.all()).apply(javaFile)).isTrue();
assertThat(predicates.and(predicates.all(), predicates.none()).apply(javaFile)).isFalse();
assertThat(predicates.and(predicates.none(), predicates.all()).apply(javaFile)).isFalse();
// collection
assertThat(predicates.and(Arrays.asList(predicates.all(), predicates.all())).apply(javaFile)).isTrue();
assertThat(predicates.and(Arrays.asList(predicates.all(), predicates.none())).apply(javaFile)).isFalse();
// array
assertThat(predicates.and(new FilePredicate[] {predicates.all(), predicates.all()}).apply(javaFile)).isTrue();
assertThat(predicates.and(new FilePredicate[] {predicates.all(), predicates.none()}).apply(javaFile)).isFalse();
}
示例5: or
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Test
public void or() {
// empty
assertThat(predicates.or().apply(javaFile)).isTrue();
assertThat(predicates.or(new FilePredicate[0]).apply(javaFile)).isTrue();
assertThat(predicates.or(Collections.<FilePredicate>emptyList()).apply(javaFile)).isTrue();
// two arguments
assertThat(predicates.or(predicates.all(), predicates.all()).apply(javaFile)).isTrue();
assertThat(predicates.or(predicates.all(), predicates.none()).apply(javaFile)).isTrue();
assertThat(predicates.or(predicates.none(), predicates.all()).apply(javaFile)).isTrue();
assertThat(predicates.or(predicates.none(), predicates.none()).apply(javaFile)).isFalse();
// collection
assertThat(predicates.or(Arrays.asList(predicates.all(), predicates.all())).apply(javaFile)).isTrue();
assertThat(predicates.or(Arrays.asList(predicates.all(), predicates.none())).apply(javaFile)).isTrue();
assertThat(predicates.or(Arrays.asList(predicates.none(), predicates.none())).apply(javaFile)).isFalse();
// array
assertThat(predicates.or(new FilePredicate[] {predicates.all(), predicates.all()}).apply(javaFile)).isTrue();
assertThat(predicates.or(new FilePredicate[] {predicates.all(), predicates.none()}).apply(javaFile)).isTrue();
assertThat(predicates.or(new FilePredicate[] {predicates.none(), predicates.none()}).apply(javaFile)).isFalse();
}
示例6: buildModel
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
protected Model<Location> buildModel(final SensorContext context) {
// Result
final Model<Location> model = new Model<>();
final ModelCreatingTreeVisitor visitor = new ModelCreatingTreeVisitor(model);
// Read all source files
final ActionParser<Tree> parser = JavaParser.createParser();
final JavaClasspath javaClassPath = new JavaClasspath(settings, context.fileSystem());
final FileSystem fs = context.fileSystem();
// Scan only main files for the 'current' language.
final FilePredicate filesToScan = fs.predicates().and(fs.predicates().hasType(Type.MAIN),
fs.predicates().hasLanguage(LANGUAGE));
for (final InputFile file : fs.inputFiles(filesToScan)) {
// Parse source
LOGGER.debug("Analyzing source file: {}", file.relativePath());
try {
visitor.on(file);
final Tree tree = parser.parse(file.contents());
// Create semantic model
LOGGER.debug("Creating semantic model ...");
SemanticModel.createFor((CompilationUnitTree) tree, javaClassPath.getElements());
// Read into model
LOGGER.debug("Reading model ...");
tree.accept(visitor);
} catch (final IOException e) {
LOGGER.warn("Could not read contents for {}", file.relativePath(), e);
}
}
return model;
}
示例7: fsCondition
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
private boolean fsCondition(DefaultSensorDescriptor descriptor) {
if (!descriptor.languages().isEmpty() || descriptor.type() != null) {
FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages());
FilePredicate typePredicate = descriptor.type() == null ? fs.predicates().all() : fs.predicates().hasType(descriptor.type());
return fs.hasFiles(fs.predicates().and(langPredicate, typePredicate));
}
return true;
}
示例8: create
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
public static OptimizedFilePredicate create(FilePredicate predicate) {
if (predicate instanceof OptimizedFilePredicate) {
return (OptimizedFilePredicate) predicate;
} else {
return new OptimizedFilePredicateAdapter(predicate);
}
}
示例9: matchesPathPatterns
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
public FilePredicate matchesPathPatterns(String[] inclusionPatterns) {
if (inclusionPatterns.length == 0) {
return TruePredicate.TRUE;
}
FilePredicate[] predicates = new FilePredicate[inclusionPatterns.length];
for (int i = 0; i < inclusionPatterns.length; i++) {
predicates[i] = new PathPatternPredicate(PathPattern.create(toAbsolutePattern(inclusionPatterns[i])));
}
return or(predicates);
}
示例10: doesNotMatchPathPatterns
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
public FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns) {
if (exclusionPatterns.length == 0) {
return TruePredicate.TRUE;
}
return not(matchesPathPatterns(exclusionPatterns));
}
示例11: hasPath
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
public FilePredicate hasPath(String s) {
File file = new File(s);
if (file.isAbsolute()) {
return hasAbsolutePath(s);
}
return hasRelativePath(s);
}
示例12: is
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
public FilePredicate is(File ioFile) {
if (ioFile.isAbsolute()) {
return hasAbsolutePath(ioFile.getAbsolutePath());
}
return hasRelativePath(ioFile.getPath());
}
示例13: hasLanguages
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
public FilePredicate hasLanguages(Collection<String> languages) {
List<FilePredicate> list = new ArrayList<>();
for (String language : languages) {
list.add(hasLanguage(language));
}
return or(list);
}
示例14: apply
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
@Override
public boolean apply(InputFile f) {
for (FilePredicate predicate : predicates) {
if (predicate.apply(f)) {
return true;
}
}
return false;
}
示例15: locateSourceFile
import org.sonar.api.batch.fs.FilePredicate; //导入依赖的package包/类
private InputFile locateSourceFile(String sourceFilePath) throws IOException {
String relativeSourceFilePath = makeRelativePath(sourceFilePath, fileSystem.baseDir());
FilePredicate filePredicate = fileSystem.predicates().matchesPathPattern("**/" + relativeSourceFilePath);
InputFile inputFile = fileSystem.inputFile(filePredicate);
if (inputFile == null) {
log.warn("Could not find input file {} in {}", relativeSourceFilePath, fileSystem.baseDir().getAbsolutePath());
}
return inputFile;
}