Skip to content

Commit

Permalink
[bach] Let version be configurable. Fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Feb 17, 2021
1 parent 1e573dd commit 3385d86
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ defaults = true
build = "verify"
[jbang]
# sorce file discovery order
# source file discovery order
# default order is the following
discovery = [".java", ".jsh", ".jar"]
[bach]
# Bach version to use
version = "16.0.2"
----

== Installation
Expand Down
8 changes: 4 additions & 4 deletions gum/bach.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func FindBach(context Context, args *ParsedArgs) *BachCommand {
config.setQuiet(quiet)
}

executable, noExecutable := findBachExecutable(context, rootdir)
executable, noExecutable := findBachExecutable(context, config, rootdir)

if noExecutable != nil {
warnNoBach(context, config)
Expand Down Expand Up @@ -164,22 +164,22 @@ func warnNoBach(context Context, config *Config) {
}
}

func findBachExecutable(context Context, dir string) (string, error) {
func findBachExecutable(context Context, config *Config, dir string) (string, error) {
java, noJava := findExecutable(context, dir, "java")
jshell, noJshell := findExecutable(context, dir, "jshell")

if noJava != nil {
if noJshell != nil {
return "", errors.New("No java nor jshell found")
}
return jshell + " https://bit.ly/bach-main-build", nil
return jshell + " https://github.com/sormuras/bach/releases/download/" + config.bach.version + "/build.jsh", nil
}

cache := filepath.Join(dir, ".bach", "cache")
if context.FileExists(cache) {
return java + " -p " + cache + " -m com.github.sormuras.bach build", nil
} else if noJshell == nil {
return jshell + " https://bit.ly/bach-main-build", nil
return jshell + " https://github.com/sormuras/bach/releases/download/" + config.bach.version + "/build.jsh", nil
} else {
return "", errors.New("jshell not found")
}
Expand Down
33 changes: 32 additions & 1 deletion gum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
gradle gradle
maven maven
jbang jbang
bach bach
}

type theme struct {
Expand Down Expand Up @@ -78,6 +79,10 @@ type jbang struct {
discovery []string
}

type bach struct {
version string
}

func (c *Config) print() {
c.theme.t.PrintSection("theme")
c.theme.t.PrintKeyValueLiteral("name", c.theme.name)
Expand Down Expand Up @@ -108,6 +113,8 @@ func (c *Config) print() {
}
c.theme.t.PrintSection("jbang")
c.theme.t.PrintKeyValueArrayS("discovery", c.jbang.discovery)
c.theme.t.PrintSection("bach")
c.theme.t.PrintKeyValueLiteral("version", c.bach.version)
}

func newConfig() *Config {
Expand All @@ -133,7 +140,9 @@ func newConfig() *Config {
d: tribool.Maybe,
mappings: make(map[string]string)},
jbang: jbang{
discovery: make([]string, 0)}}
discovery: make([]string, 0)},
bach: bach{
version: ""}}
}

func (c *Config) setQuiet(b bool) {
Expand All @@ -158,11 +167,13 @@ func (c *Config) merge(other *Config) {
c.gradle.merge(nil)
c.maven.merge(nil)
c.jbang.merge(nil)
c.bach.merge(nil)
} else {
c.general.merge(&other.general)
c.gradle.merge(&other.gradle)
c.maven.merge(&other.maven)
c.jbang.merge(&other.jbang)
c.bach.merge(&other.bach)
}
}

Expand Down Expand Up @@ -262,6 +273,14 @@ func (j *jbang) merge(other *jbang) {
}
}

func (b *bach) merge(other *bach) {
if len(b.version) == 0 && other != nil && len(other.version) > 0 {
b.version = other.version
} else {
b.version = "16.0.2"
}
}

// ReadUserConfig reads user config
func ReadUserConfig(context Context) *Config {
homedir := context.GetHomeDir()
Expand Down Expand Up @@ -308,6 +327,7 @@ func ReadConfigFile(context Context, path string) *Config {
resolveSectionGradle(t, config)
resolveSectionMaven(t, config)
resolveSectionJbang(t, config)
resolveSectionBach(t, config)

return config
}
Expand Down Expand Up @@ -464,3 +484,14 @@ func resolveSectionJbang(t *toml.Tree, config *Config) {
}
}
}

func resolveSectionBach(t *toml.Tree, config *Config) {
tt := t.Get("bach")
if tt != nil {
table := tt.(*toml.Tree)
v := table.Get("version")
if v != nil {
config.bach.version = v.(string)
}
}
}

0 comments on commit 3385d86

Please sign in to comment.