mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
added version to ScmState
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -39,6 +41,9 @@ import sonia.scm.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -47,6 +52,9 @@ import java.io.IOException;
|
||||
public class BasicContextProvider implements SCMContextProvider
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String DEFAULT_VERSION = "unknown";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_DEFAULT = ".scm";
|
||||
|
||||
@@ -56,6 +64,13 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_PROPERTY = "scm.home";
|
||||
|
||||
/** Field description */
|
||||
public static final String MAVEN_PROPERTIES =
|
||||
"/META-INF/maven/sonia.scm/scm-core/pom.properties";
|
||||
|
||||
/** Field description */
|
||||
public static final String MAVEN_PROPERTY_VERSION = "version";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -65,6 +80,7 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
public BasicContextProvider()
|
||||
{
|
||||
baseDirectory = findBaseDirectory();
|
||||
version = loadVersion();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -99,6 +115,18 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
return baseDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -132,8 +160,38 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
return directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String loadVersion()
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
InputStream input =
|
||||
BasicContextProvider.class.getResourceAsStream(MAVEN_PROPERTIES);
|
||||
|
||||
if (input != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
properties.load(input);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new ConfigurationException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return properties.getProperty(MAVEN_PROPERTY_VERSION, DEFAULT_VERSION);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private String version;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -58,4 +60,12 @@ public interface SCMContextProvider extends Closeable
|
||||
* @return
|
||||
*/
|
||||
public File getBaseDirectory();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getVersion();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user