mirror of https://github.com/apache/maven.git
PR: MNG-226
implement extension mechanism git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225463 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
527c6b4990
commit
8b01ca10f7
|
@ -21,7 +21,7 @@ import org.apache.maven.artifact.versioning.VersionRange;
|
|||
|
||||
public interface ArtifactFactory
|
||||
{
|
||||
static String ROLE = ArtifactFactory.class.getName();
|
||||
String ROLE = ArtifactFactory.class.getName();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
|
@ -56,4 +56,6 @@ public interface ArtifactFactory
|
|||
Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange );
|
||||
|
||||
Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope );
|
||||
|
||||
Artifact createExtensionArtifact( String groupId, String artifactId, String version );
|
||||
}
|
||||
|
|
|
@ -86,6 +86,11 @@ public class DefaultArtifactFactory
|
|||
return createArtifact( groupId, artifactId, version, scope, "pom" );
|
||||
}
|
||||
|
||||
public Artifact createExtensionArtifact( String groupId, String artifactId, String version )
|
||||
{
|
||||
return createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );
|
||||
}
|
||||
|
||||
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
|
||||
String inheritedScope )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.maven.extension;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Used to locate extensions.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DefaultExtensionManager
|
||||
implements ExtensionManager, Contextualizable
|
||||
{
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
||||
private ArtifactMetadataSource artifactMetadataSource;
|
||||
|
||||
private PlexusContainer container;
|
||||
|
||||
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PlexusContainerException
|
||||
{
|
||||
// TODO: version may be null
|
||||
Artifact artifact = artifactFactory.createExtensionArtifact( extension.getGroupId(), extension.getArtifactId(),
|
||||
extension.getVersion() );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ),
|
||||
project.getArtifact(),
|
||||
project.getRemoteArtifactRepositories(),
|
||||
localRepository,
|
||||
artifactMetadataSource );
|
||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
container.addJarResource( a.getFile() );
|
||||
}
|
||||
}
|
||||
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.maven.extension;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
|
||||
/**
|
||||
* Used to locate extensions.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ExtensionManager
|
||||
{
|
||||
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PlexusContainerException;
|
||||
}
|
|
@ -20,7 +20,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.extension.ExtensionManager;
|
||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Goal;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
|
@ -40,6 +42,7 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.injection.ModelDefaultsInjector;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
@ -75,6 +78,8 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
private PluginManager pluginManager;
|
||||
|
||||
private ExtensionManager extensionManager;
|
||||
|
||||
private List phases;
|
||||
|
||||
private Map defaultPhases;
|
||||
|
@ -100,6 +105,12 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
try
|
||||
{
|
||||
for ( Iterator i = project.getBuildExtensions().iterator(); i.hasNext(); )
|
||||
{
|
||||
Extension extension = (Extension) i.next();
|
||||
extensionManager.addExtension( extension, project, session.getLocalRepository() );
|
||||
}
|
||||
|
||||
for ( Iterator i = tasks.iterator(); i.hasNext(); )
|
||||
{
|
||||
String task = (String) i.next();
|
||||
|
@ -114,6 +125,10 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
response.setException( e );
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
response.setFinish( new Date() );
|
||||
|
|
|
@ -34,6 +34,22 @@
|
|||
</requirements>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.extension.ExtensionManager</role>
|
||||
<implementation>org.apache.maven.extension.DefaultExtensionManager</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
<!-- Duplicated from Maven core as it is used in the plugin manager -->
|
||||
<component>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
|
@ -114,6 +130,9 @@
|
|||
<requirement>
|
||||
<role>org.apache.maven.plugin.PluginManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.extension.ExtensionManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
|
||||
</requirement>
|
||||
|
|
|
@ -981,6 +981,15 @@
|
|||
]]></description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>extensions</name>
|
||||
<version>4.0.0</version>
|
||||
<description>A set of build extensions to use from this project.</description>
|
||||
<association>
|
||||
<type>Extension</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
|
@ -2239,7 +2248,8 @@
|
|||
<name>extensions</name>
|
||||
<version>4.0.0</version>
|
||||
<type>boolean</type>
|
||||
<description>Whether to load Maven extensions (such as packaging and type handlers) from this plugin</description>
|
||||
<description>Whether to load Maven extensions (such as packaging and type handlers) from this
|
||||
plugin</description>
|
||||
<defaultValue>false</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
|
@ -2789,6 +2799,77 @@
|
|||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
<name>Extension</name>
|
||||
<version>4.0.0</version>
|
||||
<description>Describes a build extension to utilise</description>
|
||||
<fields>
|
||||
<field>
|
||||
<name>groupId</name>
|
||||
<version>4.0.0</version>
|
||||
<description>The group of the extension's artifact.</description>
|
||||
<required>true</required>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>artifactId</name>
|
||||
<version>4.0.0</version>
|
||||
<description>The artifact ID of the extension</description>
|
||||
<required>true</required>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>version</name>
|
||||
<version>4.0.0</version>
|
||||
<description>The version of the extension</description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
</fields>
|
||||
<codeSegments>
|
||||
<codeSegment>
|
||||
<version>4.0.0</version>
|
||||
<code><![CDATA[
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( o instanceof Extension ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Extension e = (Extension) o;
|
||||
|
||||
if ( !e.getArtifactId().equals( getArtifactId() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !e.getGroupId().equals( getGroupId() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( e.getVersion() != null ? !e.getVersion().equals( getVersion() ) : getVersion() != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 17;
|
||||
result = 37 * result + getArtifactId().hashCode();
|
||||
result = 37 * result + getGroupId().hashCode();
|
||||
result = 37 * result + getVersion() != null ? getVersion().hashCode() : 0;
|
||||
return result;
|
||||
}
|
||||
]]></code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
</class>
|
||||
</classes>
|
||||
</model>
|
||||
|
||||
|
|
|
@ -1191,4 +1191,17 @@ public class MavenProject
|
|||
{
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
public List getBuildExtensions()
|
||||
{
|
||||
Build build = getBuild();
|
||||
if ( build == null || build.getExtensions() == null )
|
||||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
else
|
||||
{
|
||||
return build.getExtensions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.maven.model.BuildBase;
|
|||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.DistributionManagement;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.ModelBase;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
|
@ -446,6 +447,9 @@ public class DefaultModelInheritanceAssembler
|
|||
childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() );
|
||||
}
|
||||
|
||||
// Extensions are accumlated
|
||||
mergeExtensionLists( childBuild, parentBuild );
|
||||
|
||||
assembleBuildBaseInheritance( childBuild, parentBuild );
|
||||
}
|
||||
}
|
||||
|
@ -611,4 +615,16 @@ public class DefaultModelInheritanceAssembler
|
|||
return url + "/" + path;
|
||||
}
|
||||
}
|
||||
|
||||
private static void mergeExtensionLists( Build childBuild, Build parentBuild )
|
||||
{
|
||||
for ( Iterator i = parentBuild.getExtensions().iterator(); i.hasNext(); )
|
||||
{
|
||||
Extension e = (Extension) i.next();
|
||||
if ( !childBuild.getExtensions().contains( e ) )
|
||||
{
|
||||
childBuild.addExtension( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue