From b029b26d896f72459e447f5603d1b6849fe57ab7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 15 Mar 2013 22:11:35 +0100 Subject: [PATCH] Remove unused org.sonar.batch.bootstrap.Container --- .../org/sonar/batch/bootstrap/Container.java | 104 ----------- .../sonar/batch/bootstrap/ContainerTest.java | 166 ------------------ 2 files changed, 270 deletions(-) delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/Container.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/ContainerTest.java diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Container.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Container.java deleted file mode 100644 index b3bb30d37d1..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Container.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.bootstrap; - -import org.sonar.api.platform.ComponentContainer; - -/** - * Container describes group of components - {@link #configure()}. - * Several containers can be grouped together - {@link #installChild(Container)}. - *

- */ -public abstract class Container { - - protected ComponentContainer container; - - public ComponentContainer container() { - return container; - } - - /** - * @return this - */ - public final void init() { - init(new ComponentContainer()); - } - - /** - * @return this - */ - public final void init(ComponentContainer container) { - this.container = container; - configure(); - } - - /** - * Installs container into new scope - see http://picocontainer.org/scopes.html - * - * @return installed module - */ - public final Container installChild(Container child) { - ComponentContainer childContainer = container.createChild(); - child.init(childContainer); - return child; - } - - public final void uninstallChild() { - container.removeChild(); - } - - /** - * @return this - */ - public final Container start() { - container.startComponents(); - doStart(); - return this; - } - - protected void doStart() { - // empty method to be overridden - } - - /** - * @return this - */ - public final Container stop() { - try { - doStop(); - container.stopComponents(); - container.removeChild(); - } catch (Exception e) { - // ignore - } - return this; - } - - protected void doStop() { - // empty method to be overridden - } - - /** - * Implementation of this method must not contain conditional logic and just should contain several invocations on - * {@link #container}. - */ - protected abstract void configure(); - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ContainerTest.java deleted file mode 100644 index d19a17675e0..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ContainerTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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.bootstrap; - -import org.hamcrest.Matchers; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class ContainerTest { - - @Test - public void shouldInitModule() { - Container module = new FakeModule(FakeService.class); - module.init(); - - FakeService service = module.container.getComponentByType(FakeService.class); - assertThat(service, not(nullValue())); - assertThat(service.started, is(false)); - assertThat(module.container, notNullValue()); - } - - @Test - public void shouldStartAndStopModule() { - Container module = new FakeModule(FakeService.class); - module.init(); - module.start(); - - FakeService service = module.container.getComponentByType(FakeService.class); - assertThat(service.started, is(true)); - - module.stop(); - assertThat(service.started, is(false)); - } - - @Test(expected = RuntimeException.class) - public void shouldNotIgnoreStartFailures() { - Container module = new FakeModule(NonStartableService.class); - module.init(); - module.start(); - } - - @Test - public void shouldIgnoreStopFailures() { - Container module = new FakeModule(NonStoppableService.class); - module.init(); - module.start(); - module.stop(); // no exception is raised - } - - @Test - public void componentsShouldBeSingletons() { - Container module = new FakeModule(FakeService.class); - module.init(); - - assertThat(module.container.getComponentByType(FakeService.class) == module.container.getComponentByType(FakeService.class), is(true)); - } - - @Test - public void shouldInstallChildModule() { - Container parent = new FakeModule(FakeService.class); - parent.init(); - parent.start(); - - Container child = parent.installChild(new FakeModule(ChildService.class)); - - assertThat(parent.container.getComponentByType(ChildService.class), Matchers.nullValue());// child not accessible from parent - assertThat(child.container.getComponentByType(FakeService.class), not(nullValue())); - assertThat(child.container.getComponentByType(ChildService.class).started, is(false)); - assertThat(child.container.getComponentByType(ChildService.class).dependency, not(nullValue())); - - child.start(); - assertThat(child.container.getComponentByType(ChildService.class).started, is(true)); - - child.stop(); - assertThat(child.container.getComponentByType(ChildService.class).started, is(false)); - } - - public static class FakeModule extends Container { - private Class[] components; - - public FakeModule(Class... components) { - this.components = components; - } - - @Override - protected void configure() { - for (Class component : components) { - container.addSingleton(component); - } - } - - @Override - public boolean equals(Object obj) { - return false; - } - - @Override - public int hashCode() { - return 42; - } - } - - public static class FakeService { - boolean started = false; - - public void start() { - this.started = true; - } - - public void stop() { - this.started = false; - } - } - - public static class ChildService { - private FakeService dependency; - private boolean started = false; - - public ChildService(FakeService dependency) { - this.dependency = dependency; - } - - public void start() { - this.started = true; - } - - public void stop() { - this.started = false; - } - } - - public static class NonStoppableService { - public void stop() { - throw new IllegalStateException("Can not stop !"); - } - } - - public static class NonStartableService { - public void start() { - throw new IllegalStateException("Can not start !"); - } - } - -} -- 2.39.5