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

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

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

File.fromIOFile介绍

[英]Creates a File from an io.file and a list of sources directories
[中]从io创建文件。文件和源目录列表

代码示例

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

/**
 * Returns the Sonar file representation ({@link File}) of the given file, if that file exists in the given project.
 *
 * @param file
 *          the real file
 * @param project
 *          the project
 * @return the Sonar resource if it exists in this project, or null if not.
 */
public File fromIOFile(java.io.File file, Project project) {
 return File.fromIOFile(file, project);
}

代码示例来源:origin: org.codehaus.sonar-plugins.css/css-squid

public Resource resourceFromIOFile(File file) {
 return org.sonar.api.resources.File.fromIOFile(file, project);
}

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

@SuppressWarnings("rawtypes")
public Resource createResource(java.io.File file, List<java.io.File> sourceDirs) {
 return File.fromIOFile(file, sourceDirs);
}

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

public Resource resourceFromIOFile(File file) {
 return org.sonar.api.resources.File.fromIOFile(file, project);
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet.csharp/csharp-squid

public org.sonar.api.resources.File fromIOFile(File file) {
 return org.sonar.api.resources.File.fromIOFile(file, project);
}

代码示例来源:origin: octo-technology/sonar-objective-c

private org.sonar.api.resources.File findResource(final String filePath) {
  return org.sonar.api.resources.File.fromIOFile(new File(filePath),
      project);
}

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

public org.sonar.api.resources.File fromIOFile(String path) {
 return context.getResource(org.sonar.api.resources.File.fromIOFile(new File(new File(path).getAbsolutePath()), project));
}

代码示例来源:origin: org.codehaus.sonar.dotnet.tests/sonar-dotnet-tests-library

public org.sonar.api.resources.File fromPath(String path) {
 // Workaround SonarQube < 4.2, the context should not be required
 return context.getResource(org.sonar.api.resources.File.fromIOFile(new File(new File(path).getAbsolutePath()), project));
}

代码示例来源:origin: octo-technology/sonar-objective-c

private void saveMeasuresForFile(final CoverageMeasuresBuilder measureBuilder, final String filePath) {
  LoggerFactory.getLogger(getClass()).debug("Saving measures for {}", filePath);
  final org.sonar.api.resources.File objcfile = org.sonar.api.resources.File.fromIOFile(new File(project.getFileSystem().getBasedir(), filePath), project);
  if (fileExists(context, objcfile)) {
    LoggerFactory.getLogger(getClass()).debug(
        "File {} was found in the project.", filePath);
    saveMeasures(measureBuilder, objcfile);
  }
}

代码示例来源:origin: octo-technology/sonar-objective-c

private void save(Collection<SourceCode> squidSourceFiles) {
  for (SourceCode squidSourceFile : squidSourceFiles) {
    SourceFile squidFile = (SourceFile) squidSourceFile;
    File sonarFile = File.fromIOFile(new java.io.File(squidFile.getKey()), project);
    saveFilesComplexityDistribution(sonarFile, squidFile);
    saveFunctionsComplexityDistribution(sonarFile, squidFile);
    saveMeasures(sonarFile, squidFile);
    saveViolations(sonarFile, squidFile);
  }
}

代码示例来源:origin: org.codehaus.sonar-plugins.css/css-squid

@Override
public void leaveFile(AstNode astNode) {
 File sonarFile = File.fromIOFile(getContext().getFile(), project);
 FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(sonarFile);
 int fileLength = getContext().peekSourceCode().getInt(CssMetric.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();
 linesOfCode.clear();
 linesOfComments.clear();
}

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

/**
 * {@inheritDoc}
 */
@Override
public org.sonar.api.resources.File fromIOFile(File file, Project project) {
 if (isTestSensor()) {
  return org.sonar.api.resources.File.fromIOFile(file, project.getFileSystem().getTestDirs());
 }
 return super.fromIOFile(file, project);
}

代码示例来源:origin: org.codehaus.sonar-plugins.flex/flex-squid

@Override
public void leaveFile(AstNode astNode) {
 File sonarFile = File.fromIOFile(getContext().getFile(), project);
 FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(sonarFile);
 int fileLength = getContext().peekSourceCode().getInt(FlexMetric.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();
 linesOfCode.clear();
 linesOfComments.clear();
}

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

if (vsProject.equals(currentVsProject)) {
 if (vsProject.isTest()) {
  resource = org.sonar.api.resources.File.fromIOFile(sourceFile, project.getFileSystem().getTestDirs());
 } else {
  resource = org.sonar.api.resources.File.fromIOFile(sourceFile, project);

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

@Override
public void analyse(Project project, SensorContext sensorContext) {
 for (File file : fileSystem.files(FileQuery.onSource().onLanguage(Xml.KEY))) {
  org.sonar.api.resources.File htmlFile = org.sonar.api.resources.File.fromIOFile(file, project);
  addMeasures(sensorContext, file, htmlFile);
 }
}

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

@Override
 public void scanFile(JavaFileScannerContext context) {
  Preconditions.checkNotNull(sensorContext);
  JavaFilesCache javaFilesCache = new JavaFilesCache();
  javaFilesCache.scanFile(context);
  org.sonar.api.resources.File currentResource = org.sonar.api.resources.File.fromIOFile(context.getFile(), project);
  if (currentResource == null) {
   throw new IllegalStateException("resource not found : " + context.getFileKey());
  }
  resourceMapping.addResource(currentResource, context.getFileKey());
  for (Map.Entry<String, File> classIOFileEntry : javaFilesCache.getResourcesCache().entrySet()) {
   resourcesByClass.put(classIOFileEntry.getKey(), currentResource);
   if (context.getFileKey() != null) {
    sourceFileByClass.put(classIOFileEntry.getKey(), context.getFileKey());
   }
  }
  methodStartLines.putAll(javaFilesCache.getMethodStartLines());
  org.sonar.api.resources.File indexedResource = sensorContext.getResource(currentResource);
  if (indexedResource != null && javaFilesCache.hasSuppressWarningLines()) {
   suppressWarningsFilter.addComponent(indexedResource.getEffectiveKey(), javaFilesCache.getSuppressWarningLines());
  }
 }
}

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

@Override
public void analyse(Project project, SensorContext sensorContext) {
 // configure the lexer
 final PageLexer lexer = new PageLexer();
 // configure page scanner and the visitors
 final HtmlAstScanner scanner = setupScanner();
 for (java.io.File file : fileSystem.files(FileQuery.onSource().onLanguage(WebConstants.LANGUAGE_KEY))) {
  File resource = File.fromIOFile(file, project);
  WebSourceCode sourceCode = new WebSourceCode(file, resource);
  FileReader reader = null;
  try {
   reader = new FileReader(file);
   List<Node> nodeList = lexer.parse(reader);
   scanner.scan(nodeList, sourceCode, fileSystem.sourceCharset());
   saveMetrics(sensorContext, sourceCode);
   saveLineLevelMeasures(resource, sourceCode);
  } catch (Exception e) {
   LOG.error("Can not analyze file " + file.getAbsolutePath(), e);
  } finally {
   IOUtils.closeQuietly(reader);
  }
 }
}

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

/**
 * Analyze the XML files.
 */
public void analyse(Project project, SensorContext sensorContext) {
 Collection<AbstractXmlCheck> checks = annotationCheckFactory.getChecks();
 for (java.io.File file : fileSystem.files(FileQuery.onSource().onLanguage(Xml.KEY))) {
  try {
   File resource = File.fromIOFile(file, project);
   XmlSourceCode sourceCode = new XmlSourceCode(resource, file);
   // Do not execute any XML rule when an XML file is corrupted (SONARXML-13)
   if (sourceCode.parseSource(fileSystem)) {
    for (AbstractXmlCheck check : checks) {
     check.setRule(annotationCheckFactory.getActiveRule(check).getRule());
     check.validate(sourceCode);
    }
    saveIssue(sourceCode);
   }
  } catch (Exception e) {
   LOG.error("Could not analyze the file " + file.getAbsolutePath(), e);
  }
 }
}

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

private void saveMeasures(Collection<SourceCode> sourceFiles) {
 for (SourceCode squidFileCode : sourceFiles) {
  SourceFile squidFile = (SourceFile) squidFileCode;
  /* Create the sonar file */
  File sonarFile = File.fromIOFile(new java.io.File(squidFile.getKey()), project);
  sonarFile.setLanguage(cSharp);
  /* Fill the resource bridge API that can be used by other C# plugins to map logical resources to physical ones */
  cSharpResourcesBridge.indexFile(squidFile, sonarFile);
  /* No Sonar */
  noSonarFilter.addResource(sonarFile, squidFile.getNoSonarTagLines());
  /* Classes complexity distribution */
  saveClassesComplexityDistribution(sonarFile, squidFile);
  /* Methods complexity distribution */
  saveMethodsComplexityDistribution(sonarFile, squidFile);
  /* Check messages */
  saveViolations(squidFile, sonarFile);
  /* Metrics at the file level */
  saveMeasures(sonarFile, squidFile);
 }
 // and lock everything to prevent future modifications
 LOG.debug("Locking the C# Resource Bridge and the Sonar Index: future modifications won't be possible.");
 cSharpResourcesBridge.lock();
 resourceCreationLock.lock();
}

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

@Override
public void scanFile(JavaFileScannerContext context) {
 sonarFile = File.fromIOFile(context.getFile(), project);
 classTrees.clear();
 methods = 0;

相关文章