Tabnine Logo
FilePredicates.hasPath
Code IndexAdd Tabnine to your IDE (free)

How to use
hasPath
method
in
org.sonar.api.batch.fs.FilePredicates

Best Java code snippets using org.sonar.api.batch.fs.FilePredicates.hasPath (Showing top 20 results out of 315)

origin: SonarSource/sonarqube

@CheckForNull
private static InputFile findFile(SensorContext context, String filePath) {
 return context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
}
origin: SonarSource/sonarqube

Iterator<String> splitCoveredBlock = Splitter.on(",").split(coveredBlockStr).iterator();
String componentPath = splitCoveredBlock.next();
InputFile coveredFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(componentPath));
MutableTestable testable = perspectives.as(MutableTestable.class, coveredFile);
List<Integer> coveredLines = new ArrayList<>();
origin: SonarSource/sonarqube

@Test
public void has_path() throws Exception {
 // is relative path
 assertThat(predicates.hasPath("src/main/java/struts/Action.java").apply(javaFile)).isTrue();
 assertThat(predicates.hasPath("src/main/java/struts/Other.java").apply(javaFile)).isFalse();
 // is absolute path
 String path = javaFile.file().getAbsolutePath();
 assertThat(predicates.hasAbsolutePath(path).apply(javaFile)).isTrue();
 assertThat(predicates.hasPath(temp.newFile().getAbsolutePath()).apply(javaFile)).isFalse();
}
origin: SonarSource/sonarqube

@Override
public void execute(SensorContext context) {
 File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS));
 FileSystem fs = context.fileSystem();
 FilePredicates p = fs.predicates();
 try {
  for (String path : FileUtils.readLines(f)) {
   createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
  }
 } catch (IOException e) {
  throw new IllegalStateException(e);
 }
}
origin: SonarSource/sonarqube

private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException {
 while (fileCursor.getNext() != null) {
  checkElementName(fileCursor, "file");
  String filePath = mandatoryAttribute(fileCursor, "path");
  InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
  if (inputFile == null) {
   numberOfUnknownFiles++;
   if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) {
    firstUnknownFiles.add(filePath);
   }
   continue;
  }
  Preconditions.checkState(
   inputFile.language() != null,
   "Line %s of report refers to a file with an unknown language: %s",
   fileCursor.getCursorLocation().getLineNumber(),
   filePath);
  Preconditions.checkState(
   inputFile.type() != InputFile.Type.MAIN,
   "Line %s of report refers to a file which is not configured as a test file: %s",
   fileCursor.getCursorLocation().getLineNumber(),
   filePath);
  matchedFileKeys.add(inputFile.absolutePath());
  MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, inputFile);
  SMInputCursor testCaseCursor = fileCursor.childElementCursor();
  while (testCaseCursor.getNext() != null) {
   parseTestCase(testCaseCursor, testPlan);
  }
 }
}
origin: SonarSource/sonarqube

private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException {
 while (fileCursor.getNext() != null) {
  checkElementName(fileCursor, "file");
  String filePath = mandatoryAttribute(fileCursor, "path");
  InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
  if (inputFile == null) {
   numberOfUnknownFiles++;
   if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) {
    firstUnknownFiles.add(filePath);
   }
   continue;
  }
  Preconditions.checkState(
   inputFile.language() != null,
   "Line %s of report refers to a file with an unknown language: %s",
   fileCursor.getCursorLocation().getLineNumber(),
   filePath);
  matchedFileKeys.add(inputFile.key());
  NewCoverage newCoverage = context.newCoverage().onFile(inputFile);
  SMInputCursor lineToCoverCursor = fileCursor.childElementCursor();
  while (lineToCoverCursor.getNext() != null) {
   parseLineToCover(lineToCoverCursor, newCoverage);
  }
  newCoverage.save();
 }
}
origin: SonarSource/sonar-java

private static InputFile findInputFile(SensorContext context, List<String> sourceDirs, String relativeLinuxPath) {
 FilePredicates predicates = context.fileSystem().predicates();
 InputFile inputFile = null;
 for (String sourceDir : sourceDirs) {
  File sourceFile = new File(sourceDir, relativeLinuxPath);
  inputFile = context.fileSystem().inputFile(predicates.hasPath(sourceFile.toString()));
  if (inputFile != null) {
   break;
  }
 }
 return inputFile;
}
origin: org.sonarsource.java/external-reports

private static InputFile findInputFile(SensorContext context, List<String> sourceDirs, String relativeLinuxPath) {
 FilePredicates predicates = context.fileSystem().predicates();
 InputFile inputFile = null;
 for (String sourceDir : sourceDirs) {
  File sourceFile = new File(sourceDir, relativeLinuxPath);
  inputFile = context.fileSystem().inputFile(predicates.hasPath(sourceFile.toString()));
  if (inputFile != null) {
   break;
  }
 }
 return inputFile;
}
origin: uartois/sonar-golang

public static InputFile getByPath(final SensorContext context, final String filePath) {
final FileSystem fileSystem = context.fileSystem();
final FilePredicates predicates = fileSystem.predicates();
return fileSystem.inputFile(predicates.hasPath(filePath));
}
origin: SonarSource/sonar-java

private void onFileElement(StartElement element) {
 String filePath = getAttributeValue(element, NAME);
 if (filePath.isEmpty()) {
  inputFile = null;
  return;
 }
 FilePredicates predicates = context.fileSystem().predicates();
 inputFile = context.fileSystem().inputFile(predicates.hasPath(filePath));
 if (inputFile == null) {
  LOG.warn("No input file found for '{}'. No checkstyle issues will be imported on this file.", filePath);
 }
}
origin: Backelite/sonar-swift

private InputFile getFile(String filePath) {
  FilePredicate fp = context.fileSystem().predicates().hasPath(filePath);
  if(context.fileSystem().hasFiles(fp))
    return context.fileSystem().inputFile(fp);
  LOGGER.warn("Can't find file {}",filePath);
  return null;
}
origin: org.sonarsource.sonarqube/sonar-xoo-plugin

@Override
public void execute(SensorContext context) {
 File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS));
 FileSystem fs = context.fileSystem();
 FilePredicates p = fs.predicates();
 try {
  for (String path : FileUtils.readLines(f)) {
   createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
  }
 } catch (IOException e) {
  throw new IllegalStateException(e);
 }
}
origin: org.sonarsource.java/external-reports

private void onFileElement(StartElement element) {
 String filePath = getAttributeValue(element, NAME);
 if (filePath.isEmpty()) {
  inputFile = null;
  return;
 }
 FilePredicates predicates = context.fileSystem().predicates();
 inputFile = context.fileSystem().inputFile(predicates.hasPath(filePath));
 if (inputFile == null) {
  LOG.warn("No input file found for '{}'. No checkstyle issues will be imported on this file.", filePath);
 }
}
origin: org.codehaus.sonar.plugins/sonar-xoo-plugin

@Override
public void execute(SensorContext context) {
 File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS));
 FileSystem fs = context.fileSystem();
 FilePredicates p = fs.predicates();
 try {
  for (String path : FileUtils.readLines(f)) {
   createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
  }
 } catch (IOException e) {
  throw new IllegalStateException(e);
 }
}
origin: SonarSource/sonar-php

private InputFile getUnitTestInputFile(FileSystem fileSystem) {
 FilePredicates predicates = fileSystem.predicates();
 return fileSystem.inputFile(predicates.and(
  predicates.hasPath(file),
  predicates.hasType(InputFile.Type.TEST),
  predicates.hasLanguage(Php.KEY)));
}
origin: org.sonarsource.php/sonar-php-plugin

private InputFile getUnitTestInputFile(FileSystem fileSystem) {
 FilePredicates predicates = fileSystem.predicates();
 return fileSystem.inputFile(predicates.and(
  predicates.hasPath(file),
  predicates.hasType(InputFile.Type.TEST),
  predicates.hasLanguage(Php.KEY)));
}
origin: org.sonarsource.typescript/sonar-typescript-plugin

private static InputFile getInputFile(SensorContext context, String fileName) {
 FilePredicates predicates = context.fileSystem().predicates();
 InputFile inputFile = context.fileSystem().inputFile(predicates.hasPath(fileName));
 if (inputFile == null) {
  LOG.warn("No input file found for {}. No {} issues will be imported on this file.", fileName, LINER_NAME);
  return null;
 }
 return inputFile;
}
origin: sonar-perl/sonar-perl

  /**
   * Gets the file pointed by the report.
   *
   * @param filePath the unit test report
   */
  private InputFile getUnitTestInputFile(String filePath) {
   return fileSystem.inputFile(fileSystem.predicates().and(
    filePredicates.hasPath(filePath),
    filePredicates.hasType(InputFile.Type.TEST),
    filePredicates.hasLanguage(PerlLanguage.KEY)));
  }
}
origin: SonarSource/sonar-python

private static void saveIssues(List<Issue> issues, SensorContext context) {
 FileSystem fileSystem = context.fileSystem();
 for (Issue pylintIssue : issues) {
  String filepath = pylintIssue.getFilename();
  InputFile pyfile = fileSystem.inputFile(fileSystem.predicates().hasPath(filepath));
  if (pyfile != null) {
   ActiveRule rule = context.activeRules().find(RuleKey.of(PylintRuleRepository.REPOSITORY_KEY, pylintIssue.getRuleId()));
   processRule(pylintIssue, pyfile, rule, context);
  } else {
   LOG.warn("Cannot find the file '{}' in SonarQube, ignoring violation", filepath);
  }
 }
}
origin: uartois/sonar-golang

private void getResourceAndSaveIssue(final GoError error) {
FilePredicates predicates = fileSystem.predicates();
InputFile inputFile = fileSystem.inputFile(
  predicates.and(predicates.hasPath(error.getFilePath()), predicates.hasType(InputFile.Type.MAIN)));
GoKeyRule.init();
if (inputFile != null) {
  saveIssue(inputFile, error.getLine(), GoKeyRule.getKeyFromError(error), error.getMessage());
} else {
  LOGGER.error("Not able to find an InputFile from " + error.getFilePath());
}
}
org.sonar.api.batch.fsFilePredicateshasPath

Javadoc

if the parameter represents an absolute path for the running environment, then returns #hasAbsolutePath(String), else #hasRelativePath(String)

Warning - may not be supported in SonarLint

Popular methods of FilePredicates

  • hasLanguage
  • and
  • hasType
  • hasAbsolutePath
    Predicate that find file by its absolute path. The parameter accepts forward/back slashes as separat
  • hasRelativePath
    Predicate that gets a file by its relative path. The parameter accepts forward/back slashes as separ
  • all
    Predicate that always evaluates to true
  • matchesPathPattern
    Predicate that gets the files which "path" matches a wildcard pattern. The path is the path part of
  • or
  • hasLanguages
  • is
    Warning - may not be supported in SonarLint
  • hasStatus
    Look for InputFile having a specific InputFile#status()
  • doesNotMatchPathPatterns
    Predicate that gets the files that do not match any of the given wildcard patterns. No filter is app
  • hasStatus,
  • doesNotMatchPathPatterns,
  • not,
  • hasAnyStatus,
  • matchesPathPatterns,
  • doesNotMatchPathPattern,
  • hasExtension,
  • hasFilename,
  • hasURI

Popular in Java

  • Updating database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • setRequestProperty (URLConnection)
  • runOnUiThread (Activity)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now