/** * Gets the project test source directories. * * @return List<File> A list of all test source folders */ public List<File> getTestDirectories() { return getProject().getFileSystem().getTestDirs(); }
private Resource findResourceFor(IRuleViolation violation) { List<File> allSources = ImmutableList.copyOf(Iterables.concat(projectFileSystem.getSourceDirs(), projectFileSystem.getTestDirs())); return JavaFile.fromAbsolutePath(violation.getFilename(), allSources, true); }
/** * @param result * @return phpunit configuration option followed by the generated phpunit.xml launcher file. Or the test directory if only one. */ private String getTestDirectoryOrFiles() { List<File> testDirs = project.getFileSystem().getTestDirs(); String directoryOrFiles = null; if (testDirs.size() == 1) { directoryOrFiles = testDirs.get(0).toString(); } else { // in case of multiple source directories, phpunit.xml file is generated and passed to phpunit. LOG.warn("Phpunit does not support multiple source directories for the moment."); LOG.warn("Group your tests folder under the same directory or use phpunit.xml file"); List<File> testFiles = project.getFileSystem().getTestFiles(PHP); LOG.info("Generating phpunit.xml file containing all your test files..."); File phpunitXml = createPhpunitConfigurationFile(testFiles); LOG.warn(phpunitXml + " file generated."); directoryOrFiles = PHPUNIT_CONFIGURATION_OPTION + phpunitXml.toString(); } return directoryOrFiles; }
/** * {@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); }
/** * Gets the php file pointed by the report. * * @param report * the unit test report * @param project * the project * @return PhpFile pointed by the report */ private PhpFile getUnitTestResource(PhpUnitTestReport report, Project project) { return PhpFile.getInstance(project).fromAbsolutePath(report.getFile(), project.getFileSystem().getTestDirs(), true); }
/** * From absolute path. * * @param path * the path * @param project * the current project * @return the php file */ public PhpFile fromAbsolutePath(String path, Project project) { PhpFile phpFile = null; if (path != null) { File file = new File(path); ProjectFileSystem fileSystem = project.getFileSystem(); List<File> sourceFiles = fileSystem.getSourceFiles(PHP); List<File> testFiles = fileSystem.getTestFiles(PHP); if (sourceFiles.contains(file)) { phpFile = fromIOFile(file, fileSystem.getSourceDirs(), false); } if (phpFile == null && testFiles.contains(file)) { phpFile = fromIOFile(file, fileSystem.getTestDirs(), true); } } return phpFile; }
/** * Imports php file contains in the source and tests folders. * * @param project * the project * @param context * the context * @throws IOException * Signals that an I/O exception has occurred. */ protected void doAnalyse(Project project, SensorContext context) throws IOException { // Importing source files ProjectFileSystem fileSystem = project.getFileSystem(); Charset sourceCharset = fileSystem.getSourceCharset(); List<File> sourceDirs = fileSystem.getSourceDirs(); List<File> sourceFiles = fileSystem.getSourceFiles(PHP); parseDirs(context, sourceFiles, sourceDirs, false, sourceCharset); for (File directory : sourceDirs) { LOG.info(directory.getName()); } // Importing tests files List<File> testDirs = fileSystem.getTestDirs(); List<File> testFiles = fileSystem.getTestFiles(PHP); parseDirs(context, testFiles, testDirs, true, sourceCharset); // Display source dirs and tests directories if info level is enabled. for (File directory : testDirs) { LOG.info(directory.getName()); } }
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);
dirs = getProject().getFileSystem().getTestDirs(); } else { dirs = getProject().getFileSystem().getSourceDirs();
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);