o Removed AuthenticationInfoProvider stuff

o Added ArtifactRepositoryFactory stuff to construct with AuthenticationInfo if possible.
o Added UserModelBuilder stuff for componentizing UserModel construction.
  -> DefaultUserModelBuilder has a configuration point 'userModelPath' which can redirect where it reads user.xml from (${user.home} is substitutable here).
o Added warning message to deployment plugin when deployment repo has no authentication info available.
o Added warning message for repos with null <id/> (auth info cannot be assigned here).
o Added a couple of debug-level messages for aid in debugging repo- and userModel-related problems.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163558 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-15 21:41:06 +00:00
parent 56708f7983
commit 4d1ca8da33
42 changed files with 660 additions and 253 deletions

View File

@ -16,7 +16,6 @@ package org.apache.maven.artifact.manager;
import org.apache.maven.artifact.AbstractArtifactComponent;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
@ -51,8 +50,6 @@ public class DefaultWagonManager
private TransferListener downloadMonitor;
private AuthenticationInfoProvider authenticationInfoProvider;
public Wagon getWagon( String protocol ) throws UnsupportedProtocolException
{
Wagon wagon;
@ -79,8 +76,6 @@ public class DefaultWagonManager
// TODO: don't throw exception
public void put( File source, Artifact artifact, ArtifactRepository repository ) throws Exception
{
authenticationInfoProvider.configureAuthenticationInfo( repository );
Wagon wagon = getWagon( repository.getProtocol() );
wagon.connect( repository, getProxy( repository.getProtocol() ) );
@ -134,8 +129,6 @@ public class DefaultWagonManager
try
{
authenticationInfoProvider.configureAuthenticationInfo( repository );
Wagon wagon = getWagon( repository.getProtocol() );
// ----------------------------------------------------------------------

View File

@ -16,6 +16,7 @@ package org.apache.maven.artifact.repository;
* limitations under the License.
*/
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.repository.Repository;
/**
@ -28,15 +29,17 @@ import org.apache.maven.wagon.repository.Repository;
public class ArtifactRepository
extends Repository
{
// public ArtifactRepository()
// {
// }
public ArtifactRepository( String id, String url )
{
super( id, url );
}
public ArtifactRepository( String id, String url, AuthenticationInfo authInfo )
{
super( id, url, authInfo );
}
/*
* private String layout; public String getLayout() { if ( layout == null ) {
* return "${groupId}/${type}s/${artifactId}-${version}.${extension}"; }

View File

@ -1,15 +0,0 @@
package org.apache.maven.artifact.repository.authentication;
import org.apache.maven.wagon.repository.Repository;
/**
* @author jdcasey
*/
public interface AuthenticationInfoProvider
{
public static final String ROLE = AuthenticationInfoProvider.class.getName();
// TODO: do not throw Exception.
void configureAuthenticationInfo( Repository wagonRepository ) throws Exception;
}

View File

@ -10,6 +10,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
import org.apache.maven.wagon.TransferFailedException;
import org.codehaus.plexus.logging.Logger;
import java.util.Collections;
import java.util.HashMap;
@ -60,6 +61,11 @@ public class DefaultArtifactResolver
try
{
Logger logger = getLogger();
logger.debug("Resolving: " + artifact.getId() + " from:\n" +
"{localRepository: " + localRepository + "}\n" +
"{remoteRepositories: " + remoteRepositories + "}");
setLocalRepositoryPath( artifact, localRepository );
if ( artifact.exists() )

View File

@ -31,12 +31,9 @@
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
</requirement>
</requirements>
</component>
<!--
|
| ArtifactInstaller

View File

@ -1,16 +0,0 @@
package org.apache.maven.artifact.repository.authentication;
import org.apache.maven.wagon.repository.Repository;
/**
* @author jdcasey
*/
public class DummyAuthenticationInfoProvider
implements AuthenticationInfoProvider
{
public void configureAuthenticationInfo( Repository wagonRepository ) throws Exception
{
}
}

View File

@ -18,7 +18,6 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactComponentTestCase;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;

View File

@ -0,0 +1,10 @@
*~
*.log
target
*.ipr
*.iws
dist
target
.classpath
.project
log.txt

View File

@ -0,0 +1 @@
deploy

View File

@ -0,0 +1,21 @@
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-core-it0018</artifactId>
<version>1.0</version>
<distributionManagement>
<repository>
<id>repo1</id>
<name>Maven Repository</name>
<url>scp://repo1.maven.org/home/projects/maven/mboot-repository</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
</dependencies>
</model>

View File

@ -0,0 +1,16 @@
package org.apache.maven.it1004;
public class Person
{
private String name;
public void setName( String name )
{
this.name = name;
}
public String getName()
{
return name;
}
}

View File

@ -19,14 +19,17 @@ package org.apache.maven;
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.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.GoalNotFoundException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Repository;
import org.apache.maven.model.user.ProxyProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.UserModelUtils;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginManager;
@ -34,7 +37,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.ReactorException;
import org.apache.maven.util.UserModelUtils;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -76,6 +78,8 @@ public class DefaultMaven
protected LifecycleExecutor lifecycleExecutor;
protected PlexusContainer container;
protected ArtifactRepositoryFactory artifactRepositoryFactory;
// ----------------------------------------------------------------------
// Project execution
@ -209,6 +213,8 @@ public class DefaultMaven
MavenSession session = createSession( request );
session.setProject( project );
session.setRemoteRepositories( getArtifactRepositories( project, request.getUserModel() ) );
resolveParameters( request );
@ -255,6 +261,18 @@ public class DefaultMaven
return response;
}
private List getArtifactRepositories( MavenProject project, UserModel userModel )
{
List remoteRepos = new ArrayList();
for ( Iterator it = project.getRepositories().iterator(); it.hasNext(); )
{
Repository modelRepo = (Repository) it.next();
remoteRepos.add( artifactRepositoryFactory.createArtifactRepository( modelRepo, userModel ) );
}
return remoteRepos;
}
public MavenProject getProject( File pom, ArtifactRepository localRepository )
throws ProjectBuildingException
{

View File

@ -0,0 +1,33 @@
package org.apache.maven.artifact.repository;
/* ====================================================================
* 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.model.Repository;
import org.apache.maven.model.user.UserModel;
/**
* @author jdcasey
*/
public interface ArtifactRepositoryFactory
{
public static final String ROLE = ArtifactRepositoryFactory.class.getName();
public ArtifactRepository createArtifactRepository( Repository modelRepository, UserModel userModel );
}

View File

@ -0,0 +1,80 @@
package org.apache.maven.artifact.repository;
/* ====================================================================
* 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.model.Repository;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.UserModelUtils;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
/**
* @author jdcasey
*/
public class DefaultArtifactRepositoryFactory
extends AbstractLogEnabled
implements ArtifactRepositoryFactory
{
public ArtifactRepository createArtifactRepository( Repository modelRepository, UserModel userModel )
{
ServerProfile repoProfile = null;
String repoId = modelRepository.getId();
if ( repoId != null && repoId.length() > 0 )
{
repoProfile = UserModelUtils.getServerProfile( userModel, modelRepository.getId() );
}
else
{
Logger logger = getLogger();
if ( logger != null )
{
logger.warn( "Cannot associate authentication to repository with null id. The offending repository's URL is: "
+ modelRepository.getUrl() );
}
}
ArtifactRepository repo = null;
if ( repoProfile != null )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName( repoProfile.getUsername() );
authInfo.setPassword( repoProfile.getPassword() );
authInfo.setPrivateKey( repoProfile.getPrivateKey() );
authInfo.setPassphrase( repoProfile.getPassphrase() );
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl(), authInfo );
}
else
{
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl() );
}
return repo;
}
}

View File

@ -1,39 +0,0 @@
package org.apache.maven.artifact.repository.authentication;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.util.UserModelUtils;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.util.StringUtils;
/**
* @author jdcasey
*/
public class MavenAuthenticationInfoProvider
implements AuthenticationInfoProvider
{
public void configureAuthenticationInfo( Repository repo ) throws Exception
{
UserModel userModel = UserModelUtils.getUserModel();
String repoId = repo.getId();
if ( !StringUtils.isEmpty( repoId ) )
{
ServerProfile serverProfile = UserModelUtils.getServerProfile( userModel, repo.getId() );
AuthenticationInfo info = new AuthenticationInfo();
if ( serverProfile != null )
{
info.setUserName( serverProfile.getUsername() );
info.setPassword( serverProfile.getPassword() );
info.setPrivateKey( serverProfile.getPrivateKey() );
info.setPassphrase( serverProfile.getPassphrase() );
}
repo.setAuthenticationInfo( info );
}
}
}

View File

@ -28,17 +28,20 @@ import org.apache.maven.Maven;
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.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.model.Repository;
import org.apache.maven.model.user.MavenProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.UserModelBuilder;
import org.apache.maven.model.user.UserModelUtils;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.Plugin;
import org.apache.maven.util.UserModelUtils;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.embed.ArtifactEnabledEmbedder;
import org.codehaus.plexus.logging.Logger;
@ -87,8 +90,6 @@ public class MavenCli
// Properties mavenProperties = getMavenProperties( userConfigurationDirectory );
ArtifactRepository localRepository = getLocalRepository();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@ -122,7 +123,23 @@ public class MavenCli
EventDispatcher eventDispatcher = new DefaultEventDispatcher();
UserModel userModel = UserModelUtils.getUserModel();
// ----------------------------------------------------------------------
// Now that we have everything that we need we will fire up plexus and
// bring the maven component to life for use.
// ----------------------------------------------------------------------
ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
embedder.start( classWorld );
UserModelBuilder userModelBuilder = (UserModelBuilder) embedder.lookup( UserModelBuilder.ROLE );
UserModel userModel = userModelBuilder.buildUserModel();
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder
.lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepository localRepository = getLocalRepository( userModel, artifactRepositoryFactory );
if ( commandLine.hasOption( CLIManager.REACTOR ) )
{
@ -146,15 +163,6 @@ public class MavenCli
commandLine.getArgList(), files, userDir.getPath() );
}
// ----------------------------------------------------------------------
// Now that we have everything that we need we will fire up plexus and
// bring the maven component to life for use.
// ----------------------------------------------------------------------
ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
embedder.start( classWorld );
LoggerManager manager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
if ( commandLine.hasOption( CLIManager.DEBUG ) )
{
@ -331,10 +339,9 @@ public class MavenCli
return mavenProperties;
}
protected static ArtifactRepository getLocalRepository()
protected static ArtifactRepository getLocalRepository( UserModel userModel, ArtifactRepositoryFactory repoFactory )
throws Exception
{
UserModel userModel = UserModelUtils.getUserModel();
MavenProfile mavenProfile = UserModelUtils.getActiveMavenProfile( userModel );
String localRepository = null;
@ -352,6 +359,13 @@ public class MavenCli
// TODO [BP]: this should not be necessary - grep for and remove
System.setProperty( MavenConstants.MAVEN_REPO_LOCAL, localRepository );
return new ArtifactRepository( "local", "file://" + localRepository );
Repository repo = new Repository();
repo.setId( "local" );
repo.setUrl( "file://" + localRepository );
return repoFactory.createArtifactRepository( repo, userModel );
}
}

View File

@ -18,7 +18,6 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.Log;
@ -31,9 +30,7 @@ import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
import org.codehaus.plexus.util.dag.Vertex;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -68,6 +65,8 @@ public class MavenSession
private final UserModel userModel;
private List remoteArtifactRepos = Collections.EMPTY_LIST;
public MavenSession( PlexusContainer container, PluginManager pluginManager, UserModel userModel,
ArtifactRepository localRepository, EventDispatcher eventDispatcher, Log log, List goals )
{
@ -112,27 +111,15 @@ public class MavenSession
{
return localRepository;
}
public void setRemoteRepositories(List remoteArtifactRepos)
{
this.remoteArtifactRepos = remoteArtifactRepos;
}
public List getRemoteRepositories()
{
List result = null;
if ( project != null )
{
List repos = project.getRepositories();
result = new ArrayList( repos.size() );
for ( Iterator it = repos.iterator(); it.hasNext(); )
{
Repository repo = (Repository) it.next();
result.add( new ArtifactRepository( repo.getId(), repo.getUrl() ) );
}
}
else
{
result = Collections.EMPTY_LIST;
}
return result;
return remoteArtifactRepos;
}
public List getGoals()

View File

@ -32,6 +32,8 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import java.util.Date;
@ -46,6 +48,7 @@ import java.util.Map;
* jdcasey Exp $
*/
public class DefaultLifecycleExecutor
extends AbstractLogEnabled
implements LifecycleExecutor, Initializable
{
// ----------------------------------------------------------------------
@ -385,6 +388,11 @@ public class DefaultLifecycleExecutor
try
{
Logger logger = getLogger();
logger.debug("Resolving artifacts from:\n" +
"\t{localRepository: " + session.getLocalRepository() + "}\n" +
"\t{remoteRepositories: " + session.getRemoteRepositories() + "}");
return pluginManager.executeMojo( session, id );
}
catch ( GoalExecutionException e )

View File

@ -0,0 +1,134 @@
package org.apache.maven.model.user;
/* ====================================================================
* 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.model.user.io.xpp3.MavenUserModelXpp3Reader;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* @author jdcasey
*/
public class DefaultUserModelBuilder
extends AbstractLogEnabled
implements UserModelBuilder
{
private static final String DEFAULT_USER_MODEL_PATH = "${user.home}/.m2/user.xml";
private String userModelPath = DEFAULT_USER_MODEL_PATH;
// TODO: don't throw Exception.
public UserModel buildUserModel() throws Exception
{
UserModel model = null;
File modelFile = getUserModelFile();
if ( modelFile.exists() && modelFile.isFile() )
{
MavenUserModelXpp3Reader modelReader = new MavenUserModelXpp3Reader();
FileReader reader = null;
try
{
reader = new FileReader( modelFile );
model = modelReader.read( reader );
}
finally
{
if ( reader != null )
{
try
{
reader.close();
}
catch ( IOException e )
{
}
}
}
}
if ( model == null )
{
getLogger().debug( "UserModel not found. Creating empty instance." );
model = new UserModel();
}
return model;
}
// TODO: don't throw Exception.
// public static void setUserModel( UserModel userModel ) throws Exception
// {
// File modelFile = getUserModelFile();
//
// File modelDir = modelFile.getParentFile();
// if ( !modelDir.exists() )
// {
// modelDir.mkdirs();
// }
//
// MavenUserModelXpp3Writer modelWriter = new MavenUserModelXpp3Writer();
//
// FileWriter writer = null;
// try
// {
// writer = new FileWriter( modelFile );
//
// modelWriter.write( writer, userModel );
//
// writer.flush();
// }
// finally
// {
// if ( writer != null )
// {
// try
// {
// writer.close();
// }
// catch ( IOException e )
// {
// }
// }
// }
//
// }
private File getUserModelFile()
{
String userDir = System.getProperty( "user.home" );
String path = userModelPath;
path = path.replaceAll( "\\$\\{user.home\\}", userDir );
path = path.replaceAll( "\\\\", "/" );
path = path.replaceAll( "//", "/" );
File userModelFile = new File( path );
getLogger().debug( "Using userModel configured from: " + userModelFile );
return userModelFile;
}
}

View File

@ -0,0 +1,31 @@
package org.apache.maven.model.user;
/* ====================================================================
* 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 interface UserModelBuilder
{
public static final String ROLE = UserModelBuilder.class.getName();
// TODO: Don't throw Exception.
UserModel buildUserModel() throws Exception;
}

View File

@ -1,17 +1,22 @@
package org.apache.maven.util;
package org.apache.maven.model.user;
import org.apache.maven.model.user.DefaultProfiles;
import org.apache.maven.model.user.MavenProfile;
import org.apache.maven.model.user.ProxyProfile;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Reader;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Writer;
/* ====================================================================
* 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 java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
@ -21,8 +26,6 @@ import java.util.List;
public final class UserModelUtils
{
private static final String USER_MODEL_LOCATION = "/.m2/user.xml";
private static final String ACTIVE_MAVEN_PROFILE_ID_ENVAR = "maven.profile";
private UserModelUtils()
@ -136,95 +139,4 @@ public final class UserModelUtils
return result;
}
// TODO: don't throw Exception.
public static UserModel getUserModel() throws Exception
{
UserModel model = null;
File modelFile = getUserModelFile();
if ( modelFile.exists() && modelFile.isFile() )
{
MavenUserModelXpp3Reader modelReader = new MavenUserModelXpp3Reader();
FileReader reader = null;
try
{
reader = new FileReader( modelFile );
model = modelReader.read( reader );
}
finally
{
if ( reader != null )
{
try
{
reader.close();
}
catch ( IOException e )
{
}
}
}
}
if ( model == null )
{
model = new UserModel();
}
return model;
}
// TODO: don't throw Exception.
public static void setUserModel( UserModel userModel ) throws Exception
{
File modelFile = getUserModelFile();
File modelDir = modelFile.getParentFile();
if ( !modelDir.exists() )
{
modelDir.mkdirs();
}
MavenUserModelXpp3Writer modelWriter = new MavenUserModelXpp3Writer();
FileWriter writer = null;
try
{
writer = new FileWriter( modelFile );
modelWriter.write( writer, userModel );
writer.flush();
}
finally
{
if ( writer != null )
{
try
{
writer.close();
}
catch ( IOException e )
{
}
}
}
}
private static File getUserModelFile()
{
String userDir = System.getProperty( "user.home" );
String modelPath = userDir + USER_MODEL_LOCATION;
modelPath = modelPath.replaceAll( "\\\\", "/" );
modelPath = modelPath.replaceAll( "//", "/" );
File userModelFile = new File( modelPath );
return userModelFile;
}
}
}

View File

@ -20,6 +20,7 @@ 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;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -27,6 +28,9 @@ 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.lifecycle.GoalExecutionException;
import org.apache.maven.model.Repository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.UserModelBuilder;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -79,6 +83,10 @@ public class DefaultPluginManager
protected ArtifactFilter artifactFilter;
protected PathTranslator pathTranslator;
protected ArtifactRepositoryFactory artifactRepositoryFactory;
protected UserModelBuilder userModelBuilder;
public DefaultPluginManager()
{
@ -462,6 +470,8 @@ public class DefaultPluginManager
String expression = parameter.getExpression();
Object value = PluginParameterExpressionEvaluator.evaluate( expression, session );
getLogger().debug("Evaluated mojo parameter expression: \'" + expression + "\' to: " + value);
if ( value == null )
{
@ -567,6 +577,7 @@ public class DefaultPluginManager
"maven-core",
"maven-artifact",
"maven-model",
"maven-user-model",
"maven-monitor",
"maven-plugin",
"plexus-container-api",
@ -579,7 +590,25 @@ public class DefaultPluginManager
remotePluginRepositories = new ArrayList();
// TODO: needs to be configured from the POM element
remotePluginRepositories.add( new ArtifactRepository( "plugin-repository", "http://repo1.maven.org" ) );
UserModel userModel = null;
try
{
userModel = userModelBuilder.buildUserModel();
}
catch ( Exception e )
{
// TODO: Warn about this failure.
userModel = new UserModel();
}
Repository pluginRepo = new Repository();
pluginRepo.setId( "plugin-repository" );
pluginRepo.setUrl( "http://repo1.maven.org" );
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( pluginRepo, userModel );
remotePluginRepositories.add( pluginRepository );
}
// ----------------------------------------------------------------------

View File

@ -20,7 +20,6 @@ package org.apache.maven.plugin;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.util.introspection.ReflectionValueExtractor;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
@ -91,6 +90,10 @@ public class PluginParameterExpressionEvaluator
throw new PluginConfigurationException( "Error evaluating plugin parameter expression: " + expression, e );
}
}
else if ( expression.startsWith( "#userModel" ) )
{
value = context.getUserModel();
}
else if ( expression.equals( "#basedir" ) )
{
value = context.getProject().getFile().getParentFile().getAbsolutePath();

View File

@ -21,6 +21,7 @@ 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;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -29,6 +30,8 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.UserModelBuilder;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.interpolation.ModelInterpolationException;
@ -79,6 +82,10 @@ public class DefaultMavenProjectBuilder
private ModelDefaultsInjector modelDefaultsInjector;
private ModelInterpolator modelInterpolator;
private UserModelBuilder userModelBuilder;
private ArtifactRepositoryFactory artifactRepositoryFactory;
public void initialize()
{
@ -237,14 +244,25 @@ public class DefaultMavenProjectBuilder
return project;
}
private List buildArtifactRepositories( List repositories )
private List buildArtifactRepositories( List repositories ) throws ProjectBuildingException
{
UserModel userModel = null;
try
{
userModel = userModelBuilder.buildUserModel();
}
catch ( Exception e )
{
throw new ProjectBuildingException( "Cannot read user-model.", e );
}
List repos = new ArrayList();
for ( Iterator i = repositories.iterator(); i.hasNext(); )
{
Repository mavenRepo = (Repository) i.next();
ArtifactRepository artifactRepo = new ArtifactRepository( mavenRepo.getId(), mavenRepo.getUrl() );
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo, userModel );
if ( !repos.contains( artifactRepo ) )
{

View File

@ -21,6 +21,9 @@
<requirement>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirements>
</component>
<!--
@ -83,6 +86,12 @@
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.model.user.UserModelBuilder</role>
</requirement>
</requirements>
</component>
<!--
@ -112,16 +121,7 @@
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<implementation>org.apache.maven.artifact.factory.DefaultArtifactFactory</implementation>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.MavenAuthenticationInfoProvider</implementation>
</component>
<!--
|
| Lifecycle executor

View File

@ -24,11 +24,25 @@
<requirement>
<role>org.apache.maven.project.path.PathTranslator</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.model.user.UserModelBuilder</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.project.path.PathTranslator</role>
<implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
</component>
<component>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
</component>
<component>
<role>org.apache.maven.model.user.UserModelBuilder</role>
<implementation>org.apache.maven.model.user.DefaultUserModelBuilder</implementation>
</component>
</components>
</plexus>

View File

@ -4,7 +4,7 @@
<repositories>
<repository>
<artifactId>central</artifactId>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org</url>
</repository>

View File

@ -23,6 +23,7 @@ import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.ArtifactEnabledPlexusTestCase;
import java.io.File;
import java.net.URL;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -53,6 +54,21 @@ public class MavenTestCase
{
return getTestFile( "src/test/resources/local-repo" );
}
protected File getFileForClasspathResource( String resource )
{
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL resourceUrl = cloader.getResource( resource );
File resourceFile = null;
if(resourceUrl != null)
{
resourceFile = new File(resourceUrl.getPath());
}
return resourceFile;
}
protected ArtifactRepository getLocalRepository()
{

View File

@ -28,7 +28,7 @@ public class PluginParameterExpressionEvaluatorTest
{
super.setUp();
File f = getTestFile( "src/test/resources/pom.xml" );
File f = getFileForClasspathResource( "pom.xml" );
project = getProject( f );
}

View File

@ -35,7 +35,7 @@ public class CanonicalProjectBuilderTest
public void testProjectBuilder()
throws Exception
{
File f = getTestFile( "src/test/resources/canonical-pom.xml" );
File f = getFileForClasspathResource( "canonical-pom.xml" );
MavenProject project = getProject( f );

View File

@ -42,7 +42,7 @@ public class ReflectionValueExtractorTest
builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
File f = getTestFile( "src/test/resources/pom.xml" );
File f = getFileForClasspathResource( "pom.xml" );
project = getProject( f );
}

View File

@ -0,0 +1,37 @@
<component-set>
<components>
<component>
<role>org.apache.maven.project.MavenProjectBuilder</role>
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
</requirement>
<requirement>
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
</requirement>
<requirement>
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
</requirement>
<requirement>
<role>org.apache.maven.project.validation.ModelValidator</role>
</requirement>
<requirement>
<role>org.apache.maven.project.path.PathTranslator</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.model.user.UserModelBuilder</role>
</requirement>
</requirements>
</component>
</components>
</component-set>

View File

@ -13,7 +13,7 @@
<dependencies>
<dependency>
<groupId>modello</groupId>
<artifactId>modello</artifactId>
<artifactId>modello-core</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
@ -54,4 +54,4 @@
<scope>compile</scope>
</dependency>
</dependencies>
</model>
</model>

View File

@ -1,4 +1,4 @@
<model>
<project>
<parent>
<artifactId>maven-plugin-tools</artifactId>
<groupId>maven</groupId>
@ -88,6 +88,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-user-model</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-marmalade-factory</artifactId>
@ -103,4 +110,4 @@
<scope>compile</scope>
</dependency>
</dependencies>
</model>
</project>

View File

@ -45,6 +45,7 @@ public class MarmaladeMojoDescriptorExtractorTest
project.setFile( new File( basedir, "pom.xml" ) );
System.out.println("Basedir: " + basedir);
project.addScriptSourceRoot( basedir.getPath() );
MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup(

View File

@ -4,3 +4,5 @@ target
*.ipr
*.iws
*.iml
.classpath
.project

View File

@ -26,6 +26,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-user-model</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-artifact</artifactId>

View File

@ -20,8 +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.model.user.UserModel;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
@ -30,6 +32,40 @@ import org.apache.maven.project.MavenProject;
import java.io.File;
/**
* Requires the follow parameters:
*
* @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=""
*
* @parameter
* name="artifactRepositoryFactory"
* type="org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
* description=""
*
* @parameter
* name="userModel"
* type="org.apache.maven.model.user.UserModel"
* required="true"
* validator=""
* expression="#userModel"
* description=""
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
* @version $Id$
*/
@ -48,6 +84,10 @@ public abstract class AbstractDeployMojo
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" );
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) request.getParameter( "artifactRepositoryFactory" );
UserModel userModel = (UserModel) request.getParameter( "userModel" );
DistributionManagement distributionManagement = project.getDistributionManagement();
@ -66,7 +106,12 @@ public abstract class AbstractDeployMojo
throw new Exception( msg );
}
ArtifactRepository deploymentRepository = new ArtifactRepository( repository.getId(), repository.getUrl() );
ArtifactRepository deploymentRepository = artifactRepositoryFactory.createArtifactRepository( repository, userModel );
if(deploymentRepository.getAuthenticationInfo() == null)
{
request.getLog().warn("Deployment repository {id: \'" + repository.getId() + "\'} has no associated authentication info!");
}
// Deploy the POM
Artifact pomArtifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(),

View File

@ -37,6 +37,22 @@ package org.apache.maven.plugin.deploy;
* 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="userModel"
* type="org.apache.maven.model.user.UserModel"
* required="true"
* validator=""
* expression="#userModel"
* description=""
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$
*/

View File

@ -37,6 +37,22 @@ package org.apache.maven.plugin.deploy;
* 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="userModel"
* type="org.apache.maven.model.user.UserModel"
* required="true"
* validator=""
* expression="#userModel"
* description=""
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$
*/

View File

@ -103,6 +103,9 @@ public class SurefirePlugin
SurefireBooter surefireBooter = new SurefireBooter();
System.out.println("Setting reports dir: " + reportsDirectory);
System.out.flush();
surefireBooter.setReportsDirectory( reportsDirectory );
// ----------------------------------------------------------------------