@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); }
/** * @since 4.2 * @deprecated since 5.1 use {@link FileSystem#inputDir(java.io.File)} */ @Deprecated @CheckForNull public static Directory fromIOFile(java.io.File dir, Project module) { String relativePathFromBasedir = new PathResolver().relativePath(module.getBaseDir(), dir); if (relativePathFromBasedir != null) { return Directory.create(relativePathFromBasedir); } return null; }
public Directory getDirectory(java.io.File dir, Project module) { Directory directory = Directory.fromIOFile(dir, module); if (directory == null || directory.getKey() == null) { return Directory.create(DEFAULT_PACKAGE_NAME); } return directory; }
@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); } }
@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); } }
/** * 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 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)); }