Skip to content

Commit

Permalink
Support both single and double quotes in plugin defs (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
markelliot authored Mar 30, 2022
1 parent 04018e4 commit 2f8179e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ private void setNewPluginVersions(File sourceFile, Map<String, String> pluginUpd
static String applyUpdate(String content, String pluginName, String pluginVersion) {
Pattern pattern =
Pattern.compile(
"id(\\s+|\\s*\\()\""
"id(\\s+|\\s*\\()(\"|')"
+ Pattern.quote(pluginName)
+ "\"(\\s+|\\)\\s+)version\\s+\"([^\"]+)\"");
+ "(\"|')(\\s+|\\)\\s+)version\\s+(\"|')([^\"]+)(\"|')");
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
content =
matcher.replaceFirst(
"id$1\"" + pluginName + "\"$2version \"" + pluginVersion + "\"");
"id$1$2" + pluginName + "$3$4version $5" + pluginVersion + "$7");
}
return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ public void testApplyUpdate() {
// gradle/groovy
assertThat(applyUpdate("id \"com.foo.bar\" version \"0.1.0\"", "com.foo.bar", "0.2.0"))
.isEqualTo("id \"com.foo.bar\" version \"0.2.0\"");
assertThat(applyUpdate("id 'com.foo.bar' version '0.1.0'", "com.foo.bar", "0.2.0"))
.isEqualTo("id 'com.foo.bar' version '0.2.0'");
assertThat(applyUpdate("id 'com.foo.bar' version \"0.1.0\"", "com.foo.bar", "0.2.0"))
.isEqualTo("id 'com.foo.bar' version \"0.2.0\"");
assertThat(applyUpdate("id \"com.foo.bar\" version '0.1.0'", "com.foo.bar", "0.2.0"))
.isEqualTo("id \"com.foo.bar\" version '0.2.0'");
// gradle/kotlin
assertThat(applyUpdate("id(\"com.foo.bar\") version \"0.1.0\"", "com.foo.bar", "0.2.0"))
.isEqualTo("id(\"com.foo.bar\") version \"0.2.0\"");
// no match
assertThat(applyUpdate("id \"com.foo.baz\" version \"0.1.0\"", "com.foo.bar", "0.2.0"))
.isEqualTo("id \"com.foo.baz\" version \"0.1.0\"");
assertThat(applyUpdate("id 'com.foo.baz' version '0.1.0'", "com.foo.bar", "0.2.0"))
.isEqualTo("id 'com.foo.baz' version '0.1.0'");
}
}

0 comments on commit 2f8179e

Please sign in to comment.