public boolean accept(File dir, String name) { return accept(new File(dir, name)); }
/** * Find files that match the given patterns * * @param currentSolution * The VS solution being analyzed by sonar * @param currentProject * The VS project being analyzed * @param patterns * A list of paths or ant style patterns delimited by a comma or a semi-comma * @return The files found on the filesystem */ public static Collection<File> findFiles(VisualStudioSolution currentSolution, VisualStudioProject currentProject, String patterns) { String[] patternArray = StringUtils.split(patterns, ",;"); return findFiles(currentSolution, currentProject, patternArray); }
/** * Find files that match the given patterns * * @param currentSolution * The VS solution being analyzed by sonar * @param defaultWorkDir * A working directory * @param patternArray * A list of paths or ant style patterns * @return The files found on the filesystem */ @SuppressWarnings("unchecked") public static Collection<File> findFiles(VisualStudioSolution currentSolution, File defaultWorkDir, String... patternArray) { if (patternArray == null || patternArray.length == 0) { return Collections.EMPTY_LIST; } Set<File> result = new HashSet<File>(); for (String pattern : patternArray) { findFilesFromPattern(currentSolution, defaultWorkDir, result, pattern); } logResults(result, patternArray); return result; }
/** * Find files that match the given patterns * * @param currentSolution * The VS solution being analyzed by sonar * @param currentProject * The VS project being analyzed * @param patternArray * A list of paths or ant style patterns * @return The files found on the filesystem */ public static Collection<File> findFiles(VisualStudioSolution currentSolution, VisualStudioProject currentProject, String... patternArray) { String[] patternArrayProcessed; if (patternArray == null || patternArray.length == 0) { patternArrayProcessed = null; } else { patternArrayProcessed = new String[patternArray.length]; for (int i = 0; i < patternArray.length; i++) { patternArrayProcessed[i] = process(patternArray[i], currentProject); } } return findFiles(currentSolution, currentProject.getDirectory(), patternArrayProcessed); }
private static void findFilesFromPattern(VisualStudioSolution currentSolution, File defaultWorkDir, Set<File> result, String pattern) { String currentPattern = convertSlash(pattern); File workDir = defaultWorkDir; if (StringUtils.startsWith(pattern, SOLUTION_DIR_KEY)) { String prefix = StringUtils.substringBefore(currentPattern, "*"); if (StringUtils.contains(prefix, '/')) { workDir = browse(workDir, prefix); currentPattern = "*" + StringUtils.substringAfter(currentPattern, "*"); IOFileFilter externalFilter = new PatternFilter(workDir, currentPattern); listFiles(result, workDir, externalFilter); } else { File file = browse(workDir, currentPattern); if (file.exists()) { result.add(browse(workDir, currentPattern));
public boolean isResourceInProject(Resource<?> resource, Project project) { final boolean result; if (resource instanceof Project) { result = resource.getEffectiveKey().equals(project.getEffectiveKey()); } else { Resource<?> parent = sensorContext.getParent(resource); if (parent == null) { // should not happen result = false; } else { result = isResourceInProject(parent, project); } } return result; }
protected static void extractNDepsBinaries(String tempFolder) throws NDepsException { try { URL executableURL = NDepsRunner.class.getResource("/NDeps-" + EMBEDDED_VERSION); ZipUtils.extractArchiveFolderIntoDirectory(StringUtils.substringBefore(executableURL.getFile(), "!").substring(5), "NDeps-" + EMBEDDED_VERSION, tempFolder); } catch (IOException e) { throw new SonarException("Could not extract the embedded NDeps executable", e); } }
/** * Parses a processed violation file. * * @param file * the file to parse */ public void parse(File file) { this.repositoryKey = vsProject.isTest() ? GendarmeConstants.TEST_REPOSITORY_KEY : GendarmeConstants.REPOSITORY_KEY; if (!"cs".equals(project.getLanguageKey())) { // every repository key should be "fxcop-<language_key>", except for C# for which it is simply "fxcop" (for backward compatibility) repositoryKey += "-" + project.getLanguageKey(); } SMInputFactory inputFactory = StaxParserUtils.initStax(); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); SMHierarchicCursor cursor = inputFactory.rootElementCursor(new InputStreamReader(fileInputStream, project.getFileSystem().getSourceCharset())); SMInputCursor rulesCursor = cursor.advance().descendantElementCursor("rule"); parseRuleBlocs(rulesCursor); cursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { throw new SonarException("Error while reading Gendarme result file: " + file.getAbsolutePath(), e); } catch (FileNotFoundException e) { throw new SonarException("Cannot find Gendarme result file: " + file.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(fileInputStream); } }
public Project findParentProject(Resource<?> resource) { final Project result; if (resource instanceof Project) { result = (Project) resource; } else { Resource<?> parent = sensorContext.getParent(resource); if (parent == null) { // should not happen result = null; } else { result = findParentProject(parent); } } return result; }
private static void listFiles(Collection<File> files, File directory, IOFileFilter filter) { if (!directory.exists() || directory.isFile()) { return; } File[] found = directory.listFiles((FileFilter) filter); if (found != null) { files.addAll(Arrays.asList(found)); } File[] subDirectories = directory.listFiles((FileFilter) DirectoryFileFilter.INSTANCE); for (File subDirectory : subDirectories) { listFiles(files, subDirectory, filter); } }
Collection<File> assemblyDependencyDirectoriesFiles = FileFinder.findDirectories(solution, vsProject, assemblyDependencyDirectories); validate(assemblyToScanFiles);
/** * Find files that match the given patterns * * @param currentSolution * The VS solution being analyzed by sonar * @param defaultWorkPath * A working path that may be relative to solution root directory * @param patternArray * A list of paths or ant style patterns * @return The files found on the filesystem */ public static Collection<File> findFiles(VisualStudioSolution currentSolution, String defaultWorkPath, String... patternArray) { return findFiles(currentSolution, new File(currentSolution.getSolutionDir(), defaultWorkPath), patternArray); }
private Violation createViolationOnResource(Resource<?> resource, Integer lineNumber) { if (StringUtils.isNotEmpty(currentSource) && resource == null) { LOG.debug("Ignoring violation on file outside current project ({})", currentSource); return null; } if (resource != null && !resourceHelper.isResourceInProject(resource, project)) { LOG.debug("Ignoring violation on file outside current project ({})", resource.getKey()); return null; } Violation violation = Violation.create(currentRule, resource); if (lineNumber != null) { violation.setLineId(lineNumber); } if (StringUtils.isEmpty(currentMessage)) { violation.setMessage(currentDefaultViolationMessage); } else { violation.setMessage(currentMessage); } violation.setSeverity(currentRule.getSeverity()); context.saveViolation(violation); return violation; }
protected static void extractGendarmeBinaries(String tempFolder) throws GendarmeException { try { URL executableURL = GendarmeRunner.class.getResource("/gendarme-" + EMBEDDED_VERSION + "-bin"); ZipUtils.extractArchiveFolderIntoDirectory(StringUtils.substringBefore(executableURL.getFile(), "!").substring(5), "gendarme-" + EMBEDDED_VERSION + "-bin", tempFolder); } catch (IOException e) { throw new GendarmeException("Could not extract the embedded Gendarme executable: " + e.getMessage(), e); } }
/** * Find directories that match the given patterns * * @param currentSolution * The VS solution being analyzed by sonar * @param currentProject * The VS project being analyzed * @param patternArray * A list of paths or ant style patterns * @return The directories found on the filesystem */ public static Collection<File> findDirectories(VisualStudioSolution currentSolution, VisualStudioProject currentProject, String... patternArray) { Collection<File> files = findFiles(currentSolution, currentProject, patternArray); Collection<File> directories = new ArrayList<File>(); for (File file : files) { if (file.isDirectory()) { directories.add(file); } } return directories; }
protected Collection<java.io.File> findFiles(Project project, String... queries) { VisualStudioSolution vsSolution = microsoftWindowsEnvironment.getCurrentSolution(); VisualStudioProject vsProject = getVSProject(project); return FileFinder.findFiles(vsSolution, vsProject, queries); }
protected Collection<File> findAssembliesToScan() { Collection<File> assemblyFiles; if (assembliesToScan.length == 0) { LOG.debug("No assembly specified: will look into 'csproj' files to find which should be analyzed."); assemblyFiles = vsProject.getGeneratedAssemblies(buildConfiguration, buildPlatform); if (assemblyFiles == null || assemblyFiles.isEmpty()) { LOG.warn("No assembly found using csproj file {} with build configuration {} and platform {}", new Object[] {vsProject.getProjectFile(), buildConfiguration, buildPlatform}); } } else { // Some assemblies have been specified: let's analyze them assemblyFiles = FileFinder.findFiles(solution, vsProject, assembliesToScan); if (assemblyFiles.isEmpty()) { LOG.warn("No assembly found using patterns " + StringUtils.join(assembliesToScan, ',')); LOG.warn("Fallback to 'csproj' files to find which should be analyzed."); assemblyFiles = vsProject.getGeneratedAssemblies(buildConfiguration, buildPlatform); } } return assemblyFiles; }
if (dotSettingsFilePath != null && !StringUtils.isEmpty(dotSettingsFilePath)) { Collection<File> settingsFiles = FileFinder.findFiles(solution, vsProject, dotSettingsFilePath); if (settingsFiles.size() > 1) { throw new SonarException("More than one file matched the pattern for the ReSharper dotSettings file path");
reportFiles = FileFinder.findFiles(vsSolution, vsProject, reportPath); LOG.info("Reusing FxCop reports: " + Joiner.on(" ").join(reportFiles)); } else {
reportFiles = FileFinder.findFiles(vsSolution, vsProject, reportPath); LOG.info("Reusing Gendarme report: " + Joiner.on(" ").join(reportFiles)); } else {