From 3b51f04bd4d3b16957823f7e84a58375039c9540 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 4 Feb 2011 02:46:42 +0300 Subject: SONAR-2172: New extension point - AbstractInitializer * Mark interface DependsUponMavenPlugin by annotation SupportedEnvironment with value "maven" * Extract CoberturaMavenInitializer from CoberturaSensor * Extract CloverMavenInitializer from CloverSensor --- .../org/sonar/api/batch/AbstractInitializer.java | 46 ++++++++++++++++++++++ .../org/sonar/api/batch/SupportedEnvironment.java | 5 ++- .../api/batch/maven/DependsUponMavenPlugin.java | 4 +- 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractInitializer.java (limited to 'sonar-plugin-api/src') diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractInitializer.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractInitializer.java new file mode 100644 index 00000000000..9c34f2869c9 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractInitializer.java @@ -0,0 +1,46 @@ +/* + * 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; + +import org.sonar.api.batch.Phase.Name; +import org.sonar.api.resources.Project; + +/** + * @since 2.6 + */ +@Phase(name = Name.PRE) +public abstract class AbstractInitializer implements Sensor { + + public boolean shouldExecuteOnProject(Project project) { + return true; + } + + public void analyse(Project project, SensorContext context) { + prepare(project); + } + + public abstract void prepare(Project project); + + @Override + public String toString() { + return getClass().getSimpleName(); + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java index 7862c224b29..5a120ebbbe3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java @@ -26,8 +26,9 @@ import java.lang.annotation.Target; /** * This annotation allows to specify in which environments {@link org.sonar.api.BatchExtension} would be active. - * Consult to {@link org.sonar.api.platform.Environment} to find possible values, for example - "maven2". - * We strictly recommend you to not overuse this annotation - most preferable is to design extensions to work in all environments. + * For example: "maven", "ant". + * Usage of this annotation is discouraged and we strictly recommend you to not overuse it. + * Most preferable is to design extensions to work in all environments. * * @since 2.6 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java index 26e69a20f43..11ea8d00f75 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java @@ -20,13 +20,15 @@ package org.sonar.api.batch.maven; import org.sonar.api.BatchExtension; +import org.sonar.api.batch.SupportedEnvironment; import org.sonar.api.resources.Project; /** * Used for Sensors and PostJobs only. - * + * * @since 1.10 */ +@SupportedEnvironment("maven") public interface DependsUponMavenPlugin extends BatchExtension { MavenPluginHandler getMavenPluginHandler(Project project); -- cgit v1.2.3