MNG-5695 fixed inconsistent/incomplete custom guice scope bindings

MojoExecution scope was only available for maven plugins and could not
be used for components defined in maven core or maven code extensions.

Session scope was only available for maven core and core extensions
but did not work for components from maven plugins.

Made both custom scopes available available in all realms.

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
Igor Fedorenko 2014-09-26 20:18:47 -04:00
parent 3d2d8619b1
commit b80fb7d7ce
9 changed files with 146 additions and 47 deletions

View File

@ -61,6 +61,7 @@ import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingResult;
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.session.scope.internal.SessionScope;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;

View File

@ -24,30 +24,18 @@ import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.execution.MojoExecutionEvent;
import org.apache.maven.execution.MojoExecutionListener;
import org.apache.maven.execution.scope.MojoExecutionScoped;
import org.apache.maven.execution.scope.WeakMojoExecutionListener;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.OutOfScopeException;
import com.google.inject.Provider;
import com.google.inject.Scope;
import com.google.inject.util.Providers;
@Named
@Singleton
public class MojoExecutionScope
implements Scope, MojoExecutionListener
{
@ -158,24 +146,6 @@ public class MojoExecutionScope
return (Provider<T>) SEEDED_KEY_PROVIDER;
}
public static Module getScopeModule( PlexusContainer container )
throws ComponentLookupException
{
final MojoExecutionScope scope = container.lookup( MojoExecutionScope.class );
return new AbstractModule()
{
@Override
protected void configure()
{
bindScope( MojoExecutionScoped.class, scope );
// standard scope bindings
bind( MavenProject.class ).toProvider( MojoExecutionScope.<MavenProject> seededKeyProvider() ).in( scope );
bind( MojoExecution.class ).toProvider( MojoExecutionScope.<MojoExecution> seededKeyProvider() ).in( scope );
}
};
}
public void beforeMojoExecution( MojoExecutionEvent event )
throws MojoExecutionException
{

View File

@ -1,4 +1,4 @@
package org.apache.maven;
package org.apache.maven.execution.scope.internal;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -19,21 +19,27 @@ package org.apache.maven;
* under the License.
*/
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.maven.execution.MavenSession;
import com.google.inject.AbstractModule;
import org.apache.maven.execution.MojoExecutionListener;
@Named
public class SessionModule extends AbstractModule
{
public class MojoExecutionScopeCoreModule
extends MojoExecutionScopeModule
{
@Inject
public MojoExecutionScopeCoreModule()
{
super( new MojoExecutionScope() );
}
@Override
protected void configure()
{
SessionScope scope = new SessionScope();
bindScope( SessionScoped.class, scope );
bind( SessionScope.class ).toInstance( scope );
bind( MavenSession.class ).toProvider( SessionScope.<MavenSession>seededKeyProvider() ).in( scope );
super.configure();
bind( MojoExecutionListener.class ).toInstance( scope );
}
}

View File

@ -0,0 +1,56 @@
package org.apache.maven.execution.scope.internal;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.execution.scope.MojoExecutionScoped;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import com.google.inject.AbstractModule;
public class MojoExecutionScopeModule
extends AbstractModule
{
protected final MojoExecutionScope scope;
public MojoExecutionScopeModule( PlexusContainer container )
throws ComponentLookupException
{
this( container.lookup( MojoExecutionScope.class ) );
}
protected MojoExecutionScopeModule( MojoExecutionScope scope )
{
this.scope = scope;
}
@Override
protected void configure()
{
bindScope( MojoExecutionScoped.class, scope );
bind( MojoExecutionScope.class ).toInstance( scope );
bind( MavenProject.class ).toProvider( MojoExecutionScope.<MavenProject> seededKeyProvider() ).in( scope );
bind( MojoExecution.class ).toProvider( MojoExecutionScope.<MojoExecution> seededKeyProvider() ).in( scope );
}
}

View File

@ -22,7 +22,6 @@ package org.apache.maven.lifecycle.internal;
import java.util.HashSet;
import java.util.List;
import org.apache.maven.SessionScope;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.BuildSuccess;
import org.apache.maven.execution.ExecutionEvent;
@ -33,6 +32,7 @@ import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.apache.maven.session.scope.internal.SessionScope;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;

View File

@ -41,7 +41,7 @@ import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.classrealm.ClassRealmManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.model.Plugin;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.ContextEnabled;
@ -67,6 +67,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.session.scope.internal.SessionScopeModule;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
@ -392,8 +393,8 @@ public class DefaultMavenPluginManager
container.addComponentDescriptor( componentDescriptor );
}
( (DefaultPlexusContainer) container ).discoverComponents( pluginRealm,
MojoExecutionScope.getScopeModule( container ) );
( (DefaultPlexusContainer) container ).discoverComponents( pluginRealm, new SessionScopeModule( container ),
new MojoExecutionScopeModule( container ) );
}
catch ( ComponentLookupException e )
{

View File

@ -33,7 +33,7 @@ import java.util.Set;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.classrealm.ClassRealmManager;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
@ -48,6 +48,7 @@ import org.apache.maven.plugin.version.PluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.session.scope.internal.SessionScopeModule;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
@ -271,7 +272,8 @@ public class DefaultProjectBuildingHelper
try
{
( (DefaultPlexusContainer) container ).discoverComponents( extensionRealm,
MojoExecutionScope.getScopeModule( container ) );
new SessionScopeModule( container ),
new MojoExecutionScopeModule( container ) );
}
catch ( Exception e )
{

View File

@ -1,4 +1,4 @@
package org.apache.maven;
package org.apache.maven.session.scope.internal;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -0,0 +1,63 @@
package org.apache.maven.session.scope.internal;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.maven.SessionScoped;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import com.google.inject.AbstractModule;
@Named
public class SessionScopeModule
extends AbstractModule
{
private final SessionScope scope;
@Inject
public SessionScopeModule()
{
this( new SessionScope() );
}
public SessionScopeModule( PlexusContainer container )
throws ComponentLookupException
{
this( container.lookup( SessionScope.class ) );
}
private SessionScopeModule( SessionScope scope )
{
this.scope = scope;
}
@Override
protected void configure()
{
bindScope( SessionScoped.class, scope );
bind( SessionScope.class ).toInstance( scope );
bind( MavenSession.class ).toProvider( SessionScope.<MavenSession> seededKeyProvider() ).in( scope );
}
}