Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable default System Properties if they are not already set.
- Loading branch information
Andrew Woods
committed
Oct 21, 2013
1 parent
9bb96b9
commit f80dfc1
Showing
5 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
fcrepo-kernel/src/main/java/org/fcrepo/kernel/spring/DefaultPropertiesLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.kernel.spring; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
/** | ||
* This class loads System Properties only if: | ||
* - the context is not an integration-test, and | ||
* - the property is not already set | ||
* | ||
* @author Andrew Woods | ||
* Date: 10/15/13 | ||
*/ | ||
public class DefaultPropertiesLoader { | ||
|
||
private static final Logger LOGGER = getLogger(DefaultPropertiesLoader.class); | ||
|
||
final private static String SEP = getProperty("file.separator"); | ||
final private static String BASEDIR = getProperty("java.io.tmpdir") + SEP | ||
+ "fcrepo4-data" + SEP; | ||
|
||
private enum PROPERTIES { | ||
DEFAULT_OBJECT_STORE( | ||
"com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean.default.objectStoreDir"), | ||
OBJECT_STORE("com.arjuna.ats.arjuna.objectstore.objectStoreDir"), | ||
ISPN_CACHE("fcrepo.ispn.CacheDirPath"), | ||
ISPN_BIN_CACHE("fcrepo.ispn.binary.CacheDirPath"), | ||
MODE_INDEX("fcrepo.modeshape.index.location"), | ||
ISPN_ALT_CACHE("fcrepo.ispn.alternative.CacheDirPath"), | ||
ISPN_BIN_ALT_CACHE("fcrepo.ispn.binary.alternative.CacheDirPath"), | ||
ISPN_REPO_CACHE("fcrepo.ispn.repo.CacheDirPath"), | ||
ACTIVE_MQ("fcrepo.activemq.dir"); | ||
|
||
private String text; | ||
|
||
private PROPERTIES(String text) { | ||
this.text = text; | ||
} | ||
|
||
public String getValue() { | ||
return text; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This method loads default System Properties if: | ||
* - the context is not an integration-test, and | ||
* - the property is not already set | ||
*/ | ||
public void loadSystemProperties() { | ||
LOGGER.info("Loading properties"); | ||
|
||
if (getProperty("integration-test") == null) { | ||
LOGGER.debug("Setting default properties, if necessary."); | ||
|
||
for (PROPERTIES prop : PROPERTIES.values()) { | ||
if (getProperty(prop.getValue()) == null) { | ||
setProperty(prop.getValue()); | ||
} | ||
} | ||
} | ||
|
||
for (PROPERTIES prop : PROPERTIES.values()) { | ||
String val = prop.getValue(); | ||
LOGGER.debug("{} = {}", val, getProperty(val)); | ||
} | ||
} | ||
|
||
private static String getProperty(String property) { | ||
return System.getProperty(property); | ||
} | ||
|
||
private void setProperty(String prop) { | ||
System.setProperty(prop, BASEDIR + prop); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
fcrepo-kernel/src/test/java/org/fcrepo/kernel/spring/DefaultPropertiesLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.kernel.spring; | ||
|
||
import org.junit.Assert; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Andrew Woods | ||
* Date: 10/20/13 | ||
*/ | ||
public class DefaultPropertiesLoaderTest { | ||
|
||
private DefaultPropertiesLoader loader; | ||
|
||
private static final String PROP_FLAG = "integration-test"; | ||
private static final String PROP_TEST = "fcrepo.ispn.repo.CacheDirPath"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
loader = new DefaultPropertiesLoader(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
System.clearProperty(PROP_FLAG); | ||
System.clearProperty(PROP_TEST); | ||
} | ||
|
||
@Test | ||
public void testLoadSystemProperties() throws Exception { | ||
System.setProperty(PROP_FLAG, "true"); | ||
|
||
loader.loadSystemProperties(); | ||
Assert.assertNotNull(System.getProperty(PROP_FLAG)); | ||
Assert.assertNull(System.getProperty(PROP_TEST)); | ||
} | ||
|
||
@Test | ||
public void testLoadSystemPropertiesProduction() throws Exception { | ||
loader.loadSystemProperties(); | ||
Assert.assertNull(System.getProperty(PROP_FLAG)); | ||
Assert.assertNotNull(System.getProperty(PROP_TEST)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters