org.sonar.api.resources.File.create()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中org.sonar.api.resources.File.create()方法的一些代码示例,展示了File.create()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.create()方法的具体详情如下:
包路径:org.sonar.api.resources.File
类名称:File
方法名:create

File.create介绍

[英]Internal use only.
[中]仅供内部使用。

代码示例

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

/**
 * Internal use only.
 * @deprecated since 5.1 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
 */
@Deprecated
public static File create(String relativePathFromBasedir, Language language, boolean unitTest) {
 File file = create(relativePathFromBasedir);
 file.setLanguage(language);
 if (unitTest) {
  file.setQualifier(Qualifiers.UNIT_TEST_FILE);
 }
 return file;
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

private File getMainResource(InputFile mainFile) {
 File mainRes = File.create(mainFile.relativePath());
 // Reload
 mainRes = sonarIndex.getResource(mainRes);
 if (mainRes == null) {
  throw new IllegalArgumentException("Provided input file is not indexed or not a main file: " + mainRes);
 }
 return mainRes;
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@Override
public Resource toResource(File file) {
 if (file == null || !file.exists()) {
  return null;
 }
 String relativePath = pathResolver.relativePath(getBasedir(), file);
 if (relativePath == null) {
  return null;
 }
 return file.isFile() ? org.sonar.api.resources.File.create(relativePath) : org.sonar.api.resources.Directory.create(relativePath);
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

private File getTestResource(InputFile testFile) {
 File testRes = File.create(testFile.relativePath());
 testRes.setQualifier(Qualifiers.UNIT_TEST_FILE);
 // Reload
 testRes = sonarIndex.getResource(testRes);
 if (testRes == null) {
  throw new IllegalArgumentException("Provided input file is not indexed or not a test file: " + testFile);
 }
 return testRes;
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

/**
 * Creates a {@link File} from an absolute {@link java.io.File} and a module.
 * The returned {@link File} can be then passed for example to
 * {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)}.
 * @param file absolute path to a file
 * @param module
 * @return null if the file is not under module basedir.
 * @deprecated since 4.5 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
 */
@Deprecated
@CheckForNull
public static File fromIOFile(java.io.File file, Project module) {
 String relativePathFromBasedir = new PathResolver().relativePath(module.getBaseDir(), file);
 if (relativePathFromBasedir != null) {
  return File.create(relativePathFromBasedir);
 }
 return null;
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

@Override
public FileLinesContext createFor(InputFile inputFile) {
 File sonarFile = File.create(inputFile.relativePath());
 // Reload resource from index
 sonarFile = index.getResource(sonarFile);
 return new DefaultFileLinesContext(index, sonarFile);
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@Override
public FileLinesContext createFor(InputFile inputFile) {
 File sonarFile = File.create(inputFile.relativePath());
 // Reload resource from index
 sonarFile = index.getResource(sonarFile);
 return new DefaultFileLinesContext(index, sonarFile);
}

代码示例来源:origin: org.codehaus.sonar-plugins.javascript/sonar-javascript-plugin

protected void saveZeroValueForAllFiles(SensorContext context) {
 for (InputFile inputFile : fileSystem.inputFiles(mainFilePredicate)) {
  saveZeroValueForResource(org.sonar.api.resources.File.create(inputFile.relativePath()), context);
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@Override
 public Resource getResource(InputPath inputPath) {
  Resource r;
  if (inputPath instanceof InputDir) {
   r = Directory.create(((InputDir) inputPath).relativePath());
  } else if (inputPath instanceof InputFile) {
   r = File.create(((InputFile) inputPath).relativePath());
  } else {
   throw new IllegalArgumentException("Unknow input path type: " + inputPath);
  }
  return getResource(r);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

@Override
 public Resource getResource(InputPath inputPath) {
  Resource r;
  if (inputPath instanceof InputDir) {
   r = Directory.create(((InputDir) inputPath).relativePath());
  } else if (inputPath instanceof InputFile) {
   r = File.create(((InputFile) inputPath).relativePath());
  } else {
   throw new IllegalArgumentException("Unknow input path type: " + inputPath);
  }
  return getResource(r);
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.javascript/sonar-javascript-plugin

try {
 CoverageMeasuresBuilder fileCoverage = coveredFiles.get(inputFile);
 org.sonar.api.resources.File resource = org.sonar.api.resources.File.create(inputFile.relativePath());

代码示例来源:origin: org.sonarsource.sonar-plugins.javascript/javascript-squid

@Override
public void leaveFile(AstNode astNode) {
 FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(File.create(pathResolver.relativePath(fileSystem.baseDir(), getContext().getFile().getAbsoluteFile())));
 if (fileLinesContext != null) {
  int fileLength = getContext().peekSourceCode().getInt(EcmaScriptMetric.LINES);
  for (int line = 1; line <= fileLength; line++) {
   fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0);
   fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0);
  }
  fileLinesContext.save();
 } else {
  LOG.warn("Cannot save measures for DevCockpit for file {}. Unable to retrieve the associated sonar resource.", getContext().getFile().getName());
 }
 linesOfCode.clear();
 linesOfComments.clear();
}

代码示例来源:origin: org.codehaus.sonar-plugins.javascript/sonar-javascript-plugin

private void save(Collection<SourceCode> squidSourceFiles) {
 for (SourceCode squidSourceFile : squidSourceFiles) {
  SourceFile squidFile = (SourceFile) squidSourceFile;
  File sonarFile = context.getResource(File.create(pathResolver.relativePath(fileSystem.baseDir(), new java.io.File(squidFile.getKey()))));
  if (sonarFile != null) {
   noSonarFilter.addResource(sonarFile, squidFile.getNoSonarTagLines());
   saveClassComplexity(sonarFile, squidFile);
   saveFilesComplexityDistribution(sonarFile, squidFile);
   saveFunctionsComplexityAndDistribution(sonarFile, squidFile);
   saveMeasures(sonarFile, squidFile);
   saveIssues(sonarFile, squidFile);
  } else {
   LOG.warn("Cannot save analysis information for file {}. Unable to retrieve the associated sonar resource.", squidFile.getKey());
  }
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@Override
public void store(Issue issue) {
 Resource r;
 InputPath inputPath = issue.inputPath();
 if (inputPath != null) {
  if (inputPath instanceof InputDir) {
   r = Directory.create(inputPath.relativePath());
  } else {
   r = File.create(inputPath.relativePath());
  }
 } else {
  r = project;
 }
 Issuable issuable = perspectives.as(Issuable.class, r);
 if (issuable == null) {
  return;
 }
 issuable.addIssue(toDefaultIssue(project.getKey(), ComponentKeys.createEffectiveKey(project, r), issue));
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-checkstyle-plugin

@Override
public void addError(AuditEvent event) {
 String ruleKey = getRuleKey(event);
 if (ruleKey != null) {
  String message = getMessage(event);
  // In Checkstyle 5.5 exceptions are reported as an events from TreeWalker
  if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) {
   LOG.warn(event.getFileName() + ": " + message);
  }
  initResource(event);
  Issuable issuable = perspectives.as(Issuable.class, File.create(currentResource.relativePath()));
  Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
  if (rule != null && issuable != null) {
   IssueBuilder issueBuilder = issuable.newIssueBuilder()
    .ruleKey(rule.ruleKey())
    .message(message)
    .line(getLineId(event));
   issuable.addIssue(issueBuilder.build());
  }
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

public void execute(DefaultModuleFileSystem fs) {
  module.setBaseDir(fs.baseDir());

  for (InputFile inputFile : fs.inputFiles()) {
   String languageKey = inputFile.language();
   boolean unitTest = InputFile.Type.TEST == inputFile.type();
   Resource sonarFile = File.create(inputFile.relativePath(), languages.get(languageKey), unitTest);
   sonarIndex.index(sonarFile);
   BatchComponent file = componentCache.get(sonarFile);
   file.setInputComponent(inputFile);
   Resource sonarDir = file.parent().resource();
   InputDir inputDir = fs.inputDir(inputFile.file().getParentFile());
   componentCache.get(sonarDir).setInputComponent(inputDir);
  }
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

public void execute(DefaultModuleFileSystem fs) {
 module.setBaseDir(fs.baseDir());
 if (resourcePersister != null) {
  // Force persistence of module structure in order to know if project should be migrated
  resourcePersister.persist();
 }
 if (migration != null) {
  migration.migrateIfNeeded(module, fs);
 }
 for (InputFile inputFile : fs.inputFiles(fs.predicates().all())) {
  String languageKey = inputFile.language();
  boolean unitTest = InputFile.Type.TEST == inputFile.type();
  Resource sonarFile = File.create(inputFile.relativePath(), languages.get(languageKey), unitTest);
  sonarIndex.index(sonarFile);
 }
 if (resourcePersister != null) {
  // Persist all files in order to have snapshot availables
  resourcePersister.persist();
 }
}

相关文章