Package: KernelConfiguration

KernelConfiguration

nameinstructionbranchcomplexitylinemethod
KernelConfiguration(BundleContext)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
getConfigDirectories()
M: 6 C: 5
45%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDomain()
M: 6 C: 3
33%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getHomeDirectory()
M: 6 C: 3
33%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getStartupWaitLimit()
M: 6 C: 3
33%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getWorkDirectory()
M: 6 C: 3
33%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasText(String)
M: 6 C: 10
63%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 1
100%
M: 0 C: 1
100%
parseKernelConfigProperty(String, List)
M: 6 C: 40
87%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 7
100%
M: 0 C: 1
100%
readBundleStartupWaitLimit(BundleContext)
M: 28 C: 12
30%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 4 C: 4
50%
M: 0 C: 1
100%
readConfigDirectories(BundleContext)
M: 6 C: 31
84%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
readDomain(BundleContext)
M: 6 C: 11
65%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
readFrameworkProperty(String, BundleContext)
M: 6 C: 4
40%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
readHomeDirectory(BundleContext)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.nano.config.internal;
13:
14: import java.io.File;
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: import org.osgi.framework.BundleContext;
19: import org.slf4j.Logger;
20: import org.slf4j.LoggerFactory;
21:
22: public final class KernelConfiguration {
23:
24: private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
25:
26: static final String PROPERTY_KERNEL_CONFIG = "org.eclipse.virgo.kernel.config";
27:
28: static final String PROPERTY_KERNEL_HOME = "org.eclipse.virgo.kernel.home";
29:
30: static final String PROPERTY_KERNEL_DOMAIN = "org.eclipse.virgo.kernel.domain";
31:
32: static final String PROPERTY_KERNEL_STARTUP_WAIT_LIMIT = "org.eclipse.virgo.kernel.startup.wait.limit";
33:
34: private static final String DEFAULT_WORK_DIRECTORY_NAME = "work";
35:
36: private static final String DEFAULT_CONFIG_DIRECTORY_NAME = "config";
37:
38: private static final String DEFAULT_KERNEL_DOMAIN = "org.eclipse.virgo.kernel";
39:
40: private static final int DEFAULT_STARTUP_WAIT_LIMIT = 180; // 3 minutes
41:
42: private final File homeDirectory;
43:
44: private final File[] configDirectories;
45:
46: private final File workDirectory;
47:
48: private final String domain;
49:
50: private final int startupWaitLimit;
51:
52: public KernelConfiguration(BundleContext context) {
53: this.homeDirectory = readHomeDirectory(context);
54: this.configDirectories = readConfigDirectories(context);
55: this.workDirectory = new File(this.homeDirectory, DEFAULT_WORK_DIRECTORY_NAME);
56: this.domain = readDomain(context);
57: this.startupWaitLimit = readBundleStartupWaitLimit(context);
58: }
59:
60: public File getHomeDirectory() {
61: return homeDirectory;
62: }
63:
64: public File[] getConfigDirectories() {
65: return configDirectories.clone();
66: }
67:
68: public File getWorkDirectory() {
69: return workDirectory;
70: }
71:
72: public String getDomain() {
73: return domain;
74: }
75:
76: public int getStartupWaitLimit() {
77: return startupWaitLimit;
78: }
79:
80: private static File readHomeDirectory(BundleContext context) {
81: String kernelHomeProperty = readFrameworkProperty(PROPERTY_KERNEL_HOME, context);
82:• if (!hasText(kernelHomeProperty)) {
83: throw new IllegalStateException(PROPERTY_KERNEL_HOME + " property must be specified, and must not be empty");
84: } else {
85: return new File(kernelHomeProperty);
86: }
87: }
88:
89: private static File[] readConfigDirectories(BundleContext context) {
90: String kernelConfigProperty = readFrameworkProperty(PROPERTY_KERNEL_CONFIG, context);
91: List<File> configDirectories = new ArrayList<File>();
92:
93:• if (hasText(kernelConfigProperty)) {
94: parseKernelConfigProperty(kernelConfigProperty, configDirectories);
95: }
96:
97:• if (configDirectories.isEmpty()) {
98: configDirectories.add(new File(DEFAULT_CONFIG_DIRECTORY_NAME));
99: }
100:
101: return configDirectories.toArray(new File[configDirectories.size()]);
102: }
103:
104: private static void parseKernelConfigProperty(String kernelConfigProperty, List<File> configDirectories) {
105: String[] components = kernelConfigProperty.split(",");
106:• for (String component : components) {
107: File configDir = new File(component.trim());
108:• if (!configDir.isAbsolute()) {
109: configDir = new File(component.trim());
110: }
111: configDirectories.add(configDir);
112: }
113: }
114:
115: private static String readDomain(BundleContext context) {
116: String kernelDomainProperty = readFrameworkProperty(PROPERTY_KERNEL_DOMAIN, context);
117:• if (!hasText(kernelDomainProperty)) {
118: kernelDomainProperty = DEFAULT_KERNEL_DOMAIN;
119: }
120: return kernelDomainProperty;
121: }
122:
123: private int readBundleStartupWaitLimit(BundleContext context) {
124: String waitLimitProperty = readFrameworkProperty(PROPERTY_KERNEL_STARTUP_WAIT_LIMIT, context);
125:• if (!hasText(waitLimitProperty)) {
126: return DEFAULT_STARTUP_WAIT_LIMIT;
127: }
128:
129: try {
130: return Integer.parseInt(waitLimitProperty);
131: } catch (NumberFormatException e) {
132: LOGGER.warn("Could not parse property {} with value '{}'. Using default limit {} seconds",
133: new Object[]{PROPERTY_KERNEL_STARTUP_WAIT_LIMIT, waitLimitProperty, DEFAULT_STARTUP_WAIT_LIMIT});
134: return DEFAULT_STARTUP_WAIT_LIMIT;
135: }
136: }
137:
138: private static String readFrameworkProperty(String propertyKey, BundleContext context) {
139: return context.getProperty(propertyKey);
140: }
141:
142: private static boolean hasText(String string) {
143:• return (string != null && !string.trim().isEmpty());
144: }
145: }