mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
added api for project stages
This commit is contained in:
@@ -75,6 +75,12 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
/** Maven property for the version of the artifact */
|
/** Maven property for the version of the artifact */
|
||||||
public static final String MAVEN_PROPERTY_VERSION = "version";
|
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 ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,6 +91,7 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
{
|
{
|
||||||
baseDirectory = findBaseDirectory();
|
baseDirectory = findBaseDirectory();
|
||||||
version = loadVersion();
|
version = loadVersion();
|
||||||
|
stage = loadProjectStage();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -119,6 +126,17 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
return baseDirectory;
|
return baseDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Stage getStage()
|
||||||
|
{
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version of the SCM-Manager. If the version is not set, the
|
* Returns the version of the SCM-Manager. If the version is not set, the
|
||||||
* {@link #DEFAULT_VERSION} is returned.
|
* {@link #DEFAULT_VERSION} is returned.
|
||||||
@@ -170,6 +188,35 @@ public class BasicContextProvider implements SCMContextProvider
|
|||||||
return directory;
|
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.
|
* 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 */
|
/** The base directory of the SCM-Manager */
|
||||||
private File baseDirectory;
|
private File baseDirectory;
|
||||||
|
|
||||||
|
/** stage of the current SCM-Manager instance */
|
||||||
|
private Stage stage;
|
||||||
|
|
||||||
/** the version of the SCM-Manager */
|
/** the version of the SCM-Manager */
|
||||||
private String version;
|
private String version;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import java.io.File;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The main class for retrieving the home and the version of the SCM-Manager.
|
* 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.
|
* or with the static {@link SCMContext#getContext()} method.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -65,6 +65,15 @@ public interface SCMContextProvider extends Closeable
|
|||||||
*/
|
*/
|
||||||
public File getBaseDirectory();
|
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.
|
* Returns the version of the SCM-Manager.
|
||||||
*
|
*
|
||||||
|
|||||||
54
scm-core/src/main/java/sonia/scm/Stage.java
Normal file
54
scm-core/src/main/java/sonia/scm/Stage.java
Normal 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
|
||||||
|
}
|
||||||
@@ -311,6 +311,10 @@
|
|||||||
<name>scm.home</name>
|
<name>scm.home</name>
|
||||||
<value>${scm.home}</value>
|
<value>${scm.home}</value>
|
||||||
</systemProperty>
|
</systemProperty>
|
||||||
|
<systemProperty>
|
||||||
|
<name>scm.stage</name>
|
||||||
|
<value>${scm.stage}</value>
|
||||||
|
</systemProperty>
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<connectors>
|
<connectors>
|
||||||
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
|
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
|
||||||
@@ -333,6 +337,7 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<scm.stage>DEVELOPMENT</scm.stage>
|
||||||
<scm.home>target/scm-it</scm.home>
|
<scm.home>target/scm-it</scm.home>
|
||||||
<environment.profile>default</environment.profile>
|
<environment.profile>default</environment.profile>
|
||||||
<enunciate.version>1.25</enunciate.version>
|
<enunciate.version>1.25</enunciate.version>
|
||||||
|
|||||||
@@ -102,6 +102,12 @@ public class BootstrapListener implements ServletContextListener
|
|||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce)
|
public void contextInitialized(ServletContextEvent sce)
|
||||||
{
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("start scm-manager in stage: {}",
|
||||||
|
SCMContext.getContext().getStage());
|
||||||
|
}
|
||||||
|
|
||||||
ClassLoader classLoader = null;
|
ClassLoader classLoader = null;
|
||||||
File pluginDirectory = new File(SCMContext.getContext().getBaseDirectory(),
|
File pluginDirectory = new File(SCMContext.getContext().getBaseDirectory(),
|
||||||
PLUGIN_DIRECTORY);
|
PLUGIN_DIRECTORY);
|
||||||
@@ -130,7 +136,11 @@ public class BootstrapListener implements ServletContextListener
|
|||||||
|
|
||||||
if (classLoader != null)
|
if (classLoader != null)
|
||||||
{
|
{
|
||||||
logger.info("try to use ScmBootstrapClassLoader");
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("try to use ScmBootstrapClassLoader");
|
||||||
|
}
|
||||||
|
|
||||||
scmContextListener = BootstrapUtil.loadClass(classLoader,
|
scmContextListener = BootstrapUtil.loadClass(classLoader,
|
||||||
ServletContextListener.class, LISTENER);
|
ServletContextListener.class, LISTENER);
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
Thread.currentThread().setContextClassLoader(classLoader);
|
||||||
@@ -139,7 +149,11 @@ public class BootstrapListener implements ServletContextListener
|
|||||||
|
|
||||||
if (scmContextListener == null)
|
if (scmContextListener == null)
|
||||||
{
|
{
|
||||||
logger.warn("fallback to default classloader");
|
if (logger.isWarnEnabled())
|
||||||
|
{
|
||||||
|
logger.warn("fallback to default classloader");
|
||||||
|
}
|
||||||
|
|
||||||
scmContextListener =
|
scmContextListener =
|
||||||
BootstrapUtil.loadClass(ServletContextListener.class, LISTENER);
|
BootstrapUtil.loadClass(ServletContextListener.class, LISTENER);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user