当前位置: 首页>>代码示例>>Java>>正文


Java ClientInputFile类代码示例

本文整理汇总了Java中org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile的典型用法代码示例。如果您正苦于以下问题:Java ClientInputFile类的具体用法?Java ClientInputFile怎么用?Java ClientInputFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClientInputFile类属于org.sonarsource.sonarlint.core.client.api.common.analysis包,在下文中一共展示了ClientInputFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@CheckForNull
SonarLintInputFile create(ClientInputFile inputFile) {
  SonarLintInputFile defaultInputFile = new SonarLintInputFile(inputFile);
  defaultInputFile.setType(inputFile.isTest() ? Type.TEST : Type.MAIN);
  if (inputFile.language() != null) {
    LOG.debug("Language of file '{}' is set to '{}'", inputFile.getPath(), inputFile.language());
    defaultInputFile.setLanguage(inputFile.language());
  } else {
    defaultInputFile.setLanguage(langDetection.language(defaultInputFile));
  }

  Charset charset = inputFile.getCharset();
  InputStream stream;
  try {
    stream = inputFile.inputStream();
  } catch (IOException e) {
    throw new IllegalStateException("Failed to open a stream on file: " + inputFile.getPath(), e);
  }
  defaultInputFile.init(fileMetadata.readMetadata(stream, charset != null ? charset : Charset.defaultCharset(), inputFile.getPath()));
  return defaultInputFile;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:22,代码来源:InputFileBuilder.java

示例2: testCreate

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Test
public void testCreate() throws IOException {
  when(langDetection.language(any(InputFile.class))).thenReturn("java");

  Path path = temp.getRoot().toPath().resolve("file");
  Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
  ClientInputFile file = new TestClientInputFile(path, true, StandardCharsets.ISO_8859_1);

  InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
  SonarLintInputFile inputFile = builder.create(file);

  assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
  assertThat(inputFile.file()).isEqualTo(path.toFile());
  assertThat(inputFile.language()).isEqualTo("java");
  assertThat(inputFile.lines()).isEqualTo(1);

  assertThat(builder.langDetection()).isEqualTo(langDetection);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:19,代码来源:InputFileBuilderTest.java

示例3: toString

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Override
public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append("[\n");
  sb.append("  workDir: ").append(workDir).append("\n");
  sb.append("  extraProperties: ").append(extraProperties).append("\n");
  sb.append("  inputFiles: [\n");
  for (ClientInputFile inputFile : inputFiles) {
    sb.append("    ").append(inputFile.getPath());
    if (inputFile.isTest()) {
      sb.append(" [test]");
    }
    if (inputFile.language() != null) {
      sb.append(" [" + inputFile.language() + "]");
    }
    sb.append("\n");
  }
  sb.append("  ]\n");
  sb.append("]\n");
  return sb.toString();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:22,代码来源:StandaloneAnalysisConfiguration.java

示例4: testToString

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Test
public void testToString() throws Exception {
  Map<String, String> props = new HashMap<>();
  props.put("sonar.java.libraries", "foo bar");

  final Path srcFile1 = temp.newFile().toPath();
  final Path srcFile2 = temp.newFile().toPath();
  final Path srcFile3 = temp.newFile().toPath();
  ClientInputFile inputFile = new TestClientInputFile(srcFile1, false, StandardCharsets.UTF_8, null);
  ClientInputFile inputFileWithLanguage = new TestClientInputFile(srcFile2, false, StandardCharsets.UTF_8, "java");
  ClientInputFile testInputFile = new TestClientInputFile(srcFile3, true, StandardCharsets.UTF_8, "php");
  Path workDir = temp.newFolder().toPath();
  StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(workDir, Arrays.asList(inputFile, inputFileWithLanguage, testInputFile), props);
  assertThat(config.toString()).isEqualTo("[\n" +
    "  workDir: " + workDir.toString() + "\n" +
    "  extraProperties: {sonar.java.libraries=foo bar}\n" +
    "  inputFiles: [\n" +
    "    " + srcFile1.toString() + "\n" +
    "    " + srcFile2.toString() + " [java]\n" +
    "    " + srcFile3.toString() + " [test] [php]\n" +
    "  ]\n" +
    "]\n");
  assertThat(config.workDir()).isEqualTo(workDir);
  assertThat(config.inputFiles()).containsExactly(inputFile, inputFileWithLanguage, testInputFile);
  assertThat(config.extraProperties()).containsExactly(entry("sonar.java.libraries", "foo bar"));
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:27,代码来源:StandaloneAnalysisConfigurationTest.java

示例5: addIssue

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
public void addIssue(Trackable trackable) {
  Issue issue = trackable.getIssue();
  Long millis = trackable.getServerIssueKey() != null ? trackable.getCreationDate() : null;
  RichIssue richIssue = new RichIssueImpl(issue, id, millis);
  id++;
  ruleNameByKey.put(issue.getRuleKey(), issue.getRuleName());

  Path filePath;
  ClientInputFile inputFile = issue.getInputFile();
  if (inputFile == null) {
    // issue on project (no specific file)
    filePath = Paths.get("");
  } else {
    filePath = Paths.get(inputFile.getPath());
  }
  ResourceReport report = getOrCreate(filePath);
  summary.addIssue(richIssue);
  report.addIssue(richIssue);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:20,代码来源:IssuesReport.java

示例6: runAnalysis

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
public void runAnalysis(Map<String, String> properties, ReportFactory reportFactory, InputFileFinder finder, Path projectHome) {
  List<ClientInputFile> inputFiles;
  try {
    inputFiles = finder.collect(projectHome);
  } catch (IOException e) {
    throw new IllegalStateException("Error preparing list of files to analyze", e);
  }

  if (inputFiles.isEmpty()) {
    LOGGER.warn("No files to analyze");
    return;
  } else {
    LOGGER.debug(String.format("Submitting %d files for analysis", inputFiles.size()));
  }

  doAnalysis(properties, reportFactory, inputFiles, projectHome);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:18,代码来源:SonarLint.java

示例7: testPatternAppliedToSourceFilesOnly

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Test
public void testPatternAppliedToSourceFilesOnly() throws Exception {
  Path src = root.resolve("src");

  test1 = src.resolve("FirstTest.java");
  Path test2 = src.resolve("SecondTest.java");
  Path externalTest = root.resolve("ExternalTest.java");

  Files.createDirectories(src);

  Files.createFile(test1);
  Files.createFile(test2);
  Files.createFile(externalTest);

  fileFinder = new InputFileFinder("src/**", "*Test.*", null, Charset.defaultCharset());

  List<ClientInputFile> files = fileFinder.collect(root);
  assertThat(files).extracting("path").containsOnly(test1.toString(), test2.toString(), src1.toString());
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:20,代码来源:InputFileFinderTest.java

示例8: createTestIssue

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
private static Trackable createTestIssue(@Nullable String filePath, String ruleKey, String name, String severity, int line) {
  Issue issue = mock(Issue.class);

  if (filePath != null) {
    ClientInputFile inputFile = mock(ClientInputFile.class);
    when(inputFile.getPath()).thenReturn(filePath);
    when(issue.getInputFile()).thenReturn(inputFile);
  }

  when(issue.getStartLine()).thenReturn(line);
  when(issue.getStartLineOffset()).thenReturn(null);
  when(issue.getEndLine()).thenReturn(line);
  when(issue.getEndLineOffset()).thenReturn(null);
  when(issue.getRuleName()).thenReturn(name);
  when(issue.getRuleKey()).thenReturn(ruleKey);
  when(issue.getSeverity()).thenReturn(severity);
  return new IssueTrackable(issue);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:19,代码来源:IssuesReportTest.java

示例9: should_raise_three_issues

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Test
public void should_raise_three_issues() throws IOException {
  ClientInputFile inputFile = prepareInputFile("foo.html",
    "<html>\n" +
      "<body>\n" +
      "<a href=\"foo.png\">a</a>\n" +
      "</body>\n" +
      "</html>\n",
    false);

  List<Issue> issues = new ArrayList<>();
  sonarlintEngine.analyze(
    new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), new HashMap<>()),
    issues::add);

  assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(
    tuple("Web:DoctypePresenceCheck", 1, inputFile.getPath(), "MAJOR"),
    tuple("Web:LinkToImageCheck", 3, inputFile.getPath(), "MAJOR"),
    tuple("Web:PageWithoutTitleCheck", 1, inputFile.getPath(), "MAJOR"));
}
 
开发者ID:SonarSource,项目名称:sonar-web,代码行数:21,代码来源:SonarLintTest.java

示例10: createInputFile

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
private ClientInputFile createInputFile(final Path path, final boolean isTest) {
  return new ClientInputFile() {

    @Override
    public Path getPath() {
      return path;
    }

    @Override
    public boolean isTest() {
      return isTest;
    }

    @Override
    public Charset getCharset() {
      return StandardCharsets.UTF_8;
    }

    @Override
    public <G> G getClientObject() {
      return null;
    }

  };
}
 
开发者ID:SonarSource,项目名称:sonar-web,代码行数:26,代码来源:SonarLintTest.java

示例11: DefaultClientIssue

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
public DefaultClientIssue(String severity, @Nullable String type, ActiveRule activeRule, Rule rule, String primaryMessage, @Nullable TextRange textRange,
  @Nullable ClientInputFile clientInputFile, List<org.sonar.api.batch.sensor.issue.Issue.Flow> flows) {
  super(textRange);
  this.severity = severity;
  this.type = type;
  this.activeRule = activeRule;
  this.rule = rule;
  this.primaryMessage = primaryMessage;
  this.clientInputFile = clientInputFile;
  this.flows = flows.stream().map(f -> new DefaultFlow(f.locations())).collect(Collectors.toList());
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:12,代码来源:DefaultClientIssue.java

示例12: testCreateWithLanguageSet

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Test
public void testCreateWithLanguageSet() throws IOException {
  Path path = temp.getRoot().toPath().resolve("file");
  Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
  ClientInputFile file = new TestClientInputFile(path, true, StandardCharsets.ISO_8859_1, "cpp");

  InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
  SonarLintInputFile inputFile = builder.create(file);

  assertThat(inputFile.language()).isEqualTo("cpp");
  verifyZeroInteractions(langDetection);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:13,代码来源:InputFileBuilderTest.java

示例13: testCreateError

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Test
public void testCreateError() throws IOException {
  when(langDetection.language(any(InputFile.class))).thenReturn("java");
  ClientInputFile file = new TestClientInputFile(Paths.get("INVALID"), true, StandardCharsets.ISO_8859_1);

  InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);

  exception.expect(IllegalStateException.class);
  exception.expectMessage("Failed to open a stream on file");
  builder.create(file);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:12,代码来源:InputFileBuilderTest.java

示例14: doAnalysis

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@Override
protected void doAnalysis(Map<String, String> properties, ReportFactory reportFactory, List<ClientInputFile> inputFiles, Path baseDirPath) {
  Date start = new Date();
  ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration(moduleKey, baseDirPath, baseDirPath.resolve(".sonarlint"),
    inputFiles, properties);
  IssueCollector collector = new IssueCollector();
  AnalysisResults result = engine.analyze(config, collector);
  engine.downloadServerIssues(getServerConfiguration(server), moduleKey);
  Collection<Trackable> trackables = matchAndTrack(baseDirPath, collector.get());
  generateReports(trackables, result, reportFactory, baseDirPath.getFileName().toString(), baseDirPath, start);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:12,代码来源:ConnectedSonarLint.java

示例15: getRelativePath

import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile; //导入依赖的package包/类
@CheckForNull
String getRelativePath(Path baseDirPath, Issue issue) {
  ClientInputFile inputFile = issue.getInputFile();
  if (inputFile == null) {
    return null;
  }

  return toSonarQubePath(baseDirPath.relativize(Paths.get(inputFile.getPath())).toString());
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:10,代码来源:ConnectedSonarLint.java


注:本文中的org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。