Skip to content

Commit e739361

Browse files
committed
- fix count by adding a HashSet with visited sources
1 parent bd0de30 commit e739361

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public LSS editSources(LSS sourceSet) {
181181
return null;
182182
}
183183

184+
recipeRunStats.recordSourceVisited(source);
184185
SourceFile after = source;
185186

186187
try {

rewrite-core/src/main/java/org/openrewrite/table/RecipeRunStats.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
public class RecipeRunStats extends DataTable<RecipeRunStats.Row> {
3737
private final MeterRegistry registry = new SimpleMeterRegistry();
38+
private final Set<Path> sourceFileVisited = new HashSet<>();
3839
private final Set<Path> sourceFileChanged = new HashSet<>();
3940

4041
public RecipeRunStats(Recipe recipe) {
@@ -43,6 +44,10 @@ public RecipeRunStats(Recipe recipe) {
4344
"Statistics used in analyzing the performance of recipes.");
4445
}
4546

47+
public void recordSourceVisited(SourceFile source) {
48+
sourceFileVisited.add(source.getSourcePath());
49+
}
50+
4651
public void recordSourceFileChanged(@Nullable SourceFile before, @Nullable SourceFile after) {
4752
if (after != null) {
4853
sourceFileChanged.add(after.getSourcePath());
@@ -73,7 +78,7 @@ public void flush(ExecutionContext ctx) {
7378
Timer scanner = registry.find("rewrite.recipe.scan").tag("name", recipeName).timer();
7479
Row row = new Row(
7580
recipeName,
76-
Long.valueOf(editor.count()).intValue(),
81+
sourceFileVisited.size(),
7782
sourceFileChanged.size(),
7883
scanner == null ? 0 : (long) scanner.totalTime(TimeUnit.NANOSECONDS),
7984
scanner == null ? 0 : scanner.takeSnapshot().percentileValues()[0].value(TimeUnit.NANOSECONDS),

rewrite-core/src/test/java/org/openrewrite/table/RecipeRunStatsTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ void singleRow() {
7878
RecipeRunStats.Row row = rows.get(0);
7979
assertThat(row.getRecipe()).endsWith("RecipeWithApplicabilityTest");
8080
assertThat(row.getSourceFiles())
81-
.as("Test framework will invoke the recipe once when it is expected to make a change, " +
82-
"then once again when it is expected to make no change")
83-
.isEqualTo(2);
81+
.isEqualTo(1);
8482
assertThat(row.getEditMaxNs()).isGreaterThan(0);
8583
assertThat(row.getEditTotalTimeNs())
8684
.as("Cumulative time should be greater than any single visit time")
@@ -112,11 +110,11 @@ void sourceFilesCountStatsForSameRecipe() {
112110
.hasSize(2);
113111
for (RecipeRunStats.Row row : rows) {
114112
assertThat(row.getSourceFiles())
115-
.as("If the same recipe runs with different parameters it shouldn't increment source files count")
116-
.isEqualTo(2);
113+
.as("If the same recipe runs with different parameters it shouldn't increment several times source files count")
114+
.isEqualTo(1);
117115
}
118116
}).expectedCyclesThatMakeChanges(2),
119117
text("sem", "sam2")
120118
);
121119
}
122-
}
120+
}

0 commit comments

Comments
 (0)