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);
}
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));
}
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);
}
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);
}
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;
}
Aggregations