aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-01-15 11:32:06 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2013-01-15 11:32:06 +0100
commite22444e60337cdca715efdfccec93b5b85915199 (patch)
tree7263d45ed2721ca236d2e25f05184c4b7c7d7b37 /sonar-batch/src
parent1f49941cf2e2485abc0c64d1bd0ffa4b563aed77 (diff)
downloadsonarqube-e22444e60337cdca715efdfccec93b5b85915199.tar.gz
sonarqube-e22444e60337cdca715efdfccec93b5b85915199.zip
SONAR-4069 Add a new task to list all available tasks
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskDefinition.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskExecutor.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskDefinition.java42
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskExecutor.java41
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/tasks/TaskManager.java4
6 files changed, 93 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java
index f25bc762354..57393008adf 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java
@@ -24,6 +24,7 @@ import org.sonar.api.batch.TaskDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.tasks.AnalyseProjectTaskDefinition;
+import org.sonar.batch.tasks.ListTaskDefinition;
import org.sonar.batch.tasks.TaskManager;
/**
@@ -46,6 +47,7 @@ public class TaskBootstrapModule extends Module {
private void registerCoreTaskDefinitions() {
container.addSingleton(AnalyseProjectTaskDefinition.class);
+ container.addSingleton(ListTaskDefinition.class);
}
private void registerTaskDefinitionExtensions() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskDefinition.java
index a1284efe54e..ba8b98dbed3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskDefinition.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskDefinition.java
@@ -29,8 +29,8 @@ public class AnalyseProjectTaskDefinition implements TaskDefinition {
public TaskDescriptor getTaskDescriptor() {
return TaskDescriptor.create()
- .setDescription("Analysis")
- .setName("Analysis")
+ .setDescription("Start a Sonar analysis of a project")
+ .setName("Sonar project analysis")
.setCommand(COMMAND)
.setRequiresProject(true);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskExecutor.java
index 4f76e5f72c3..fa8936aaf2e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/AnalyseProjectTaskExecutor.java
@@ -19,11 +19,13 @@
*/
package org.sonar.batch.tasks;
+import org.sonar.api.batch.RequiresProject;
import org.sonar.api.batch.TaskExecutor;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.bootstrap.AnalyseProjectModule;
+@RequiresProject
public class AnalyseProjectTaskExecutor implements TaskExecutor {
private final ComponentContainer container;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskDefinition.java
new file mode 100644
index 00000000000..8e71f18eec5
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskDefinition.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.tasks;
+
+import org.sonar.api.batch.TaskDefinition;
+import org.sonar.api.batch.TaskDescriptor;
+import org.sonar.api.batch.TaskExecutor;
+
+public class ListTaskDefinition implements TaskDefinition {
+
+ public static final String COMMAND = "list-tasks";
+
+ public TaskDescriptor getTaskDescriptor() {
+ return TaskDescriptor.create()
+ .setDescription("List all available tasks on the Sonar server")
+ .setName("List tasks")
+ .setCommand(COMMAND)
+ .setRequiresProject(false);
+ }
+
+ public Class<? extends TaskExecutor> getExecutor() {
+ return ListTaskExecutor.class;
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskExecutor.java
new file mode 100644
index 00000000000..45226963b80
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTaskExecutor.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.tasks;
+
+import org.sonar.api.batch.TaskDefinition;
+import org.sonar.api.batch.TaskDescriptor;
+import org.sonar.api.batch.TaskExecutor;
+
+public class ListTaskExecutor implements TaskExecutor {
+
+ private final TaskManager taskManager;
+
+ public ListTaskExecutor(TaskManager taskManager) {
+ this.taskManager = taskManager;
+ }
+
+ public void execute() {
+ for (TaskDefinition task : taskManager.getTasks()) {
+ TaskDescriptor desc = task.getTaskDescriptor();
+ System.out.println(" " + desc.getCommand() + ": " + desc.getDecription());
+ }
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/TaskManager.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/TaskManager.java
index c518d2fde96..92ef002a4ef 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/tasks/TaskManager.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/TaskManager.java
@@ -39,4 +39,8 @@ public class TaskManager {
throw new SonarException("No task found for command: " + command);
}
+ public TaskDefinition[] getTasks() {
+ return tasks;
+ }
+
}