------------------------

o Factored the layout for a repository into a separate set of components in o.a.m.a.repository.layout

o Added new DefaultRepositoryLayout that uses the repo layout in http://docs.codehaus.org/pages/viewpage.action?pageId=22230 (it is not used by default until we get the repo1 conversion done)

o Added command-line switches to force legacy local-repo or new format (-a/-A, I know, but try to find something that makes more sense!)

o Added path formatting to the repository itself, which is now constructed with a ArtifactRepositoryLayout instance (since layout should be tied to the repository)

o Removed path formatting altogether from the DefaultArtifactHandlerManager.

o Changed the AbstractArtifactBasedComponent (or whatever it's called) to use the repository formatting in the path() and localPath() methods.

o Moved the plugin repo construction (still intact as a hard-coded singleton list) into the DefaultMavenProjectBuilder, where it will eventually build from POM info.

o Added a new method to build an artifact repository for a <distributionManagement/> section, if possible. This reduced the strain on mojos to construct an ArtifactRepository on demand.

o Refactored all *DeployMojo to use #project.distributionManagementArtifactRepository instead of the #settings, #component..ArtifactRepositoryFactory, ... that it used to require. This is a big simplifying step.

o Removed remote artifact repository construction from DefaultMaven, and changed the MavenSession to delegate to MavenProject for remoteArtifactRepositories, just as it does for pluginRepositories.

o Added remoteArtifactRepositories, pluginArtifactRepositories, distributionManagementArtifactRepository to MavenProject as a cache for the higher-level repos used throughout the system. This is project info, so it belongs here.

o Fixed all the tests in maven-core and maven-artifact which I broke. :)

o Dropped what is probably a big format-bomb, since the Eclipse formatter doesn't really handle 'throws Exception' wrapping the right way.

o Added MavenProject to the MavenSession constructor, since there should always be a MavenProject associated with a build, even if it's just the super-pom.

TODO:
--------------------------

- Write an integration/unit test to ensure that the new repo format works with $classifier (was: $extra) and $groupId[0]/../$groupId[n]. This is a simple adaptation of the old layout, but still needs testing.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163638 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-21 08:18:34 +00:00
parent e1f51a9ad4
commit 590e952f02
34 changed files with 904 additions and 547 deletions

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
@ -38,15 +39,21 @@ public class AbstractArtifactComponent
return artifactHandlerManager.getArtifactHandler( type );
}
protected String path( Artifact artifact ) throws ArtifactHandlerNotFoundException
protected String path( Artifact artifact, ArtifactRepository remoteRepository ) throws ArtifactPathFormatException
{
return artifactHandlerManager.path( artifact );
return remoteRepository.pathOf( artifact );
}
protected String localPath( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactPathFormatException
{
return localRepository.getBasedir() + "/" + localRepository.pathOf( artifact );
}
protected void setLocalRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactHandlerNotFoundException
throws ArtifactPathFormatException
{
String artifactPath = artifactHandlerManager.localRepositoryPath( artifact, localRepository );
String artifactPath = localPath( artifact, localRepository );
artifact.setPath( artifactPath );
}

View File

@ -22,7 +22,9 @@ public interface Artifact
{
// TODO: into scope handler
String SCOPE_COMPILE = "compile";
String SCOPE_TEST = "test";
String SCOPE_RUNTIME = "runtime";
String getGroupId();
@ -35,6 +37,11 @@ public interface Artifact
String getType();
String getClassifier();
// only providing this since classifier is *very* optional...
boolean hasClassifier();
String getExtension();
// ----------------------------------------------------------------------
@ -56,4 +63,4 @@ public interface Artifact
String getId();
String getConflictId();
}
}

View File

@ -16,6 +16,8 @@ package org.apache.maven.artifact;
* limitations under the License.
*/
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
/**
@ -25,7 +27,7 @@ import java.io.File;
public class DefaultArtifact
implements Artifact
{
// ----------------------------------------------------------------------
// These are the only things i need to specify
// ----------------------------------------------------------------------
@ -38,6 +40,8 @@ public class DefaultArtifact
private String type;
private String classifier;
private String scope;
private String extension;
@ -47,11 +51,22 @@ public class DefaultArtifact
/**
* @todo this should be replaced by type handler
*/
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, String extension )
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type,
String extension )
{
if(type == null)
this( groupId, artifactId, version, scope, type, null, extension );
}
/**
* !!! WARNING !!! Never put <classifier/> in the POM. It is for mojo use
* only. Classifier is for specifying derived artifacts, like ejb-client.
*/
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type,
String classifier, String extension )
{
if ( type == null )
{
throw new NullPointerException("Artifact type cannot be null.");
throw new NullPointerException( "Artifact type cannot be null." );
}
this.groupId = groupId;
@ -64,12 +79,24 @@ public class DefaultArtifact
this.scope = scope;
this.classifier = classifier;
this.extension = extension;
}
public DefaultArtifact( String groupId, String artifactId, String version, String type )
{
this( groupId, artifactId, version, null, type, type );
this( groupId, artifactId, version, null, type, null, type );
}
public String getClassifier()
{
return classifier;
}
public boolean hasClassifier()
{
return StringUtils.isNotEmpty( classifier );
}
public String getScope()
@ -142,12 +169,13 @@ public class DefaultArtifact
public String getId()
{
return getGroupId() + ":" + getArtifactId() + ":" + getType() + ":" + getVersion();
return getConflictId() + ":" + getVersion();
}
public String getConflictId()
{
return getGroupId() + ":" + getArtifactId() + ":" + getType();
return getGroupId() + ":" + getArtifactId() + ":" + getType()
+ ( hasClassifier() ? ( ":" + getClassifier() ) : "" );
}
// ----------------------------------------------------------------------
@ -168,7 +196,6 @@ public class DefaultArtifact
{
Artifact other = (Artifact) o;
return this.groupId.equals( other.getGroupId() ) && this.artifactId.equals( other.getArtifactId() ) && this.version.equals(
other.getVersion() ) && this.type.equals( other.getType() );
return getId().equals( other.getId() );
}
}

View File

@ -1,8 +1,6 @@
package org.apache.maven.artifact.handler.manager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.Set;
@ -30,15 +28,14 @@ public interface ArtifactHandlerManager
{
String ROLE = ArtifactHandlerManager.class.getName();
ArtifactHandler getArtifactHandler( String type )
throws ArtifactHandlerNotFoundException;
ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException;
String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactHandlerNotFoundException;
String path( Artifact artifact )
throws ArtifactHandlerNotFoundException;
// String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
// throws ArtifactHandlerNotFoundException;
//
// String path( Artifact artifact )
// throws ArtifactHandlerNotFoundException;
Set getHandlerTypes();
}
}

View File

@ -16,10 +16,8 @@ package org.apache.maven.artifact.handler.manager;
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.StringUtils;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import java.util.Map;
import java.util.Set;
@ -34,8 +32,9 @@ public class DefaultArtifactHandlerManager
{
private Map artifactHandlers;
public ArtifactHandler getArtifactHandler( String type )
throws ArtifactHandlerNotFoundException
private ArtifactRepositoryLayout artifactRepositoryLayout;
public ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException
{
ArtifactHandler handler = (ArtifactHandler) artifactHandlers.get( type );
@ -56,58 +55,29 @@ public class DefaultArtifactHandlerManager
//
// ----------------------------------------------------------------------
private String layout;
// public String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
// throws ArtifactHandlerNotFoundException
// {
// return localRepository.getBasedir() + "/" + path( artifact );
// }
//
// public String artifactUrl( Artifact artifact, ArtifactRepository remoteRepository )
// throws ArtifactHandlerNotFoundException
// {
// return remoteRepository.getUrl() + "/" + path( artifact );
// }
//
// public String path( Artifact artifact )
// throws ArtifactHandlerNotFoundException
// {
// if ( artifact.getType() == null )
// {
// throw new ArtifactHandlerNotFoundException( "Artifact handler is null for artifact " + artifact );
// }
//
// ArtifactHandler handler = getArtifactHandler( artifact.getType() );
//
// return artifactRepositoryLayout.pathOf( artifact, handler );
// }
public String getLayout()
{
if ( layout == null )
{
return "${groupId}/${directory}/${artifactId}-${version}.${extension}";
}
return layout;
}
public String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactHandlerNotFoundException
{
return localRepository.getBasedir() + "/" + path( artifact );
}
public String artifactUrl( Artifact artifact, ArtifactRepository remoteRepository )
throws ArtifactHandlerNotFoundException
{
return remoteRepository.getUrl() + "/" + path( artifact );
}
public String path( Artifact artifact )
throws ArtifactHandlerNotFoundException
{
if ( artifact.getType() == null )
{
throw new ArtifactHandlerNotFoundException( "Artifact handler is null for artifact " + artifact );
}
ArtifactHandler handler = getArtifactHandler( artifact.getType() );
return interpolateLayout( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), handler.directory(), handler.extension() );
}
private String interpolateLayout( String groupId, String artifactId, String version, String directory,
String extension )
{
String layout = getLayout();
layout = StringUtils.replace( layout, "${groupId}", groupId );
layout = StringUtils.replace( layout, "${artifactId}", artifactId );
layout = StringUtils.replace( layout, "${directory}", directory );
layout = StringUtils.replace( layout, "${version}", version );
layout = StringUtils.replace( layout, "${extension}", extension );
return layout;
}
}

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.AbstractArtifactComponent;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
@ -69,9 +70,9 @@ public class DefaultArtifactInstaller
{
throw new ArtifactInstallationException( "Error installing artifact: ", e );
}
catch ( ArtifactHandlerNotFoundException e )
catch ( ArtifactPathFormatException e )
{
throw new ArtifactInstallationException( "Error installing artifact: ", e );
}
}
}
}

View File

@ -80,7 +80,7 @@ public class DefaultWagonManager
wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.put( source, path( artifact ) );
wagon.put( source, path( artifact, repository ) );
wagon.disconnect();
@ -148,7 +148,9 @@ public class DefaultWagonManager
wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.get( path( artifact ), temp );
String remotePath = path( artifact, repository );
wagon.get( remotePath, temp );
// TODO [BP]: put all disconnects in finally
wagon.disconnect();

View File

@ -16,6 +16,9 @@ package org.apache.maven.artifact.repository;
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.repository.Repository;
@ -29,14 +32,26 @@ import org.apache.maven.wagon.repository.Repository;
public class ArtifactRepository
extends Repository
{
public ArtifactRepository( String id, String url )
private final ArtifactRepositoryLayout layout;
public ArtifactRepository( String id, String url, ArtifactRepositoryLayout layout )
{
super( id, url );
this.layout = layout;
}
public ArtifactRepository( String id, String url, AuthenticationInfo authInfo )
public ArtifactRepository( String id, String url, AuthenticationInfo authInfo, ArtifactRepositoryLayout layout )
{
super( id, url, authInfo );
this.layout = layout;
}
public String pathOf( Artifact artifact ) throws ArtifactPathFormatException
{
return layout.pathOf( artifact );
}
}

View File

@ -0,0 +1,78 @@
package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.codehaus.plexus.util.StringUtils;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
/**
* @author jdcasey
*/
public abstract class AbstractArtifactRepositoryLayout
implements ArtifactRepositoryLayout
{
private ArtifactHandlerManager artifactHandlerManager;
protected abstract String layoutPattern();
protected abstract String groupIdAsPath( String groupId );
public String pathOf( Artifact artifact ) throws ArtifactPathFormatException
{
String path = layoutPattern();
String groupPath = groupIdAsPath( artifact.getGroupId() );
path = StringUtils.replace( path, "${groupPath}", groupPath );
path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
path = StringUtils.replace( path, "${version}", artifact.getVersion() );
if ( artifact.hasClassifier() )
{
path = StringUtils.replace( path, "${classifier}", artifact.getClassifier() );
}
else
{
path = StringUtils.replace( path, "-${classifier}", "" );
}
ArtifactHandler artifactHandler = null;
try
{
artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() );
}
catch ( ArtifactHandlerNotFoundException e )
{
throw new ArtifactPathFormatException( "Cannot find ArtifactHandler for artifact: \'" + artifact.getId()
+ "\'.", e );
}
path = StringUtils.replace( path, "${directory}", artifactHandler.directory() );
path = StringUtils.replace( path, "${extension}", artifact.getExtension() );
return path;
}
}

View File

@ -0,0 +1,32 @@
package org.apache.maven.artifact.repository.layout;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
/**
* @author jdcasey
*/
public class ArtifactPathFormatException
extends Exception
{
public ArtifactPathFormatException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -0,0 +1,32 @@
package org.apache.maven.artifact.repository.layout;
/* ====================================================================
* Copyright 2001-2004 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;
/**
* @author jdcasey
*/
public interface ArtifactRepositoryLayout
{
String ROLE = ArtifactRepositoryLayout.class.getName();
String pathOf( Artifact artifact ) throws ArtifactPathFormatException;
}

View File

@ -0,0 +1,37 @@
package org.apache.maven.artifact.repository.layout;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
/**
* @author jdcasey
*/
public class DefaultRepositoryLayout
extends AbstractArtifactRepositoryLayout
{
protected String layoutPattern()
{
return "${groupId}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
}
protected String groupIdAsPath( String groupId )
{
return groupId.replace( '.', '/' );
}
}

View File

@ -0,0 +1,37 @@
package org.apache.maven.artifact.repository.layout;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
/**
* @author jdcasey
*/
public class LegacyRepositoryLayout
extends AbstractArtifactRepositoryLayout
{
protected String layoutPattern()
{
return "${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}";
}
protected String groupIdAsPath( String groupId )
{
return groupId;
}
}

View File

@ -3,11 +3,11 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.AbstractArtifactComponent;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
import org.apache.maven.wagon.TransferFailedException;
@ -45,7 +45,7 @@ public class DefaultArtifactResolver
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
@ -65,8 +65,8 @@ public class DefaultArtifactResolver
try
{
Logger logger = getLogger();
logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository +
"}\n" + "{remoteRepositories: " + remoteRepositories + "}" );
logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository
+ "}\n" + "{remoteRepositories: " + remoteRepositories + "}" );
setLocalRepositoryPath( artifact, localRepository );
@ -77,14 +77,14 @@ public class DefaultArtifactResolver
wagonManager.get( artifact, remoteRepositories, localRepository );
}
catch ( ArtifactHandlerNotFoundException e )
{
throw new ArtifactResolutionException( "Error resolving artifact: ", e );
}
catch ( TransferFailedException e )
{
throw new ArtifactResolutionException( artifactNotFound( artifact, remoteRepositories ), e );
}
catch ( ArtifactPathFormatException e )
{
throw new ArtifactResolutionException( "Error resolving artifact: ", e );
}
return artifact;
}
@ -95,8 +95,9 @@ public class DefaultArtifactResolver
{
StringBuffer sb = new StringBuffer();
sb.append( "The artifact is not present locally as:" ).append( LS ).append( LS ).append( artifact.getPath() ).append(
LS ).append( LS ).append( "or in any of the specified remote repositories:" ).append( LS ).append( LS );
sb.append( "The artifact is not present locally as:" ).append( LS ).append( LS ).append( artifact.getPath() )
.append( LS ).append( LS ).append( "or in any of the specified remote repositories:" ).append( LS )
.append( LS );
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
@ -134,8 +135,8 @@ public class DefaultArtifactResolver
// ----------------------------------------------------------------------
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
ArtifactResolutionResult artifactResolutionResult;
@ -158,16 +159,16 @@ public class DefaultArtifactResolver
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return resolveTransitively( Collections.singleton( artifact ), remoteRepositories, localRepository, source );
@ -178,9 +179,8 @@ public class DefaultArtifactResolver
// ----------------------------------------------------------------------
private ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter )
throws TransitiveArtifactResolutionException
List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter ) throws TransitiveArtifactResolutionException
{
ArtifactResolutionResult result = new ArtifactResolutionResult();
@ -215,14 +215,14 @@ public class DefaultArtifactResolver
// TODO: scope handler
boolean updateScope = false;
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) &&
Artifact.SCOPE_TEST.equals( knownArtifact.getScope() ) )
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() )
&& Artifact.SCOPE_TEST.equals( knownArtifact.getScope() ) )
{
updateScope = true;
}
if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) &&
!Artifact.SCOPE_COMPILE.equals( knownArtifact.getScope() ) )
if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() )
&& !Artifact.SCOPE_COMPILE.equals( knownArtifact.getScope() ) )
{
updateScope = true;
}
@ -231,9 +231,10 @@ public class DefaultArtifactResolver
{
// TODO: Artifact factory?
// TODO: [jc] Is this a better way to centralize artifact construction here?
Artifact artifact = artifactConstructionSupport.createArtifact( knownArtifact.getGroupId(),
knownArtifact.getArtifactId(),
knownVersion, newArtifact.getScope(),
Artifact artifact = artifactConstructionSupport.createArtifact( knownArtifact.getGroupId(),
knownArtifact.getArtifactId(),
knownVersion,
newArtifact.getScope(),
knownArtifact.getType(),
knownArtifact.getExtension() );
resolvedArtifacts.put( artifact.getConflictId(), artifact );
@ -260,8 +261,8 @@ public class DefaultArtifactResolver
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact +
"] : ", e );
throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact
+ "] : ", e );
}
// the pom for given dependency exisit we will add it to the
@ -287,7 +288,7 @@ public class DefaultArtifactResolver
{
setLocalRepositoryPath( artifact, localRepository );
}
catch ( ArtifactHandlerNotFoundException e )
catch ( ArtifactPathFormatException e )
{
throw new TransitiveArtifactResolutionException( "Error collecting artifact: ", e );
}

View File

@ -67,6 +67,23 @@
</requirements>
</component>
<component>
<role>org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout</implementation>
</component>
<component>
<role>org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout</role>
<role-hint>legacy</role-hint>
<implementation>org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
</requirements>
</component>
<!--
|
| ArtifactHandlerManager
@ -82,7 +99,7 @@
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb</role-hint>

View File

@ -17,8 +17,8 @@
package org.apache.maven.artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
@ -47,8 +47,9 @@ public abstract class ArtifactComponentTestCase
protected abstract String component();
/** Return an existing file, not a directory - causes creation to fail. */
protected ArtifactRepository badLocalRepository() throws IOException
/** Return an existing file, not a directory - causes creation to fail.
* @throws Exception*/
protected ArtifactRepository badLocalRepository() throws Exception
{
String path = "target/test-classes/repositories/" + component() + "/bad-local-repository";
@ -56,45 +57,59 @@ public abstract class ArtifactComponentTestCase
f.createNewFile();
ArtifactRepository localRepository = new ArtifactRepository( "test", "file://" + f.getPath() );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository localRepository = new ArtifactRepository( "test", "file://" + f.getPath(), repoLayout );
return localRepository;
}
protected ArtifactRepository localRepository()
protected ArtifactRepository localRepository() throws Exception
{
String path = "target/test-classes/repositories/" + component() + "/local-repository";
File f = new File( getBasedir(), path );
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" + f.getPath() );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" + f.getPath(), repoLayout );
return localRepository;
}
protected ArtifactRepository remoteRepository()
protected ArtifactRepository remoteRepository() throws Exception
{
String path = "target/test-classes/repositories/" + component() + "/remote-repository";
File f = new File( getBasedir(), path );
ArtifactRepository repository = new ArtifactRepository( "test", "file://" + f.getPath() );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository repository = new ArtifactRepository( "test", "file://" + f.getPath(), repoLayout );
return repository;
}
protected ArtifactRepository badRemoteRepository()
protected ArtifactRepository badRemoteRepository() throws Exception
{
ArtifactRepository repository = new ArtifactRepository( "test", "http://foo.bar/repository" );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository repository = new ArtifactRepository( "test", "http://foo.bar/repository", repoLayout );
return repository;
}
protected void assertRemoteArtifactPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
protected void assertRemoteArtifactPresent( Artifact artifact ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
ArtifactRepository remoteRepo = remoteRepository();
File file = new File( remoteRepository().getBasedir(), path );
String path = remoteRepo.pathOf( artifact );
File file = new File( remoteRepo.getBasedir(), path );
if ( !file.exists() )
{
@ -102,11 +117,13 @@ public abstract class ArtifactComponentTestCase
}
}
protected void assertLocalArtifactPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
protected void assertLocalArtifactPresent( Artifact artifact ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
ArtifactRepository localRepo = localRepository();
File file = new File( localRepository().getBasedir(), path );
String path = localRepo.pathOf( artifact );
File file = new File( localRepo.getBasedir(), path );
if ( !file.exists() )
{
@ -114,11 +131,13 @@ public abstract class ArtifactComponentTestCase
}
}
protected void assertRemoteArtifactNotPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
protected void assertRemoteArtifactNotPresent( Artifact artifact ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
ArtifactRepository remoteRepo = remoteRepository();
File file = new File( remoteRepository().getBasedir(), path );
String path = remoteRepo.pathOf( artifact );
File file = new File( remoteRepo.getBasedir(), path );
if ( file.exists() )
{
@ -126,11 +145,13 @@ public abstract class ArtifactComponentTestCase
}
}
protected void assertLocalArtifactNotPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
protected void assertLocalArtifactNotPresent( Artifact artifact ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
ArtifactRepository localRepo = localRepository();
File file = new File( localRepository().getBasedir(), path );
String path = localRepo.pathOf( artifact );
File file = new File( localRepo.getBasedir(), path );
if ( file.exists() )
{
@ -142,7 +163,7 @@ public abstract class ArtifactComponentTestCase
//
// ----------------------------------------------------------------------
protected List remoteRepositories()
protected List remoteRepositories() throws Exception
{
List remoteRepositories = new ArrayList();
@ -185,7 +206,7 @@ public abstract class ArtifactComponentTestCase
protected void createArtifact( Artifact artifact, ArtifactRepository repository ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
String path = repository.pathOf( artifact );
File artifactFile = new File( repository.getBasedir(), path );
@ -223,7 +244,7 @@ public abstract class ArtifactComponentTestCase
protected void deleteArtifact( Artifact artifact, ArtifactRepository repository ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
String path = repository.pathOf( artifact );
File artifactFile = new File( repository.getBasedir(), path );

View File

@ -36,7 +36,6 @@ import java.util.Set;
// to change them when i change the layout of the repositories. So i want to generate
// the structure i want to test by using the artifact handler manager which dictates
// the layout used for a particular artifact type.
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -135,15 +134,13 @@ public class ArtifactResolverTest
return super.createArtifact( groupId, artifactId, version, type );
}
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository()
throws Exception
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() throws Exception
{
Artifact g = createLocalArtifact( "g", "1.0" );
Artifact h = createLocalArtifact( "h", "1.0" );
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
ArtifactMetadataSource mds = new ArtifactMetadataSource() {
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
@ -180,8 +177,7 @@ public class ArtifactResolverTest
Artifact j = createRemoteArtifact( "j", "1.0" );
deleteLocalArtifact( j );
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
ArtifactMetadataSource mds = new ArtifactMetadataSource() {
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
@ -209,7 +205,7 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( j );
}
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository()
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository() throws Exception
{
Artifact k = createArtifact( "k", "1.0" );
@ -224,8 +220,7 @@ public class ArtifactResolverTest
}
}
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood()
throws Exception
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throws Exception
{
Artifact l = createRemoteArtifact( "l", "1.0" );
deleteLocalArtifact( l );
@ -239,17 +234,17 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( l );
}
/*
public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepositoryAndLocalCannotBeCreated()
throws Exception
{
Artifact m = createRemoteArtifact( "m", "1.0" );
/*
public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepositoryAndLocalCannotBeCreated()
throws Exception
{
Artifact m = createRemoteArtifact( "m", "1.0" );
artifactResolver.resolve( m, remoteRepositories(), badLocalRepository() );
artifactResolver.resolve( m, remoteRepositories(), badLocalRepository() );
// TODO [failing test case]: throw and handle a more informative exception
}
*/
// TODO [failing test case]: throw and handle a more informative exception
}
*/
}

View File

@ -24,7 +24,6 @@ import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Repository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginExecutionException;
@ -82,8 +81,7 @@ public class DefaultMaven
// Project execution
// ----------------------------------------------------------------------
public MavenExecutionResponse execute( MavenExecutionRequest request )
throws ReactorException
public MavenExecutionResponse execute( MavenExecutionRequest request ) throws ReactorException
{
EventDispatcher dispatcher = request.getEventDispatcher();
String event = MavenEvents.REACTOR_EXECUTION;
@ -189,14 +187,9 @@ public class DefaultMaven
}
private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project,
EventDispatcher dispatcher, List goals )
throws Exception
EventDispatcher dispatcher, List goals ) throws Exception
{
MavenSession session = createSession( request );
session.setProject( project );
session.setRemoteRepositories( getArtifactRepositories( project, request.getSettings() ) );
MavenSession session = createSession( request, project );
resolveParameters( request );
@ -254,20 +247,7 @@ public class DefaultMaven
return response;
}
private List getArtifactRepositories( MavenProject project, MavenSettings settings )
{
List remoteRepos = new ArrayList();
for ( Iterator it = project.getRepositories().iterator(); it.hasNext(); )
{
Repository modelRepo = (Repository) it.next();
remoteRepos.add( artifactRepositoryFactory.createArtifactRepository( modelRepo, settings ) );
}
return remoteRepos;
}
public MavenProject getProject( File pom, ArtifactRepository localRepository )
throws ProjectBuildingException
public MavenProject getProject( File pom, ArtifactRepository localRepository ) throws ProjectBuildingException
{
if ( pom.exists() )
{
@ -289,18 +269,18 @@ public class DefaultMaven
// the session type would be specific to the request i.e. having a project
// or not.
protected MavenSession createSession( MavenExecutionRequest request )
protected MavenSession createSession( MavenExecutionRequest request, MavenProject project )
{
return new MavenSession( container, pluginManager, request.getSettings(), request.getLocalRepository(),
request.getEventDispatcher(), request.getLog(), request.getGoals() );
return new MavenSession( project, container, pluginManager, request.getSettings(),
request.getLocalRepository(), request.getEventDispatcher(), request.getLog(),
request.getGoals() );
}
/**
* @todo [BP] this might not be required if there is a better way to pass
* them in. It doesn't feel quite right.
*/
private void resolveParameters( MavenExecutionRequest request )
throws ComponentLookupException
private void resolveParameters( MavenExecutionRequest request ) throws ComponentLookupException
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
@ -320,8 +300,7 @@ public class DefaultMaven
// Lifecylce Management
// ----------------------------------------------------------------------
public void contextualize( Context context )
throws ContextException
public void contextualize( Context context ) throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
@ -398,8 +377,9 @@ public class DefaultMaven
Runtime r = Runtime.getRuntime();
getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" +
( r.totalMemory() / mb ) + "M" );
getLogger().info(
"Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/"
+ ( r.totalMemory() / mb ) + "M" );
}
protected void line()

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository;
* ====================================================================
*/
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Repository;
import org.apache.maven.settings.MavenSettings;
@ -28,6 +29,7 @@ public interface ArtifactRepositoryFactory
public static final String ROLE = ArtifactRepositoryFactory.class.getName();
public ArtifactRepository createArtifactRepository( Repository modelRepository, MavenSettings settings );
public ArtifactRepository createArtifactRepository( Repository modelRepository, MavenSettings settings,
ArtifactRepositoryLayout repositoryLayout );
}

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository;
* ====================================================================
*/
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Repository;
import org.apache.maven.settings.MavenSettings;
import org.apache.maven.settings.Server;
@ -32,7 +33,8 @@ public class DefaultArtifactRepositoryFactory
implements ArtifactRepositoryFactory
{
public ArtifactRepository createArtifactRepository( Repository modelRepository, MavenSettings settings )
public ArtifactRepository createArtifactRepository( Repository modelRepository, MavenSettings settings,
ArtifactRepositoryLayout repositoryLayout )
{
Server repoProfile = null;
@ -47,8 +49,9 @@ public class DefaultArtifactRepositoryFactory
Logger logger = getLogger();
if ( logger != null )
{
logger.warn( "Cannot associate authentication to repository with null id. The offending repository's URL is: "
+ modelRepository.getUrl() );
logger
.warn( "Cannot associate authentication to repository with null id. The offending repository's URL is: "
+ modelRepository.getUrl() );
}
}
@ -66,11 +69,12 @@ public class DefaultArtifactRepositoryFactory
authInfo.setPassphrase( repoProfile.getPassphrase() );
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl(), authInfo );
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl(), authInfo,
repositoryLayout );
}
else
{
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl() );
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl(), repositoryLayout );
}
return repo;

View File

@ -29,6 +29,7 @@ import org.apache.maven.MavenConstants;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
@ -66,8 +67,7 @@ public class MavenCli
public static File userDir = new File( System.getProperty( "user.dir" ) );
public static int main( String[] args, ClassWorld classWorld )
throws Exception
public static int main( String[] args, ClassWorld classWorld ) throws Exception
{
// ----------------------------------------------------------------------
// Setup the command line parser
@ -132,12 +132,32 @@ public class MavenCli
embedder.start( classWorld );
MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
MavenSettings settings = settingsBuilder.buildSettings();
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepository localRepository = getLocalRepository( settings, artifactRepositoryFactory );
MavenSettings settings = settingsBuilder.buildSettings();
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder
.lookup( ArtifactRepositoryFactory.ROLE );
// TODO: Switch the default repository layout id to "default" when the
// conversion is done.
String repoLayoutId = "legacy";
if ( commandLine.hasOption( CLIManager.VERSION_1_REPO ) )
{
repoLayoutId = "legacy";
}
if ( commandLine.hasOption( CLIManager.VERSION_2_REPO ) )
{
repoLayoutId = "default";
}
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) embedder
.lookup(
ArtifactRepositoryLayout.ROLE,
repoLayoutId );
ArtifactRepository localRepository = getLocalRepository( settings, artifactRepositoryFactory, repositoryLayout );
if ( commandLine.hasOption( CLIManager.REACTOR ) )
{
@ -146,10 +166,11 @@ public class MavenCli
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
request =
new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher,
commandLine.getArgList(),
FileUtils.getFiles( userDir, includes, excludes ), userDir.getPath() );
request = new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher,
commandLine.getArgList(), FileUtils.getFiles( userDir,
includes,
excludes ),
userDir.getPath() );
}
else
{
@ -204,9 +225,9 @@ public class MavenCli
}
}
// ----------------------------------------------------------------------
// System properties handling
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// System properties handling
// ----------------------------------------------------------------------
private static void initializeSystemProperties( CommandLine commandLine )
{
@ -250,9 +271,9 @@ public class MavenCli
System.setProperty( name, value );
}
// ----------------------------------------------------------------------
// Command line manager
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Command line manager
// ----------------------------------------------------------------------
static class CLIManager
{
@ -276,33 +297,48 @@ public class MavenCli
public static final char NON_RECURSIVE = 'N';
public static final char VERSION_1_REPO = 'A';
// TODO: this is a hack until we can get the main repo converted...
public static final char VERSION_2_REPO = 'a';
public CLIManager()
{
options = new Options();
options.addOption( OptionBuilder.withLongOpt( "nobanner" ).withDescription( "Suppress logo banner" ).create(
NO_BANNER ) );
options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription(
"Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
options.addOption( OptionBuilder.withLongOpt( "offline" ).hasArg().withDescription( "Work offline" ).create(
WORK_OFFLINE ) );
options.addOption( OptionBuilder.withLongOpt( "mojoDescriptors" ).withDescription(
"Display available mojoDescriptors" ).create( LIST_GOALS ) );
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create(
HELP ) );
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Build is happening offline" ).create(
WORK_OFFLINE ) );
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create(
VERSION ) );
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create(
DEBUG ) );
options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription(
"Execute goals for project found in the reactor" ).create( REACTOR ) );
options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription(
"Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
options.addOption( OptionBuilder.withLongOpt( "nobanner" ).withDescription( "Suppress logo banner" )
.create( NO_BANNER ) );
options
.addOption( OptionBuilder.withLongOpt( "define" ).hasArg()
.withDescription( "Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
options.addOption( OptionBuilder.withLongOpt( "offline" ).hasArg().withDescription( "Work offline" )
.create( WORK_OFFLINE ) );
options
.addOption( OptionBuilder.withLongOpt( "mojoDescriptors" )
.withDescription( "Display available mojoDescriptors" ).create( LIST_GOALS ) );
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" )
.create( HELP ) );
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Build is happening offline" )
.create( WORK_OFFLINE ) );
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" )
.create( VERSION ) );
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" )
.create( DEBUG ) );
options.addOption( OptionBuilder.withLongOpt( "reactor" )
.withDescription( "Execute goals for project found in the reactor" )
.create( REACTOR ) );
options.addOption( OptionBuilder.withLongOpt( "non-recursive" )
.withDescription( "Do not recurse into sub-projects" )
.create( NON_RECURSIVE ) );
options.addOption( OptionBuilder.withLongOpt( "v1-local-repository" )
.withDescription( "Use legacy layout for local artifact repository" )
.create( VERSION_1_REPO ) );
options.addOption( OptionBuilder.withLongOpt( "v2-local-repository" )
.withDescription( "Use new layout for local artifact repository" )
.create( VERSION_2_REPO ) );
}
public CommandLine parse( String[] args )
throws ParseException
public CommandLine parse( String[] args ) throws ParseException
{
CommandLineParser parser = new PosixParser();
return parser.parse( options, args );
@ -315,9 +351,9 @@ public class MavenCli
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
protected static File getUserConfigurationDirectory()
{
@ -326,7 +362,7 @@ public class MavenCli
{
if ( !mavenUserConfigurationDirectory.mkdirs() )
{
//throw a configuration exception
//throw a configuration exception
}
}
return mavenUserConfigurationDirectory;
@ -347,8 +383,9 @@ public class MavenCli
return mavenProperties;
}
protected static ArtifactRepository getLocalRepository( MavenSettings settings, ArtifactRepositoryFactory repoFactory )
throws Exception
protected static ArtifactRepository getLocalRepository( MavenSettings settings,
ArtifactRepositoryFactory repoFactory,
ArtifactRepositoryLayout repositoryLayout ) throws Exception
{
Profile profile = settings.getActiveProfile();
@ -361,11 +398,10 @@ public class MavenCli
if ( localRepository == null )
{
String userConfigurationDirectory = System.getProperty( "user.home" ) + "/.m2";
localRepository =
new File( userConfigurationDirectory, MavenConstants.MAVEN_REPOSITORY ).getAbsolutePath();
localRepository = new File( userConfigurationDirectory, MavenConstants.MAVEN_REPOSITORY ).getAbsolutePath();
}
// TODO [BP]: this should not be necessary - grep for and remove
// TODO [BP]: this should not be necessary - grep for and remove
System.setProperty( MavenConstants.MAVEN_REPO_LOCAL, localRepository );
Repository repo = new Repository();
@ -374,6 +410,6 @@ public class MavenCli
repo.setUrl( "file://" + localRepository );
return repoFactory.createArtifactRepository( repo, settings );
return repoFactory.createArtifactRepository( repo, settings, repositoryLayout );
}
}

View File

@ -30,10 +30,8 @@ import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
import org.codehaus.plexus.util.dag.Vertex;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -49,8 +47,6 @@ public class MavenSession
private PluginManager pluginManager;
private Set remoteRepositories;
private DAG dag;
private List goals;
@ -65,11 +61,12 @@ public class MavenSession
private final MavenSettings settings;
private List remoteArtifactRepos = Collections.EMPTY_LIST;
public MavenSession( PlexusContainer container, PluginManager pluginManager, MavenSettings settings,
ArtifactRepository localRepository, EventDispatcher eventDispatcher, Log log, List goals )
public MavenSession( MavenProject project, PlexusContainer container, PluginManager pluginManager,
MavenSettings settings, ArtifactRepository localRepository, EventDispatcher eventDispatcher,
Log log, List goals )
{
this.project = project;
this.container = container;
this.pluginManager = pluginManager;
@ -102,24 +99,14 @@ public class MavenSession
return project;
}
public void setProject( MavenProject project )
{
this.project = project;
}
public ArtifactRepository getLocalRepository()
{
return localRepository;
}
public void setRemoteRepositories(List remoteArtifactRepos)
{
this.remoteArtifactRepos = remoteArtifactRepos;
}
public List getRemoteRepositories()
{
return remoteArtifactRepos;
return project.getRemoteArtifactRepositories();
}
public List getGoals()
@ -179,4 +166,9 @@ public class MavenSession
return chainToHere;
}
public List getPluginRepositories()
{
return project.getPluginArtifactRepositories();
}
}

View File

@ -75,8 +75,7 @@ public class DefaultLifecycleExecutor
* @param tasks
* @param session
*/
public MavenExecutionResponse execute( List tasks, MavenSession session )
throws LifecycleExecutionException
public MavenExecutionResponse execute( List tasks, MavenSession session ) throws LifecycleExecutionException
{
MavenExecutionResponse response = new MavenExecutionResponse();
@ -206,8 +205,7 @@ public class DefaultLifecycleExecutor
* @param mavenSession
* @throws Exception
*/
private void processPluginPhases( Plugin plugin, MavenSession mavenSession, Map phaseMap )
throws Exception
private void processPluginPhases( Plugin plugin, MavenSession mavenSession, Map phaseMap ) throws Exception
{
String groupId = plugin.getGroupId();
@ -243,8 +241,8 @@ public class DefaultLifecycleExecutor
if ( mojoDescriptor == null )
{
throw new LifecycleExecutionException(
"A goal '" + mojoId + "' was declared in pom.xml, but does not exist" );
throw new LifecycleExecutionException( "A goal '" + mojoId
+ "' was declared in pom.xml, but does not exist" );
}
configureMojo( mojoDescriptor, phaseMap );
@ -269,8 +267,7 @@ public class DefaultLifecycleExecutor
* @param mojoDescriptor
* @throws Exception
*/
private void configureMojo( MojoDescriptor mojoDescriptor, Map phaseMap )
throws Exception
private void configureMojo( MojoDescriptor mojoDescriptor, Map phaseMap ) throws Exception
{
if ( mojoDescriptor.getPhase() != null )
{
@ -280,8 +277,7 @@ public class DefaultLifecycleExecutor
}
}
private void processGoalChain( String task, MavenSession session, Map phaseMap )
throws Exception
private void processGoalChain( String task, MavenSession session, Map phaseMap ) throws Exception
{
if ( phaseMap.containsKey( task ) )
{
@ -312,8 +308,7 @@ public class DefaultLifecycleExecutor
}
}
private void verifyMojoPhase( String task, MavenSession session, Map phaseMap )
throws Exception
private void verifyMojoPhase( String task, MavenSession session, Map phaseMap ) throws Exception
{
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
@ -332,8 +327,7 @@ public class DefaultLifecycleExecutor
configureMojo( mojoDescriptor, phaseMap );
}
private void executePhase( String phase, MavenSession session, Map phaseMap )
throws PluginExecutionException
private void executePhase( String phase, MavenSession session, Map phaseMap ) throws PluginExecutionException
{
// only execute up to the given phase
int index = phases.indexOf( phaseMap.get( phase ) );
@ -373,8 +367,7 @@ public class DefaultLifecycleExecutor
}
}
protected void executeMojo( String id, MavenSession session )
throws PluginExecutionException
protected void executeMojo( String id, MavenSession session ) throws PluginExecutionException
{
// ----------------------------------------------------------------------
// We have something of the form <pluginId>:<mojoId>, so this might be

View File

@ -19,7 +19,6 @@ package org.apache.maven.plugin;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.MavenMetadataSource;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@ -28,7 +27,6 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Repository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -38,7 +36,6 @@ import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.settings.MavenSettings;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.codehaus.plexus.ArtifactEnabledContainer;
import org.codehaus.plexus.PlexusConstants;
@ -84,8 +81,6 @@ public class DefaultPluginManager
protected PluginDescriptorBuilder pluginDescriptorBuilder;
protected List remotePluginRepositories;
protected ArtifactFilter artifactFilter;
protected PathTranslator pathTranslator;
@ -141,8 +136,7 @@ public class DefaultPluginManager
private Set pluginsInProcess = new HashSet();
public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor )
throws CycleDetectedException
public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor ) throws CycleDetectedException
{
if ( pluginsInProcess.contains( mavenPluginDescriptor.getPluginId() ) )
{
@ -213,8 +207,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
public void verifyPluginForGoal( String goalName, MavenSession session )
throws Exception
public void verifyPluginForGoal( String goalName, MavenSession session ) throws Exception
{
String pluginId = getPluginId( goalName );
@ -223,8 +216,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
public void verifyPlugin( String groupId, String artifactId, MavenSession session )
throws Exception
public void verifyPlugin( String groupId, String artifactId, MavenSession session ) throws Exception
{
if ( !isPluginInstalled( groupId, artifactId ) )
{
@ -286,8 +278,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
protected void addPlugin( Artifact pluginArtifact, MavenSession session )
throws Exception
protected void addPlugin( Artifact pluginArtifact, MavenSession session ) throws Exception
{
ArtifactResolver artifactResolver = null;
MavenProjectBuilder mavenProjectBuilder = null;
@ -301,7 +292,7 @@ public class DefaultPluginManager
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, artifactResolver,
remotePluginRepositories,
session.getPluginRepositories(),
session.getLocalRepository(), metadataSource,
artifactFilter );
}
@ -323,8 +314,7 @@ public class DefaultPluginManager
// Plugin execution
// ----------------------------------------------------------------------
public void executeMojo( MavenSession session, String goalName )
throws PluginExecutionException
public void executeMojo( MavenSession session, String goalName ) throws PluginExecutionException
{
try
{
@ -459,8 +449,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request )
throws Exception
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request ) throws Exception
{
if ( request != null && request.getParameters() != null )
{
@ -555,8 +544,7 @@ public class DefaultPluginManager
}
}
public Map createParameters( MojoDescriptor goal, MavenSession session )
throws PluginConfigurationException
public Map createParameters( MojoDescriptor goal, MavenSession session ) throws PluginConfigurationException
{
List parameters = goal.getParameters();
@ -616,8 +604,8 @@ public class DefaultPluginManager
if ( type != null && ( type.equals( "File" ) || type.equals( "java.io.File" ) ) )
{
value = pathTranslator.alignToBaseDirectory( (String) value,
session.getProject().getFile().getParentFile() );
value = pathTranslator.alignToBaseDirectory( (String) value, session.getProject().getFile()
.getParentFile() );
map.put( key, value );
}
}
@ -674,8 +662,8 @@ public class DefaultPluginManager
{
StringBuffer message = new StringBuffer();
message.append( "The '" + parameter.getName() ).append( "' parameter is required for the execution of the " ).append(
mojo.getId() ).append( " mojo and cannot be null." );
message.append( "The '" + parameter.getName() ).append( "' parameter is required for the execution of the " )
.append( mojo.getId() ).append( " mojo and cannot be null." );
return message.toString();
}
@ -684,8 +672,7 @@ public class DefaultPluginManager
// Lifecycle
// ----------------------------------------------------------------------
public void contextualize( Context context )
throws ContextException
public void contextualize( Context context ) throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
@ -693,35 +680,19 @@ public class DefaultPluginManager
public void initialize()
{
// TODO: configure this from bootstrap or scan lib
artifactFilter = new ExclusionSetFilter( new String[]{"maven-core", "maven-artifact", "maven-model",
"maven-settings", "maven-monitor", "maven-plugin",
"plexus-container-api", "plexus-container-default",
"plexus-artifact-container", "wagon-provider-api",
"classworlds"} );
artifactFilter = new ExclusionSetFilter( new String[] {
"maven-core",
"maven-artifact",
"maven-model",
"maven-settings",
"maven-monitor",
"maven-plugin",
"plexus-container-api",
"plexus-container-default",
"plexus-artifact-container",
"wagon-provider-api",
"classworlds" } );
// TODO: move this to be configurable from the Maven component
remotePluginRepositories = new ArrayList();
// TODO: needs to be configured from the POM element
MavenSettings settings = null;
try
{
settings = mavenSettingsBuilder.buildSettings();
}
catch ( Exception e )
{
getLogger().error( "Failed to build MavenSettings from xml file. Using defaults.", e );
settings = new MavenSettings();
}
Repository pluginRepo = new Repository();
pluginRepo.setId( "plugin-repository" );
pluginRepo.setUrl( "http://repo1.maven.org" );
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( pluginRepo, settings );
remotePluginRepositories.add( pluginRepository );
}
// ----------------------------------------------------------------------
@ -729,7 +700,7 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver,
MavenProjectBuilder mavenProjectBuilder )
MavenProjectBuilder mavenProjectBuilder )
throws ArtifactResolutionException
{
MavenProject project = context.getProject();

View File

@ -22,9 +22,11 @@ import org.apache.maven.artifact.MavenMetadataSource;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
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.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
@ -38,7 +40,12 @@ import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.settings.MavenSettings;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.StringUtils;
@ -61,8 +68,10 @@ import java.util.Map;
*/
public class DefaultMavenProjectBuilder
extends AbstractLogEnabled
implements MavenProjectBuilder, Initializable
implements MavenProjectBuilder, Initializable, Contextualizable
{
private PlexusContainer container;
private ArtifactResolver artifactResolver;
private ArtifactFactory artifactFactory;
@ -100,8 +109,7 @@ public class DefaultMavenProjectBuilder
return build( project, localRepository, true, true );
}
public MavenProject build( File project, ArtifactRepository localRepository )
throws ProjectBuildingException
public MavenProject build( File project, ArtifactRepository localRepository ) throws ProjectBuildingException
{
return build( project, localRepository, false, true );
}
@ -113,8 +121,7 @@ public class DefaultMavenProjectBuilder
}
private MavenProject build( File projectDescriptor, ArtifactRepository localRepository,
boolean resolveDependencies, boolean sourceProject )
throws ProjectBuildingException
boolean resolveDependencies, boolean sourceProject ) throws ProjectBuildingException
{
try
{
@ -137,7 +144,8 @@ public class DefaultMavenProjectBuilder
previous = current;
}
project = processProjectLogic( project, localRepository, resolveDependencies, sourceProject );
project = processProjectLogic( project, localRepository, aggregatedRemoteWagonRepositories,
resolveDependencies, sourceProject );
return project;
}
@ -148,7 +156,7 @@ public class DefaultMavenProjectBuilder
}
private MavenProject processProjectLogic( MavenProject project, ArtifactRepository localRepository,
boolean resolveDependencies, boolean sourceProject )
List remoteRepositories, boolean resolveDependencies, boolean sourceProject )
throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException
{
Model model = project.getModel();
@ -173,8 +181,34 @@ public class DefaultMavenProjectBuilder
}
project = new MavenProject( model );
try
{
project.setPluginArtifactRepositories( buildPluginRepositories( model.getPluginRepositories() ) );
}
catch ( Exception e )
{
throw new ProjectBuildingException( "Error building plugin repository list.", e );
}
DistributionManagement dm = model.getDistributionManagement();
if ( dm != null )
{
try
{
project
.setDistributionManagementArtifactRepository( buildDistributionManagementRepository( dm
.getRepository() ) );
}
catch ( Exception e )
{
throw new ProjectBuildingException( "Error building distribution management repository.", e );
}
}
project.setFile( projectDescriptor );
project.setParent( parentProject );
project.setRemoteArtifactRepositories( remoteRepositories );
project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) );
// ----------------------------------------------------------------------
@ -191,11 +225,10 @@ public class DefaultMavenProjectBuilder
if ( resolveDependencies )
{
List repos = buildArtifactRepositories( project.getRepositories() );
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), repos,
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
remoteRepositories,
localRepository, sourceReader );
project.addArtifacts( result.getArtifacts().values() );
@ -216,7 +249,7 @@ public class DefaultMavenProjectBuilder
}
private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository,
LinkedList lineage, List aggregatedRemoteWagonRepositories )
LinkedList lineage, List aggregatedRemoteWagonRepositories )
throws ProjectBuildingException
{
Model model = readModel( projectDescriptor );
@ -228,8 +261,7 @@ public class DefaultMavenProjectBuilder
}
private MavenProject assembleLineage( Model model, ArtifactRepository localRepository, LinkedList lineage,
List aggregatedRemoteWagonRepositories )
throws ProjectBuildingException
List aggregatedRemoteWagonRepositories ) throws ProjectBuildingException
{
MavenProject project = new MavenProject( model );
@ -261,8 +293,8 @@ public class DefaultMavenProjectBuilder
// as we go in order to do this.
// ----------------------------------------------------------------------
aggregatedRemoteWagonRepositories.addAll(
buildArtifactRepositories( project.getModel().getRepositories() ) );
aggregatedRemoteWagonRepositories
.addAll( buildArtifactRepositories( project.getModel().getRepositories() ) );
MavenProject parent;
Model cachedModel = getCachedModel( parentModel.getGroupId(), parentModel.getArtifactId(),
@ -283,8 +315,7 @@ public class DefaultMavenProjectBuilder
return project;
}
private List buildArtifactRepositories( List repositories )
throws ProjectBuildingException
private List buildArtifactRepositories( List repositories ) throws ProjectBuildingException
{
MavenSettings settings = null;
@ -298,11 +329,26 @@ public class DefaultMavenProjectBuilder
}
List repos = new ArrayList();
// TODO: Replace with repository layout detection. This is a nasty hack.
String remoteRepoLayoutId = "legacy";
ArtifactRepositoryLayout remoteRepoLayout = null;
try
{
remoteRepoLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
remoteRepoLayoutId );
}
catch ( ComponentLookupException e )
{
throw new ProjectBuildingException( "Cannot find repository layout for: \'" + remoteRepoLayoutId + "\'.", e );
}
for ( Iterator i = repositories.iterator(); i.hasNext(); )
{
Repository mavenRepo = (Repository) i.next();
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo, settings );
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo, settings,
remoteRepoLayout );
if ( !repos.contains( artifactRepo ) )
{
@ -312,8 +358,55 @@ public class DefaultMavenProjectBuilder
return repos;
}
private Model readModel( File file )
throws ProjectBuildingException
private List buildPluginRepositories( List pluginRepositories ) throws Exception
{
List remotePluginRepositories = new ArrayList();
// TODO: needs to be configured from the POM element
MavenSettings settings = mavenSettingsBuilder.buildSettings();
Repository pluginRepo = new Repository();
pluginRepo.setId( "plugin-repository" );
pluginRepo.setUrl( "http://repo1.maven.org" );
// TODO: [jc] change this to detect the repository layout type somehow...
String repoLayoutId = "legacy";
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) container
.lookup(
ArtifactRepositoryLayout.ROLE,
repoLayoutId );
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( pluginRepo, settings,
repositoryLayout );
remotePluginRepositories.add( pluginRepository );
return remotePluginRepositories;
}
private ArtifactRepository buildDistributionManagementRepository( Repository dmRepo ) throws Exception
{
// TODO: needs to be configured from the POM element
MavenSettings settings = mavenSettingsBuilder.buildSettings();
// TODO: [jc] change this to detect the repository layout type somehow...
String repoLayoutId = "legacy";
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) container
.lookup(
ArtifactRepositoryLayout.ROLE,
repoLayoutId );
ArtifactRepository dmArtifactRepository = artifactRepositoryFactory.createArtifactRepository( dmRepo, settings,
repositoryLayout );
return dmArtifactRepository;
}
private Model readModel( File file ) throws ProjectBuildingException
{
try
{
@ -326,12 +419,12 @@ public class DefaultMavenProjectBuilder
catch ( Exception e )
{
throw new ProjectBuildingException(
"Error while reading model from file '" + file.getAbsolutePath() + "'.", e );
"Error while reading model from file '" + file.getAbsolutePath() + "'.",
e );
}
}
private Model readModel( URL url )
throws ProjectBuildingException
private Model readModel( URL url ) throws ProjectBuildingException
{
try
{
@ -360,8 +453,8 @@ public class DefaultMavenProjectBuilder
catch ( ArtifactResolutionException e )
{
// @todo use parent.toString() if modello could generate it, or specify in a code segment
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":" +
parent.getArtifactId() + "-" + parent.getVersion(), e );
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":"
+ parent.getArtifactId() + "-" + parent.getVersion(), e );
}
return artifact.getFile();
@ -381,20 +474,22 @@ public class DefaultMavenProjectBuilder
throws ProjectBuildingException
{
Model superModel = getSuperModel();
superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID );
superModel.setArtifactId( STANDALONE_SUPERPOM_ARTIFACTID );
superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
MavenProject project = new MavenProject( superModel );
try
{
project.setFile( new File( ".", "pom.xml" ) );
project = processProjectLogic( project, localRepository, false, false );
List remoteRepositories = buildArtifactRepositories( superModel.getRepositories() );
project = processProjectLogic( project, localRepository, remoteRepositories, false, false );
return project;
}
@ -412,11 +507,15 @@ public class DefaultMavenProjectBuilder
//
// ----------------------------------------------------------------------
private Model getSuperModel()
throws ProjectBuildingException
private Model getSuperModel() throws ProjectBuildingException
{
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MavenConstants.MAVEN_MODEL_VERSION + ".xml" );
return readModel( url );
}
public void contextualize( Context context ) throws Exception
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
@ -73,8 +74,10 @@ public class MavenProject
private Set artifacts;
private List remoteArtifactRepositories;
private List collectedProjects = Collections.EMPTY_LIST;
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public MavenProject( Model model )
@ -102,6 +105,16 @@ public class MavenProject
this.parent = parent;
}
public void setRemoteArtifactRepositories( List remoteArtifactRepositories )
{
this.remoteArtifactRepositories = remoteArtifactRepositories;
}
public List getRemoteArtifactRepositories()
{
return remoteArtifactRepositories;
}
public boolean hasParent()
{
return getParent() != null;
@ -147,6 +160,10 @@ public class MavenProject
private List scriptSourceRoots = new ArrayList();
private List pluginArtifactRepositories;
private ArtifactRepository distMgmtArtifactRepository;
public void addCompileSourceRoot( String path )
{
if ( path != null )
@ -237,8 +254,8 @@ public class MavenProject
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals(
a.getScope() ) )
if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() )
|| Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
list.add( a.getPath() );
}
@ -592,8 +609,7 @@ public class MavenProject
* <li>do a topo sort on the graph that remains.</li>
* </ul>
*/
public static List getSortedProjects( List projects )
throws CycleDetectedException
public static List getSortedProjects( List projects ) throws CycleDetectedException
{
DAG dag = new DAG();
@ -652,7 +668,7 @@ public class MavenProject
public void addArtifacts( Collection newArtifacts )
{
// project.getArtifacts().addAll( result.getArtifacts().values() );
// project.getArtifacts().addAll( result.getArtifacts().values() );
// We need to override the scope if one declared it higher
// TODO: could surely be more efficient, and use the scope handler, be part of maven-artifact...
Map artifacts = new HashMap();
@ -669,14 +685,13 @@ public class MavenProject
{
Artifact existing = (Artifact) artifacts.get( id );
boolean updateScope = false;
if ( Artifact.SCOPE_RUNTIME.equals( a.getScope() ) &&
Artifact.SCOPE_TEST.equals( existing.getScope() ) )
if ( Artifact.SCOPE_RUNTIME.equals( a.getScope() ) && Artifact.SCOPE_TEST.equals( existing.getScope() ) )
{
updateScope = true;
}
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) &&
!Artifact.SCOPE_COMPILE.equals( existing.getScope() ) )
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() )
&& !Artifact.SCOPE_COMPILE.equals( existing.getScope() ) )
{
updateScope = true;
}
@ -685,11 +700,10 @@ public class MavenProject
{
// TODO: Artifact factory?
// TODO: [jc] Is this a better way to centralize artifact construction here?
Artifact artifact = artifactConstructionSupport.createArtifact( existing.getGroupId(),
existing.getArtifactId(),
existing.getVersion(),
a.getScope(),
existing.getType(),
Artifact artifact = artifactConstructionSupport.createArtifact( existing.getGroupId(),
existing.getArtifactId(),
existing.getVersion(),
a.getScope(), existing.getType(),
existing.getExtension() );
artifacts.put( id, artifact );
@ -702,5 +716,26 @@ public class MavenProject
}
setArtifacts( new HashSet( artifacts.values() ) );
}
public void setPluginArtifactRepositories( List pluginArtifactRepositories )
{
this.pluginArtifactRepositories = pluginArtifactRepositories;
}
public List getPluginArtifactRepositories()
{
return pluginArtifactRepositories;
}
public void setDistributionManagementArtifactRepository( ArtifactRepository distMgmtArtifactRepository )
{
this.distMgmtArtifactRepository = distMgmtArtifactRepository;
}
public ArtifactRepository getDistributionManagementArtifactRepository()
{
return distMgmtArtifactRepository;
}
}

View File

@ -17,6 +17,7 @@ package org.apache.maven;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@ -36,8 +37,7 @@ public class MavenTestCase
protected MavenProjectBuilder projectBuilder;
protected void setUp()
throws Exception
protected void setUp() throws Exception
{
super.setUp();
@ -70,9 +70,13 @@ public class MavenTestCase
return resourceFile;
}
protected ArtifactRepository getLocalRepository()
protected ArtifactRepository getLocalRepository() throws Exception
{
ArtifactRepository r = new ArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath() );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository r = new ArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(),
repoLayout );
return r;
}
@ -81,16 +85,14 @@ public class MavenTestCase
// Project building
// ----------------------------------------------------------------------
protected MavenProject getProjectWithDependencies( File pom )
throws Exception
protected MavenProject getProjectWithDependencies( File pom ) throws Exception
{
return projectBuilder.buildWithDependencies( pom, getLocalRepository() );
}
protected MavenProject getProject( File pom )
throws Exception
protected MavenProject getProject( File pom ) throws Exception
{
return projectBuilder.build( pom, getLocalRepository() );
}
}
}

View File

@ -2,6 +2,7 @@ package org.apache.maven.plugin;
import org.apache.maven.MavenTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
@ -37,17 +38,13 @@ public class PluginParameterExpressionEvaluatorTest
{
String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
ArtifactRepository repo = new ArtifactRepository( "local", "here" );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository repo = new ArtifactRepository( "local", "here", repoLayout );
PluginManager mgr = (PluginManager) lookup( PluginManager.ROLE );
PlexusContainer container = getContainer();
MavenSession session = new MavenSession( container,
mgr,
new MavenSettings(),
repo,
new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Build build = new Build();
build.setDirectory( expected.substring( 0, expected.length() - "/classes".length() ) );
@ -58,7 +55,9 @@ public class PluginParameterExpressionEvaluatorTest
MavenProject project = new MavenProject( model );
project.setFile( new File( "pom.xml" ).getCanonicalFile() );
session.setProject( project );
MavenSession session = new MavenSession( project, container, mgr, new MavenSettings(), repo,
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", session );
@ -74,17 +73,18 @@ public class PluginParameterExpressionEvaluatorTest
{
String role = "#component.org.apache.maven.project.MavenProjectBuilder";
ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com" );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com", repoLayout );
PluginManager mgr = (PluginManager) lookup( PluginManager.ROLE );
PlexusContainer container = getContainer();
MavenSession session = new MavenSession( container,
mgr,
new MavenSettings(),
repo,
new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ),
MavenSession session = new MavenSession( null, // don't need a project for this test.
container, mgr, new MavenSettings(), repo,
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Object value = PluginParameterExpressionEvaluator.evaluate( role, session );
assertNotNull( value );
@ -92,20 +92,20 @@ public class PluginParameterExpressionEvaluatorTest
public void testLocalRepositoryExtraction() throws Exception
{
ArtifactRepository repo = new ArtifactRepository( "local", "target/repo" );
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository repo = new ArtifactRepository( "local", "target/repo", repoLayout );
PluginManager mgr = (PluginManager) lookup( PluginManager.ROLE );
PlexusContainer container = getContainer();
MavenSession session = new MavenSession( container,
mgr,
new MavenSettings(),
repo,
new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ),
MavenSession session = new MavenSession( null, // don't need a project for this test.
container, mgr, new MavenSettings(), repo,
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", session );
assertEquals( "local", ((ArtifactRepository) value).getId() );
assertEquals( "local", ( (ArtifactRepository) value ).getId() );
}
}

View File

@ -20,7 +20,6 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.MavenMetadataSource;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.factory.DefaultArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -43,7 +42,7 @@ public class ProjectClasspathArtifactResolver
extends MavenMetadataSource
{
private ArtifactFactory artifactFactory = new DefaultArtifactFactory();
public Source( ArtifactResolver artifactResolver )
{
super( artifactResolver );
@ -75,25 +74,29 @@ public class ProjectClasspathArtifactResolver
}
protected void setLocalRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactHandlerNotFoundException
{
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source, ArtifactFilter filter )
ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifacts, remoteRepositories, localRepository, new Source( this ), filter );
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifacts, remoteRepositories, localRepository, new Source( this ) );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifact, remoteRepositories, localRepository, new Source( this ) );
}

View File

@ -20,14 +20,10 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.MavenSettings;
import java.io.File;
@ -51,19 +47,11 @@ import java.io.File;
* description=""
*
* @parameter
* name="artifactRepositoryFactory"
* type="org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* name="deploymentRepository"
* type="org.apache.maven.artifact.repository.ArtifactRepository"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* description=""
*
* @parameter
* name="settings"
* type="org.apache.maven.settings.MavenSettings"
* required="true"
* validator=""
* expression="#settings"
* expression="#project.distributionManagementArtifactRepository"
* description=""
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
@ -73,39 +61,26 @@ public abstract class AbstractDeployMojo
extends AbstractPlugin
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" );
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) request.getParameter( "artifactRepositoryFactory" );
MavenSettings settings = (MavenSettings) request.getParameter( "settings" );
DistributionManagement distributionManagement = project.getDistributionManagement();
ArtifactRepository deploymentRepository = (ArtifactRepository) request.getParameter( "deploymentRepository" );
if ( distributionManagement == null )
if ( deploymentRepository == null )
{
String msg = "Deployment failed: distributionManagement element" + " was not specified in the pom";
String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
+ " distributionManagement element";
throw new Exception( msg );
}
Repository repository = distributionManagement.getRepository();
if ( repository == null )
if ( deploymentRepository.getAuthenticationInfo() == null )
{
String msg = "Deployment failed: repository element" + " was not specified in the pom inside" +
" distributionManagement element";
throw new Exception( msg );
}
ArtifactRepository deploymentRepository = artifactRepositoryFactory.createArtifactRepository( repository, settings );
if(deploymentRepository.getAuthenticationInfo() == null)
{
getLog().warn("Deployment repository {id: \'" + repository.getId() + "\'} has no associated authentication info!");
getLog().warn(
"Deployment repository {id: \'" + deploymentRepository.getId()
+ "\'} has no associated authentication info!" );
}
// Deploy the POM

View File

@ -38,19 +38,11 @@ package org.apache.maven.plugin.deploy;
* description=""
*
* @parameter
* name="artifactRepositoryFactory"
* type="org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* name="deploymentRepository"
* type="org.apache.maven.artifact.repository.ArtifactRepository"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* description=""
*
* @parameter
* name="settings"
* type="org.apache.maven.settings.MavenSettings"
* required="true"
* validator=""
* expression="#settings"
* expression="#project.distributionManagementArtifactRepository"
* description=""
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@ -59,4 +51,4 @@ package org.apache.maven.plugin.deploy;
public class DeployMojo
extends AbstractDeployMojo
{
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin.jar;
package org.apache.maven.plugin.ejb;
/*
* Copyright 2001-2005 The Apache Software Foundation.
@ -113,8 +113,7 @@ public class EjbMojo
/**
* @todo Add license files in META-INF directory.
*/
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
// ----------------------------------------------------------------------
//
@ -142,8 +141,8 @@ public class EjbMojo
String ejbJarXmlFile = "META-INF/ejb-jar.xml";
archiver.getArchiver().addDirectory( new File( outputDirectory ), new String[]{"**/**"},
new String[]{ejbJarXmlFile, "**/package.html"} );
archiver.getArchiver().addDirectory( new File( outputDirectory ), new String[] { "**/**" },
new String[] { ejbJarXmlFile, "**/package.html" } );
archiver.getArchiver().addFile( new File( outputDirectory, ejbJarXmlFile ), ejbJarXmlFile );
@ -160,12 +159,17 @@ public class EjbMojo
clientArchiver.setOutputFile( jarFile );
clientArchiver.getArchiver().addDirectory( new File( outputDirectory ), new String[]{"**/**"},
new String[]{"**/*Bean.class", "**/*CMP.class",
"**/*Session.class", "**/package.html"} );
clientArchiver.getArchiver().addDirectory(
new File( outputDirectory ),
new String[] { "**/**" },
new String[] {
"**/*Bean.class",
"**/*CMP.class",
"**/*Session.class",
"**/package.html" } );
// create archive
clientArchiver.createArchive( request );
}
}
}
}

View File

@ -30,46 +30,51 @@ import org.apache.maven.project.MavenProject;
/**
* @goal deploy
* @description deploys a JAR to remote repository
* @parameter name="project" type="org.apache.maven.project.MavenProject"
* required="true" validator="" expression="#project" description=""
* @parameter name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
* @parameter name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true" validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true" validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* @parameter
* name="deploymentRepository"
* type="org.apache.maven.artifact.repository.ArtifactRepository"
* required="true"
* validator=""
* expression="#project.distributionManagementArtifactRepository"
* description=""
*
*/
public class JarDeployMojo
extends AbstractPlugin
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" );
//@todo this will be duplicated in case of every mojo which implements
// deploy goal
// this should be pushed into the ArtifactDeployer component
DistributionManagement distributionManagement = project.getDistributionManagement();
ArtifactRepository deploymentRepository = (ArtifactRepository) request.getParameter( "deploymentRepository" );
if ( distributionManagement == null )
if ( deploymentRepository == null )
{
String msg = "Deployment failed: distributionManagement element" + " was not specified in the pom";
String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
+ " distributionManagement element";
throw new Exception( msg );
}
Repository repository = distributionManagement.getRepository();
if ( repository == null )
if ( deploymentRepository.getAuthenticationInfo() == null )
{
String msg = "Deployment failed: repository element" + " was not specified in the pom inside" +
" distributionManagement element";
throw new Exception( msg );
getLog().warn(
"Deployment repository {id: \'" + deploymentRepository.getId()
+ "\'} has no associated authentication info!" );
}
ArtifactRepository deploymentRepository = new ArtifactRepository( repository.getId(), repository.getUrl() );
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
project.getPackaging() );

View File

@ -33,67 +33,55 @@ import java.io.File;
/**
* @goal deploy
* @description deploys a pom to remote repository
* @parameter name="project" type="org.apache.maven.project.MavenProject"
* required="true" validator="" expression="#project" description=""
* @parameter name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true" validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* @parameter name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
* @parameter name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* @parameter name="artifactRepositoryFactory"
* type="org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* description=""
* @parameter name="settings"
* type="org.apache.maven.settings.MavenSettings"
* required="true"
* validator=""
* expression="#settings"
* description=""
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* @parameter
* name="deploymentRepository"
* type="org.apache.maven.artifact.repository.ArtifactRepository"
* required="true"
* validator=""
* expression="#project.distributionManagementArtifactRepository"
* description=""
*/
public class PomDeployMojo
extends AbstractPlugin
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" );
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) request.getParameter(
"artifactRepositoryFactory" );
ArtifactRepository deploymentRepository = (ArtifactRepository) request.getParameter( "deploymentRepository" );
MavenSettings settings = (MavenSettings) request.getParameter( "settings" );
// TODO: validation instead
if ( project.getDistributionManagement() == null )
if ( deploymentRepository == null )
{
// TODO: simple failure response
throw new Exception( "distributionManagement is required for deployment" );
String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
+ " distributionManagement element";
throw new Exception( msg );
}
Repository repository = project.getDistributionManagement().getRepository();
ArtifactRepository deploymentRepository = artifactRepositoryFactory.createArtifactRepository( repository,
settings );
if ( deploymentRepository.getAuthenticationInfo() == null )
{
getLog().warn(
"Deployment repository {id: \'" + repository.getId() + "\'} has no associated authentication info!" );
"Deployment repository {id: \'" + deploymentRepository.getId()
+ "\'} has no associated authentication info!" );
}
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),