Search in sources :

Example 11 with DefaultInputModule

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

the class DefaultComponentTreeTest method test.

@Test
public void test() {
    DefaultInputComponent root = new DefaultInputModule("root");
    DefaultInputComponent mod1 = new DefaultInputModule("mod1");
    DefaultInputComponent mod2 = new DefaultInputModule("mod2");
    DefaultInputComponent mod3 = new DefaultInputModule("mod3");
    DefaultInputComponent mod4 = new DefaultInputModule("mod4");
    tree.index(mod1, root);
    tree.index(mod2, mod1);
    tree.index(mod3, root);
    tree.index(mod4, root);
    assertThat(tree.getChildren(root)).containsOnly(mod1, mod3, mod4);
    assertThat(tree.getChildren(mod4)).isEmpty();
    assertThat(tree.getChildren(mod1)).containsOnly(mod2);
    assertThat(tree.getParent(mod4)).isEqualTo(root);
    assertThat(tree.getParent(mod2)).isEqualTo(mod1);
    assertThat(tree.getParent(mod1)).isEqualTo(root);
    assertThat(tree.getParent(root)).isNull();
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) Test(org.junit.Test)

Example 12 with DefaultInputModule

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

the class DefaultInputModuleHierarchyTest method test.

@Test
public void test() {
    DefaultInputModule root = new DefaultInputModule("root");
    DefaultInputModule mod1 = new DefaultInputModule("mod1");
    DefaultInputModule mod2 = new DefaultInputModule("mod2");
    DefaultInputModule mod3 = new DefaultInputModule("mod3");
    DefaultInputModule mod4 = new DefaultInputModule("mod4");
    moduleHierarchy.setRoot(root);
    moduleHierarchy.index(mod1, root);
    moduleHierarchy.index(mod2, mod1);
    moduleHierarchy.index(mod3, root);
    moduleHierarchy.index(mod4, root);
    assertThat(moduleHierarchy.children(root)).containsOnly(mod1, mod3, mod4);
    assertThat(moduleHierarchy.children(mod4)).isEmpty();
    assertThat(moduleHierarchy.children(mod1)).containsOnly(mod2);
    assertThat(moduleHierarchy.parent(mod4)).isEqualTo(root);
    assertThat(moduleHierarchy.parent(mod2)).isEqualTo(mod1);
    assertThat(moduleHierarchy.parent(mod1)).isEqualTo(root);
    assertThat(moduleHierarchy.parent(root)).isNull();
    assertThat(moduleHierarchy.root()).isEqualTo(root);
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Test(org.junit.Test)

Example 13 with DefaultInputModule

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

the class MetadataGeneratorProviderTest method create_builder.

@Test
public void create_builder() {
    StatusDetectionFactory statusDetectionFactory = mock(StatusDetectionFactory.class, Mockito.RETURNS_MOCKS);
    MetadataGeneratorProvider factory = new MetadataGeneratorProvider();
    assertThat(factory.provide(new DefaultInputModule("module"), statusDetectionFactory, new FileMetadata())).isNotNull();
}
Also used : FileMetadata(org.sonar.api.batch.fs.internal.FileMetadata) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Test(org.junit.Test)

Example 14 with DefaultInputModule

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

the class MetadataGeneratorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    metadata = new FileMetadata();
    generator = new MetadataGenerator(new DefaultInputModule("module"), statusDetection, metadata);
}
Also used : FileMetadata(org.sonar.api.batch.fs.internal.FileMetadata) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Before(org.junit.Before)

Example 15 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule 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)

Aggregations

DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)32 Test (org.junit.Test)19 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)9 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)9 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)8 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)7 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)6 InputFile (org.sonar.api.batch.fs.InputFile)5 Before (org.junit.Before)4 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)4 CheckForNull (javax.annotation.CheckForNull)3 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)3 PathResolver (org.sonar.api.scan.filesystem.PathResolver)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)3 File (java.io.File)2 AnalysisMode (org.sonar.api.batch.AnalysisMode)2 InputComponent (org.sonar.api.batch.fs.InputComponent)2 InputDir (org.sonar.api.batch.fs.InputDir)2