001/* 002 * Copyright (C) 2012 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.base; 016 017import com.google.common.annotations.GwtIncompatible; 018import javax.annotation.CheckForNull; 019 020/** 021 * Represents a {@linkplain System#getProperties() standard system property}. 022 * 023 * @author Kurt Alfred Kluever 024 * @since 15.0 025 */ 026@GwtIncompatible // java.lang.System#getProperty 027@ElementTypesAreNonnullByDefault 028public enum StandardSystemProperty { 029 030 /** Java Runtime Environment version. */ 031 JAVA_VERSION("java.version"), 032 033 /** Java Runtime Environment vendor. */ 034 JAVA_VENDOR("java.vendor"), 035 036 /** Java vendor URL. */ 037 JAVA_VENDOR_URL("java.vendor.url"), 038 039 /** Java installation directory. */ 040 JAVA_HOME("java.home"), 041 042 /** Java Virtual Machine specification version. */ 043 JAVA_VM_SPECIFICATION_VERSION("java.vm.specification.version"), 044 045 /** Java Virtual Machine specification vendor. */ 046 JAVA_VM_SPECIFICATION_VENDOR("java.vm.specification.vendor"), 047 048 /** Java Virtual Machine specification name. */ 049 JAVA_VM_SPECIFICATION_NAME("java.vm.specification.name"), 050 051 /** Java Virtual Machine implementation version. */ 052 JAVA_VM_VERSION("java.vm.version"), 053 054 /** Java Virtual Machine implementation vendor. */ 055 JAVA_VM_VENDOR("java.vm.vendor"), 056 057 /** Java Virtual Machine implementation name. */ 058 JAVA_VM_NAME("java.vm.name"), 059 060 /** Java Runtime Environment specification version. */ 061 JAVA_SPECIFICATION_VERSION("java.specification.version"), 062 063 /** Java Runtime Environment specification vendor. */ 064 JAVA_SPECIFICATION_VENDOR("java.specification.vendor"), 065 066 /** Java Runtime Environment specification name. */ 067 JAVA_SPECIFICATION_NAME("java.specification.name"), 068 069 /** Java class format version number. */ 070 JAVA_CLASS_VERSION("java.class.version"), 071 072 /** Java class path. */ 073 JAVA_CLASS_PATH("java.class.path"), 074 075 /** List of paths to search when loading libraries. */ 076 JAVA_LIBRARY_PATH("java.library.path"), 077 078 /** Default temp file path. */ 079 JAVA_IO_TMPDIR("java.io.tmpdir"), 080 081 /** Name of JIT compiler to use. */ 082 JAVA_COMPILER("java.compiler"), 083 084 /** 085 * Path of extension directory or directories. 086 * 087 * @deprecated This property was <a 088 * href="https://openjdk.java.net/jeps/220#Removed:-The-extension-mechanism">deprecated</a> in 089 * Java 8 and removed in Java 9. We do not plan to remove this API from Guava, but if you are 090 * using it, it is probably not doing what you want. 091 */ 092 @Deprecated 093 JAVA_EXT_DIRS("java.ext.dirs"), 094 095 /** Operating system name. */ 096 OS_NAME("os.name"), 097 098 /** Operating system architecture. */ 099 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}