@Override public void execute(ComputationStep.Context context) { List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); try (CloseableIterator<ScannerReport.ContextProperty> it = reportReader.readContextProperties()) { it.forEachRemaining( contextProperty -> { String propertyKey = contextProperty.getKey(); if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) .setSnapshotUuid(analysisMetadataHolder.getUuid())); } }); } analysisMetadataHolder.getScmRevisionId().ifPresent(scmRevisionId -> analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(SCM_REVISION_ID) .setValue(scmRevisionId) .setSnapshotUuid(analysisMetadataHolder.getUuid()))); if (analysisPropertyDtos.isEmpty()) { return; } try (DbSession dbSession = dbClient.openSession(false)) { dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos); dbSession.commit(); } }
@Test public void scannerContext_loads_properties_from_scanner_report() { reportReader.putContextProperties(asList(ScannerReport.ContextProperty.newBuilder().setKey("foo").setValue("bar").build())); underTest.finished(true); verify(postProjectAnalysisTask).finished(projectAnalysisArgumentCaptor.capture()); org.sonar.api.ce.posttask.ScannerContext scannerContext = projectAnalysisArgumentCaptor.getValue().getScannerContext(); assertThat(scannerContext.getProperties()).containsExactly(entry("foo", "bar")); }
@Override public void execute() { final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); reportReader.readContextProperties().forEachRemaining( contextProperty -> { String propertyKey = contextProperty.getKey(); if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) .setSnapshotUuid(analysisMetadataHolder.getUuid())); } }); if (analysisPropertyDtos.isEmpty()) { return; } try (DbSession dbSession = dbClient.openSession(false)) { dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos); dbSession.commit(); } }
static ScannerContextImpl from(CloseableIterator<ScannerReport.ContextProperty> it) { try { ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder(); while (it.hasNext()) { ScannerReport.ContextProperty prop = it.next(); mapBuilder.put(prop.getKey(), prop.getValue()); } return new ScannerContextImpl(mapBuilder.build()); } finally { it.close(); } } }
public CloseableIterator<ScannerReport.ContextProperty> readContextProperties() { File file = fileStructure.contextProperties(); if (!fileExists(file)) { return emptyCloseableIterator(); } return Protobuf.readStream(file, ScannerReport.ContextProperty.parser()); }
static ScannerContextImpl from(CloseableIterator<ScannerReport.ContextProperty> it) { try { ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder(); while (it.hasNext()) { ScannerReport.ContextProperty prop = it.next(); mapBuilder.put(prop.getKey(), prop.getValue()); } return new ScannerContextImpl(mapBuilder.build()); } finally { it.close(); } } }
public CloseableIterator<ScannerReport.ContextProperty> readContextProperties() { File file = fileStructure.contextProperties(); if (!fileExists(file)) { return emptyCloseableIterator(); } return Protobuf.readStream(file, ScannerReport.ContextProperty.parser()); }
private static ScannerReport.ContextProperty newContextProperty(String key, String value) { return ScannerReport.ContextProperty.newBuilder() .setKey(key) .setValue(value) .build(); } }
private static ScannerReport.ContextProperty newContextProperty(String key, String value) { return ScannerReport.ContextProperty.newBuilder() .setKey(key) .setValue(value) .build(); } }