diff --git a/scm-core/src/main/java/sonia/scm/BasicContextProvider.java b/scm-core/src/main/java/sonia/scm/BasicContextProvider.java index bd55d8c682..cc30c81fdd 100644 --- a/scm-core/src/main/java/sonia/scm/BasicContextProvider.java +++ b/scm-core/src/main/java/sonia/scm/BasicContextProvider.java @@ -75,6 +75,12 @@ public class BasicContextProvider implements SCMContextProvider /** Maven property for the version of the artifact */ public static final String MAVEN_PROPERTY_VERSION = "version"; + /** + * Java system property for the SCM-Manager project stage + * @since 1.12 + */ + public static final String STAGE_PROPERTY = "scm.stage"; + //~--- constructors --------------------------------------------------------- /** @@ -85,6 +91,7 @@ public class BasicContextProvider implements SCMContextProvider { baseDirectory = findBaseDirectory(); version = loadVersion(); + stage = loadProjectStage(); } //~--- methods -------------------------------------------------------------- @@ -119,6 +126,17 @@ public class BasicContextProvider implements SCMContextProvider return baseDirectory; } + /** + * {@inheritDoc} + * + * @return + */ + @Override + public Stage getStage() + { + return stage; + } + /** * Returns the version of the SCM-Manager. If the version is not set, the * {@link #DEFAULT_VERSION} is returned. @@ -170,6 +188,35 @@ public class BasicContextProvider implements SCMContextProvider return directory; } + /** + * Find the current stage. + * + * + * @return current stage + */ + private Stage loadProjectStage() + { + Stage s = Stage.PRODUCTION; + String stageProperty = System.getProperty(STAGE_PROPERTY); + + if (Util.isNotEmpty(stageProperty)) + { + try + { + s = Stage.valueOf(stageProperty.toUpperCase()); + } + catch (IllegalArgumentException ex) + { + + // do not use logger or IOUtil, + // http://www.slf4j.org/codes.html#substituteLogger + ex.printStackTrace(System.err); + } + } + + return s; + } + /** * Loads the version of the SCM-Manager from maven properties file. * @@ -269,6 +316,9 @@ public class BasicContextProvider implements SCMContextProvider /** The base directory of the SCM-Manager */ private File baseDirectory; + /** stage of the current SCM-Manager instance */ + private Stage stage; + /** the version of the SCM-Manager */ private String version; } diff --git a/scm-core/src/main/java/sonia/scm/SCMContextProvider.java b/scm-core/src/main/java/sonia/scm/SCMContextProvider.java index 6a5d14b796..f8906b02d7 100644 --- a/scm-core/src/main/java/sonia/scm/SCMContextProvider.java +++ b/scm-core/src/main/java/sonia/scm/SCMContextProvider.java @@ -40,7 +40,7 @@ import java.io.File; /** * The main class for retrieving the home and the version of the SCM-Manager. - * This class is a singleton which can be retrieved via injection + * This class is a singleton which can be retrieved via injection * or with the static {@link SCMContext#getContext()} method. * * @author Sebastian Sdorra @@ -65,6 +65,15 @@ public interface SCMContextProvider extends Closeable */ public File getBaseDirectory(); + /** + * Returns the current stage of SCM-Manager. + * + * + * @return stage of SCM-Manager + * @since 1.12 + */ + public Stage getStage(); + /** * Returns the version of the SCM-Manager. * diff --git a/scm-core/src/main/java/sonia/scm/Stage.java b/scm-core/src/main/java/sonia/scm/Stage.java new file mode 100644 index 0000000000..78b8ba890b --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/Stage.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm; + +/** + * The constants in this class represent the current state of the running + * SCM_Manager instance. The stage can be queried by calling + * {@link SCMContextProvider#getProjectStage()}. + * + * @author Sebastian Sdorra + * @since 1.12 + */ +public enum Stage +{ + + /** + * This value indicates SCM-Manager is right now in development. + */ + DEVELOPMENT, + + /** + * This value indicates SCM-Manager is right now productive. + */ + PRODUCTION +} diff --git a/scm-webapp/pom.xml b/scm-webapp/pom.xml index fb6a7ac420..f474375601 100644 --- a/scm-webapp/pom.xml +++ b/scm-webapp/pom.xml @@ -311,6 +311,10 @@ scm.home ${scm.home} + + scm.stage + ${scm.stage} + @@ -333,6 +337,7 @@ + DEVELOPMENT target/scm-it default 1.25 diff --git a/scm-webapp/src/main/java/sonia/scm/boot/BootstrapListener.java b/scm-webapp/src/main/java/sonia/scm/boot/BootstrapListener.java index f2eda228b0..9e8e90f47e 100644 --- a/scm-webapp/src/main/java/sonia/scm/boot/BootstrapListener.java +++ b/scm-webapp/src/main/java/sonia/scm/boot/BootstrapListener.java @@ -102,6 +102,12 @@ public class BootstrapListener implements ServletContextListener @Override public void contextInitialized(ServletContextEvent sce) { + if (logger.isInfoEnabled()) + { + logger.info("start scm-manager in stage: {}", + SCMContext.getContext().getStage()); + } + ClassLoader classLoader = null; File pluginDirectory = new File(SCMContext.getContext().getBaseDirectory(), PLUGIN_DIRECTORY); @@ -130,7 +136,11 @@ public class BootstrapListener implements ServletContextListener if (classLoader != null) { - logger.info("try to use ScmBootstrapClassLoader"); + if (logger.isInfoEnabled()) + { + logger.info("try to use ScmBootstrapClassLoader"); + } + scmContextListener = BootstrapUtil.loadClass(classLoader, ServletContextListener.class, LISTENER); Thread.currentThread().setContextClassLoader(classLoader); @@ -139,7 +149,11 @@ public class BootstrapListener implements ServletContextListener if (scmContextListener == null) { - logger.warn("fallback to default classloader"); + if (logger.isWarnEnabled()) + { + logger.warn("fallback to default classloader"); + } + scmContextListener = BootstrapUtil.loadClass(ServletContextListener.class, LISTENER); }