Skip to content

Commit

Permalink
Incorporate review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed Aug 6, 2024
1 parent 112d12e commit f40ca17
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ class BallerinaPlugin implements Plugin<Project> {
}

project.tasks.register('initializeVariables') {
if (ballerinaExtension.isConnector) {
def balVersion = getProjectBalVersion(project)
println("[Info] project builds using Ballerina distribution: $balVersion")
}

String packageName = ballerinaExtension.module
String organization
if (ballerinaExtension.packageOrganization == null) {
Expand Down Expand Up @@ -264,27 +259,28 @@ class BallerinaPlugin implements Plugin<Project> {
}

def versionOutput = output.toString()
def pattern = ~"Ballerina (\\d+\\.\\d+\\.\\d+) \\(Swan Lake Update \\d+\\)"
def matcher = pattern.matcher(versionOutput)
if (!matcher.find()) {
throw new GradleException("Failed to parse the Ballerina version")
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 installedVersion = matcher.group(1)
def configuredVersion = getProjectBalVersion(project)

def configuredVersion = project.findProperty('ballerinaLangVersion')
if (installedVersion != configuredVersion) {
if (ignoreVersionMismatch) {
println("[Warn] Ignoring Ballerina version mismatch. Expected: $configuredVersion, but found: $installedVersion.")
println("[Warning] Ignoring Ballerina version mismatch. Expected: $configuredVersion, but found: $installedVersion.")
return
}
throw new GradleException("Ballerina version mismatch. Expected: $configuredVersion, but found: $installedVersion, hence exiting")
}

}

project.tasks.register('build') {
dependsOn(project.initializeVariables)
dependsOn(project.verifyLocalBalVersion)
dependsOn(project.updateTomlFiles)
finalizedBy(project.commitTomlFiles)
Expand Down Expand Up @@ -404,7 +400,6 @@ class BallerinaPlugin implements Plugin<Project> {
}

project.tasks.register('test') {
dependsOn(project.initializeVariables)
dependsOn(project.verifyLocalBalVersion)
dependsOn(project.updateTomlFiles)
finalizedBy(project.commitTomlFiles)
Expand Down Expand Up @@ -435,9 +430,4 @@ class BallerinaPlugin implements Plugin<Project> {
delete "$project.rootDir/target"
}
}

static String getProjectBalVersion(Project project) {
def projectBalVersion = project.findProperty('ballerinaLangVersion')
return projectBalVersion
}
}

0 comments on commit f40ca17

Please sign in to comment.