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.
pull/97/merge
Andy Wilkinson 11 years ago
parent f8d5802230
commit 1a76c972e3

@ -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);

Loading…
Cancel
Save