mirror of https://github.com/apache/maven.git
o Restored more backward-compat code
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@805995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d42a58e1e0
commit
14a19354e0
|
@ -1243,7 +1243,7 @@ public class DefaultLifecycleExecutor
|
|||
//TODO: take repo mans into account as one may be aggregating prefixes of many
|
||||
//TODO: collect at the root of the repository, read the one at the root, and fetch remote if something is missing
|
||||
// or the user forces the issue
|
||||
public Plugin findPluginForPrefix( String prefix, MavenSession session )
|
||||
Plugin findPluginForPrefix( String prefix, MavenSession session )
|
||||
throws NoPluginFoundForPrefixException
|
||||
{
|
||||
// [prefix]:[goal]
|
||||
|
|
|
@ -25,6 +25,9 @@ import java.util.Map;
|
|||
public interface LifecycleMapping
|
||||
{
|
||||
|
||||
@Deprecated
|
||||
String ROLE = LifecycleMapping.class.getName();
|
||||
|
||||
Map<String, Lifecycle> getLifecycles();
|
||||
|
||||
@Deprecated
|
||||
|
|
|
@ -52,6 +52,9 @@ public class DefaultBuildPluginManager
|
|||
@Requirement
|
||||
private MavenPluginManager mavenPluginManager;
|
||||
|
||||
@Requirement
|
||||
private LegacySupport legacySupport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
|
@ -87,12 +90,16 @@ public class DefaultBuildPluginManager
|
|||
ClassRealm oldLookupRealm = container.getLookupRealm();
|
||||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
MavenSession oldSession = legacySupport.getSession();
|
||||
|
||||
try
|
||||
{
|
||||
mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution );
|
||||
|
||||
Thread.currentThread().setContextClassLoader( pluginRealm );
|
||||
|
||||
legacySupport.setSession( session );
|
||||
|
||||
// NOTE: DuplicateArtifactAttachmentException is currently unchecked, so be careful removing this try/catch!
|
||||
// This is necessary to avoid creating compatibility problems for existing plugins that use
|
||||
// MavenProjectHelper.attachArtifact(..).
|
||||
|
@ -125,6 +132,8 @@ public class DefaultBuildPluginManager
|
|||
}
|
||||
|
||||
Thread.currentThread().setContextClassLoader( oldClassLoader );
|
||||
|
||||
legacySupport.setSession( oldSession );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
/*
|
||||
* 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.MavenSession;
|
||||
|
||||
/**
|
||||
* Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an
|
||||
* internal utility interface that is only public for technical reasons, it is not part of the public API. In
|
||||
* particular, this interface can be changed or deleted without prior notice.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public interface LegacySupport
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets the currently active session. Some legacy components are basically stateful and their API is missing
|
||||
* parameters that would be required to delegate to a stateless component. Saving the session (in a thread-local
|
||||
* variable) is our best effort to record any state that is required to enable proper delegation.
|
||||
*
|
||||
* @param session The currently active session, may be {@code null}.
|
||||
*/
|
||||
void setSession( MavenSession session );
|
||||
|
||||
/**
|
||||
* Gets the currently active session.
|
||||
*
|
||||
* @return The currently active session or {@code null} if none.
|
||||
*/
|
||||
MavenSession getSession();
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.apache.maven.plugin.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.MavenSession;
|
||||
import org.apache.maven.plugin.LegacySupport;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
/**
|
||||
* Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an
|
||||
* internal utility component that is only public for technical reasons, it is not part of the public API. In
|
||||
* particular, this component can be changed or deleted without prior notice.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
@Component( role = LegacySupport.class )
|
||||
public class DefaultLegacySupport
|
||||
implements LegacySupport
|
||||
{
|
||||
|
||||
private ThreadLocal<MavenSession> session = new ThreadLocal<MavenSession>();
|
||||
|
||||
public void setSession( MavenSession session )
|
||||
{
|
||||
if ( session == null )
|
||||
{
|
||||
this.session.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.session.set( session );
|
||||
}
|
||||
}
|
||||
|
||||
public MavenSession getSession()
|
||||
{
|
||||
return session.get();
|
||||
}
|
||||
|
||||
}
|
|
@ -22,26 +22,37 @@ package org.apache.maven.plugin.internal;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.BuildPluginManager;
|
||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
||||
import org.apache.maven.plugin.InvalidPluginException;
|
||||
import org.apache.maven.plugin.LegacySupport;
|
||||
import org.apache.maven.plugin.MavenPluginManager;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.PluginConfigurationException;
|
||||
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.plugin.version.DefaultPluginVersionRequest;
|
||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||
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.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
@ -55,7 +66,31 @@ public class DefaultPluginManager
|
|||
{
|
||||
|
||||
@Requirement
|
||||
private BuildPluginManager pluginManager;
|
||||
private PlexusContainer container;
|
||||
|
||||
@Requirement
|
||||
private MavenPluginManager pluginManager;
|
||||
|
||||
@Requirement
|
||||
private PluginVersionResolver pluginVersionResolver;
|
||||
|
||||
@Requirement
|
||||
private LegacySupport legacySupport;
|
||||
|
||||
private RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project )
|
||||
{
|
||||
RepositoryRequest request = new DefaultRepositoryRequest();
|
||||
|
||||
request.setCache( session.getRepositoryCache() );
|
||||
request.setLocalRepository( session.getLocalRepository() );
|
||||
if ( project != null )
|
||||
{
|
||||
request.setRemoteRepositories( project.getPluginArtifactRepositories() );
|
||||
}
|
||||
request.setOffline( session.isOffline() );
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
public void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
|
||||
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
|
||||
|
@ -67,15 +102,65 @@ public class DefaultPluginManager
|
|||
public Object getPluginComponent( Plugin plugin, String role, String roleHint )
|
||||
throws PluginManagerException, ComponentLookupException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
MavenSession session = legacySupport.getSession();
|
||||
|
||||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
RepositoryRequest repositoryRequest = getRepositoryRequest( session, session.getCurrentProject() );
|
||||
|
||||
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
||||
|
||||
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
|
||||
ClassRealm oldRealm = container.getLookupRealm();
|
||||
try
|
||||
{
|
||||
container.setLookupRealm( pluginDescriptor.getClassRealm() );
|
||||
|
||||
return container.lookup( role, roleHint );
|
||||
}
|
||||
finally
|
||||
{
|
||||
container.setLookupRealm( oldRealm );
|
||||
}
|
||||
}
|
||||
|
||||
public Map getPluginComponents( Plugin plugin, String role )
|
||||
throws ComponentLookupException, PluginManagerException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
MavenSession session = legacySupport.getSession();
|
||||
|
||||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
RepositoryRequest repositoryRequest = getRepositoryRequest( session, session.getCurrentProject() );
|
||||
|
||||
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
||||
|
||||
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
|
||||
ClassRealm oldRealm = container.getLookupRealm();
|
||||
try
|
||||
{
|
||||
container.setLookupRealm( pluginDescriptor.getClassRealm() );
|
||||
|
||||
return container.lookupMap( role );
|
||||
}
|
||||
finally
|
||||
{
|
||||
container.setLookupRealm( oldRealm );
|
||||
}
|
||||
}
|
||||
|
||||
public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
|
||||
|
@ -95,8 +180,7 @@ public class DefaultPluginManager
|
|||
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() );
|
||||
}
|
||||
|
||||
public PluginDescriptor loadPluginFully( Plugin plugin, MavenProject project, MavenSession session )
|
||||
|
@ -104,8 +188,18 @@ public class DefaultPluginManager
|
|||
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
PluginDescriptor pluginDescriptor = loadPluginDescriptor( plugin, project, session );
|
||||
|
||||
try
|
||||
{
|
||||
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
|
||||
}
|
||||
catch ( PluginResolutionException e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
||||
|
@ -114,8 +208,33 @@ public class DefaultPluginManager
|
|||
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
|
||||
repositoryRequest.setLocalRepository( localRepository );
|
||||
repositoryRequest.setRemoteRepositories( project.getPluginArtifactRepositories() );
|
||||
repositoryRequest.setOffline( settings.isOffline() );
|
||||
|
||||
if ( plugin.getVersion() == null )
|
||||
{
|
||||
PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, repositoryRequest );
|
||||
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return pluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
||||
}
|
||||
catch ( PluginResolutionException e )
|
||||
{
|
||||
throw new PluginNotFoundException( plugin, repositoryRequest.getRemoteRepositories() );
|
||||
}
|
||||
catch ( PluginDescriptorParsingException e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
catch ( InvalidPluginDescriptorException e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public interface PluginVersionResolver
|
|||
*
|
||||
* @param request The request that holds the details about the plugin and the repositories to consult, must not be
|
||||
* {@code null}.
|
||||
* @return The result of the version resolutioh, never {@code null}.
|
||||
* @return The result of the version resolution, never {@code null}.
|
||||
* @throws PluginVersionResolutionException If the plugin version could not be resolved.
|
||||
*/
|
||||
PluginVersionResult resolve( PluginVersionRequest request )
|
||||
|
|
Loading…
Reference in New Issue