components.addAll(builder.components);
components.add(builder.environment);
projectReactor = builder.projectReactor;
- logging = LoggingConfiguration.create().setProperties((Map) projectReactor.getRoot().getProperties());
- }
-
- /**
- * Disable the internal configuration of Logback. In this case the batch bootstrapper must provide its
- * own implementation of SLF4J.
- */
- public Batch disableLoggingConfiguration() {
- this.logging = null;
- return this;
+ if (builder.isEnableLoggingConfiguration()) {
+ logging = LoggingConfiguration.create().setProperties((Map) projectReactor.getRoot().getProperties());
+ }
}
public LoggingConfiguration getLoggingConfiguration() {
private ProjectReactor projectReactor;
private EnvironmentInformation environment;
private List components = Lists.newArrayList();
+ private boolean enableLoggingConfiguration = true;
private Builder() {
}
- public ProjectReactor getProjectReactor() {
- return projectReactor;
- }
-
public Builder setProjectReactor(ProjectReactor projectReactor) {
this.projectReactor = projectReactor;
return this;
}
- public EnvironmentInformation getEnvironment() {
- return environment;
- }
-
public Builder setEnvironment(EnvironmentInformation env) {
this.environment = env;
return this;
}
- public List getComponents() {
- return components;
- }
-
public Builder setComponents(List l) {
this.components = l;
return this;
return this;
}
+ public boolean isEnableLoggingConfiguration() {
+ return enableLoggingConfiguration;
+ }
+
+ /**
+ * Logback is configured by default. It can be disabled, but n this case the batch bootstrapper must provide its
+ * own implementation of SLF4J.
+ */
+ public Builder setEnableLoggingConfiguration(boolean b) {
+ this.enableLoggingConfiguration = b;
+ return this;
+ }
+
public Batch build() {
if (projectReactor == null) {
- throw new IllegalArgumentException("ProjectReactor is not set");
+ throw new IllegalStateException("ProjectReactor is not set");
}
if (environment == null) {
- throw new IllegalArgumentException("EnvironmentInfo is not set");
+ throw new IllegalStateException("EnvironmentInfo is not set");
}
if (components == null) {
- throw new IllegalArgumentException("Batch components are not set");
+ throw new IllegalStateException("Batch components are not set");
}
return new Batch(this);
}
package org.sonar.batch.bootstrapper;
import org.junit.Test;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.batch.bootstrap.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
public void testBuilder() {
Batch batch = newBatch();
assertNotNull(batch);
+
}
private Batch newBatch() {
.build();
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = IllegalStateException.class)
public void shouldFailIfNoEnvironment() {
Batch.builder()
.setProjectReactor(new ProjectReactor(org.sonar.api.batch.bootstrap.ProjectDefinition.create()))
.build();
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = IllegalStateException.class)
public void shouldFailIfNoProjectReactor() {
Batch.builder()
.setEnvironment(new EnvironmentInformation("Gradle", "1.0"))
.build();
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = IllegalStateException.class)
public void shouldFailIfNullComponents() {
Batch.builder()
.setProjectReactor(new ProjectReactor(org.sonar.api.batch.bootstrap.ProjectDefinition.create()))
@Test
public void shouldDisableLoggingConfiguration() {
- Batch batch = newBatch();
- batch.disableLoggingConfiguration();
+ Batch batch = Batch.builder()
+ .setEnvironment(new EnvironmentInformation("Gradle", "1.0"))
+ .setProjectReactor(new ProjectReactor(org.sonar.api.batch.bootstrap.ProjectDefinition.create()))
+ .addComponent("fake")
+ .setEnableLoggingConfiguration(false)
+ .build();
assertNull(batch.getLoggingConfiguration());
}