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; } }
/** * 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; }
/** * 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; }
@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); } }