Search in sources :

Example 41 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class InputFileBuilderTest method setUp.

@Before
public void setUp() throws IOException {
    baseDir = temp.newFolder().toPath();
    DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey("module1").setBaseDir(baseDir.toFile()), 0);
    PathResolver pathResolver = new PathResolver();
    LanguageDetection langDetection = mock(LanguageDetection.class);
    MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
    BatchIdGenerator idGenerator = new BatchIdGenerator();
    Settings settings = new MapSettings();
    builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) PathResolver(org.sonar.api.scan.filesystem.PathResolver) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Before(org.junit.Before)

Example 42 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class SymbolizableBuilderTest method project_should_not_be_highlightable.

@Test
public void project_should_not_be_highlightable() {
    SymbolizableBuilder builder = new SymbolizableBuilder(mock(DefaultSensorStorage.class), mock(AnalysisMode.class));
    Perspective perspective = builder.loadPerspective(Symbolizable.class, new DefaultInputModule("struts"));
    assertThat(perspective).isNull();
}
Also used : Perspective(org.sonar.api.component.Perspective) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) DefaultSensorStorage(org.sonar.scanner.sensor.DefaultSensorStorage) AnalysisMode(org.sonar.api.batch.AnalysisMode) Test(org.junit.Test)

Example 43 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class MetadataPublisher method addModulesRelativePaths.

private void addModulesRelativePaths(ScannerReport.Metadata.Builder builder) {
    LinkedList<DefaultInputModule> queue = new LinkedList<>();
    queue.add(moduleHierarchy.root());
    while (!queue.isEmpty()) {
        DefaultInputModule module = queue.removeFirst();
        queue.addAll(moduleHierarchy.children(module));
        String relativePath = moduleHierarchy.relativePathToRoot(module);
        if (relativePath != null) {
            builder.putModulesProjectRelativePathByKey(module.key(), relativePath);
        }
    }
    ScmProvider scmProvider = scmConfiguration.provider();
    if (scmProvider == null) {
        return;
    }
    Path projectBasedir = moduleHierarchy.root().getBaseDir();
    try {
        builder.setRelativePathFromScmRoot(toSonarQubePath(scmProvider.relativePathFromScmRoot(projectBasedir)));
    } catch (UnsupportedOperationException e) {
        LOG.debug(e.getMessage());
    }
}
Also used : ScmProvider(org.sonar.api.batch.scm.ScmProvider) Path(java.nio.file.Path) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) LinkedList(java.util.LinkedList)

Example 44 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class ModuleIndexer method indexChildren.

private void indexChildren(DefaultInputModule parent) {
    for (DefaultInputModule module : moduleHierarchy.children(parent)) {
        componentStore.put(module);
        indexChildren(module);
    }
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule)

Example 45 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class SensorContextTesterTest method testMeasures.

@Test
public void testMeasures() throws IOException {
    assertThat(tester.measures("foo:src/Foo.java")).isEmpty();
    assertThat(tester.measure("foo:src/Foo.java", "ncloc")).isNull();
    tester.<Integer>newMeasure().on(new TestInputFileBuilder("foo", "src/Foo.java").build()).forMetric(CoreMetrics.NCLOC).withValue(2).save();
    assertThat(tester.measures("foo:src/Foo.java")).hasSize(1);
    assertThat(tester.measure("foo:src/Foo.java", "ncloc")).isNotNull();
    tester.<Integer>newMeasure().on(new TestInputFileBuilder("foo", "src/Foo.java").build()).forMetric(CoreMetrics.LINES).withValue(4).save();
    assertThat(tester.measures("foo:src/Foo.java")).hasSize(2);
    assertThat(tester.measure("foo:src/Foo.java", "ncloc")).isNotNull();
    assertThat(tester.measure("foo:src/Foo.java", "lines")).isNotNull();
    tester.<Integer>newMeasure().on(new DefaultInputModule(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()))).forMetric(CoreMetrics.DIRECTORIES).withValue(4).save();
    assertThat(tester.measures("foo")).hasSize(1);
    assertThat(tester.measure("foo", "directories")).isNotNull();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Test(org.junit.Test)

Aggregations

DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)57 Test (org.junit.Test)34 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)17 File (java.io.File)9 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)9 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)9 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)8 Path (java.nio.file.Path)6 InputFile (org.sonar.api.batch.fs.InputFile)6 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)5 Before (org.junit.Before)4 InputComponent (org.sonar.api.batch.fs.InputComponent)4 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)4 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 CheckForNull (javax.annotation.CheckForNull)3 InputDir (org.sonar.api.batch.fs.InputDir)3 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)3 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)3