Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2014-2014 The Kuali Foundation Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php 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.kuali.common.core.system;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.collect.Sets.newHashSet;
 import static com.google.common.collect.Sets.newTreeSet;
 import static org.kuali.common.core.json.jackson.JacksonContext.newDefaultObjectMapper;
 import static org.kuali.common.util.PropertyUtils.newHashMap;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 
 public class VirtualSystemHelper {
 
 	private static final JsonNodeFactory FACTORY = new JsonNodeFactory(false);
 	private static final String PROPERTIES = "properties";
 	private static final String ENVIRONMENT = "environment";
 	private static final String SEPARATOR = ".";

System property keys that are required to be present on every JVM
 
Mappings between required system property keys and the strongly typed field they correspond to in the VirtualSystem object
 
Produce an immutable VirtualSystem representing the current state of the system we are running on.
 
 	public static VirtualSystem createVirtualSystem() {
 		// Get a handle to our customized json service
 
 		// Create a json node representing the current state of the system we are running on
 
 		// This json represents java.class.path, java.library.path, and java.ext.dirs as delimited strings
 		String json = service.writeString(jsonNode);
 
 		// This service contains a custom deserializer mixin that parses delimited strings into List<File>
 		return service.readString(jsonVirtualSystem.class);
 	}
 
 	protected static JsonNode newVirtualSystemJsonNode() {
 		Properties system = System.getProperties();
 		Properties mapped = VirtualSystemPropertiesFunction.build().apply(system);
 		Node<Stringnode = new NestedKeysFunction().apply(paths);
 		JsonNodeContext context = JsonNodeContext.of(mappednode);
 		ObjectNode objectNode = ..apply(context);
 		objectNode.put(getObjectNode(newHashMap(system)));
 		objectNode.put(getObjectNode(System.getenv()));
 		return objectNode;
 	}
 
 	protected static ObjectNode getObjectNode(Map<StringStringproperties) {
 		ObjectNode objectNode = new ObjectNode();
 		for (String key : newTreeSet(properties.keySet())) {
			objectNode.put(keynew TextNode(properties.get(key)));
		}
		return objectNode;
	}
	protected static JsonService newCustomJsonService() {
		JacksonContext context = JacksonContext.builder().withMapper(mapper).build();
		return new JacksonJsonService(context);
	}
	private static final class SystemPropertyPathDeserializer {
		private List<Fileclasspath;
	}
	private static final ImmutableBiMap<StringStringgetPropertyMappings() {
		BiMap<StringStringmappings = HashBiMap.create();
		mappings.put("path.separator""pathSeparator");
		mappings.put("file.separator""fileSeparator");
		mappings.put("line.separator""lineSeparator");
		mappings.put("java.class.path""java.classpath");
		mappings.put("java.class.version""java.classVersion");
		mappings.put("java.io.tmpdir""java.tmpDir");
		mappings.put("java.ext.dirs""java.extensionDirs");
		mappings.put("java.library.path""java.libraryPaths");
		mappings.put("java.version""java.runtime.version");
		mappings.put("java.vendor""java.runtime.vendor");
		mappings.put("java.vendor.url""java.runtime.vendorUrl");
		mappings.put("java.specification.version""java.runtime.specification.version");
		mappings.put("java.specification.vendor""java.runtime.specification.vendor");
		mappings.put("java.specification.name""java.runtime.specification.name");
		for (String key : mappings.keySet()) {
			checkArgument(required.contains(key), "unknown key [%s]"key);
		}
		return ImmutableBiMap.copyOf(mappings);
	}
	private static final ImmutableSet<StringgetRequiredPropertyKeys() {
		Set<Stringkeys = newHashSet();
		keys.add("java.version");
		keys.add("java.vendor");
		keys.add("java.vendor.url");
		keys.add("java.home");
		keys.add("java.vm.specification.version");
		keys.add("java.vm.specification.vendor");
		keys.add("java.vm.specification.name");
		keys.add("java.vm.version");
		keys.add("java.vm.vendor");
		keys.add("java.vm.name");
		keys.add("java.specification.version");
		keys.add("java.specification.vendor");
		keys.add("java.specification.name");
		keys.add("java.class.version");
		keys.add("java.class.path");
		keys.add("java.library.path");
		keys.add("java.io.tmpdir");
		// keys.add("java.compiler"); javadoc states this is required, but it sure isn't
		keys.add("java.ext.dirs");
		keys.add("os.name");
		keys.add("os.arch");
		keys.add("os.version");
		keys.add("file.separator");
		keys.add("path.separator");
		keys.add("line.separator");
		keys.add("user.name");
		keys.add("user.home");
		keys.add("user.dir");
		return ImmutableSet.copyOf(keys);
	}
New to GrepCode? Check out our FAQ X