-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0c1770
commit 172c354
Showing
4 changed files
with
251 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
object JavaOptions { | ||
class JavaOption( | ||
val option: String, | ||
val args: List[String], | ||
val isSupported: Int => Boolean | ||
) { | ||
override def hashCode(): Int = | ||
41 * option.hashCode | ||
|
||
override def equals(other: Any): Boolean = | ||
other match { | ||
case that: JavaOption => | ||
this.option == that.option && | ||
this.args.size == that.args.size && | ||
this.args.sorted.zip(that.args.sorted).forall { case (s1, s2) => s1 == s2 } | ||
case _ => false | ||
} | ||
|
||
override def toString = | ||
(option :: args).mkString("JavaOption(", " ", ")") | ||
} | ||
|
||
def property( | ||
key: String, | ||
value: String, | ||
isSupported: Int => Boolean = _ => true | ||
): JavaOption = | ||
new JavaOption(s"-D$key=$value", List.empty, isSupported) | ||
def extra( | ||
name: String, | ||
arguments: List[String] = List.empty, | ||
isSupported: Int => Boolean = _ => true | ||
): JavaOption = new JavaOption(s"-X$name", arguments, isSupported) | ||
|
||
def minHeapSize(size: String): JavaOption = | ||
extra("ms", List(size)) | ||
|
||
def maxHeapSize(size: String): JavaOption = | ||
extra("mx", List(size)) | ||
|
||
def advanced( | ||
name: String, | ||
arguments: List[String] = List.empty, | ||
isSupported: Int => Boolean = _ => true | ||
): JavaOption = new JavaOption(s"-XX:$name", arguments, isSupported) | ||
|
||
def addOpens(module: String, `package`: String, reflectingModule: String) = | ||
new JavaOption("--add-opens", List(s"$module/${`package`}=$reflectingModule"), _ >= 17) | ||
def optionsForVersion( | ||
javaVersion: Int, | ||
proposedJavacOptions: Set[JavaOption] | ||
): Set[JavaOption] = | ||
proposedJavacOptions.filter(_.isSupported(javaVersion)) | ||
|
||
def tokensForVersion( | ||
javaVersion: Int, | ||
proposedJavacOptions: Set[JavaOption] | ||
): Seq[String] = | ||
optionsForVersion(javaVersion, proposedJavacOptions).toList | ||
.flatMap(opt => opt.option :: opt.args) | ||
|
||
def defaults(javaVersion: Int): Seq[String] = | ||
tokensForVersion( | ||
javaVersion, | ||
Set( | ||
property("file.encoding", "UTF-8"), | ||
addOpens("java.base", "java.util", "ALL-UNNAMED"), | ||
addOpens("java.base", "java.lang.invoke", "ALL-UNNAMED"), | ||
addOpens("java.base", "java.lang", "ALL-UNNAMED") | ||
) | ||
) | ||
|
||
def testDefaults(javaVersion: Int): Seq[String] = | ||
tokensForVersion( | ||
javaVersion, | ||
Set( | ||
minHeapSize("512m"), | ||
maxHeapSize("2G"), | ||
advanced("UseParallelGC"), | ||
property("scio.ignoreVersionWarning", "true"), | ||
property("org.slf4j.simpleLogger.defaultLogLevel", "info"), | ||
property("org.slf4j.simpleLogger.logFile", "scio.log") | ||
) ++ Set( | ||
"bigquery.project", | ||
"bigquery.secret", | ||
"cloudsql.sqlserver.password" | ||
).flatMap(prop => sys.props.get(prop).map(value => property(prop, value))) | ||
) | ||
} |
Oops, something went wrong.