mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
merge global cache configuration attributes
This commit is contained in:
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ import javax.xml.transform.Transformer;
|
|||||||
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.TransformerFactory;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.w3c.dom.Attr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -291,7 +293,13 @@ public class EhCacheConfigurationReader
|
|||||||
Element rootEl = merged.createElementNS("http://ehcache.org/ehcache.xsd",
|
Element rootEl = merged.createElementNS("http://ehcache.org/ehcache.xsd",
|
||||||
"ehcache");
|
"ehcache");
|
||||||
|
|
||||||
for (Node node : map.values())
|
for (Attr attribute : attributeMap.values())
|
||||||
|
{
|
||||||
|
Attr mergedAttr = (Attr) merged.adoptNode(attribute);
|
||||||
|
rootEl.setAttributeNode(mergedAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Node node : nodeMap.values())
|
||||||
{
|
{
|
||||||
Node mergedNode = merged.adoptNode(node);
|
Node mergedNode = merged.adoptNode(node);
|
||||||
|
|
||||||
@@ -351,6 +359,23 @@ public class EhCacheConfigurationReader
|
|||||||
*/
|
*/
|
||||||
private void readConfiguration(Element rootEl)
|
private void readConfiguration(Element rootEl)
|
||||||
{
|
{
|
||||||
|
NamedNodeMap attributes = rootEl.getAttributes();
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); i++)
|
||||||
|
{
|
||||||
|
Node node = attributes.item(i);
|
||||||
|
|
||||||
|
if (Node.ATTRIBUTE_NODE == node.getNodeType())
|
||||||
|
{
|
||||||
|
String name = node.getNodeName();
|
||||||
|
|
||||||
|
if (!name.startsWith("xmlns") && (node instanceof Attr))
|
||||||
|
{
|
||||||
|
attributeMap.put(node.getNodeName(), (Attr) node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NodeList list = rootEl.getChildNodes();
|
NodeList list = rootEl.getChildNodes();
|
||||||
|
|
||||||
for (int i = 0; i < list.getLength(); i++)
|
for (int i = 0; i < list.getLength(); i++)
|
||||||
@@ -368,7 +393,7 @@ public class EhCacheConfigurationReader
|
|||||||
name = nameNode.getNodeValue();
|
name = nameNode.getNodeValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
map.put(new Id(element, name), node);
|
nodeMap.put(new Id(element, name), node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,5 +498,8 @@ public class EhCacheConfigurationReader
|
|||||||
private DocumentBuilder builder;
|
private DocumentBuilder builder;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Map<Id, Node> map = Maps.newLinkedHashMap();
|
private Map<Id, Node> nodeMap = Maps.newLinkedHashMap();
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Map<String, Attr> attributeMap = Maps.newLinkedHashMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,21 @@ public class EhConfigurationReaderTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGlobalAttributes()
|
||||||
|
{
|
||||||
|
EhConfigurationTestReader reader =
|
||||||
|
new EhConfigurationTestReader("cache.006.xml");
|
||||||
|
Configuration c = createConfiguration(reader);
|
||||||
|
|
||||||
|
assertFalse(c.getUpdateCheck());
|
||||||
|
assertEquals("512M", c.getMaxBytesLocalDiskAsString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -175,6 +190,21 @@ public class EhConfigurationReaderTest
|
|||||||
checkDefaultConfiguration(c, 170l, 18900l);
|
checkDefaultConfiguration(c, 170l, 18900l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOverrideGlobalAttributes()
|
||||||
|
{
|
||||||
|
EhConfigurationTestReader reader =
|
||||||
|
new EhConfigurationTestReader("cache.006.xml", null, "cache.007.xml");
|
||||||
|
Configuration c = createConfiguration(reader);
|
||||||
|
|
||||||
|
assertTrue(c.getUpdateCheck());
|
||||||
|
assertEquals("1G", c.getMaxBytesLocalDiskAsString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
38
scm-webapp/src/test/resources/sonia/scm/cache/cache.006.xml
vendored
Normal file
38
scm-webapp/src/test/resources/sonia/scm/cache/cache.006.xml
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--*
|
||||||
|
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
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<ehcache xmlns="http://ehcache.org/ehcache.xsd"
|
||||||
|
updateCheck="false"
|
||||||
|
maxBytesLocalDisk="512M">
|
||||||
|
|
||||||
|
</ehcache>
|
||||||
38
scm-webapp/src/test/resources/sonia/scm/cache/cache.007.xml
vendored
Normal file
38
scm-webapp/src/test/resources/sonia/scm/cache/cache.007.xml
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--*
|
||||||
|
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
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<ehcache xmlns="http://ehcache.org/ehcache.xsd"
|
||||||
|
updateCheck="true"
|
||||||
|
maxBytesLocalDisk="1G">
|
||||||
|
|
||||||
|
</ehcache>
|
||||||
Reference in New Issue
Block a user