From: Simon Brandhof Date: Mon, 16 Jan 2012 11:14:50 +0000 (+0100) Subject: Refactor org.sonar.batch.bootstrapper.Batch X-Git-Tag: 2.14~307 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a5dd732ef923e3db4fbaa0545fa78bd83a148fc7;p=sonarqube.git Refactor org.sonar.batch.bootstrapper.Batch --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java index 3aaeb3f8993..7c05398b27d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java @@ -44,16 +44,9 @@ public final class Batch { 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() { @@ -94,32 +87,21 @@ public final class Batch { 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; @@ -135,15 +117,28 @@ public final class Batch { 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); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java index c1718c1e56c..eeb52de2918 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java @@ -20,7 +20,7 @@ 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; @@ -31,6 +31,7 @@ public class BatchTest { public void testBuilder() { Batch batch = newBatch(); assertNotNull(batch); + } private Batch newBatch() { @@ -41,7 +42,7 @@ public class BatchTest { .build(); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void shouldFailIfNoEnvironment() { Batch.builder() .setProjectReactor(new ProjectReactor(org.sonar.api.batch.bootstrap.ProjectDefinition.create())) @@ -49,7 +50,7 @@ public class BatchTest { .build(); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void shouldFailIfNoProjectReactor() { Batch.builder() .setEnvironment(new EnvironmentInformation("Gradle", "1.0")) @@ -57,7 +58,7 @@ public class BatchTest { .build(); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void shouldFailIfNullComponents() { Batch.builder() .setProjectReactor(new ProjectReactor(org.sonar.api.batch.bootstrap.ProjectDefinition.create())) @@ -68,8 +69,12 @@ public class BatchTest { @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()); }