aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-03-27 07:21:33 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-03-31 15:14:42 +0400
commit839e764f272932b2a01450d7b3e2a97a4cf06746 (patch)
tree01699aa30acdc47bb13b8921d05b8c4d34911b66 /sonar-batch
parentf9e8c73f19309058017cf0b38c7ec0c4d5df7494 (diff)
downloadsonarqube-839e764f272932b2a01450d7b3e2a97a4cf06746.tar.gz
sonarqube-839e764f272932b2a01450d7b3e2a97a4cf06746.zip
SONAR-2279 API : new extension points to handle lifecycle events
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/SonarEvent.java)9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionHandler.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/events/EventHandler.java29
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseHandler.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java21
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/SensorExecutionHandler.java)21
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorExecutionEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionEvent.java)24
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsPhaseEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/DecoratorsPhaseEvent.java)28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/DecoratorsPhaseHandler.java)29
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/SensorExecutionEvent.java)24
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java (renamed from sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseEvent.java)24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/events/EventBusTest.java6
17 files changed, 126 insertions, 208 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/SonarEvent.java b/sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java
index 9a544bd6488..a9a98c19e1c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/SonarEvent.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java
@@ -19,15 +19,16 @@
*/
package org.sonar.batch.events;
+import org.sonar.api.batch.events.EventHandler;
+
/**
- * Root of all Sonar events.
+ * Root of all Sonar Batch events.
*
* @param <H> handler type
- * @since 2.7
*/
-public abstract class SonarEvent<H extends EventHandler> {
+public abstract class BatchEvent<H extends EventHandler> {
- protected SonarEvent() {
+ protected BatchEvent() {
}
/**
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionHandler.java b/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionHandler.java
deleted file mode 100644
index 3cf7af0c064..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionHandler.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.events;
-
-public interface DecoratorExecutionHandler extends EventHandler {
-
- void onDecoratorExecution(DecoratorExecutionEvent event);
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java b/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java
index c02d6d0d7e5..765c7a72f13 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java
@@ -20,15 +20,14 @@
package org.sonar.batch.events;
import com.google.common.collect.Lists;
+import org.sonar.api.batch.events.EventHandler;
import org.sonar.api.utils.Logs;
import java.util.List;
/**
- * Dispatches {@link SonarEvent}s. Eases decoupling by allowing objects to interact without having direct dependencies upon one another, and
+ * Dispatches {@link BatchEvent}s. Eases decoupling by allowing objects to interact without having direct dependencies upon one another, and
* without requiring event sources to deal with maintaining handler lists.
- *
- * @since 2.7
*/
public class EventBus {
@@ -41,11 +40,11 @@ public class EventBus {
/**
* Fires the given event.
*/
- public void fireEvent(SonarEvent event) {
+ public void fireEvent(BatchEvent event) {
doFireEvent(event);
}
- private void doFireEvent(SonarEvent event) {
+ private void doFireEvent(BatchEvent event) {
List<EventHandler> handlers = getDispatchList(event.getType());
Logs.INFO.trace("Dispatch event {} for {}", event, handlers);
for (EventHandler handler : handlers) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/EventHandler.java b/sonar-batch/src/main/java/org/sonar/batch/events/EventHandler.java
deleted file mode 100644
index 55ed106eca4..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/events/EventHandler.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.events;
-
-/**
- * Marker interface for event handlers.
- *
- * @since 2.7
- */
-public interface EventHandler {
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseHandler.java b/sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseHandler.java
deleted file mode 100644
index 74be799aa2e..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseHandler.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.events;
-
-public interface SensorsPhaseHandler extends EventHandler {
-
- void onSensorsPhase(SensorsPhaseEvent event);
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java
index 9c6bd043834..798fdd2d441 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java
@@ -19,24 +19,21 @@
*/
package org.sonar.batch.index;
-import java.util.List;
-import java.util.Map;
-
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.events.DecoratorExecutionHandler;
+import org.sonar.api.batch.events.DecoratorsPhaseHandler;
+import org.sonar.api.batch.events.SensorExecutionHandler;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.MeasureData;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.PersistenceMode;
-import org.sonar.batch.events.DecoratorExecutionEvent;
-import org.sonar.batch.events.DecoratorExecutionHandler;
-import org.sonar.batch.events.DecoratorsPhaseEvent;
-import org.sonar.batch.events.DecoratorsPhaseHandler;
-import org.sonar.batch.events.SensorExecutionEvent;
-import org.sonar.batch.events.SensorExecutionHandler;
+
+import java.util.List;
+import java.util.Map;
/**
* @since 2.7
@@ -102,20 +99,20 @@ public class MemoryOptimizer implements SensorExecutionHandler, DecoratorExecuti
}
public void onSensorExecution(SensorExecutionEvent event) {
- if (event.isDoneExecution()) {
+ if (event.isEnd()) {
flushMemory();
session.commit();
}
}
public void onDecoratorExecution(DecoratorExecutionEvent event) {
- if (event.isDoneExecution()) {
+ if (event.isEnd()) {
flushMemory();
}
}
public void onDecoratorsPhase(DecoratorsPhaseEvent event) {
- if (event.isPhaseDone()) {
+ if (event.isEnd()) {
session.commit();
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/SensorExecutionHandler.java b/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java
index 8d33e28a419..09d8d0df85f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/SensorExecutionHandler.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java
@@ -17,10 +17,25 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.events;
+package org.sonar.batch.phases;
-public interface SensorExecutionHandler extends EventHandler {
+import org.sonar.api.batch.events.EventHandler;
+import org.sonar.batch.events.BatchEvent;
- void onSensorExecution(SensorExecutionEvent event);
+abstract class AbstractPhaseEvent<H extends EventHandler> extends BatchEvent<H> {
+
+ private final boolean start;
+
+ AbstractPhaseEvent(boolean start) {
+ this.start = start;
+ }
+
+ public final boolean isStart() {
+ return start;
+ }
+
+ public final boolean isEnd() {
+ return !start;
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorExecutionEvent.java
index d55e3eb0524..bbfa7440888 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorExecutionEvent.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorExecutionEvent.java
@@ -17,35 +17,25 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.events;
+package org.sonar.batch.phases;
import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.events.DecoratorExecutionHandler;
-/**
- * Fired on each execution of {@link Decorator} on start and on finish.
- */
-public class DecoratorExecutionEvent extends SonarEvent<DecoratorExecutionHandler> {
+class DecoratorExecutionEvent extends AbstractPhaseEvent<DecoratorExecutionHandler>
+ implements org.sonar.api.batch.events.DecoratorExecutionHandler.DecoratorExecutionEvent {
- private Decorator decorator;
- private boolean start;
+ private final Decorator decorator;
- public DecoratorExecutionEvent(Decorator decorator, boolean start) {
+ DecoratorExecutionEvent(Decorator decorator, boolean start) {
+ super(start);
this.decorator = decorator;
- this.start = start;
}
public Decorator getDecorator() {
return decorator;
}
- public boolean isStartExecution() {
- return start;
- }
-
- public boolean isDoneExecution() {
- return !start;
- }
-
@Override
public void dispatch(DecoratorExecutionHandler handler) {
handler.onDecoratorExecution(this);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
index 70cc2a1d16b..4d4607accd6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
@@ -29,8 +29,6 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.DecoratorsSelector;
import org.sonar.batch.DefaultDecoratorContext;
-import org.sonar.batch.events.DecoratorExecutionEvent;
-import org.sonar.batch.events.DecoratorsPhaseEvent;
import org.sonar.batch.events.EventBus;
import java.util.Collection;
@@ -50,9 +48,9 @@ public class DecoratorsExecutor implements BatchComponent {
public void execute(Project project) {
Collection<Decorator> decorators = decoratorsSelector.select(project);
- eventBus.fireEvent(new DecoratorsPhaseEvent(decorators, true));
+ eventBus.fireEvent(new DecoratorsPhaseEvent(Lists.newArrayList(decorators), true));
decorateResource(project, decorators, true);
- eventBus.fireEvent(new DecoratorsPhaseEvent(decorators, false));
+ eventBus.fireEvent(new DecoratorsPhaseEvent(Lists.newArrayList(decorators), false));
}
private DecoratorContext decorateResource(Resource resource, Collection<Decorator> decorators, boolean executeDecorators) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorsPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsPhaseEvent.java
index d88468c47aa..dedbb82a9e6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorsPhaseEvent.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsPhaseEvent.java
@@ -17,37 +17,27 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.events;
+package org.sonar.batch.phases;
import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.events.DecoratorsPhaseHandler;
-import java.util.Collection;
+import java.util.List;
-/**
- * Fired before execution of {@link Decorator}s and after.
- */
-public class DecoratorsPhaseEvent extends SonarEvent<DecoratorsPhaseHandler> {
+class DecoratorsPhaseEvent extends AbstractPhaseEvent<DecoratorsPhaseHandler>
+ implements org.sonar.api.batch.events.DecoratorsPhaseHandler.DecoratorsPhaseEvent {
- private Collection<Decorator> decorators;
- private boolean start;
+ private List<Decorator> decorators;
- public DecoratorsPhaseEvent(Collection<Decorator> decorators, boolean start) {
+ DecoratorsPhaseEvent(List<Decorator> decorators, boolean start) {
+ super(start);
this.decorators = decorators;
- this.start = start;
}
- public Collection<Decorator> getDecorators() {
+ public List<Decorator> getDecorators() {
return decorators;
}
- public boolean isPhaseStart() {
- return start;
- }
-
- public boolean isPhaseDone() {
- return !start;
- }
-
@Override
protected void dispatch(DecoratorsPhaseHandler handler) {
handler.onDecoratorsPhase(this);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
index 4146e92ab75..b93ce783751 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
@@ -19,14 +19,15 @@
*/
package org.sonar.batch.phases;
-import java.util.Arrays;
-import java.util.Collection;
-
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
+import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.PersistenceManager;
+import java.util.Arrays;
+import java.util.Collection;
+
public final class Phases {
public static Collection<Class> getPhaseClasses() {
@@ -36,6 +37,7 @@ public final class Phases {
InitializersExecutor.class);
}
+ private EventBus eventBus;
private DecoratorsExecutor decoratorsExecutor;
private MavenPhaseExecutor mavenPhaseExecutor;
private MavenPluginsConfigurator mavenPluginsConfigurator;
@@ -50,7 +52,8 @@ public final class Phases {
public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, UpdateStatusJob updateStatusJob,
- PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index) {
+ PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
+ EventBus eventBus) {
this.decoratorsExecutor = decoratorsExecutor;
this.mavenPhaseExecutor = mavenPhaseExecutor;
this.mavenPluginsConfigurator = mavenPluginsConfigurator;
@@ -67,6 +70,7 @@ public final class Phases {
* Executed on each module
*/
public void execute(Project project) {
+ eventBus.fireEvent(new ProjectAnalysisEvent(project, true));
mavenPluginsConfigurator.execute(project);
mavenPhaseExecutor.execute(project);
initializersExecutor.execute(project);
@@ -82,6 +86,7 @@ public final class Phases {
postJobsExecutor.execute(project, sensorContext);
}
cleanMemory();
+ eventBus.fireEvent(new ProjectAnalysisEvent(project, false));
}
private void cleanMemory() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java
index 07ceaba617d..e090966d42f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java
@@ -19,25 +19,21 @@
*/
package org.sonar.batch.phases;
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.events.DecoratorExecutionHandler;
+import org.sonar.api.batch.events.DecoratorsPhaseHandler;
+import org.sonar.api.batch.events.SensorExecutionHandler;
+import org.sonar.api.batch.events.SensorsPhaseHandler;
import org.sonar.api.utils.TimeProfiler;
-import org.sonar.batch.events.DecoratorExecutionEvent;
-import org.sonar.batch.events.DecoratorExecutionHandler;
-import org.sonar.batch.events.DecoratorsPhaseEvent;
-import org.sonar.batch.events.DecoratorsPhaseHandler;
-import org.sonar.batch.events.SensorExecutionEvent;
-import org.sonar.batch.events.SensorExecutionHandler;
-import org.sonar.batch.events.SensorsPhaseEvent;
-import org.sonar.batch.events.SensorsPhaseHandler;
+
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
public class PhasesTimeProfiler implements SensorExecutionHandler, DecoratorExecutionHandler, DecoratorsPhaseHandler, SensorsPhaseHandler {
@@ -47,13 +43,13 @@ public class PhasesTimeProfiler implements SensorExecutionHandler, DecoratorExec
private DecoratorsProfiler decoratorsProfiler = new DecoratorsProfiler();
public void onSensorsPhase(SensorsPhaseEvent event) {
- if (event.isPhaseStart()) {
+ if (event.isStart()) {
LOG.debug("Sensors : {}", StringUtils.join(event.getSensors(), " -> "));
}
}
public void onSensorExecution(SensorExecutionEvent event) {
- if (event.isStartExecution()) {
+ if (event.isStart()) {
profiler.start("Sensor " + event.getSensor());
} else {
profiler.stop();
@@ -61,7 +57,7 @@ public class PhasesTimeProfiler implements SensorExecutionHandler, DecoratorExec
}
public void onDecoratorExecution(DecoratorExecutionEvent event) {
- if (event.isStartExecution()) {
+ if (event.isStart()) {
decoratorsProfiler.start(event.getDecorator());
} else {
decoratorsProfiler.stop();
@@ -69,7 +65,7 @@ public class PhasesTimeProfiler implements SensorExecutionHandler, DecoratorExec
}
public void onDecoratorsPhase(DecoratorsPhaseEvent event) {
- if (event.isPhaseStart()) {
+ if (event.isStart()) {
LOG.info("Execute decorators...");
if (LOG.isDebugEnabled()) {
LOG.debug("Decorators: {}", StringUtils.join(event.getDecorators(), " -> "));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorsPhaseHandler.java b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java
index 73b2a689f61..50384d64203 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/DecoratorsPhaseHandler.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java
@@ -17,10 +17,33 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.events;
+package org.sonar.batch.phases;
-public interface DecoratorsPhaseHandler extends EventHandler {
+import org.sonar.api.batch.events.ProjectAnalysisHandler;
+import org.sonar.api.resources.Project;
- void onDecoratorsPhase(DecoratorsPhaseEvent event);
+class ProjectAnalysisEvent extends AbstractPhaseEvent<ProjectAnalysisHandler>
+ implements org.sonar.api.batch.events.ProjectAnalysisHandler.ProjectAnalysisEvent {
+
+ private final Project project;
+
+ ProjectAnalysisEvent(Project project, boolean start) {
+ super(start);
+ this.project = project;
+ }
+
+ public Project getProject() {
+ return project;
+ }
+
+ @Override
+ protected void dispatch(ProjectAnalysisHandler handler) {
+ handler.onProjectAnalysis(this);
+ }
+
+ @Override
+ protected Class getType() {
+ return ProjectAnalysisHandler.class;
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/SensorExecutionEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java
index 50ec16564ed..13445dac0b0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/SensorExecutionEvent.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java
@@ -17,35 +17,25 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.events;
+package org.sonar.batch.phases;
import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.events.SensorExecutionHandler;
-/**
- * Fired on each execution of {@link Sensor} on start and on finish.
- */
-public class SensorExecutionEvent extends SonarEvent<SensorExecutionHandler> {
+class SensorExecutionEvent extends AbstractPhaseEvent<SensorExecutionHandler>
+ implements org.sonar.api.batch.events.SensorExecutionHandler.SensorExecutionEvent {
- private Sensor sensor;
- private boolean start;
+ private final Sensor sensor;
- public SensorExecutionEvent(Sensor sensor, boolean start) {
+ SensorExecutionEvent(Sensor sensor, boolean start) {
+ super(start);
this.sensor = sensor;
- this.start = start;
}
public Sensor getSensor() {
return sensor;
}
- public boolean isStartExecution() {
- return start;
- }
-
- public boolean isDoneExecution() {
- return !start;
- }
-
@Override
public void dispatch(SensorExecutionHandler handler) {
handler.onSensorExecution(this);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
index ba767cd0d40..474f53be173 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
@@ -19,8 +19,7 @@
*/
package org.sonar.batch.phases;
-import java.util.Collection;
-
+import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
@@ -33,8 +32,8 @@ import org.sonar.api.resources.Project;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.batch.MavenPluginExecutor;
import org.sonar.batch.events.EventBus;
-import org.sonar.batch.events.SensorExecutionEvent;
-import org.sonar.batch.events.SensorsPhaseEvent;
+
+import java.util.Collection;
public class SensorsExecutor implements BatchComponent {
private static final Logger LOG = LoggerFactory.getLogger(SensorsExecutor.class);
@@ -50,7 +49,7 @@ public class SensorsExecutor implements BatchComponent {
}
public void execute(Project project, SensorContext context) {
- eventBus.fireEvent(new SensorsPhaseEvent(sensors, true));
+ eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), true));
for (Sensor sensor : sensors) {
executeMavenPlugin(project, sensor);
@@ -60,7 +59,7 @@ public class SensorsExecutor implements BatchComponent {
eventBus.fireEvent(new SensorExecutionEvent(sensor, false));
}
- eventBus.fireEvent(new SensorsPhaseEvent(sensors, false));
+ eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), false));
}
private void executeMavenPlugin(Project project, Sensor sensor) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java
index 04fbcb37ad4..a411e1427aa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/events/SensorsPhaseEvent.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java
@@ -17,33 +17,27 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.events;
+package org.sonar.batch.phases;
import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.events.SensorsPhaseHandler;
-import java.util.Collection;
+import java.util.List;
-/**
- * Fired before execution of {@link Sensor}s and after.
- */
-public class SensorsPhaseEvent extends SonarEvent<SensorsPhaseHandler> {
+class SensorsPhaseEvent extends AbstractPhaseEvent<SensorsPhaseHandler>
+ implements org.sonar.api.batch.events.SensorsPhaseHandler.SensorsPhaseEvent {
- private Collection<Sensor> sensors;
- private boolean start;
+ private final List<Sensor> sensors;
- public SensorsPhaseEvent(Collection<Sensor> sensors, boolean start) {
+ SensorsPhaseEvent(List<Sensor> sensors, boolean start) {
+ super(start);
this.sensors = sensors;
- this.start = start;
}
- public Collection<Sensor> getSensors() {
+ public List<Sensor> getSensors() {
return sensors;
}
- public boolean isPhaseStart() {
- return start;
- }
-
@Override
protected void dispatch(SensorsPhaseHandler handler) {
handler.onSensorsPhase(this);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/events/EventBusTest.java b/sonar-batch/src/test/java/org/sonar/batch/events/EventBusTest.java
index 5817a80a336..ba91d5ba61c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/events/EventBusTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/events/EventBusTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.events;
+import org.sonar.api.batch.events.EventHandler;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -45,7 +47,7 @@ public class EventBusTest {
void onEvent(FirstEvent event);
}
- static class FirstEvent extends SonarEvent<FirstHandler> {
+ static class FirstEvent extends BatchEvent<FirstHandler> {
@Override
protected void dispatch(FirstHandler handler) {
handler.onEvent(this);
@@ -61,7 +63,7 @@ public class EventBusTest {
void onEvent(SecondEvent event);
}
- static class SecondEvent extends SonarEvent<SecondHandler> {
+ static class SecondEvent extends BatchEvent<SecondHandler> {
@Override
protected void dispatch(SecondHandler handler) {
handler.onEvent(this);