Package com.vaadin.copilot
Class GradleFileRewriter
java.lang.Object
com.vaadin.copilot.GradleFileRewriter
Rewriter for
build.gradle files that supports dependency, property
and repository updates while trying to preserve the original formatting.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordstatic final record -
Constructor Summary
ConstructorsConstructorDescriptionGradleFileRewriter(Path file) Creates a rewriter for the given Gradle build file. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddDependency(String groupId, String artifactId, String version) Adds dependency to build.gradle if needed.voidaddPluginRepository(String id, String url) Adds plugin repository to build.gradle if it does not exist.voidaddRepository(String id, String url) Adds repository to build.gradle if it does not exist.findDependency(String groupId, String artifactId) Finds the dependency with the given groupId and artifactId inside the dependencies block.findDependencyByGroupIdAndArtifactId(String groupId, String artifactId) Finds dependency under dependencies and dependencyManagement blocks by groupId and artifactId.findPropertyByKey(String propertyKey) Finds the property by key.Checks whether buildscript repositories block exists.Checks whether repositories block exists.booleanChecks plugin repository exists in buildscript repositories block by id.booleanhasPluginRepositoryByIdAndUrl(String id, String url) Checks plugin repository exists in buildscript repositories block by id and url.booleanChecks plugin repository exists in buildscript repositories block by url.booleanChecks repository exists in repositories block by id.booleanhasRepositoryByIdAndUrl(String id, String url) Checks repository exists in repositories block by id and url.booleanhasRepositoryByUrl(String url) Checks repository exists in repositories block by url.voidsave()Apply all modifications to a temporary file and then replace the original.voidupdateDependencyVersion(GradleFileRewriter.Dependency dependency, String newVersion) Updates the dependency version for the provided dependency.voidupdateProperty(GradleFileRewriter.Property property, String newValue) Updates the given property value.
-
Constructor Details
-
GradleFileRewriter
Creates a rewriter for the given Gradle build file.- Parameters:
file- thebuild.gradlefile to be modified- Throws:
IOException- if the file cannot be read
-
-
Method Details
-
findDependencyByGroupIdAndArtifactId
public GradleFileRewriter.Dependency findDependencyByGroupIdAndArtifactId(String groupId, String artifactId) Finds dependency under dependencies and dependencyManagement blocks by groupId and artifactId.- Parameters:
groupId- group idartifactId- artifact id- Returns:
- dependency if found,
nullotherwise
-
findDependency
Finds the dependency with the given groupId and artifactId inside the dependencies block.- Parameters:
groupId- group idartifactId- artifact id- Returns:
- optional dependency when found
-
getRepositoriesBlock
Checks whether repositories block exists.- Returns:
- block if found,
Optional.empty()otherwise
-
getPluginRepositoriesBlock
Checks whether buildscript repositories block exists.- Returns:
- block if found,
Optional.empty()otherwise
-
hasRepositoryByIdAndUrl
Checks repository exists in repositories block by id and url.- Parameters:
id- repository nameurl- repository url- Returns:
trueif found,falseotherwise
-
hasRepositoryById
Checks repository exists in repositories block by id.- Parameters:
id- repository name- Returns:
trueif found,falseotherwise
-
hasRepositoryByUrl
Checks repository exists in repositories block by url.- Parameters:
url- repository url- Returns:
trueif found,falseotherwise
-
addRepository
Adds repository to build.gradle if it does not exist.- Parameters:
id- repository nameurl- repository url
-
hasPluginRepositoryByIdAndUrl
Checks plugin repository exists in buildscript repositories block by id and url.- Parameters:
id- repository nameurl- repository url- Returns:
trueif found,falseotherwise
-
hasPluginRepositoryById
Checks plugin repository exists in buildscript repositories block by id.- Parameters:
id- repository name- Returns:
trueif found,falseotherwise
-
hasPluginRepositoryByUrl
Checks plugin repository exists in buildscript repositories block by url.- Parameters:
url- repository url- Returns:
trueif found,falseotherwise
-
addPluginRepository
Adds plugin repository to build.gradle if it does not exist.- Parameters:
id- repository nameurl- repository url
-
findPropertyByKey
Finds the property by key.- Parameters:
propertyKey- property key- Returns:
- property if found,
nullotherwise
-
addDependency
Adds dependency to build.gradle if needed.- Parameters:
groupId- group idartifactId- artifact idversion- dependency version, can benull- Returns:
trueif dependency was added,falsewhen it already existed
-
updateDependencyVersion
Updates the dependency version for the provided dependency.- Parameters:
dependency- dependency to updatenewVersion- new version
-
updateProperty
Updates the given property value.- Parameters:
property- property to updatenewValue- new value
-
save
Apply all modifications to a temporary file and then replace the original.- Throws:
IOException- when a file operation fails
-