Adding ability to reorient the build context manager to a new container context.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@504418 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-02-07 02:40:48 +00:00
parent ad35b458bf
commit 9e03384f41
4 changed files with 29 additions and 36 deletions

View File

@ -1,5 +1,7 @@
package org.apache.maven.context; package org.apache.maven.context;
import org.codehaus.plexus.context.Context;
/** /**
* Manager interface used to store, read, and clear the BuildContext out of the container. * Manager interface used to store, read, and clear the BuildContext out of the container.
* *
@ -10,11 +12,6 @@ public interface BuildContextManager
String ROLE = BuildContextManager.class.getName(); String ROLE = BuildContextManager.class.getName();
/**
* Create a new instance of BuildContext
*/
BuildContext newUnstoredInstance();
/** /**
* Read the BuildContext from the container. If it doesn't already exist, optionally create it. * Read the BuildContext from the container. If it doesn't already exist, optionally create it.
*/ */
@ -31,4 +28,12 @@ public interface BuildContextManager
*/ */
void clearBuildContext(); void clearBuildContext();
/**
* Re-orient this BuildContextManager to use the given Plexus Context instance, returning
* the original Context instance so it can be restored later. This can be important when the
* BuildContextManager is instantiated inside a Maven plugin, but the plugin needs to use the
* context associated with the core of Maven (in case multiple contexts are used).
*/
Context reorientToContext( Context context );
} }

View File

@ -32,15 +32,6 @@ public class DefaultBuildContextManager
this.context = context; this.context = context;
} }
/**
* Create a new instance of DefaultBuildContext, and return it. Each method call creates a brand
* new instance.
*/
public BuildContext newUnstoredInstance()
{
return new DefaultBuildContext();
}
/** /**
* Clear the contents of the build context inside the container context. * Clear the contents of the build context inside the container context.
*/ */
@ -128,4 +119,12 @@ public class DefaultBuildContextManager
this.context = context; this.context = context;
} }
public Context reorientToContext( Context context )
{
Context oldContext = this.context;
this.context = context;
return oldContext;
}
} }

View File

@ -9,6 +9,8 @@ public abstract class AbstractBuildContextManagerTest
protected abstract String getRoleHintBeforeSetUp(); protected abstract String getRoleHintBeforeSetUp();
protected abstract BuildContext createBuildContext();
protected BuildContextManager getBuildContextManager() protected BuildContextManager getBuildContextManager()
{ {
return mgr; return mgr;
@ -21,28 +23,10 @@ public abstract class AbstractBuildContextManagerTest
mgr = (BuildContextManager) lookup( BuildContextManager.ROLE, getRoleHintBeforeSetUp() ); mgr = (BuildContextManager) lookup( BuildContextManager.ROLE, getRoleHintBeforeSetUp() );
} }
public void testNewUnstoredInstance_ShouldReturnValidContextInstance()
{
BuildContext context = mgr.newUnstoredInstance();
assertNotNull( context );
String key = "key";
String value = "value";
context.put( key, value );
assertEquals( value, context.get( key ) );
context.delete( key );
assertNull( context.get( key ) );
}
public void testNewUnstoredInstance_SuccessiveCallsShouldReturnDistinctContextInstances() public void testNewUnstoredInstance_SuccessiveCallsShouldReturnDistinctContextInstances()
{ {
BuildContext context = mgr.newUnstoredInstance(); BuildContext context = createBuildContext();
BuildContext context2 = mgr.newUnstoredInstance(); BuildContext context2 = createBuildContext();
assertNotNull( context ); assertNotNull( context );
assertNotNull( context2 ); assertNotNull( context2 );
@ -51,7 +35,7 @@ public abstract class AbstractBuildContextManagerTest
public void testStoreAndRead_ShouldRetrieveStoredValueAfterRead() public void testStoreAndRead_ShouldRetrieveStoredValueAfterRead()
{ {
BuildContext ctx = mgr.newUnstoredInstance(); BuildContext ctx = createBuildContext();
String key = "key"; String key = "key";
String value = "value"; String value = "value";
@ -68,7 +52,7 @@ public abstract class AbstractBuildContextManagerTest
public void testStoreAndClear_ShouldNotRetrieveStoredValueAfterClear() public void testStoreAndClear_ShouldNotRetrieveStoredValueAfterClear()
{ {
BuildContext ctx = mgr.newUnstoredInstance(); BuildContext ctx = createBuildContext();
String key = "key"; String key = "key";
String value = "value"; String value = "value";

View File

@ -9,4 +9,9 @@ public class DefaultBuildContextManagerTest
return DefaultBuildContextManager.ROLE_HINT; return DefaultBuildContextManager.ROLE_HINT;
} }
protected BuildContext createBuildContext()
{
return new DefaultBuildContext();
}
} }