oh-my-posh/src/segments/java.go

62 lines
1.2 KiB
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
2021-03-17 00:16:19 -07:00
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/properties"
)
2021-03-17 00:16:19 -07:00
2022-01-26 05:10:18 -08:00
type Java struct {
2021-12-03 11:19:57 -08:00
language
2021-03-17 00:16:19 -07:00
}
func (j *Java) Template() string {
return languageTemplate
2021-03-17 00:16:19 -07:00
}
func (j *Java) Init(props properties.Properties, env environment.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")
2021-03-17 00:16:19 -07:00
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()
2021-03-17 00:16:19 -07:00
}