@Override public boolean apply(InputFile f) { return uri.equals(f.uri()); }
@Test public void has_uri() throws Exception { URI uri = javaFile.uri(); assertThat(predicates.hasURI(uri).apply(javaFile)).isTrue(); assertThat(predicates.hasURI(temp.newFile().toURI()).apply(javaFile)).isFalse(); }
@Override public boolean apply(InputFile f) { return uri.equals(f.uri()); }
@Override public boolean apply(InputFile f) { return uri.equals(f.uri()); } }
/** * @return Matching File object of InputFile */ public static File getFile(InputFile file) { return Paths.get(file.uri()).toFile(); }
private String getRelativePathToSourceDirs(InputFile file) { for (Path p : sourcePaths) { try { String s = p.toAbsolutePath().relativize(Paths.get(file.uri())).toString(); if (!Strings.isNullOrEmpty(s) && !s.startsWith("..")) return s; } catch (IllegalArgumentException uncaught) { // Path#relativize() can throw IllegalArgumentException // We just swallow it... } } return ""; }
AnalysisRequest(InputFile file, Rule[] rules) { this.fileUri = file.uri().toString(); this.fileContent = fileContent(file); if (this.fileContent.startsWith("#!")) { String[] lines = this.fileContent.split("\r\n|\n|\r", -1); this.fileContent = this.fileContent.substring(lines[0].length()); } this.rules = rules; }
/** * @return Relative path of InputFile */ public static String getRelativePath(InputFile file, FileSystem fs) { return fs.baseDir().toPath().toAbsolutePath().relativize(Paths.get(file.uri())).toString().replace('\\', '/'); }
/** * @return Absolute path of InputFile */ public static String getAbsolutePath(InputFile file) { return PathUtils.sanitize(Paths.get(file.uri()).toString()); }
AnalysisRequest(InputFile file, Rule[] rules) { this.fileUri = file.uri().toString(); this.fileContent = fileContent(file); if (this.fileContent.startsWith("#!")) { String[] lines = this.fileContent.split("\r\n|\n|\r", -1); this.fileContent = this.fileContent.substring(lines[0].length()); } this.rules = rules; }
@Override public String getRequestForRunner(String tsconfigPath, Iterable<InputFile> inputFiles, TypeScriptRules typeScriptRules, String projectRoot) { SonarTSRequest request = new SonarTSRequest(); request.filepaths = StreamSupport.stream(inputFiles.spliterator(), false).map(inputFile -> Paths.get(inputFile.uri()).toString()).toArray(String[]::new); request.tsconfig = tsconfigPath; request.rules = SensorContextUtils.convertToRulesToExecute(typeScriptRules); request.projectRoot = projectRoot; return new Gson().toJson(request); }
ContextualAnalysisRequest(InputFile inputFile, TypeScriptRules typeScriptRules, String projectRoot, @Nullable String tsconfigPath) throws IOException { Path path = Paths.get(inputFile.uri()); this.file = path.toString(); this.content = inputFile.contents(); this.rules = SensorContextUtils.convertToRulesToExecute(typeScriptRules); this.projectRoot = projectRoot; if (tsconfigPath != null) { this.tsconfigPath = new File(projectRoot, tsconfigPath).getAbsolutePath(); } else { this.tsconfigPath = null; } } }
private void processParseException(Exception e, SensorContext context, InputFile inputFile) { reportAnalysisError(e, context, inputFile); LOG.warn(String.format("Unable to analyse file %s;", inputFile.uri())); LOG.debug("Cause: {}", e.getMessage()); if (parsingErrorCheckEnabled) { createParsingErrorIssue(e, context, inputFile); } }
@Override public boolean accept(InputFile inputFile) { if (!TypeScriptLanguage.KEY.equals(inputFile.language())) { return true; } String[] excludedPatterns = this.configuration.getStringArray(TypeScriptPlugin.TS_EXCLUSIONS_KEY); String relativePath = inputFile.uri().toString(); return !WildcardPattern.match(WildcardPattern.create(excludedPatterns), relativePath); } }
@Override public boolean accept(InputFile inputFile) { if (!GoLanguage.KEY.equals(inputFile.language())) { return true; } String[] excludedPatterns = this.configuration.getStringArray(GoPlugin.EXCLUSIONS_KEY); String relativePath = inputFile.uri().toString(); return !WildcardPattern.match(WildcardPattern.create(excludedPatterns), relativePath); }
/** * Tells with Ant style {@code filepattern} if the file analyzed being is included. / are always used as the * file separator * * @param filePattern an Ant style file pattern ({@code **\/*.yaml}, etc.) * @return {@code true} is the path of the file source code being checked matches the passed pattern, * {@code false} otherwise */ protected boolean isFileIncluded(@Nullable String filePattern) { if (filePattern != null) { return WildcardPattern.create(filePattern) .match(getYamlSourceCode().getYamlFile().uri().getPath()); } else { return true; } }
private void analyze(InputFile file, SensorContext context) { AnalysisRequest analysisRequest = new AnalysisRequest(file, rules); try { String result = eslintBridgeServer.call(GSON.toJson(analysisRequest)); AnalysisResponseIssue[] issues = toIssues(result); for (AnalysisResponseIssue issue : issues) { saveIssue(file, context, issue); } } catch (IOException e) { LOG.error("Failed to get response while analyzing " + file.uri(), e); } }
private void analyze(InputFile file, SensorContext context) { AnalysisRequest analysisRequest = new AnalysisRequest(file, rules); try { String result = eslintBridgeServer.call(GSON.toJson(analysisRequest)); AnalysisResponseIssue[] issues = toIssues(result); for (AnalysisResponseIssue issue : issues) { saveIssue(file, context, issue); } } catch (IOException e) { LOG.error("Failed to get response while analyzing " + file.uri(), e); } }
@VisibleForTesting void runCheck(SensorContext context, SonarXmlCheck check, RuleKey ruleKey, XmlFile newXmlFile) { try { check.scanFile(context, ruleKey, newXmlFile); } catch (Exception e) { logFailingRule(ruleKey, newXmlFile.getInputFile().uri(), e); } }
private Issue toIssue(PostJobIssue postJobIssue) { File file = null; if (postJobIssue.inputComponent() instanceof InputFile) { InputFile inputFile = (InputFile) Objects.requireNonNull(postJobIssue.inputComponent()); file = new File(inputFile.uri()); } return Issue.newBuilder().key(postJobIssue.key()).componentKey(postJobIssue.componentKey()).severity(postJobIssue.severity()).ruleKey(postJobIssue.ruleKey().toString()) .message(postJobIssue.message()).line(postJobIssue.line()).file(file).newIssue(postJobIssue.isNew()).build(); }