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

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

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

origin: SonarSource/sonarqube

@Test
public void has_absolute_path() throws Exception {
 String path = javaFile.file().getAbsolutePath();
 assertThat(predicates.hasAbsolutePath(path).apply(javaFile)).isTrue();
 assertThat(predicates.hasAbsolutePath(path.replaceAll("/", "\\\\")).apply(javaFile)).isTrue();
 assertThat(predicates.hasAbsolutePath(temp.newFile().getAbsolutePath()).apply(javaFile)).isFalse();
 assertThat(predicates.hasAbsolutePath("src/main/java/struts/Action.java").apply(javaFile)).isFalse();
}
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

@Test
public void files() {
 assertThat(fs.inputFiles(fs.predicates().all())).isEmpty();
 fs.add(new TestInputFileBuilder("foo", "src/Foo.php").setLanguage("php").build());
 fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
 fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build());
 // no language
 fs.add(new TestInputFileBuilder("foo", "src/readme.txt").build());
 assertThat(fs.inputFile(fs.predicates().hasRelativePath("src/Bar.java"))).isNotNull();
 assertThat(fs.inputFile(fs.predicates().hasRelativePath("does/not/exist"))).isNull();
 assertThat(fs.inputFile(fs.predicates().hasAbsolutePath(new File(basedir, "src/Bar.java").getAbsolutePath()))).isNotNull();
 assertThat(fs.inputFile(fs.predicates().hasAbsolutePath(new File(basedir, "does/not/exist").getAbsolutePath()))).isNull();
 assertThat(fs.inputFile(fs.predicates().hasAbsolutePath(new File(basedir, "../src/Bar.java").getAbsolutePath()))).isNull();
 assertThat(fs.inputFile(fs.predicates().hasURI(new File(basedir, "src/Bar.java").toURI()))).isNotNull();
 assertThat(fs.inputFile(fs.predicates().hasURI(new File(basedir, "does/not/exist").toURI()))).isNull();
 assertThat(fs.inputFile(fs.predicates().hasURI(new File(basedir, "../src/Bar.java").toURI()))).isNull();
 assertThat(fs.files(fs.predicates().all())).hasSize(4);
 assertThat(fs.files(fs.predicates().hasLanguage("java"))).hasSize(2);
 assertThat(fs.files(fs.predicates().hasLanguage("cobol"))).isEmpty();
 assertThat(fs.hasFiles(fs.predicates().all())).isTrue();
 assertThat(fs.hasFiles(fs.predicates().hasLanguage("java"))).isTrue();
 assertThat(fs.hasFiles(fs.predicates().hasLanguage("cobol"))).isFalse();
 assertThat(fs.inputFiles(fs.predicates().all())).hasSize(4);
 assertThat(fs.inputFiles(fs.predicates().hasLanguage("php"))).hasSize(1);
 assertThat(fs.inputFiles(fs.predicates().hasLanguage("java"))).hasSize(2);
 assertThat(fs.inputFiles(fs.predicates().hasLanguage("cobol"))).isEmpty();
 assertThat(fs.languages()).containsOnly("java", "php");
}
origin: pmayweg/sonar-groovy

@CheckForNull
private InputFile getInputFile(String filename, List<String> sourceDirs) {
 for (String sourceDir : sourceDirs) {
  String fileAbsolutePath = sourceDir + "/" + filename;
  InputFile file = fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(fileAbsolutePath));
  if (file != null) {
   return file;
  }
 }
 return null;
}
origin: org.sonarsource.sonar-plugins.javascript/javascript-squid

@Nullable
private Symbolizable symbolizableFor(File file) {
 if (resourcePerspectives == null) {
  return null;
 }
 InputFile inputFile = fs.inputFile(fs.predicates().hasAbsolutePath(file.getAbsolutePath()));
 if (inputFile != null) {
  return resourcePerspectives.as(Symbolizable.class, inputFile);
 } else {
  LOG.warn("No symbol highlighting for file: " + file.getPath() + ". Unable to find associate SonarQube resource.");
  return null;
 }
}
origin: SonarSource/sonar-go

private static FilePredicate testFilePredicate(FilePredicates predicates, Path path) {
 return predicates.and(
  predicates.hasType(Type.TEST),
  predicates.hasAbsolutePath(path.toString()),
  predicates.hasLanguage(GoLanguage.KEY));
}
origin: org.codehaus.sonar-plugins.java/sonar-checkstyle-plugin

private void initResource(AuditEvent event) {
 if (currentResource == null) {
  String absoluteFilename = event.getFileName();
  currentResource = fs.inputFile(fs.predicates().hasAbsolutePath(absoluteFilename));
 }
}
origin: checkstyle/sonar-checkstyle

private void initResource(AuditEvent event) {
  if (currentResource == null) {
    final String absoluteFilename = event.getFileName();
    currentResource = fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(
        absoluteFilename));
  }
}
origin: pmayweg/sonar-groovy

@CheckForNull
private InputFile inputFileFor(SensorContext context, String path) {
 return context.fileSystem().inputFile(context.fileSystem().predicates().hasAbsolutePath(path));
}
origin: mrprince/sonar-p3c-pmd

private InputFile findResourceFor(RuleViolation violation) {
 return fs.inputFile(fs.predicates().hasAbsolutePath(violation.getFilename()));
}
origin: pmayweg/sonar-groovy

private String getFilename(List<String> sourceDirectories, String packPath, String attrFilename) throws XMLStreamException {
 FilePredicates pred = fileSystem.predicates();
 for (String directory : sourceDirectories) {
  String path = directory + packPath + "/" + attrFilename;
  if (fileSystem.hasFiles(pred.and(pred.hasType(Type.MAIN), pred.hasAbsolutePath(path)))) {
   return path;
  }
 }
 return packPath + "/" + attrFilename;
}
origin: org.sonarsource.typescript/sonar-typescript-plugin

static void saveIssues(SensorContext sensorContext, Issue[] issues, TypeScriptRules typeScriptRules) {
 FileSystem fs = sensorContext.fileSystem();
 for (Issue issue : issues) {
  InputFile inputFile = fs.inputFile(fs.predicates().hasAbsolutePath(issue.name));
  if (inputFile != null) {
   saveIssue(sensorContext, typeScriptRules, issue, inputFile);
  }
 }
}
origin: SonarSource/sonar-go

/**
 *  It is possible that absolutePath references a file that does not exist in the file system.
 *  It happens when go tests where executed on a different computer.
 *  Even when absolute path does not match a file of the project, this method try to find a valid
 *  mach using a shorter relative path.
 *  @see <a href="https://github.com/SonarSource/sonar-go/issues/218">sonar-go/issues/218</a>
 */
private static InputFile findInputFile(String absolutePath, FileSystem fileSystem) {
 FilePredicates predicates = fileSystem.predicates();
 InputFile inputFile = fileSystem.inputFile(predicates.hasAbsolutePath(absolutePath));
 if (inputFile != null) {
  return inputFile;
 }
 LOG.debug("Resolving file {} using relative path", absolutePath);
 Path path = Paths.get(absolutePath);
 inputFile = fileSystem.inputFile(predicates.hasRelativePath(path.toString()));
 while (inputFile == null && path.getNameCount() > 1) {
  path = path.subpath(1, path.getNameCount());
  inputFile = fileSystem.inputFile(predicates.hasRelativePath(path.toString()));
 }
 return inputFile;
}
origin: Backelite/sonar-swift

  private void recordIssue(final String line) {
    LOGGER.debug("record issue {}", line);

    Pattern pattern = Pattern.compile("(.*.swift):(\\w+):?(\\w+)?: (warning|error): (.*) \\((\\w+)");
    Matcher matcher = pattern.matcher(line);
    while (matcher.find()) {
      String filePath = matcher.group(1);
      int lineNum = Integer.parseInt(matcher.group(2));
      String message = matcher.group(5);
      String ruleId = matcher.group(6);

      FilePredicate fp = context.fileSystem().predicates().hasAbsolutePath(filePath);
      if (!context.fileSystem().hasFiles(fp)) {
        LOGGER.warn("file not included in sonar {}", filePath);
        continue;
      }

      InputFile inputFile = context.fileSystem().inputFile(fp);
      NewIssueLocation dil = new DefaultIssueLocation()
        .on(inputFile)
        .at(inputFile.selectLine(lineNum))
        .message(message);
      context.newIssue()
        .forRule(RuleKey.of(SwiftLintRulesDefinition.REPOSITORY_KEY, ruleId))
        .at(dil)
        .save();
    }
  }
}
origin: Backelite/sonar-swift

  private void collectFileViolations(String filePath, NodeList nodeList) {
    File file = new File(filePath);
    FilePredicate fp = context.fileSystem().predicates().hasAbsolutePath(file.getAbsolutePath());
    if(!context.fileSystem().hasFiles(fp)){
      LOGGER.warn("file not included in sonar {}", filePath);
    }
    InputFile inputFile = context.fileSystem().inputFile(fp);
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        NewIssueLocation dil = new DefaultIssueLocation()
          .on(inputFile)
          .at(inputFile.selectLine(Integer.valueOf(element.getAttribute(LINE))))
          .message(element.getTextContent());
        context.newIssue()
          .forRule(RuleKey.of(OCLintRulesDefinition.REPOSITORY_KEY, element.getAttribute(RULE)))
          .at(dil)
          .save();
      }
    }
  }
}
origin: Stratio/sonar-scala-plugin

@CheckForNull
private Resource getResource(String fileRelativePath, SensorContext context) {
  for (InputFile sourceDir : fileSystem.inputFiles(fileSystem.predicates().hasType(InputFile.Type.MAIN))) {
    String absolutePath = sourceDir.absolutePath();
    if (absolutePath.endsWith(fileRelativePath)) {
      InputFile scalaFile = fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(sourceDir.absolutePath()));
      if (scalaFile != null) {
        return context.getResource(scalaFile);
      }
    }
  }
  return null;
}

origin: Backelite/sonar-swift

  private void recordIssue(final String line) {
    LOGGER.debug("record issue {}", line);

    Pattern pattern = Pattern.compile("(.*.swift):(\\w+):(\\w+): (.*): \\[(.*)\\] (.*)");
    Matcher matcher = pattern.matcher(line);
    while (matcher.find()) {
      String filePath = matcher.group(1);
      int lineNum = Integer.parseInt(matcher.group(2));
      String ruleId = matcher.group(5);
      String message = matcher.group(6);

      FilePredicate fp = context.fileSystem().predicates().hasAbsolutePath(filePath);
      if (!context.fileSystem().hasFiles(fp)) {
        LOGGER.warn("file not included in sonar {}", filePath);
        continue;
      }

      InputFile inputFile = context.fileSystem().inputFile(fp);
      NewIssueLocation dil = new DefaultIssueLocation()
        .on(inputFile)
        .at(inputFile.selectLine(lineNum))
        .message(message);
      context.newIssue()
        .forRule(RuleKey.of(TailorRulesDefinition.REPOSITORY_KEY, ruleId))
        .at(dil)
        .save();
    }
  }
}
origin: SonarSource/SonarJS

private static InputFile getInputFile(SensorContext context, String fileName) {
 FilePredicates predicates = context.fileSystem().predicates();
 InputFile inputFile = context.fileSystem().inputFile(predicates.or(predicates.hasRelativePath(fileName), predicates.hasAbsolutePath(fileName)));
 if (inputFile == null) {
  LOG.warn("No input file found for {}. No {} issues will be imported on this file.", fileName, LINTER_NAME);
  return null;
 }
 return inputFile;
}
origin: org.sonarsource.javascript/sonar-javascript-plugin

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

InputFile getInputFile(SensorContext context, String filePath) {
 FilePredicates predicates = context.fileSystem().predicates();
 InputFile inputFile = context.fileSystem().inputFile(predicates.or(predicates.hasRelativePath(filePath), predicates.hasAbsolutePath(filePath)));
 if (inputFile == null) {
  LOG.warn(logPrefix() + "No input file found for {}. No {} issues will be imported on this file.", filePath, linterName());
  return null;
 }
 return inputFile;
}
org.sonar.api.batch.fsFilePredicateshasAbsolutePath

Javadoc

Predicate that find file by its absolute path. The parameter accepts forward/back slashes as separator and non-normalized values (/path/to/../foo.txt is same as /path/foo.txt).

Warning - may not be supported in SonarLint

Popular methods of FilePredicates

  • hasLanguage
  • and
  • hasType
  • hasPath
    if the parameter represents an absolute path for the running environment, then returns #hasAbsoluteP
  • 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

  • Making http requests using okhttp
  • startActivity (Activity)
  • requestLocationUpdates (LocationManager)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Reference (javax.naming)
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JPanel (javax.swing)
  • Best IntelliJ plugins
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