Skip to content

Commit

Permalink
Restructure bal-version parsing error handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed Aug 6, 2024
1 parent 4ae17cc commit a45b7c3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ class BallerinaPlugin implements Plugin<Project> {
}

def versionOutput = output.toString()
def installedVersion = ""
try {
def balVersion = versionOutput.split("\n")[0]
installedVersion = balVersion
.replaceAll("Ballerina ", '')
.replaceAll("\\(Swan Lake Update \\d+\\)", '')
.replaceAll("\\s+", '')
} catch (Exception e) {
throw new GradleException("Failed to parse the Ballerina version: $versionOutput", e)
def balVersion = versionOutput.split("\n")[0]
def installedVersion = balVersion
.replaceAll("Ballerina ", '')
.replaceAll("\\(Swan Lake Update \\d+\\)", '')
.replaceAll("\\s+", '')

def balVersionPattern = ~/^\d{4}\.\d+\.\d+$/
if (!balVersionPattern.matcher(installedVersion).matches()) {
throw new GradleException("Failed to parse the Ballerina version. Balllerina CLI output: $versionOutput Extracted version:$installedVersion")
}

def configuredVersion = project.findProperty('ballerinaLangVersion')
Expand Down

0 comments on commit a45b7c3

Please sign in to comment.