mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
create static read method for GuavaCacheConfigurationReader
This commit is contained in:
@@ -85,7 +85,7 @@ public class GuavaCacheConfigurationReader
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public GuavaCacheConfigurationReader()
|
private GuavaCacheConfigurationReader()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -107,54 +107,9 @@ public class GuavaCacheConfigurationReader
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public GuavaCacheManagerConfiguration read()
|
public static GuavaCacheManagerConfiguration read()
|
||||||
{
|
{
|
||||||
URL defaultConfigUrl = getDefaultResource();
|
return new GuavaCacheConfigurationReader().doRead();
|
||||||
|
|
||||||
if (defaultConfigUrl == null)
|
|
||||||
{
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"could not find default cache configuration");
|
|
||||||
}
|
|
||||||
|
|
||||||
GuavaCacheManagerConfiguration config = readConfiguration(defaultConfigUrl,
|
|
||||||
true);
|
|
||||||
|
|
||||||
Iterator<URL> it = getModuleResources();
|
|
||||||
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
GuavaCacheManagerConfiguration moduleConfig =
|
|
||||||
readConfiguration(it.next(), false);
|
|
||||||
|
|
||||||
if (moduleConfig != null)
|
|
||||||
{
|
|
||||||
config = merge(config, moduleConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File manualFile = getManualFileResource();
|
|
||||||
|
|
||||||
if (manualFile.exists())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
GuavaCacheManagerConfiguration manualConfig =
|
|
||||||
readConfiguration(manualFile.toURI().toURL(), false);
|
|
||||||
|
|
||||||
config = merge(config, manualConfig);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException ex)
|
|
||||||
{
|
|
||||||
logger.error("malformed url", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("could not find manual configuration at {}", manualFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -222,6 +177,62 @@ public class GuavaCacheConfigurationReader
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GuavaCacheManagerConfiguration doRead()
|
||||||
|
{
|
||||||
|
URL defaultConfigUrl = getDefaultResource();
|
||||||
|
|
||||||
|
if (defaultConfigUrl == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"could not find default cache configuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
GuavaCacheManagerConfiguration config = readConfiguration(defaultConfigUrl,
|
||||||
|
true);
|
||||||
|
|
||||||
|
Iterator<URL> it = getModuleResources();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
GuavaCacheManagerConfiguration moduleConfig =
|
||||||
|
readConfiguration(it.next(), false);
|
||||||
|
|
||||||
|
if (moduleConfig != null)
|
||||||
|
{
|
||||||
|
config = merge(config, moduleConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File manualFile = getManualFileResource();
|
||||||
|
|
||||||
|
if (manualFile.exists())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GuavaCacheManagerConfiguration manualConfig =
|
||||||
|
readConfiguration(manualFile.toURI().toURL(), false);
|
||||||
|
|
||||||
|
config = merge(config, manualConfig);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException ex)
|
||||||
|
{
|
||||||
|
logger.error("malformed url", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.warn("could not find manual configuration at {}", manualFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ package sonia.scm.cache;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
@@ -67,9 +68,18 @@ public class GuavaCacheManager implements CacheManager
|
|||||||
*/
|
*/
|
||||||
public GuavaCacheManager()
|
public GuavaCacheManager()
|
||||||
{
|
{
|
||||||
GuavaCacheConfigurationReader reader = new GuavaCacheConfigurationReader();
|
this(GuavaCacheConfigurationReader.read());
|
||||||
GuavaCacheManagerConfiguration config = reader.read();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
protected GuavaCacheManager(GuavaCacheManagerConfiguration config)
|
||||||
|
{
|
||||||
defaultConfiguration = config.getDefaultCache();
|
defaultConfiguration = config.getDefaultCache();
|
||||||
|
|
||||||
for (GuavaNamedCacheConfiguration ncc : config.getCaches())
|
for (GuavaNamedCacheConfiguration ncc : config.getCaches())
|
||||||
|
|||||||
Reference in New Issue
Block a user