added api for project stages

This commit is contained in:
Sebastian Sdorra
2012-02-03 17:41:11 +01:00
parent c608187eab
commit 38fde6e46b
5 changed files with 135 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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.
*

View File

@@ -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
}

View File

@@ -311,6 +311,10 @@
<name>scm.home</name>
<value>${scm.home}</value>
</systemProperty>
<systemProperty>
<name>scm.stage</name>
<value>${scm.stage}</value>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
@@ -333,6 +337,7 @@
</build>
<properties>
<scm.stage>DEVELOPMENT</scm.stage>
<scm.home>target/scm-it</scm.home>
<environment.profile>default</environment.profile>
<enunciate.version>1.25</enunciate.version>

View File

@@ -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);
}