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 org.checkerframework.checker.nullness.compatqual.NullableDecl; 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 027public enum StandardSystemProperty { 028 029 /** Java Runtime Environment version. */ 030 JAVA_VERSION("java.version"), 031 032 /** Java Runtime Environment vendor. */ 033 JAVA_VENDOR("java.vendor"), 034 035 /** Java vendor URL. */ 036 JAVA_VENDOR_URL("java.vendor.url"), 037 038 /** Java installation directory. */ 039 JAVA_HOME("java.home"), 040 041 /** Java Virtual Machine specification version. */ 042 JAVA_VM_SPECIFICATION_VERSION("java.vm.specification.version"), 043 044 /** Java Virtual Machine specification vendor. */ 045 JAVA_VM_SPECIFICATION_VENDOR("java.vm.specification.vendor"), 046 047 /** Java Virtual Machine specification name. */ 048 JAVA_VM_SPECIFICATION_NAME("java.vm.specification.name"), 049 050 /** Java Virtual Machine implementation version. */ 051 JAVA_VM_VERSION("java.vm.version"), 052 053 /** Java Virtual Machine implementation vendor. */ 054 JAVA_VM_VENDOR("java.vm.vendor"), 055 056 /** Java Virtual Machine implementation name. */ 057 JAVA_VM_NAME("java.vm.name"), 058 059 /** Java Runtime Environment specification version. */ 060 JAVA_SPECIFICATION_VERSION("java.specification.version"), 061 062 /** Java Runtime Environment specification vendor. */ 063 JAVA_SPECIFICATION_VENDOR("java.specification.vendor"), 064 065 /** Java Runtime Environment specification name. */ 066 JAVA_SPECIFICATION_NAME("java.specification.name"), 067 068 /** Java class format version number. */ 069 JAVA_CLASS_VERSION("java.class.version"), 070 071 /** Java class path. */ 072 JAVA_CLASS_PATH("java.class.path"), 073 074 /** List of paths to search when loading libraries. */ 075 JAVA_LIBRARY_PATH("java.library.path"), 076 077 /** Default temp file path. */ 078 JAVA_IO_TMPDIR("java.io.tmpdir"), 079 080 /** Name of JIT compiler to use. */ 081 JAVA_COMPILER("java.compiler"), 082 083 /** 084 * Path of extension directory or directories. 085 * 086 * @deprecated This property was <a 087 * href="https://openjdk.java.net/jeps/220#Removed:-The-extension-mechanism">deprecated</a> in 088 * Java 8 and removed in Java 9. We do not plan to remove this API from Guava, but if you are 089 * using it, it is probably not doing what you want. 090 */ 091 @Deprecated 092 JAVA_EXT_DIRS("java.ext.dirs"), 093 094 /** Operating system name. */ 095 OS_NAME("os.name"), 096 097 /** Operating system architecture. */ 098 OS_ARCH("os.arch"), 099 100 /** Operating system version. */ 101 OS_VERSION("os.version"), 102 103 /** File separator ("/" on UNIX). */ 104 FILE_SEPARATOR("file.separator"), 105 106 /** Path separator (":" on UNIX). */ 107 PATH_SEPARATOR("path.separator"), 108 109 /** Line separator ("\n" on UNIX). */ 110 LINE_SEPARATOR("line.separator"), 111 112 /** User's account name. */ 113 USER_NAME("user.name"), 114 115 /** User's home directory. */ 116 USER_HOME("user.home"), 117 118 /** User's current working directory. */ 119 USER_DIR("user.dir"); 120 121 private final String key; 122 123 StandardSystemProperty(String key) { 124 this.key = key; 125 } 126 127 /** Returns the key used to lookup this system property. */ 128 public String key() { 129 return key; 130 } 131 132 /** 133 * Returns the current value for this system property by delegating to {@link 134 * System#getProperty(String)}. 135 * 136 * <p>The value returned by this method is non-null except in rare circumstances: 137 * 138 * <ul> 139 * <li>{@link #JAVA_EXT_DIRS} was deprecated in Java 8 and removed in Java 9. We have not 140 * confirmed whether it is available under older versions. 141 * <li>{@link #JAVA_COMPILER}, while still listed as required as of Java 15, is typically not 142 * available even under older version. 143 * <li>Any property may be cleared through APIs like {@link System#clearProperty}. 144 * <li>Unusual environments like GWT may have their own special handling of system properties. 145 * </ul> 146 * 147 * <p>Note that {@code StandardSystemProperty} does not provide constants for more recently added 148 * properties, including: 149 * 150 * <ul> 151 * <li>{@code java.vendor.version} (added in Java 11, listed as optional as of Java 13) 152 * <li>{@code jdk.module.*} (added in Java 9, optional) 153 * </ul> 154 */ 155 @NullableDecl 156 public String value() { 157 return System.getProperty(key); 158 } 159 160 /** Returns a string representation of this system property. */ 161 @Override 162 public String toString() { 163 return key() + "=" + value(); 164 } 165}