Coverage Summary for Class: StandardSystemProperty (com.google.common.base)

Class Class, % Method, % Line, %
StandardSystemProperty 100% (1/1) 66.7% (4/6) 94.3% (33/35)


1 /* 2  * Copyright (C) 2012 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.base; 16  17 import com.google.common.annotations.GwtIncompatible; 18 import javax.annotation.CheckForNull; 19  20 /** 21  * Represents a {@linkplain System#getProperties() standard system property}. 22  * 23  * @author Kurt Alfred Kluever 24  * @since 15.0 25  */ 26 @GwtIncompatible // java.lang.System#getProperty 27 @ElementTypesAreNonnullByDefault 28 public enum StandardSystemProperty { 29  30  /** Java Runtime Environment version. */ 31  JAVA_VERSION("java.version"), 32  33  /** Java Runtime Environment vendor. */ 34  JAVA_VENDOR("java.vendor"), 35  36  /** Java vendor URL. */ 37  JAVA_VENDOR_URL("java.vendor.url"), 38  39  /** Java installation directory. */ 40  JAVA_HOME("java.home"), 41  42  /** Java Virtual Machine specification version. */ 43  JAVA_VM_SPECIFICATION_VERSION("java.vm.specification.version"), 44  45  /** Java Virtual Machine specification vendor. */ 46  JAVA_VM_SPECIFICATION_VENDOR("java.vm.specification.vendor"), 47  48  /** Java Virtual Machine specification name. */ 49  JAVA_VM_SPECIFICATION_NAME("java.vm.specification.name"), 50  51  /** Java Virtual Machine implementation version. */ 52  JAVA_VM_VERSION("java.vm.version"), 53  54  /** Java Virtual Machine implementation vendor. */ 55  JAVA_VM_VENDOR("java.vm.vendor"), 56  57  /** Java Virtual Machine implementation name. */ 58  JAVA_VM_NAME("java.vm.name"), 59  60  /** Java Runtime Environment specification version. */ 61  JAVA_SPECIFICATION_VERSION("java.specification.version"), 62  63  /** Java Runtime Environment specification vendor. */ 64  JAVA_SPECIFICATION_VENDOR("java.specification.vendor"), 65  66  /** Java Runtime Environment specification name. */ 67  JAVA_SPECIFICATION_NAME("java.specification.name"), 68  69  /** Java class format version number. */ 70  JAVA_CLASS_VERSION("java.class.version"), 71  72  /** Java class path. */ 73  JAVA_CLASS_PATH("java.class.path"), 74  75  /** List of paths to search when loading libraries. */ 76  JAVA_LIBRARY_PATH("java.library.path"), 77  78  /** Default temp file path. */ 79  JAVA_IO_TMPDIR("java.io.tmpdir"), 80  81  /** Name of JIT compiler to use. */ 82  JAVA_COMPILER("java.compiler"), 83  84  /** 85  * Path of extension directory or directories. 86  * 87  * @deprecated This property was <a 88  * href="https://openjdk.java.net/jeps/220#Removed:-The-extension-mechanism">deprecated</a> in 89  * Java 8 and removed in Java 9. We do not plan to remove this API from Guava, but if you are 90  * using it, it is probably not doing what you want. 91  */ 92  @Deprecated 93  JAVA_EXT_DIRS("java.ext.dirs"), 94  95  /** Operating system name. */ 96  OS_NAME("os.name"), 97  98  /** Operating system architecture. */ 99  OS_ARCH("os.arch"), 100  101  /** Operating system version. */ 102  OS_VERSION("os.version"), 103  104  /** File separator ("/" on UNIX). */ 105  FILE_SEPARATOR("file.separator"), 106  107  /** Path separator (":" on UNIX). */ 108  PATH_SEPARATOR("path.separator"), 109  110  /** Line separator ("\n" on UNIX). */ 111  LINE_SEPARATOR("line.separator"), 112  113  /** User's account name. */ 114  USER_NAME("user.name"), 115  116  /** User's home directory. */ 117  USER_HOME("user.home"), 118  119  /** User's current working directory. */ 120  USER_DIR("user.dir"); 121  122  private final String key; 123  124  StandardSystemProperty(String key) { 125  this.key = key; 126  } 127  128  /** Returns the key used to lookup this system property. */ 129  public String key() { 130  return key; 131  } 132  133  /** 134  * Returns the current value for this system property by delegating to {@link 135  * System#getProperty(String)}. 136  * 137  * <p>The value returned by this method is non-null except in rare circumstances: 138  * 139  * <ul> 140  * <li>{@link #JAVA_EXT_DIRS} was deprecated in Java 8 and removed in Java 9. We have not 141  * confirmed whether it is available under older versions. 142  * <li>{@link #JAVA_COMPILER}, while still listed as required as of Java 15, is typically not 143  * available even under older version. 144  * <li>Any property may be cleared through APIs like {@link System#clearProperty}. 145  * <li>Unusual environments like GWT may have their own special handling of system properties. 146  * </ul> 147  * 148  * <p>Note that {@code StandardSystemProperty} does not provide constants for more recently added 149  * properties, including: 150  * 151  * <ul> 152  * <li>{@code java.vendor.version} (added in Java 11, listed as optional as of Java 13) 153  * <li>{@code jdk.module.*} (added in Java 9, optional) 154  * </ul> 155  */ 156  @CheckForNull 157  public String value() { 158  return System.getProperty(key); 159  } 160  161  /** Returns a string representation of this system property. */ 162  @Override 163  public String toString() { 164  return key() + "=" + value(); 165  } 166 }