aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-02-27 18:25:32 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2013-02-27 18:25:32 +0100
commit041dceb1c50d4e1c073e044ab37a610faae2d6a4 (patch)
tree19fe404d95c095fbd9cc26191ac58b65c143105c
parentd3cf13a01891639342cfe34d28d01bf3ce183fa1 (diff)
downloadsonarqube-041dceb1c50d4e1c073e044ab37a610faae2d6a4.tar.gz
sonarqube-041dceb1c50d4e1c073e044ab37a610faae2d6a4.zip
Fix after refactoring for views
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskContainer.java20
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskContainer.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapContainer.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskBootstrapContainerTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskContainerTest.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java6
7 files changed, 24 insertions, 35 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
index 80f2c1f48bd..54c8c7b8524 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
@@ -58,6 +58,9 @@ public class BootstrapContainer extends Container {
@Override
protected void configure() {
container.addSingleton(globalProperties);
+ if (reactor != null) {
+ container.addSingleton(reactor);
+ }
container.addSingleton(new PropertiesConfiguration());
container.addSingleton(BootstrapSettings.class);
container.addSingleton(ServerClient.class);
@@ -95,7 +98,7 @@ public class BootstrapContainer extends Container {
@Override
protected void doStart() {
- Container childModule = new TaskBootstrapContainer(taskCommand, reactor);
+ Container childModule = new TaskBootstrapContainer(taskCommand);
try {
installChild(childModule);
childModule.start();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskContainer.java
index 1df65ec74cb..24c8463fcca 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskContainer.java
@@ -22,13 +22,13 @@ package org.sonar.batch.bootstrap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.DefaultResourceCreationLock;
+import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.components.PastSnapshotFinder;
import org.sonar.batch.components.PastSnapshotFinderByDate;
@@ -62,8 +62,6 @@ import org.sonar.jpa.dao.MeasuresDao;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.JpaDatabaseSession;
-import javax.annotation.Nullable;
-
/**
* Level-3 components. Task-level components that don't depends on project.
*/
@@ -73,11 +71,11 @@ public class ProjectLessTaskContainer extends Container {
private TaskDefinition taskDefinition;
- private ProjectReactor reactor;
+ private boolean projectPresent;
- public ProjectLessTaskContainer(TaskDefinition task, @Nullable ProjectReactor reactor) {
+ public ProjectLessTaskContainer(TaskDefinition task, boolean projectPresent) {
this.taskDefinition = task;
- this.reactor = reactor;
+ this.projectPresent = projectPresent;
}
@Override
@@ -86,6 +84,11 @@ public class ProjectLessTaskContainer extends Container {
registerDatabaseComponents();
registerCoreProjectLessTasks();
registerProjectLessTaskExtensions();
+ if (projectPresent && ExtensionUtils.requiresProject(taskDefinition.getTask())) {
+ container.addSingleton(ProjectExclusions.class);
+ container.addSingleton(ProjectReactorReady.class);
+ container.addSingleton(DryRunDatabase.class);
+ }
}
private void registerCoreComponents() {
@@ -119,7 +122,7 @@ public class ProjectLessTaskContainer extends Container {
container.addSingleton(DefaultResourcePersister.class);
container.addSingleton(SourcePersister.class);
container.addSingleton(DefaultNotificationManager.class);
-
+ container.addSingleton(ProjectConfigurator.class);
}
private void registerDatabaseComponents() {
@@ -156,13 +159,12 @@ public class ProjectLessTaskContainer extends Container {
*/
@Override
protected void doStart() {
- boolean projectPresent = (reactor != null);
if (ExtensionUtils.requiresProject(taskDefinition.getTask())) {
if (!projectPresent) {
throw new SonarException("Task '" + taskDefinition.getName() + "' requires to be run on a project");
}
// Create a new child container to put project specific components
- Container childModule = new ProjectTaskContainer(taskDefinition, reactor);
+ Container childModule = new ProjectTaskContainer(taskDefinition);
try {
installChild(childModule);
childModule.start();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskContainer.java
index a5ea55a2da9..e63a411bdb3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskContainer.java
@@ -22,12 +22,10 @@ package org.sonar.batch.bootstrap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.DefaultFileLinesContextFactory;
-import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.scan.ScanTask;
@@ -46,16 +44,12 @@ public class ProjectTaskContainer extends Container {
private TaskDefinition taskDefinition;
- private ProjectReactor reactor;
-
- public ProjectTaskContainer(TaskDefinition task, ProjectReactor reactor) {
+ public ProjectTaskContainer(TaskDefinition task) {
this.taskDefinition = task;
- this.reactor = reactor;
}
@Override
protected void configure() {
- container.addSingleton(reactor);
registerCoreProjectTasks();
registerCoreComponentsRequiringProject();
registerProjectTaskExtensions();
@@ -71,14 +65,10 @@ public class ProjectTaskContainer extends Container {
}
private void registerCoreComponentsRequiringProject() {
- container.addSingleton(ProjectExclusions.class);
- container.addSingleton(ProjectReactorReady.class);
container.addSingleton(ProjectTree.class);
- container.addSingleton(ProjectConfigurator.class);
container.addSingleton(DefaultIndex.class);
container.addSingleton(DefaultFileLinesContextFactory.class);
container.addSingleton(ProjectLock.class);
- container.addSingleton(DryRunDatabase.class);
// graphs
container.addSingleton(ScanGraph.create());
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapContainer.java
index 8bc1d412bbe..22a60f8c162 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapContainer.java
@@ -34,11 +34,9 @@ import javax.annotation.Nullable;
public class TaskBootstrapContainer extends Container {
private String taskCommand;
- private ProjectReactor reactor;
- public TaskBootstrapContainer(@Nullable String taskCommand, @Nullable ProjectReactor reactor) {
+ public TaskBootstrapContainer(@Nullable String taskCommand) {
this.taskCommand = taskCommand;
- this.reactor = reactor;
}
@Override
@@ -65,11 +63,11 @@ public class TaskBootstrapContainer extends Container {
}
private void executeTask(TaskDefinition taskDefinition) {
- boolean projectPresent = (reactor != null);
+ boolean projectPresent = (container.getComponentByType(ProjectReactor.class) != null);
if (ExtensionUtils.requiresProject(taskDefinition.getTask()) && !projectPresent) {
throw new SonarException("Task '" + taskDefinition.getName() + "' requires to be run on a project");
}
- Container childModule = new ProjectLessTaskContainer(taskDefinition, reactor);
+ Container childModule = new ProjectLessTaskContainer(taskDefinition, projectPresent);
try {
installChild(childModule);
childModule.start();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskBootstrapContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskBootstrapContainerTest.java
index 148449bfce7..9e6b7320a2a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskBootstrapContainerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskBootstrapContainerTest.java
@@ -44,7 +44,7 @@ public class TaskBootstrapContainerTest {
}
};
bootstrapModule.init();
- TaskBootstrapContainer module = new TaskBootstrapContainer("inspect", null);
+ TaskBootstrapContainer module = new TaskBootstrapContainer("inspect");
bootstrapModule.installChild(module);
thrown.expect(SonarException.class);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskContainerTest.java
index ce956d6bd84..92cde480b91 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskContainerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskContainerTest.java
@@ -20,8 +20,6 @@
package org.sonar.batch.bootstrap;
import org.junit.Test;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.task.TaskDefinition;
@@ -42,7 +40,7 @@ public class TaskContainerTest {
}
};
bootstrapModule.init();
- ProjectTaskContainer module = new ProjectTaskContainer(TaskDefinition.create(), new ProjectReactor(ProjectDefinition.create()));
+ ProjectTaskContainer module = new ProjectTaskContainer(TaskDefinition.create());
bootstrapModule.installChild(module);
verify(extensionInstaller).installTaskExtensions(any(ComponentContainer.class), eq(true));
@@ -59,7 +57,7 @@ public class TaskContainerTest {
}
};
bootstrapModule.init();
- ProjectLessTaskContainer module = new ProjectLessTaskContainer(TaskDefinition.create(), null);
+ ProjectLessTaskContainer module = new ProjectLessTaskContainer(TaskDefinition.create(), false);
bootstrapModule.installChild(module);
verify(extensionInstaller).installTaskExtensions(any(ComponentContainer.class), eq(false));
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
index 073c47cbec2..96d3663b6fa 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
@@ -19,8 +19,7 @@
*/
package org.sonar.api.batch.bootstrap;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.task.TaskExtension;
/**
* This extension point allows to change project structure at runtime. It is executed once during task startup.
@@ -34,8 +33,7 @@ import org.sonar.api.batch.InstantiationStrategy;
*
* @since 2.9
*/
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public abstract class ProjectBuilder implements BatchExtension {
+public abstract class ProjectBuilder implements TaskExtension {
private ProjectReactor reactor;