oh-my-posh/src/segment_java.go

59 lines
1.2 KiB
Go
Raw Normal View History

2021-03-17 00:16:19 -07:00
package main
import "fmt"
type java struct {
2021-12-03 11:19:57 -08:00
language
2021-03-17 00:16:19 -07:00
}
func (j *java) string() string {
segmentTemplate := j.language.props.getString(SegmentTemplate, "{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}")
return j.language.string(segmentTemplate, j)
2021-03-17 00:16:19 -07:00
}
2022-01-01 11:09:52 -08:00
func (j *java) init(props Properties, env Environment) {
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
2021-03-17 00:16:19 -07:00
javaCmd := &cmd{
executable: "java",
args: []string{"-Xinternalversion"},
regex: javaRegex,
}
2021-12-03 11:19:57 -08:00
j.language = language{
2021-03-17 00:16:19 -07:00
env: env,
props: props,
extensions: []string{
"pom.xml",
"build.gradle.kts",
"build.sbt",
".java-version",
".deps.edn",
"project.clj",
"build.boot",
"*.java",
"*.class",
"*.gradle",
"*.jar",
"*.clj",
"*.cljc",
},
}
javaHome := j.language.env.getenv("JAVA_HOME")
if len(javaHome) > 0 {
java := fmt.Sprintf("%s/bin/java", javaHome)
j.language.commands = []*cmd{
{
executable: java,
args: []string{"-Xinternalversion"},
regex: javaRegex,
},
javaCmd,
}
return
}
j.language.commands = []*cmd{javaCmd}
}
func (j *java) enabled() bool {
return j.language.enabled()
}