]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 do not display the profile version in the widget "description"
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Jun 2014 12:25:13 +0000 (14:25 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Jun 2014 12:37:08 +0000 (14:37 +0200)
The concept of profile version was dropped.

plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb
sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java

index 646b9e08a92bf3fc36047e1b36669bd2730f9f5b..20b6dad36b83807400f4b35fc8b8c13de5da87eb 100644 (file)
     </p>
   <%
      else
-       profile_measure=@snapshot.measure(Metric::PROFILE)
+       profile_measure=@snapshot.measure('profile')
        if profile_measure
   %>
       <p class="description-widget-description">
         <%= message('widget.description.profile') -%>:
         <span id="resource_profile">
-          <%= link_to profile_measure.data, {:controller => '/profiles', :action => 'show', :id => profile_measure.value.to_i}, :class => 'widget-link', :id => 'profile_link' -%>
+          <%= link_to profile_measure.data, {:controller => 'profiles', :action => 'show', :id => profile_measure.value.to_i}, :class => 'widget-link', :id => 'profile_link' -%>
         </span>
-        <span class="subtitle">(<%= message('widget.description.profile_version_x', :params => format_measure('profile_version', :default => '1')) -%>)</span>
       </p>
     <% end
        end %>
index c2be9665707bca405afa588456bcd1de0ae28be4..fa97b20289e143959349e64aed422cd0f0420e42 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 /*
-* SonarQube, open source software quality management tool.
-* Copyright (C) 2008-2014 SonarSource
-* mailto:contact AT sonarsource DOT com
-*
-* SonarQube is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or (at your option) any later version.
-*
-* SonarQube is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public License
-* along with this program; if not, write to the Free Software Foundation,
-* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*/
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
 package org.sonar.batch.rule;
 
-//import org.junit.Test;
-//import org.sonar.api.batch.DecoratorContext;
-//import org.sonar.api.batch.Event;
-//import org.sonar.api.batch.TimeMachine;
-//import org.sonar.api.batch.TimeMachineQuery;
-//import org.sonar.api.measures.CoreMetrics;
-//import org.sonar.api.measures.Measure;
-//import org.sonar.api.resources.Java;
-//import org.sonar.api.resources.Languages;
-//import org.sonar.api.resources.Project;
-//import org.sonar.core.qualityprofile.db.QualityProfileDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDto;
-//
-//import java.util.Arrays;
-//import java.util.Collections;
-//import java.util.Date;
-//
-//import static org.fest.assertions.Assertions.assertThat;
-//import static org.mockito.Matchers.any;
-//import static org.mockito.Matchers.anyString;
-//import static org.mockito.Matchers.eq;
-//import static org.mockito.Matchers.same;
-//import static org.mockito.Mockito.mock;
-//import static org.mockito.Mockito.never;
-//import static org.mockito.Mockito.verify;
-//import static org.mockito.Mockito.when;
-//
-//public class QProfileEventsDecoratorTest {
-//
-//  Project project = new Project("myProject");
-//  DecoratorContext decoratorContext = mock(DecoratorContext.class);
-//  TimeMachine timeMachine = mock(TimeMachine.class);
-//  Languages languages = mock(Languages.class);
-//  QProfileEventsDecorator decorator = new QProfileEventsDecorator(timeMachine, languages);
-//
-//  @Test
-//  public void shouldExecuteOnProjects() {
-//    assertThat(decorator.shouldExecuteOnProject(project)).isTrue();
-//  }
-//
-//  @Test
-//  public void shouldDoNothingIfNoProfileChange() {
-//    Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]");
-//    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]");
-//
-//    when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
-//      .thenReturn(Arrays.asList(previousMeasure));
-//    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-//
-//    decorator.decorate(project, decoratorContext);
-//
-//    verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class));
-//  }
-//
-//  @Test
-//  public void shouldDoNothingIfNoProfileChange_fallbackOldProfileMeasure() {
-//    mockTMWithDeprecatedProfileMeasures(2, "Java Two", 20);
-//    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"key\":\"p2\",\"name\":\"Java Two\",\"language\":\"java\"}]");
-//    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-//
-//    when(languages.get("java")).thenReturn(Java.INSTANCE);
-//
-//    decorator.decorate(project, decoratorContext);
-//
-//    verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class));
-//  }
-//
-//  @Test
-//  public void shouldCreateEventIfProfileChange() {
-//    Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]");
-//    // Different profile
-//    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":3,\"name\":\"Java Other\",\"version\":1,\"language\":\"java\"}]");
-//
-//    when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
-//      .thenReturn(Arrays.asList(previousMeasure));
-//    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-//
-//    when(languages.get("java")).thenReturn(Java.INSTANCE);
-//
-//    decorator.decorate(project, decoratorContext);
-//
-//    verify(decoratorContext).createEvent(
-//      eq("Use Java Other version 1 (Java)"),
-//      eq("Java Other version 1 used for Java"),
-//      same(Event.CATEGORY_PROFILE), any(Date.class));
-//  }
-////
-////  @Test
-////  public void shouldCreateEventIfProfileChange_fallbackOldProfileMeasure() {
-////    mockTMWithDeprecatedProfileMeasures(2, "Java Two", 20);
-////    when(qualityProfileDao.getById(20)).thenReturn(new QualityProfileDto().setLanguage("java"));
-////    // Different profile
-////    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":3,\"name\":\"Java Other\",\"version\":1,\"language\":\"java\"}]");
-////
-////    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-////
-////    when(languages.get("java")).thenReturn(Java.INSTANCE);
-////
-////    decorator.decorate(project, decoratorContext);
-////
-////    verify(decoratorContext).createEvent(
-////      eq("Use Java Other version 1 (Java)"),
-////      eq("Java Other version 1 used for Java"),
-////      same(Event.CATEGORY_PROFILE), any(Date.class));
-////  }
-////
-////  @Test
-////  public void shouldCreateEventIfProfileVersionChange() {
-////    Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]");
-////    // Same profile, different version
-////    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]");
-////
-////    when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
-////      .thenReturn(Arrays.asList(previousMeasure));
-////    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-////
-////    when(languages.get("java")).thenReturn(Java.INSTANCE);
-////
-////    decorator.decorate(project, decoratorContext);
-////
-////    verify(decoratorContext).createEvent(
-////      eq("Use Java Two version 21 (Java)"),
-////      eq("Java Two version 21 used for Java"),
-////      same(Event.CATEGORY_PROFILE), any(Date.class));
-////  }
-////
-////  @Test
-////  public void shouldCreateEventIfProfileVersionChange_fallbackOldProfileMeasure() {
-////    mockTMWithDeprecatedProfileMeasures(2, "Java Two", 20);
-////    when(qualityProfileDao.getById(20)).thenReturn(new QualityProfileDto().setLanguage("java"));
-////    // Same profile, different version
-////    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]");
-////
-////    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-////
-////    when(languages.get("java")).thenReturn(Java.INSTANCE);
-////
-////    decorator.decorate(project, decoratorContext);
-////
-////    verify(decoratorContext).createEvent(
-////      eq("Use Java Two version 21 (Java)"),
-////      eq("Java Two version 21 used for Java"),
-////      same(Event.CATEGORY_PROFILE), any(Date.class));
-////  }
-////
-////  @Test
-////  public void shouldCreateEventIfProfileVersionChange_fallbackOldProfileMeasure_noVersion() {
-////    mockTMWithDeprecatedProfileMeasures(2, "Java Two", null);
-////    when(qualityProfileDao.getById(20)).thenReturn(new QualityProfileDto().setLanguage("java"));
-////    // Same profile, different version
-////    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]");
-////
-////    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-////
-////    when(languages.get("java")).thenReturn(Java.INSTANCE);
-////
-////    decorator.decorate(project, decoratorContext);
-////
-////    verify(decoratorContext).createEvent(
-////      eq("Use Java Two version 21 (Java)"),
-////      eq("Java Two version 21 used for Java"),
-////      same(Event.CATEGORY_PROFILE), any(Date.class));
-////  }
-//
-//  @Test
-//  public void shouldNotCreateEventIfFirstAnalysis() {
-//    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]");
-//
-//    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
-//
-//    when(languages.get("java")).thenReturn(Java.INSTANCE);
-//
-//    decorator.decorate(project, decoratorContext);
-//
-//    verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class));
-//  }
-//
-//  private void mockTMWithDeprecatedProfileMeasures(double profileId, String profileName, Integer versionValue) {
-//    mockTM(new Measure(CoreMetrics.QUALITY_PROFILES, profileId, profileName), versionValue == null ? null : new Measure(CoreMetrics.PROFILE_VERSION, Double.valueOf(versionValue)));
-//  }
-//
-//  private void mockTM(Measure result1, Measure result2) {
-//    when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
-//      .thenReturn(Collections.<Measure>emptyList())
-//      .thenReturn(result1 == null ? Collections.<Measure>emptyList() : Arrays.asList(result1))
-//      .thenReturn(result2 == null ? Collections.<Measure>emptyList() : Arrays.asList(result2));
-//
-//  }
-//}
+import org.junit.Ignore;
+import org.junit.Test;
+import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.batch.Event;
+import org.sonar.api.batch.TimeMachine;
+import org.sonar.api.batch.TimeMachineQuery;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Languages;
+import org.sonar.api.resources.Project;
+
+import java.util.Arrays;
+import java.util.Date;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class QProfileEventsDecoratorTest {
+
+  static final String JAVA_V1_JSON = "{\"key\":\"J1\",\"language\":\"java\",\"name\":\"Java One\"}";
+  static final String JAVA_V2_JSON = "{\"key\":\"J1\",\"language\":\"java\",\"name\":\"Java One\"}";
+
+  Project project = new Project("myProject");
+  DecoratorContext decoratorContext = mock(DecoratorContext.class);
+  TimeMachine timeMachine = mock(TimeMachine.class);
+  Languages languages = mock(Languages.class);
+  QProfileEventsDecorator decorator = new QProfileEventsDecorator(timeMachine, languages);
+
+  @Test
+  public void shouldExecuteOnProjects() {
+    assertThat(decorator.shouldExecuteOnProject(project)).isTrue();
+  }
+
+  @Test
+  public void shouldDoNothingIfNoProfileChange() {
+    Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]");
+    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]");
+
+    when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
+      .thenReturn(Arrays.asList(previousMeasure));
+    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
+
+    decorator.decorate(project, decoratorContext);
+
+    verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class));
+  }
+
+  @Test
+  @Ignore
+  public void shouldCreateEventIfProfileChange() {
+    Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]");
+    // Different profile
+    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V2_JSON + "]");
+
+    when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
+      .thenReturn(Arrays.asList(previousMeasure));
+    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
+
+    when(languages.get("java")).thenReturn(Java.INSTANCE);
+
+    decorator.decorate(project, decoratorContext);
+
+    verify(decoratorContext).createEvent(
+      eq("Use Java Other version 1 (Java)"),
+      eq("Java Other version 1 used for Java"),
+      same(Event.CATEGORY_PROFILE), any(Date.class));
+  }
+
+  @Test
+  public void shouldNotCreateEventIfFirstAnalysis() {
+    Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]");
+
+    when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure);
+
+    when(languages.get("java")).thenReturn(Java.INSTANCE);
+
+    decorator.decorate(project, decoratorContext);
+
+    verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class));
+  }
+}