Search in sources :

Example 1 with AbstractProjectOrModule

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

the class DefaultInputProjectTest method testEncoding.

@Test
public void testEncoding() throws IOException {
    ProjectDefinition def = ProjectDefinition.create();
    def.setKey("projectKey");
    def.setName("projectName");
    File baseDir = temp.newFolder();
    def.setBaseDir(baseDir);
    def.setProjectVersion("version");
    def.setDescription("desc");
    File workDir = temp.newFolder();
    def.setWorkDir(workDir);
    def.setSources("file1");
    def.setProperty("sonar.sourceEncoding", "UTF-16");
    AbstractProjectOrModule project = new DefaultInputProject(def);
    assertThat(project.getEncoding()).isEqualTo(StandardCharsets.UTF_16);
}
Also used : DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 2 with AbstractProjectOrModule

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

the class TestInputFileBuilderTest method testCreateInputModule.

@Test
public void testCreateInputModule() throws IOException {
    File baseDir = temp.newFolder();
    AbstractProjectOrModule module = TestInputFileBuilder.newDefaultInputModule("key", baseDir);
    assertThat(module.key()).isEqualTo("key");
    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS));
}
Also used : AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 3 with AbstractProjectOrModule

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

the class DefaultMeasureTest method build_project_measure.

@Test
public void build_project_measure() throws IOException {
    SensorStorage storage = Mockito.mock(SensorStorage.class);
    AbstractProjectOrModule module = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
    DefaultMeasure<Integer> newMeasure = new DefaultMeasure<Integer>(storage).forMetric(CoreMetrics.LINES).on(module).withValue(3);
    Assertions.assertThat(newMeasure.inputComponent()).isEqualTo(module);
    Assertions.assertThat(newMeasure.metric()).isEqualTo(CoreMetrics.LINES);
    Assertions.assertThat(newMeasure.value()).isEqualTo(3);
    newMeasure.save();
    Mockito.verify(storage).store(newMeasure);
}
Also used : DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 4 with AbstractProjectOrModule

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

the class DefaultInputModuleHierarchy method relativePath.

@Override
@CheckForNull
public String relativePath(DefaultInputModule module) {
    AbstractProjectOrModule parent = parent(module);
    if (parent == null) {
        return "";
    }
    Path parentBaseDir = parent.getBaseDir();
    Path moduleBaseDir = module.getBaseDir();
    return PathResolver.relativize(parentBaseDir, moduleBaseDir).orElse(null);
}
Also used : Path(java.nio.file.Path) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) CheckForNull(javax.annotation.CheckForNull)

Example 5 with AbstractProjectOrModule

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

the class AnalysisContextReportPublisher method collectModuleSpecificProps.

/**
 * Only keep props that are not in parent
 */
private Map<String, String> collectModuleSpecificProps(DefaultInputModule module) {
    Map<String, String> moduleSpecificProps = new HashMap<>();
    AbstractProjectOrModule parent = hierarchy.parent(module);
    if (parent == null) {
        moduleSpecificProps.putAll(module.properties());
    } else {
        Map<String, String> parentProps = parent.properties();
        for (Map.Entry<String, String> entry : module.properties().entrySet()) {
            if (!parentProps.containsKey(entry.getKey()) || !parentProps.get(entry.getKey()).equals(entry.getValue())) {
                moduleSpecificProps.put(entry.getKey(), entry.getValue());
            }
        }
    }
    return moduleSpecificProps;
}
Also used : HashMap(java.util.HashMap) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AbstractProjectOrModule (org.sonar.api.batch.fs.internal.AbstractProjectOrModule)7 Test (org.junit.Test)4 File (java.io.File)3 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)3 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CheckForNull (javax.annotation.CheckForNull)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)1 ScannerPlugin (org.sonar.scanner.bootstrap.ScannerPlugin)1 QProfile (org.sonar.scanner.rule.QProfile)1