@@ -87,6 +87,7 @@ final class CachingGlue implements Glue {
87
87
private Locale locale = null ;
88
88
private StepExpressionFactory stepExpressionFactory = null ;
89
89
private boolean dirtyCache = false ;
90
+ private boolean hasScenarioScopedGlue = false ;
90
91
91
92
CachingGlue (EventBus bus ) {
92
93
this .bus = bus ;
@@ -108,42 +109,47 @@ public void addAfterAllHook(StaticHookDefinition afterAllHook) {
108
109
public void addStepDefinition (StepDefinition stepDefinition ) {
109
110
stepDefinitions .add (stepDefinition );
110
111
dirtyCache = true ;
112
+ hasScenarioScopedGlue |= stepDefinition instanceof ScenarioScoped ;
111
113
}
112
114
113
115
@ Override
114
116
public void addBeforeHook (HookDefinition hookDefinition ) {
115
117
beforeHooks .add (CoreHookDefinition .create (hookDefinition , bus ::generateId ));
116
118
beforeHooks .sort (HOOK_ORDER_ASCENDING );
119
+ hasScenarioScopedGlue |= hookDefinition instanceof ScenarioScoped ;
117
120
}
118
121
119
122
@ Override
120
123
public void addAfterHook (HookDefinition hookDefinition ) {
121
124
afterHooks .add (CoreHookDefinition .create (hookDefinition , bus ::generateId ));
122
125
afterHooks .sort (HOOK_ORDER_ASCENDING );
126
+ hasScenarioScopedGlue |= hookDefinition instanceof ScenarioScoped ;
123
127
}
124
128
125
129
@ Override
126
130
public void addBeforeStepHook (HookDefinition hookDefinition ) {
127
131
beforeStepHooks .add (CoreHookDefinition .create (hookDefinition , bus ::generateId ));
128
132
beforeStepHooks .sort (HOOK_ORDER_ASCENDING );
133
+ hasScenarioScopedGlue |= hookDefinition instanceof ScenarioScoped ;
129
134
}
130
135
131
136
@ Override
132
137
public void addAfterStepHook (HookDefinition hookDefinition ) {
133
138
afterStepHooks .add (CoreHookDefinition .create (hookDefinition , bus ::generateId ));
134
139
afterStepHooks .sort (HOOK_ORDER_ASCENDING );
140
+ hasScenarioScopedGlue |= hookDefinition instanceof ScenarioScoped ;
135
141
}
136
142
137
143
@ Override
138
144
public void addParameterType (ParameterTypeDefinition parameterType ) {
139
145
parameterTypeDefinitions .add (parameterType );
140
146
dirtyCache = true ;
147
+ hasScenarioScopedGlue |= parameterType instanceof ScenarioScoped ;
141
148
}
142
149
143
150
@ Override
144
151
public void addDataTableType (DataTableTypeDefinition dataTableType ) {
145
152
dataTableTypeDefinitions .add (dataTableType );
146
- dirtyCache = true ;
147
153
}
148
154
149
155
@ Override
@@ -169,7 +175,6 @@ public void addDefaultDataTableCellTransformer(
169
175
@ Override
170
176
public void addDocStringType (DocStringTypeDefinition docStringType ) {
171
177
docStringTypeDefinitions .add (docStringType );
172
- dirtyCache = true ;
173
178
}
174
179
175
180
List <StaticHookDefinition > getBeforeAllHooks () {
@@ -246,8 +251,10 @@ void prepareGlue(Locale locale) throws DuplicateStepDefinitionException {
246
251
boolean firstTime = stepTypeRegistry == null ;
247
252
boolean languageChanged = !locale .equals (this .locale );
248
253
boolean mustRebuildCache = false ;
249
- if (firstTime || languageChanged || dirtyCache ) {
254
+ if (firstTime || languageChanged || dirtyCache || hasScenarioScopedGlue ) {
250
255
// conditions changed => invalidate the glue cache
256
+ // Note: we have a prudent approach of avoiding caching if
257
+ // scenario-scoped glue exist (e.g. cucumber-java8).
251
258
this .locale = locale ;
252
259
stepTypeRegistry = new StepTypeRegistry (locale );
253
260
stepExpressionFactory = new StepExpressionFactory (stepTypeRegistry , bus );
@@ -483,14 +490,8 @@ void removeScenarioScopedGlue() {
483
490
dirty = true ;
484
491
dirtyCache = true ;
485
492
}
486
- if (removeScenarioScopedGlue (dataTableTypeDefinitions )) {
487
- dirty = true ;
488
- dirtyCache = true ;
489
- }
490
- if (removeScenarioScopedGlue (docStringTypeDefinitions )) {
491
- dirty = true ;
492
- dirtyCache = true ;
493
- }
493
+ dirty |= removeScenarioScopedGlue (dataTableTypeDefinitions );
494
+ dirty |= removeScenarioScopedGlue (docStringTypeDefinitions );
494
495
if (removeScenarioScopedGlue (parameterTypeDefinitions )) {
495
496
dirty = true ;
496
497
dirtyCache = true ;
@@ -501,6 +502,7 @@ void removeScenarioScopedGlue() {
501
502
if (dirty ) {
502
503
stepDefinitionsByPattern .clear ();
503
504
}
505
+ hasScenarioScopedGlue = false ;
504
506
}
505
507
506
508
private boolean removeScenarioScopedGlue (Iterable <?> glues ) {
0 commit comments