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