]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3308 Revert back changes
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 25 May 2012 07:46:38 +0000 (09:46 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Fri, 25 May 2012 07:47:46 +0000 (09:47 +0200)
=> Too many side effects
=> Still need to handle the original exception

plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java

index 39bb7264db3752d09461020f96928007e8cb09b9..0c4825fc77a9a700b23afa2b83ce2a1de37ef7f0 100644 (file)
@@ -31,8 +31,6 @@ import java.util.Iterator;
 @NotDryRun
 public class VersionEventsSensor implements Sensor {
 
-  private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
-
   public boolean shouldExecuteOnProject(Project project) {
     return true;
   }
@@ -47,19 +45,11 @@ public class VersionEventsSensor implements Sensor {
 
   private void deleteDeprecatedEvents(Project project, SensorContext context) {
     String version = project.getAnalysisVersion();
-    boolean isReleaseVersion = !version.endsWith(SNAPSHOT_SUFFIX);
-    String snapshotVersionToDelete = isReleaseVersion ? version + SNAPSHOT_SUFFIX : "";
     for (Iterator<Event> it = context.getEvents(project).iterator(); it.hasNext();) {
       Event event = it.next();
-      if (event.isVersionCategory()) {
-        if (snapshotVersionToDelete.equals(event.getName()) || (version.equals(event.getName()) && !isReleaseVersion)) {
-          it.remove();
-          context.deleteEvent(event);
-        } else if (version.equals(event.getName()) && isReleaseVersion) {
-          // we try to delete a released version that already exists in the project history => this shouldn't happen
-          throw new IllegalStateException("A Sonar analysis can't delete a released version that already exists in the project history (version "
-            + version + "). Please change the version of the project or clean its history first.");
-        }
+      if (event.isVersionCategory() && version.equals(event.getName())) {
+        it.remove();
+        context.deleteEvent(event);
       }
     }
   }
index b92dbf587cfee3b90385f8f47585111d08a677f2..c1dbd67d4f1f90521c888acbc27f5f54b6b6e2d1 100644 (file)
@@ -30,6 +30,8 @@ import org.sonar.api.resources.Resource;
 
 import java.util.Date;
 
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.anyObject;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
@@ -44,6 +46,16 @@ public class VersionEventsSensorTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
+  @Test
+  public void shouldExecuteOnProject() throws Exception {
+    assertThat(new VersionEventsSensor().shouldExecuteOnProject(null), is(true));
+  }
+
+  @Test
+  public void testToString() throws Exception {
+    assertThat(new VersionEventsSensor().toString(), is("VersionEventsSensor"));
+  }
+
   @Test
   public void shouldDoNothingIfNoVersion() {
     VersionEventsSensor sensor = new VersionEventsSensor();
@@ -90,52 +102,11 @@ public class VersionEventsSensorTest {
     verify(context).createEvent(eq(project), eq("1.5-SNAPSHOT"), (String) isNull(), eq(Event.CATEGORY_VERSION), (Date) isNull());
   }
 
-  @Test
-  public void shouldDeleteAssociatedSnapshotWhenReleasing() {
-    Event snapshotVersion = mockVersionEvent("1.5-SNAPSHOT");
-    Event otherEvent = mockVersionEvent("1.4");
-
-    SensorContext context = mock(SensorContext.class);
-    Project project = mock(Project.class);
-    when(project.getAnalysisVersion()).thenReturn("1.5");
-    when(context.getEvents(project)).thenReturn(Lists.newArrayList(snapshotVersion, otherEvent));
-
-    VersionEventsSensor sensor = new VersionEventsSensor();
-    sensor.analyse(project, context);
-
-    verify(context).deleteEvent(snapshotVersion);
-    verify(context).createEvent(eq(project), eq("1.5"), (String) isNull(), eq(Event.CATEGORY_VERSION), (Date) isNull());
-  }
-
-  @Test
-  public void shouldFailIfTryingToDeleteReleasedVersion() {
-    // Given
-    Event snapshotEvent1 = mockVersionEvent("1.5-SNAPSHOT");
-    Event releaseEvent2 = mockVersionEvent("1.4");
-    Event snapshotEvent2 = mockVersionEvent("1.3-SNAPSHOT");
-
-    VersionEventsSensor sensor = new VersionEventsSensor();
-    SensorContext context = mock(SensorContext.class);
-
-    Project project = mock(Project.class);
-    when(project.getAnalysisVersion()).thenReturn("1.4");
-
-    when(context.getEvents(project)).thenReturn(Lists.newArrayList(snapshotEvent1, releaseEvent2, snapshotEvent2));
-
-    // Expect
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("A Sonar analysis can't delete a released version that already exists in the project history (version 1.4). " +
-      "Please change the version of the project or clean its history first.");
-
-    // When
-    sensor.analyse(project, context);
-
-  }
-
   private Event mockVersionEvent(String version) {
     Event event = mock(Event.class);
     when(event.isVersionCategory()).thenReturn(true);
     when(event.getName()).thenReturn(version);
     return event;
   }
+
 }