]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20582 make the gitlab vulnerability synchronization conditional on having sent...
authorSteve Marion <steve.marion@sonarsource.com>
Thu, 1 Feb 2024 12:55:56 +0000 (13:55 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 6 Feb 2024 16:38:17 +0000 (16:38 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PreMeasuresComputationCheck.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PreMeasuresComputationChecksStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PreMeasuresComputationChecksStepTest.java
server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java

index c747d892539e340d2cf2af3820c75f552fdd892a..cda06cbb481e407d8eedffd215f8ff5e2a52e98a 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.ce.task.projectanalysis.measure;
 
 import org.sonar.api.ExtensionPoint;
 import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.config.Configuration;
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
 
 /**
@@ -47,9 +48,10 @@ public interface PreMeasuresComputationCheck {
 
     Branch getBranch();
 
+    Configuration getConfiguration();
   }
 
-  class PreMeasuresComputationCheckException extends Exception {
+  class PreMeasuresComputationCheckException extends RuntimeException {
     public PreMeasuresComputationCheckException(String message) {
       super(message);
     }
index c88c88ae4c6bbe2fcb8fe54b994e2f0dc5744122..6eb936f9d119cdf5cbac34aac4a6726c7193b478 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.measure;
 
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.System2;
 import org.sonar.ce.task.log.CeTaskMessages;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
+import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.ce.task.step.ComputationStep;
 import org.sonar.db.dismissmessage.MessageType;
 
@@ -38,11 +40,15 @@ public class PreMeasuresComputationChecksStep implements ComputationStep {
   private final AnalysisMetadataHolder analysisMetadataHolder;
   private final PreMeasuresComputationCheck[] extensions;
   private final CeTaskMessages ceTaskMessages;
+  private final ConfigurationRepository configurationRepository;
 
 
-  public PreMeasuresComputationChecksStep(AnalysisMetadataHolder analysisMetadataHolder, CeTaskMessages ceTaskMessages, PreMeasuresComputationCheck... extensions) {
+  public PreMeasuresComputationChecksStep(
+    AnalysisMetadataHolder analysisMetadataHolder, CeTaskMessages ceTaskMessages,
+    ConfigurationRepository configurationRepository, PreMeasuresComputationCheck... extensions) {
     this.analysisMetadataHolder = analysisMetadataHolder;
     this.ceTaskMessages = ceTaskMessages;
+    this.configurationRepository = configurationRepository;
     this.extensions = extensions;
   }
 
@@ -75,5 +81,10 @@ public class PreMeasuresComputationChecksStep implements ComputationStep {
       return analysisMetadataHolder.getBranch();
     }
 
+    @Override
+    public Configuration getConfiguration() {
+      return configurationRepository.getConfiguration();
+    }
+
   }
 }
index 6654d5edb1b091e613cc8def9ef7ca9745a6350c..de68f6843df062d2f0444846b223bab9839cd08a 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.measure;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.InOrder;
 import org.sonar.ce.task.log.CeTaskMessages;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
+import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.ce.task.projectanalysis.measure.PreMeasuresComputationCheck.Context;
 import org.sonar.ce.task.step.TestComputationStepContext;
 import org.sonar.db.component.BranchType;
@@ -44,6 +46,12 @@ public class PreMeasuresComputationChecksStepTest {
 
   public AnalysisMetadataHolderRule analysisMetadataHolder = mock();
   public CeTaskMessages ceTaskMessages = mock();
+  public ConfigurationRepository configurationRepository = mock();
+
+  @Before
+  public void setup() {
+
+  }
 
   @Test
   public void execute_extensions() throws PreMeasuresComputationCheckException {
@@ -114,9 +122,9 @@ public class PreMeasuresComputationChecksStepTest {
 
   private PreMeasuresComputationChecksStep newStep(PreMeasuresComputationCheck... preMeasuresComputationChecks) {
     if (preMeasuresComputationChecks.length == 0) {
-      return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages);
+      return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages, configurationRepository);
     }
-    return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages, preMeasuresComputationChecks);
+    return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages, configurationRepository, preMeasuresComputationChecks);
   }
 
   private void mockBranch(String branchName) {
index d300c2da1301e15ef86446a528ee7a338133f60f..ace5247e7f831c14c755fdc034261f559d05194b 100644 (file)
@@ -446,8 +446,8 @@ public class PropertiesDaoIT {
     insertProperty("global.two", "two", null, null, null, null, null);
 
     List<PropertyDto> properties = underTest.selectGlobalProperties(db.getSession());
-    assertThat(properties.size())
-      .isEqualTo(2);
+    assertThat(properties)
+      .hasSize(2);
 
     assertThat(findByKey(properties, "global.one"))
       .extracting(PropertyDto::getKey, PropertyDto::getEntityUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
@@ -535,6 +535,10 @@ public class PropertiesDaoIT {
     assertThat(property)
       .extracting(PropertyDto::getKey, PropertyDto::getEntityUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
       .containsExactly("project.one", "uuid10", null, "one");
+
+    assertThat(underTest.selectProjectProperty("uuid10", "project.one"))
+      .isPresent()
+      .contains(property);
   }
 
   @Test
index b6034ab4d6493989f3d4c2d6d870e4a62abaf748..7b024c72b48e248c5df1d4e3d23a2ef34b1edee6 100644 (file)
@@ -27,6 +27,7 @@ import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -136,6 +137,12 @@ public class PropertiesDao implements Dao {
     return getMapper(dbSession).selectByKey(new PropertyDto().setKey(propertyKey).setEntityUuid(projectUuid));
   }
 
+  public Optional<PropertyDto> selectProjectProperty(String projectUuid, String propertyKey) {
+    try (DbSession session = mybatis.openSession(false)) {
+      return Optional.ofNullable(selectProjectProperty(session, projectUuid, propertyKey));
+    }
+  }
+
   public List<PropertyDto> selectByQuery(PropertyQuery query, DbSession session) {
     return getMapper(session).selectByQuery(query);
   }