/*
* Copyright 2003-2009 OFFIS, Henri Tremblay
*
* 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.easymock.internal;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
/**
* Contains properties used by EasyMock to change its default behavior. The
* loading order is (any step being able to overload the properties of the
* previous step):
*
*
easymock.properties in classpath default package
*
System properties
*
explicit call to setProperty
*
*/
public final class EasyMockProperties {
private static final String PREFIX = "easymock.";
// volatile for double-checked locking
private static volatile EasyMockProperties instance;
private final Properties properties = new Properties();
public static EasyMockProperties getInstance() {
if (instance == null) {
synchronized (EasyMockProperties.class) {
// ///CLOVER:OFF
if (instance == null) {
// ///CLOVER:ON
instance = new EasyMockProperties();
}
}
}
return instance;
}
private EasyMockProperties() {
// Load the easymock.properties file
InputStream in = getClassLoader().getResourceAsStream(
"easymock.properties");
if (in != null) {
in = new BufferedInputStream(in);
try {
properties.load(in);
} catch (IOException e) {
throw new RuntimeException(
"Failed to read easymock.properties file");
} finally {
try {
in.close();
} catch (IOException e) {
// Doesn't matter
}
}
}
// Then overload it with system properties
for (Map.Entry