Search in sources :

Example 6 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonar-java by SonarSource.

the class SurefireUtilsTest method should_get_report_paths_from_property.

@Test
public void should_get_report_paths_from_property() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.junit.reportPaths", "target/surefire,submodule/target/surefire");
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromProperty"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(2);
    File directory1 = directories.get(0);
    assertThat(directory1.exists()).isTrue();
    assertThat(directory1.isDirectory()).isTrue();
    File directory2 = directories.get(1);
    assertThat(directory2.exists()).isTrue();
    assertThat(directory2.isDirectory()).isTrue();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 7 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonar-java by SonarSource.

the class SurefireUtilsTest method should_only_use_new_property_if_both_set.

@Test
public void should_only_use_new_property_if_both_set() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.junit.reportsPath", "../shouldGetReportsPathFromDeprecatedProperty/target/surefire");
    settings.setProperty("sonar.junit.reportPaths", "target/surefire,submodule/target/surefire");
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromProperty"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(2);
    File directory1 = directories.get(0);
    assertThat(directory1.exists()).isTrue();
    assertThat(directory1.isDirectory()).isTrue();
    File directory2 = directories.get(1);
    assertThat(directory2.exists()).isTrue();
    assertThat(directory2.isDirectory()).isTrue();
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Property 'sonar.junit.reportsPath' is deprecated and will be ignored, as property 'sonar.junit.reportPaths' is also set.");
    assertThat(logTester.logs(LoggerLevel.INFO)).doesNotContain("Property 'sonar.junit.reportsPath' is deprecated. Use property 'sonar.junit.reportPaths' instead.");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 8 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class JGitBlameCommandTest method return_early_when_clone_with_reference_detected.

@Test
public void return_early_when_clone_with_reference_detected() throws IOException {
    File projectDir = temp.newFolder();
    javaUnzip("dummy-git-reference-clone.zip", projectDir);
    Path baseDir = projectDir.toPath().resolve("dummy-git2");
    DefaultFileSystem fs = new DefaultFileSystem(baseDir);
    when(input.fileSystem()).thenReturn(fs);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setModuleBaseDir(baseDir).build();
    when(input.filesToBlame()).thenReturn(Collections.singleton(inputFile));
    // register warning
    AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
    JGitBlameCommand jGitBlameCommand = new JGitBlameCommand(new PathResolver(), analysisWarnings);
    TestBlameOutput output = new TestBlameOutput();
    jGitBlameCommand.blame(input, output);
    assertThat(logTester.logs()).first().matches(s -> s.contains("This git repository references another local repository which is not well supported"));
    // contains commits referenced from the old clone and commits in the new clone
    assertThat(output.blame).containsKey(inputFile);
    assertThat(output.blame.get(inputFile).stream().map(BlameLine::revision)).containsOnly("6b3aab35a3ea32c1636fee56f996e677653c48ea", "843c7c30d7ebd9a479e8f1daead91036c75cbc4e", "0d269c1acfb8e6d4d33f3c43041eb87e0df0f5e7");
    verifyZeroInteractions(analysisWarnings);
}
Also used : Path(java.nio.file.Path) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) PathResolver(org.sonar.api.scan.filesystem.PathResolver) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) AnalysisWarnings(org.sonar.api.notifications.AnalysisWarnings) Test(org.junit.Test)

Example 9 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class DefaultInputModule method initSources.

@CheckForNull
private List<Path> initSources(ProjectDefinition module, String propertyKey) {
    if (!module.properties().containsKey(propertyKey)) {
        return null;
    }
    List<Path> result = new ArrayList<>();
    PathResolver pathResolver = new PathResolver();
    String srcPropValue = module.properties().get(propertyKey);
    if (srcPropValue != null) {
        for (String sourcePath : parseAsCsv(propertyKey, srcPropValue)) {
            File dirOrFile = pathResolver.relativeFile(getBaseDir().toFile(), sourcePath);
            if (dirOrFile.exists()) {
                result.add(dirOrFile.toPath());
            }
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) CheckForNull(javax.annotation.CheckForNull)

Example 10 with PathResolver

use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.

the class AbsolutePathPredicate method get.

@Override
public Iterable<InputFile> get(Index index) {
    String relative = PathUtils.sanitize(new PathResolver().relativePath(baseDir.toFile(), new File(path)));
    if (relative == null) {
        return Collections.emptyList();
    }
    InputFile f = index.inputFile(relative);
    return f != null ? Arrays.asList(f) : Collections.emptyList();
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

PathResolver (org.sonar.api.scan.filesystem.PathResolver)19 File (java.io.File)12 Test (org.junit.Test)7 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)7 Before (org.junit.Before)6 InputFile (org.sonar.api.batch.fs.InputFile)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)5 MapSettings (org.sonar.api.config.internal.MapSettings)4 Path (java.nio.file.Path)3 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)3 Matchers.anyString (org.mockito.Matchers.anyString)2 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 MapSettings (org.sonar.api.config.MapSettings)2 AnalysisWarnings (org.sonar.api.notifications.AnalysisWarnings)2 MeasureCache (org.sonar.scanner.scan.measure.MeasureCache)2 ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1 AnalysisMode (org.sonar.api.batch.AnalysisMode)1