o Changed array to atomicreference since arrays are not thread-safe

This commit is contained in:
Kristian Rosenvold 2012-11-29 22:17:04 +01:00 committed by Kristian Rosenvold
parent e8df4ca993
commit 2103c82d57
1 changed files with 8 additions and 6 deletions

View File

@ -19,9 +19,11 @@
* under the License.
*/
import java.util.concurrent.atomic.AtomicReference;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.codehaus.plexus.component.annotations.Component;
import org.sonatype.aether.RepositorySystemSession;
/**
@ -37,29 +39,29 @@ public class DefaultLegacySupport
implements LegacySupport
{
private static final ThreadLocal<MavenSession[]> session = new InheritableThreadLocal<MavenSession[]>();
private static final ThreadLocal<AtomicReference<MavenSession>> session = new InheritableThreadLocal<AtomicReference<MavenSession>>();
public void setSession( MavenSession session )
{
if ( session == null )
{
MavenSession[] oldSession = DefaultLegacySupport.session.get();
AtomicReference<MavenSession> oldSession = DefaultLegacySupport.session.get();
if ( oldSession != null )
{
oldSession[0] = null;
oldSession.set( null);
DefaultLegacySupport.session.remove();
}
}
else
{
DefaultLegacySupport.session.set( new MavenSession[] { session } );
DefaultLegacySupport.session.set( new AtomicReference<MavenSession>( session ));
}
}
public MavenSession getSession()
{
MavenSession[] currentSession = DefaultLegacySupport.session.get();
return currentSession != null ? currentSession[0] : null;
AtomicReference<MavenSession> currentSession = DefaultLegacySupport.session.get();
return currentSession != null ? currentSession.get() : null;
}
public RepositorySystemSession getRepositorySession()