Skip to content

Commit

Permalink
Add functionality to generate new build file
Browse files Browse the repository at this point in the history
Extended the PackageSearchGradleModule to generate a new build file if it does not exist when adding a dependency. The build file is created with appropriate syntax based on whether its format is Kotlin or not. This enhancement caters for both scenarios enhancing our application's flexibility.

(cherry picked from commit 5492ba3)
  • Loading branch information
lamba92 committed May 23, 2024
1 parent 9437822 commit 16fc7f9
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import com.jetbrains.packagesearch.plugin.core.utils.validateRepositoryType
import com.jetbrains.packagesearch.plugin.gradle.utils.toUnifiedRepository
import com.jetbrains.packagesearch.plugin.gradle.utils.validateRepositoryType
import java.nio.file.Path
import kotlin.io.path.createParentDirectories
import kotlin.io.path.exists
import kotlin.io.path.extension
import kotlin.io.path.writeText
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.jetbrains.packagesearch.api.v3.ApiPackage
Expand Down Expand Up @@ -86,6 +90,22 @@ data class PackageSearchGradleModule(
selectedScope: String?,
) {
validateMavenPackageType(apiPackage)

if (buildFilePath == null || !buildFilePath.exists()) {
val isKotlin = buildFilePath?.extension?.equals("kts", ignoreCase = true) == true
buildFilePath?.createParentDirectories()
?.writeText(buildString {
appendLine("dependencies {")
if (isKotlin) {
appendLine(" $selectedScope(\"${apiPackage.groupId}:${apiPackage.artifactId}:${selectedVersion}\")")
} else {
appendLine(" $selectedScope '${apiPackage.groupId}:${apiPackage.artifactId}:${selectedVersion}'")
}
appendLine("}")
})
return
}

modifier.addDependency(
module = nativeModule,
descriptor = UnifiedDependency(
Expand Down

0 comments on commit 16fc7f9

Please sign in to comment.