This repository was archived by the owner on Aug 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSysProp.scala
108 lines (87 loc) · 3.63 KB
/
SysProp.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright 2011-2011 Christos KK Loverdos
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
*
* 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 com.ckkloverdos.sys
import collection.immutable.SortedSet
import com.ckkloverdos.convert.Converters
/**
* Abstraction for jvm system properties.
*
* @author Christos KK Loverdos <loverdos@gmail.com>.
*/
final class SysProp(val name: String) extends SysVar[SysProp](System.getProperty(_)) {
@throws(classOf[NullPointerException])
def update(newValue: String) = {
// Will throw NPE if null
System.setProperty(name, newValue)
}
override def toString: String = "SysProp(%s, %s)".format(name, value)
override def equals(any: Any) = any match {
case other: SysProp => other.name == name
case _ => false
}
}
object SysProp {
lazy val JavaVersion = this("java.version")
lazy val JavaVendor = this("java.vendor")
lazy val JavaVendorURL = this("java.vendor.url")
lazy val JavaHome = this("java.home")
lazy val JavaVMSpecificationVersion = this("java.vm.specification.version")
lazy val JavaVMSpecificationVendor = this("java.vm.specification.vendor")
lazy val JavaVMSpecificationName = this("java.vm.specification.name")
lazy val JavaVMVersion = this("java.vm.version")
lazy val JavaVMVendor = this("java.vm.vendor")
lazy val JavaVMName = this("java.vm.name")
lazy val JavaSpecificationVersion = this("java.specification.version")
lazy val JavaSpecificationVendor = this("java.specification.vendor")
lazy val JavaSpecificationName = this("java.specification.name")
lazy val JavaClassVersion = this("java.class.version")
lazy val UserName = this("user.name")
lazy val UserHome = this("user.home")
lazy val UserDir = this("user.dir")
lazy val JavaClassPath = this("java.class.path")
lazy val JavaLibraryPath = this("java.library.path")
lazy val JavaIOTmpDir = this("java.io.tmpdir")
lazy val OsName = this("os.name")
lazy val OsVersion = this("os.version")
lazy val OsArch = this("os.arch")
lazy val LineSeparator = this("line.separator")
lazy val FileSeparator = this("file.separator")
lazy val PathSeparator = this("path.separator")
lazy val JavaCompiler = this("java.compiler")
lazy val JavaExtDirs = this("java.ext.dirs")
lazy val FileEncoding = this("file.encoding")
lazy val StandardsProps = SortedSet(
JavaVersion, JavaVendor, JavaVendorURL, JavaHome,
JavaVMSpecificationVersion, JavaVMSpecificationVendor, JavaVMSpecificationName,
JavaVMVersion, JavaVMVendor, JavaVMName,
JavaSpecificationVersion, JavaSpecificationVendor, JavaSpecificationName,
JavaClassVersion,
UserName, UserHome, UserDir,
JavaClassPath, JavaLibraryPath, JavaIOTmpDir,
OsName, OsVersion, OsArch,
LineSeparator, FileSeparator, PathSeparator,
JavaCompiler, JavaExtDirs,
FileEncoding
)
def apply(name: String): SysProp = new SysProp(name)
def isSysPropTrue(name: String)(implicit converters: Converters = Converters.DefaultConverters): Boolean = {
val maybeValue = for {
propValue <- SysProp(name)
booleanValue <- converters.convertToBoolean(propValue)
} yield booleanValue
maybeValue.getOr(false)
}
}