Skip to content

Commit 1de72dc

Browse files
authored
Fixes parsing subprojects (#65)
The post-release action was failing when trying to parse the subprojects because the description of the Wavefront registry now has a single quote in it. This broke the logic used to parse subprojects. The logic has been updated to be more robust and handle this situation.
1 parent 897837b commit 1de72dc

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/main/java/io/micrometer/release/common/GradleParser.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
import java.util.HashSet;
2323
import java.util.List;
2424
import java.util.Set;
25+
import java.util.regex.Matcher;
26+
import java.util.regex.Pattern;
2527

2628
public class GradleParser {
2729

2830
private static final Logger log = LoggerFactory.getLogger(GradleParser.class);
2931

32+
private static final Pattern PROJECTS_LINE_PATTERN = Pattern.compile("Project ':([\\w-]+)'");
33+
3034
private final List<String> excludedDependencyScopes = List.of("testCompile", "testImplementation", "checkstyle",
3135
"runtime", "nohttp", "testRuntime", "optional");
3236

@@ -39,10 +43,7 @@ public GradleParser(ProcessRunner processRunner) {
3943
public Set<Dependency> fetchAllDependencies() {
4044
log.info("Fetching test and optional dependencies...");
4145
List<String> projectLines = projectLines();
42-
List<String> subprojects = projectLines.stream()
43-
.filter(line -> line.contains("Project") && line.contains(":") && line.contains("'"))
44-
.map(line -> line.substring(line.indexOf(":") + 1, line.lastIndexOf("'")).trim())
45-
.toList();
46+
List<String> subprojects = getSubprojects(projectLines);
4647

4748
log.info("Subprojects: {}", subprojects);
4849

@@ -86,6 +87,18 @@ else if (line.isEmpty() || line.isBlank()) {
8687
return dependencies;
8788
}
8889

90+
// Visible for testing
91+
static List<String> getSubprojects(List<String> projectLines) {
92+
return projectLines.stream()
93+
.filter(line -> line.contains("Project") && line.contains(":") && line.contains("'"))
94+
.map(line -> {
95+
Matcher matcher = PROJECTS_LINE_PATTERN.matcher(line);
96+
matcher.find();
97+
return matcher.group(1);
98+
})
99+
.toList();
100+
}
101+
89102
private static String extractVersion(String line) {
90103
if (line == null || line.trim().isEmpty()) {
91104
return null;

src/test/java/io/micrometer/release/common/GradleParserTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,16 @@ void should_run_project_lines() {
6363
verify(runner).runSilently(List.of("./gradlew", "projects"));
6464
}
6565

66+
@Test
67+
void should_get_subprojects_with_single_quote_in_description() {
68+
var projectLines = List.of(
69+
"+--- Project ':micrometer-registry-wavefront' - MeterRegistry implementation for Wavefront. This module is deprecated due to Wavefront's End of Life Announcement.",
70+
"+--- Project ':micrometer-registry-signalfx' - MeterRegistry implementation for sending metrics to SignalFX. This module is deprecated in favor of the micrometer-registry-otlp module.",
71+
"+--- Project ':micrometer-registry-statsd' - Application monitoring instrumentation facade");
72+
73+
then(GradleParser.getSubprojects(projectLines)).hasSize(3)
74+
.containsExactlyInAnyOrder("micrometer-registry-wavefront", "micrometer-registry-signalfx",
75+
"micrometer-registry-statsd");
76+
}
77+
6678
}

src/test/resources/gradle/projects_output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Root project 'micrometer'
3838
+--- Project ':micrometer-registry-signalfx' - Application monitoring instrumentation facade
3939
+--- Project ':micrometer-registry-stackdriver' - Application monitoring instrumentation facade
4040
+--- Project ':micrometer-registry-statsd' - Application monitoring instrumentation facade
41-
+--- Project ':micrometer-registry-wavefront' - Application monitoring instrumentation facade
41+
+--- Project ':micrometer-registry-wavefront' - MeterRegistry implementation for Wavefront. This module is deprecated due to Wavefront's End of Life Announcement.
4242
+--- Project ':micrometer-samples-boot2' - Application monitoring instrumentation facade
4343
+--- Project ':micrometer-samples-boot2-reactive' - Application monitoring instrumentation facade
4444
+--- Project ':micrometer-samples-core' - Application monitoring instrumentation facade

0 commit comments

Comments
 (0)