org.sonar.api.resources.File类的使用及代码示例

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

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

File介绍

[英]This class is an implementation of a resource of type FILE
[中]此类是FILE类型资源的实现

代码示例

代码示例来源: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/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.sonarsource.java/java-squid

public void addResource(File resource, String fileKey) {
 directories.put(resource.getParent(), resource);
 fileKeyByResource.put(resource, fileKey);
}

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

public Resource getUnitTestResource(String filename) {

    org.sonar.api.resources.File sonarFile = new org.sonar.api.resources.File(filename);
    sonarFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
    return sonarFile;
  }
}

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

/**
 * {@inheritDoc}
 *
 * @see Resource#getLongName()
 */
@Override
public String getLongName() {
 return StringUtils.defaultIfBlank(getPath(), getKey());
}

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

if (reference instanceof File) {
 File referenceFile = (File) reference;
 isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier());
 relativePathFromSourceDir = referenceFile.relativePathFromSourceDir();
} else if (reference instanceof Directory) {
 isDir = true;
  Bucket b = getBucket(isDir ? Directory.fromIOFile(abs, getProject()) : File.fromIOFile(abs, getProject()));
  if (b != null) {
   return b;

代码示例来源: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-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.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/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-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());
  LOG.debug("Default value of zero will be saved for file: {}", resource.getPath());
  LOG.debug("Because: either was not present in LCOV report either was not able to retrieve associated SonarQube resource");
  saveZeroValueForResource(resource, context);

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

@Override
public void analyse(Project module, org.sonar.api.batch.SensorContext context) {
 createIssueOnDir(new Directory(""));
 File src = module.getFileSystem().getSourceDirs().get(0);
 for (File f : fileSystem.files(FileQuery.onMain().onLanguage(Xoo.KEY))) {
  String relativePathFromSourceDir = new PathResolver().relativePath(src, f);
  org.sonar.api.resources.File sonarFile = new org.sonar.api.resources.File(relativePathFromSourceDir);
  Issuable issuable = perspectives.as(Issuable.class, sonarFile);
  issuable.addIssue(issuable.newIssueBuilder()
   .ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY))
   .message("Issue created using deprecated API")
   .line(1)
   .build());
  sonarFile = context.getResource(sonarFile);
  Directory parent = sonarFile.getParent();
  createIssueOnDir(parent);
 }
}

代码示例来源: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) {
 File file = new File();
 String normalizedPath = normalize(relativePathFromBasedir);
 file.setKey(normalizedPath);
 file.setPath(normalizedPath);
 String directoryPath;
 if (normalizedPath != null && normalizedPath.contains(Directory.SEPARATOR)) {
  directoryPath = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR);
  file.filename = StringUtils.substringAfterLast(normalizedPath, Directory.SEPARATOR);
 } else {
  directoryPath = Directory.SEPARATOR;
  file.filename = normalizedPath;
 }
 file.parent = Directory.create(directoryPath);
 return file;
}

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

@Override
public String getSource(Resource reference) {
 Resource resource = getResource(reference);
 if (resource instanceof File) {
  File file = (File) resource;
  Project module = currentProject;
  ProjectDefinition def = projectTree.getProjectDefinition(module);
  try {
   return FileUtils.readFileToString(new java.io.File(def.getBaseDir(), file.getPath()));
  } catch (IOException e) {
   throw new IllegalStateException("Unable to read file content " + reference, e);
  }
 }
 return null;
}

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

/**
* Creates a File from an io.file and a list of sources directories
* @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
*/
@Deprecated
@CheckForNull
public static File fromIOFile(java.io.File file, List<java.io.File> sourceDirs) {
 PathResolver.RelativePath relativePath = new PathResolver().relativePath(sourceDirs, file);
 if (relativePath != null) {
  return new File(relativePath.path());
 }
 return null;
}

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

if (reference instanceof File) {
 File referenceFile = (File) reference;
 isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier());
 relativePathFromSourceDir = referenceFile.relativePathFromSourceDir();
} else if (reference instanceof Directory) {
 isDir = true;
  java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src);
  java.io.File abs = new java.io.File(dirOrFile, relativePathFromSourceDir);
  Bucket b = getBucket(isDir ? Directory.fromIOFile(abs, getProject()) : File.fromIOFile(abs, getProject()));
  if (b != null) {
   return b;

代码示例来源: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-plugin-api

@Override
 public String toString() {
  return new ToStringBuilder(this)
   .append("key", getKey())
   .append("path", getPath())
   .append("filename", filename)
   .append("language", language)
   .toString();
 }
}

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

@Override
public String getSource(Resource reference) {
 Resource resource = getResource(reference);
 if (resource instanceof File) {
  File file = (File) resource;
  Project module = currentProject;
  ProjectDefinition def = projectTree.getProjectDefinition(module);
  try {
   return FileUtils.readFileToString(new java.io.File(def.getBaseDir(), file.getPath()));
  } catch (IOException e) {
   throw new IllegalStateException("Unable to read file content " + reference, e);
  }
 }
 return null;
}

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

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

相关文章