Search in sources :

Example 1 with PathResolver

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

the class FileSystemLogger method logPaths.

private static void logPaths(Logger logger, String label, File baseDir, List<File> paths) {
    if (!paths.isEmpty()) {
        PathResolver resolver = new PathResolver();
        StringBuilder sb = new StringBuilder(label);
        for (Iterator<File> it = paths.iterator(); it.hasNext(); ) {
            File file = it.next();
            String relativePathToBaseDir = resolver.relativePath(baseDir, file);
            if (relativePathToBaseDir == null) {
                sb.append(file);
            } else if (StringUtils.isBlank(relativePathToBaseDir)) {
                sb.append(".");
            } else {
                sb.append(relativePathToBaseDir);
            }
            if (it.hasNext()) {
                sb.append(", ");
            }
        }
        logger.info(sb.toString());
    }
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File)

Example 2 with PathResolver

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

the class CoveragePublisherTest method prepare.

@Before
public void prepare() throws IOException {
    String moduleKey = "foo";
    inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build();
    InputComponentStore componentCache = new InputComponentStore(new PathResolver());
    componentCache.put(TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()));
    componentCache.put(inputFile);
    measureCache = mock(MeasureCache.class);
    when(measureCache.byMetric(anyString(), anyString())).thenReturn(null);
    publisher = new CoveragePublisher(componentCache, measureCache);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) MeasureCache(org.sonar.scanner.scan.measure.MeasureCache) PathResolver(org.sonar.api.scan.filesystem.PathResolver) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Example 3 with PathResolver

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

the class MeasuresPublisherTest method prepare.

@Before
public void prepare() throws IOException {
    String moduleKey = "foo";
    inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
    inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
    InputComponentStore componentCache = new InputComponentStore(new PathResolver());
    componentCache.put(inputModule);
    componentCache.put(inputFile);
    measureCache = mock(MeasureCache.class);
    when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
    publisher = new MeasuresPublisher(componentCache, measureCache, mock(TestPlanBuilder.class));
    outputDir = temp.newFolder();
    writer = new ScannerReportWriter(outputDir);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) MeasureCache(org.sonar.scanner.scan.measure.MeasureCache) PathResolver(org.sonar.api.scan.filesystem.PathResolver) Matchers.anyString(org.mockito.Matchers.anyString) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Before(org.junit.Before)

Example 4 with PathResolver

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

the class JSONReportTest method before.

@Before
public void before() throws Exception {
    moduleHierarchy = mock(InputModuleHierarchy.class);
    userRepository = mock(UserRepositoryLoader.class);
    File projectBaseDir = temp.newFolder();
    fs = new DefaultFileSystem(projectBaseDir.toPath());
    SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
    when(server.getVersion()).thenReturn("3.6");
    InputComponentStore inputComponentStore = new InputComponentStore(new PathResolver());
    DefaultComponentTree inputComponentTree = new DefaultComponentTree();
    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(projectBaseDir).setKey("struts"), 1);
    inputComponentStore.put(rootModule);
    DefaultInputModule moduleA = new DefaultInputModule("struts-core");
    inputComponentTree.index(moduleA, rootModule);
    DefaultInputModule moduleB = new DefaultInputModule("struts-ui");
    inputComponentTree.index(moduleB, rootModule);
    DefaultInputDir inputDir = new DefaultInputDir("struts", "src/main/java/org/apache/struts", TestInputFileBuilder.nextBatchId()).setModuleBaseDir(projectBaseDir.toPath());
    DefaultInputFile inputFile = new TestInputFileBuilder("struts", "src/main/java/org/apache/struts/Action.java").setModuleBaseDir(projectBaseDir.toPath()).build();
    inputFile.setStatus(InputFile.Status.CHANGED);
    inputFile.setPublish(true);
    inputComponentStore.put(inputFile);
    inputComponentStore.put(inputDir);
    inputComponentTree.index(inputDir, rootModule);
    inputComponentTree.index(inputFile, inputDir);
    when(moduleHierarchy.children(rootModule)).thenReturn(Arrays.asList(moduleA, moduleB));
    when(moduleHierarchy.parent(moduleA)).thenReturn(rootModule);
    when(moduleHierarchy.parent(moduleB)).thenReturn(rootModule);
    when(moduleHierarchy.relativePath(moduleA)).thenReturn("core");
    when(moduleHierarchy.relativePath(moduleB)).thenReturn("ui");
    RulesBuilder builder = new RulesBuilder();
    builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles");
    rules = builder.build();
    jsonReport = new JSONReport(moduleHierarchy, settings, fs, server, rules, issueCache, rootModule, inputComponentStore, userRepository, inputComponentTree);
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) UserRepositoryLoader(org.sonar.scanner.repository.user.UserRepositoryLoader) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) DefaultComponentTree(org.sonar.scanner.scan.DefaultComponentTree) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 5 with PathResolver

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

the class SurefireUtilsTest method return_default_value_if_property_unset.

@Test
public void return_default_value_if_property_unset() throws Exception {
    MapSettings settings = new MapSettings();
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(1);
    File directory = directories.get(0);
    assertThat(directory.getCanonicalPath()).endsWith("target" + File.separator + "surefire-reports");
    assertThat(directory.exists()).isFalse();
    assertThat(directory.isDirectory()).isFalse();
    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)

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