--- /dev/null
+/*
+ * 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;
+
+import org.sonar.api.batch.events.EventHandler;
+
+/**
+ * Root of all Sonar Batch events.
+ *
+ * @param <H> handler type
+ */
+public abstract class BatchEvent<H extends EventHandler> {
+
+ protected BatchEvent() {
+ }
+
+ /**
+ * Do not call directly - should be called only by {@link EventBus}.
+ * Typically should be implemented as following: <code>handler.onEvent(this)</code>
+ */
+ protected abstract void dispatch(H handler);
+
+ /**
+ * Returns class of associated handler. Used by {@link EventBus} to dispatch events to the correct handlers.
+ */
+ protected abstract Class getType();
+
+}
+++ /dev/null
-/*
- * 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;
-
-import org.sonar.api.batch.Decorator;
-
-/**
- * Fired on each execution of {@link Decorator} on start and on finish.
- */
-public class DecoratorExecutionEvent extends SonarEvent<DecoratorExecutionHandler> {
-
- private Decorator decorator;
- private boolean start;
-
- public DecoratorExecutionEvent(Decorator decorator, boolean 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);
- }
-
- @Override
- public Class getType() {
- return DecoratorExecutionHandler.class;
- }
-
-}
+++ /dev/null
-/*
- * 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);
-
-}
+++ /dev/null
-/*
- * 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;
-
-import org.sonar.api.batch.Decorator;
-
-import java.util.Collection;
-
-/**
- * Fired before execution of {@link Decorator}s and after.
- */
-public class DecoratorsPhaseEvent extends SonarEvent<DecoratorsPhaseHandler> {
-
- private Collection<Decorator> decorators;
- private boolean start;
-
- public DecoratorsPhaseEvent(Collection<Decorator> decorators, boolean start) {
- this.decorators = decorators;
- this.start = start;
- }
-
- public Collection<Decorator> getDecorators() {
- return decorators;
- }
-
- public boolean isPhaseStart() {
- return start;
- }
-
- public boolean isPhaseDone() {
- return !start;
- }
-
- @Override
- protected void dispatch(DecoratorsPhaseHandler handler) {
- handler.onDecoratorsPhase(this);
- }
-
- @Override
- protected Class getType() {
- return DecoratorsPhaseHandler.class;
- }
-
-}
+++ /dev/null
-/*
- * 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 DecoratorsPhaseHandler extends EventHandler {
-
- void onDecoratorsPhase(DecoratorsPhaseEvent event);
-
-}
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 {
/**
* 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) {
+++ /dev/null
-/*
- * 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 {
-
-}
+++ /dev/null
-/*
- * 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;
-
-import org.sonar.api.batch.Sensor;
-
-/**
- * Fired on each execution of {@link Sensor} on start and on finish.
- */
-public class SensorExecutionEvent extends SonarEvent<SensorExecutionHandler> {
-
- private Sensor sensor;
- private boolean start;
-
- public SensorExecutionEvent(Sensor sensor, boolean 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);
- }
-
- @Override
- public Class getType() {
- return SensorExecutionHandler.class;
- }
-
-}
+++ /dev/null
-/*
- * 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 SensorExecutionHandler extends EventHandler {
-
- void onSensorExecution(SensorExecutionEvent event);
-
-}
+++ /dev/null
-/*
- * 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;
-
-import org.sonar.api.batch.Sensor;
-
-import java.util.Collection;
-
-/**
- * Fired before execution of {@link Sensor}s and after.
- */
-public class SensorsPhaseEvent extends SonarEvent<SensorsPhaseHandler> {
-
- private Collection<Sensor> sensors;
- private boolean start;
-
- public SensorsPhaseEvent(Collection<Sensor> sensors, boolean start) {
- this.sensors = sensors;
- this.start = start;
- }
-
- public Collection<Sensor> getSensors() {
- return sensors;
- }
-
- public boolean isPhaseStart() {
- return start;
- }
-
- @Override
- protected void dispatch(SensorsPhaseHandler handler) {
- handler.onSensorsPhase(this);
- }
-
- @Override
- protected Class getType() {
- return SensorsPhaseHandler.class;
- }
-
-}
+++ /dev/null
-/*
- * 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);
-
-}
+++ /dev/null
-/*
- * 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;
-
-/**
- * Root of all Sonar events.
- *
- * @param <H> handler type
- * @since 2.7
- */
-public abstract class SonarEvent<H extends EventHandler> {
-
- protected SonarEvent() {
- }
-
- /**
- * Do not call directly - should be called only by {@link EventBus}.
- * Typically should be implemented as following: <code>handler.onEvent(this)</code>
- */
- protected abstract void dispatch(H handler);
-
- /**
- * Returns class of associated handler. Used by {@link EventBus} to dispatch events to the correct handlers.
- */
- protected abstract Class getType();
-
-}
*/
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
}
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();
}
}
--- /dev/null
+/*
+ * 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.phases;
+
+import org.sonar.api.batch.events.EventHandler;
+import org.sonar.batch.events.BatchEvent;
+
+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;
+ }
+
+}
--- /dev/null
+/*
+ * 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.phases;
+
+import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.events.DecoratorExecutionHandler;
+
+class DecoratorExecutionEvent extends AbstractPhaseEvent<DecoratorExecutionHandler>
+ implements org.sonar.api.batch.events.DecoratorExecutionHandler.DecoratorExecutionEvent {
+
+ private final Decorator decorator;
+
+ DecoratorExecutionEvent(Decorator decorator, boolean start) {
+ super(start);
+ this.decorator = decorator;
+ }
+
+ public Decorator getDecorator() {
+ return decorator;
+ }
+
+ @Override
+ public void dispatch(DecoratorExecutionHandler handler) {
+ handler.onDecoratorExecution(this);
+ }
+
+ @Override
+ public Class getType() {
+ return DecoratorExecutionHandler.class;
+ }
+
+}
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;
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) {
--- /dev/null
+/*
+ * 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.phases;
+
+import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.events.DecoratorsPhaseHandler;
+
+import java.util.List;
+
+class DecoratorsPhaseEvent extends AbstractPhaseEvent<DecoratorsPhaseHandler>
+ implements org.sonar.api.batch.events.DecoratorsPhaseHandler.DecoratorsPhaseEvent {
+
+ private List<Decorator> decorators;
+
+ DecoratorsPhaseEvent(List<Decorator> decorators, boolean start) {
+ super(start);
+ this.decorators = decorators;
+ }
+
+ public List<Decorator> getDecorators() {
+ return decorators;
+ }
+
+ @Override
+ protected void dispatch(DecoratorsPhaseHandler handler) {
+ handler.onDecoratorsPhase(this);
+ }
+
+ @Override
+ protected Class getType() {
+ return DecoratorsPhaseHandler.class;
+ }
+
+}
*/
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() {
InitializersExecutor.class);
}
+ private EventBus eventBus;
private DecoratorsExecutor decoratorsExecutor;
private MavenPhaseExecutor mavenPhaseExecutor;
private MavenPluginsConfigurator mavenPluginsConfigurator;
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;
* Executed on each module
*/
public void execute(Project project) {
+ eventBus.fireEvent(new ProjectAnalysisEvent(project, true));
mavenPluginsConfigurator.execute(project);
mavenPhaseExecutor.execute(project);
initializersExecutor.execute(project);
postJobsExecutor.execute(project, sensorContext);
}
cleanMemory();
+ eventBus.fireEvent(new ProjectAnalysisEvent(project, false));
}
private void cleanMemory() {
*/
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 {
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();
}
public void onDecoratorExecution(DecoratorExecutionEvent event) {
- if (event.isStartExecution()) {
+ if (event.isStart()) {
decoratorsProfiler.start(event.getDecorator());
} else {
decoratorsProfiler.stop();
}
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(), " -> "));
--- /dev/null
+/*
+ * 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.phases;
+
+import org.sonar.api.batch.events.ProjectAnalysisHandler;
+import org.sonar.api.resources.Project;
+
+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;
+ }
+
+}
--- /dev/null
+/*
+ * 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.phases;
+
+import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.events.SensorExecutionHandler;
+
+class SensorExecutionEvent extends AbstractPhaseEvent<SensorExecutionHandler>
+ implements org.sonar.api.batch.events.SensorExecutionHandler.SensorExecutionEvent {
+
+ private final Sensor sensor;
+
+ SensorExecutionEvent(Sensor sensor, boolean start) {
+ super(start);
+ this.sensor = sensor;
+ }
+
+ public Sensor getSensor() {
+ return sensor;
+ }
+
+ @Override
+ public void dispatch(SensorExecutionHandler handler) {
+ handler.onSensorExecution(this);
+ }
+
+ @Override
+ public Class getType() {
+ return SensorExecutionHandler.class;
+ }
+
+}
*/
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;
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);
}
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);
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) {
--- /dev/null
+/*
+ * 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.phases;
+
+import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.events.SensorsPhaseHandler;
+
+import java.util.List;
+
+class SensorsPhaseEvent extends AbstractPhaseEvent<SensorsPhaseHandler>
+ implements org.sonar.api.batch.events.SensorsPhaseHandler.SensorsPhaseEvent {
+
+ private final List<Sensor> sensors;
+
+ SensorsPhaseEvent(List<Sensor> sensors, boolean start) {
+ super(start);
+ this.sensors = sensors;
+ }
+
+ public List<Sensor> getSensors() {
+ return sensors;
+ }
+
+ @Override
+ protected void dispatch(SensorsPhaseHandler handler) {
+ handler.onSensorsPhase(this);
+ }
+
+ @Override
+ protected Class getType() {
+ return SensorsPhaseHandler.class;
+ }
+
+}
*/
package org.sonar.batch.events;
+import org.sonar.api.batch.events.EventHandler;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
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);
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);
--- /dev/null
+/*
+ * 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.api.batch.events;
+
+import org.sonar.api.batch.Decorator;
+
+/**
+ * @since 2.8
+ */
+public interface DecoratorExecutionHandler extends EventHandler {
+
+ /**
+ * This interface is not intended to be implemented by clients.
+ */
+ public interface DecoratorExecutionEvent {
+
+ Decorator getDecorator();
+
+ boolean isStart();
+
+ boolean isEnd();
+
+ }
+
+ /**
+ * Called before and after execution of {@link Decorator}.
+ */
+ void onDecoratorExecution(DecoratorExecutionEvent event);
+
+}
--- /dev/null
+/*
+ * 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.api.batch.events;
+
+import org.sonar.api.batch.Decorator;
+
+import java.util.List;
+
+/**
+ * @since 2.8
+ */
+public interface DecoratorsPhaseHandler extends EventHandler {
+
+ /**
+ * This interface is not intended to be implemented by clients.
+ */
+ public interface DecoratorsPhaseEvent {
+
+ /**
+ * @return list of Decorators in the order of execution
+ */
+ List<Decorator> getDecorators();
+
+ boolean isStart();
+
+ boolean isEnd();
+
+ }
+
+ /**
+ * Called before and after execution of all {@link Decorator}s.
+ */
+ void onDecoratorsPhase(DecoratorsPhaseEvent event);
+
+}
--- /dev/null
+/*
+ * 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.api.batch.events;
+
+import org.sonar.api.BatchExtension;
+
+/**
+ * Marker interface for event handlers.
+ * This interface is not intended to be implemented by clients.
+ *
+ * @since 2.8
+ */
+public interface EventHandler extends BatchExtension {
+
+}
--- /dev/null
+/*
+ * 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.api.batch.events;
+
+import org.sonar.api.resources.Project;
+
+/**
+ * @since 2.8
+ */
+public interface ProjectAnalysisHandler extends EventHandler {
+
+ /**
+ * This interface is not intended to be implemented by clients.
+ */
+ public interface ProjectAnalysisEvent {
+
+ Project getProject();
+
+ boolean isStart();
+
+ boolean isEnd();
+
+ }
+
+ /**
+ * Called before and after analysis of project.
+ */
+ void onProjectAnalysis(ProjectAnalysisEvent event);
+
+}
--- /dev/null
+/*
+ * 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.api.batch.events;
+
+import org.sonar.api.batch.Sensor;
+
+/**
+ * @since 2.8
+ */
+public interface SensorExecutionHandler extends EventHandler {
+
+ /**
+ * This interface is not intended to be implemented by clients.
+ */
+ public interface SensorExecutionEvent {
+
+ Sensor getSensor();
+
+ boolean isStart();
+
+ boolean isEnd();
+
+ }
+
+ /**
+ * Called before and after execution of {@link Sensor}.
+ */
+ void onSensorExecution(SensorExecutionEvent event);
+
+}
--- /dev/null
+/*
+ * 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.api.batch.events;
+
+import org.sonar.api.batch.Sensor;
+
+import java.util.List;
+
+/**
+ * @since 2.8
+ */
+public interface SensorsPhaseHandler extends EventHandler {
+
+ /**
+ * This interface is not intended to be implemented by clients.
+ */
+ public interface SensorsPhaseEvent {
+
+ /**
+ * @return list of Sensors in the order of execution
+ */
+ List<Sensor> getSensors();
+
+ boolean isStart();
+
+ boolean isEnd();
+
+ }
+
+ /**
+ * Called before and after execution of all {@link Sensor}s.
+ */
+ void onSensorsPhase(SensorsPhaseEvent event);
+
+}