Commit 1a76c972 authored by Andy Wilkinson's avatar Andy Wilkinson

Always install new GrapeEngine

Previously, GrapeEngineInstaller would only install its GrapeEngine
if an engine had not already been installed. As the Grape class stores
the engine in a static field, this meant that the engine would only be
installed once for the lifetime of Grape's classloader. This caused
an ordering issue in SampleIntegrationTests.

The test for the integration sample clears the
disableSpringSnapshotRepos system property to allow M1 of the
integration DSL to be resolved. However, this property is only
examined and honoured in AetherGrapeEngine's constructor. If another
test had run and had already created and installed an
AetherGrapeEngine, the new AetherGrapeEngine that allowed the use of
snapshot repositories would not be installed and the test would fail.

This commit updates GrapeEngineInstaller so that it always installs
its GrapeEngine, overwriting any previously installed engine.
parent f8d58022
......@@ -37,17 +37,7 @@ public class GrapeEngineInstaller {
try {
Field instanceField = Grape.class.getDeclaredField("instance");
instanceField.setAccessible(true);
GrapeEngine existingGrapeEngine = (GrapeEngine) instanceField.get(null);
if (existingGrapeEngine == null) {
instanceField.set(null, this.grapeEngine);
}
else if (!existingGrapeEngine.getClass().equals(
this.grapeEngine.getClass())) {
throw new IllegalStateException(
"Another GrapeEngine of a different type has already been initialized");
}
instanceField.set(null, this.grapeEngine);
}
catch (Exception ex) {
throw new IllegalStateException("Failed to install GrapeEngine", ex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment