]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6589 move LanguageRepository out of ComputationContext
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 28 May 2015 07:38:49 +0000 (09:38 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 1 Jun 2015 15:08:29 +0000 (17:08 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
server/sonar-server/src/main/java/org/sonar/server/computation/context/ComputationContext.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityProfileEventsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java

index e6edb3836840917b33dd77aaafff7b8c498a8148..76a82b541fe8b733bdb4c866c2a49a60895d0e7d 100644 (file)
@@ -29,13 +29,11 @@ import org.sonar.server.db.DbClient;
 public class ComputationContext implements org.sonar.server.computation.context.ComputationContext {
   private final DbClient dbClient;
   private final Component component;
-  private final LanguageRepository languageRepository;
 
   public ComputationContext(BatchReportReader reportReader, String projectKey, Settings projectSettings, DbClient dbClient,
     ComponentTreeBuilder componentTreeBuilder, LanguageRepository languageRepository) {
     this.dbClient = dbClient;
     this.component = componentTreeBuilder.build(this);
-    this.languageRepository = languageRepository;
   }
 
   @Override
@@ -51,8 +49,4 @@ public class ComputationContext implements org.sonar.server.computation.context.
     return dbClient;
   }
 
-  @Override
-  public LanguageRepository getLanguageRepository() {
-    return languageRepository;
-  }
 }
index 171639acbc42bff638035d5354280df0cb5e4b6a..9a0a838ae6cb7ced6b6722a24ed610b4e0cf42d1 100644 (file)
 package org.sonar.server.computation.context;
 
 import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.language.LanguageRepository;
 
 public interface ComputationContext {
 
   Component getRoot();
 
-  LanguageRepository getLanguageRepository();
-
 }
index 511bb9b14f612c3d597ad157aff73636b175c253..ab85fb602af71a733de43db4cf236ccc00dd9006 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
 import org.sonar.server.computation.event.Event;
 import org.sonar.server.computation.event.EventRepository;
+import org.sonar.server.computation.language.LanguageRepository;
 import org.sonar.server.computation.measure.MeasureRepository;
 import org.sonar.server.computation.qualityprofile.QPMeasureData;
 import org.sonar.server.computation.qualityprofile.QualityProfile;
@@ -47,10 +48,12 @@ import static org.sonar.server.computation.component.DepthTraversalTypeAwareVisi
 public class QualityProfileEventsStep implements ComputationStep {
   private final MeasureRepository measureRepository;
   private final EventRepository eventRepository;
+  private final LanguageRepository languageRepository;
 
-  public QualityProfileEventsStep(MeasureRepository measureRepository, EventRepository eventRepository) {
+  public QualityProfileEventsStep(MeasureRepository measureRepository, EventRepository eventRepository, LanguageRepository languageRepository) {
     this.measureRepository = measureRepository;
     this.eventRepository = eventRepository;
+    this.languageRepository = languageRepository;
   }
 
   @Override
@@ -119,16 +122,16 @@ public class QualityProfileEventsStep implements ComputationStep {
     eventRepository.add(component, createQProfileEvent(component, profile, "Use %s"));
   }
 
-  private static Event createQProfileEvent(Component component, QualityProfile profile, String namePattern) {
+  private Event createQProfileEvent(Component component, QualityProfile profile, String namePattern) {
     return createQProfileEvent(component, profile, namePattern, null);
   }
 
-  private static Event createQProfileEvent(Component component, QualityProfile profile, String namePattern, @Nullable String data) {
+  private Event createQProfileEvent(Component component, QualityProfile profile, String namePattern, @Nullable String data) {
     return Event.createProfile(String.format(namePattern, profileLabel(component, profile)), data, null);
   }
 
-  private static String profileLabel(Component component, QualityProfile profile) {
-    Optional<Language> language = component.getContext().getLanguageRepository().find(profile.getLanguageKey());
+  private String profileLabel(Component component, QualityProfile profile) {
+    Optional<Language> language = languageRepository.find(profile.getLanguageKey());
     String languageName = language.isPresent() ? language.get().getName() : profile.getLanguageKey();
     return String.format("'%s' (%s)", profile.getQpName(), languageName);
   }
index 0f86e6d7c9d9afed4b2cbeed7b714588831fe8ef..2812600334e9f3ff5a22cfc3268db20d12e980c3 100644 (file)
@@ -76,7 +76,7 @@ public class QualityProfileEventsStepTest {
   private EventRepository eventRepository = mock(EventRepository.class);
   private ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
 
-  private QualityProfileEventsStep underTest = new QualityProfileEventsStep(measureRepository, eventRepository);
+  private QualityProfileEventsStep underTest = new QualityProfileEventsStep(measureRepository, eventRepository, languageRepository);
 
   @Test
   public void no_effect_if_no_previous_measure() {