Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubramanianaks committed Jun 9, 2023
1 parent 597106e commit 843328e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,15 @@ func (cc *createCmd) detectDefaults(detectedLang *config.DraftConfig, lowerLang
defer f.Close()
detectedDefaults := make([]config.BuilderVarDefault, 0)
scanner := bufio.NewScanner(f)
// this separator is used to split the line from build.gradle ex: sourceCompatibility = '1.8'
// output will be ['sourceCompatibility', '1.8'] or ["sourceCompatibility", "1.8"]
separator := func(c rune) bool { return c == ' ' || c == '=' }
// this func takes care of removing the single or double quotes from split array output
cutset := func(c rune) bool { return c == '\'' || c == '"' }
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "sourceCompatibility") {
detectedVersion := strings.FieldsFunc(line, separator)[1] // sourceCompatibility = '1.8'
detectedVersion := strings.FieldsFunc(line, separator)[1] // example array after split ["sourceCompatibility", "1.8"]
detectedVersion = strings.TrimFunc(detectedVersion, cutset)
detectedVersion = detectedVersion + "-jre"
builderVarDefault := config.BuilderVarDefault{
Expand All @@ -461,7 +464,7 @@ func (cc *createCmd) detectDefaults(detectedLang *config.DraftConfig, lowerLang
}

if strings.Contains(line, "targetCompatibility") {
detectedBuilderVersion := strings.FieldsFunc(line, separator)[1] // targetCompatibility = '1.8'
detectedBuilderVersion := strings.FieldsFunc(line, separator)[1] // example array after split ["targetCompatibility", "1.8"]
detectedBuilderVersion = strings.TrimFunc(detectedBuilderVersion, cutset)
detectedBuilderVersion = "jdk" + detectedBuilderVersion
detectedBuilderVar := config.BuilderVarDefault{
Expand Down

0 comments on commit 843328e

Please sign in to comment.