diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java index 6ec2a2188f..b2df01a458 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java @@ -53,7 +53,12 @@ public interface ArtifactRepository String getKey(); + // // New interface methods for the repository system. - + // Artifact find( Artifact artifact ); + + void setAuthentication( Authentication authentication ); + + Authentication getAuthentication(); } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java index 0cc24d7983..7cab89b7f4 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java @@ -27,9 +27,11 @@ public interface ArtifactRepositoryFactory String LOCAL_REPOSITORY_ID = "local"; + @Deprecated ArtifactRepositoryLayout getLayout( String layoutId ) throws UnknownRepositoryLayoutException; + @Deprecated ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId, boolean uniqueVersion ) throws UnknownRepositoryLayoutException; diff --git a/maven-compat/src/main/java/org/apache/maven/repository/Authentication.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/Authentication.java similarity index 90% rename from maven-compat/src/main/java/org/apache/maven/repository/Authentication.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/Authentication.java index afd2101099..63f7f2c8b6 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/Authentication.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/Authentication.java @@ -1,4 +1,4 @@ -package org.apache.maven.repository; +package org.apache.maven.artifact.repository; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -20,7 +20,13 @@ */ public class Authentication -{ +{ + public Authentication( String userName, String password ) + { + this.userName = userName; + this.password = password; + } + /** * Username used to login to the host */ diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java index 2d0257626f..c08c18c3a3 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -203,4 +203,17 @@ public Artifact find( Artifact artifact ) return artifact; } + + // + // This implementation does not support authentication + // + public Authentication getAuthentication() + { + return null; + } + + public void setAuthentication( Authentication authentication ) + { + // do nothing + } } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java index 7f2b399039..598217b833 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java @@ -25,7 +25,6 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -//TODO: http://jira.codehaus.org/browse/MNG-4215 //TODO: completely separate local and remote artifact repositories public class MavenArtifactRepository implements ArtifactRepository @@ -44,6 +43,8 @@ public class MavenArtifactRepository private ArtifactRepositoryPolicy releases; + private Authentication authentication; + public MavenArtifactRepository() { } @@ -343,4 +344,13 @@ protected static boolean eq( T s1, T s2 ) return s1 != null ? s1.equals( s2 ) : s2 == null; } + public Authentication getAuthentication() + { + return authentication; + } + + public void setAuthentication( Authentication authentication ) + { + this.authentication = authentication; + } } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index e5b143bc58..10eeb66ddf 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -1,28 +1,25 @@ package org.apache.maven.repository; /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -33,6 +30,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.Authentication; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; @@ -63,7 +61,7 @@ /** * @author Jason van Zyl */ -@Component( role = RepositorySystem.class, hint = "default" ) +@Component(role = RepositorySystem.class, hint = "default") public class LegacyRepositorySystem implements RepositorySystem { @@ -79,6 +77,9 @@ public class LegacyRepositorySystem @Requirement private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; + @Requirement + private Map layouts; + @Requirement private MirrorBuilder mirrorBuilder; @@ -97,7 +98,7 @@ public Artifact createArtifact( String groupId, String artifactId, String versio { return artifactFactory.createBuildArtifact( groupId, artifactId, version, packaging ); } - + public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier ) { return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); @@ -120,9 +121,7 @@ public Artifact createDependencyArtifact( Dependency d ) return null; } - Artifact artifact = - artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), - d.getClassifier(), d.getScope(), d.isOptional() ); + Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope(), d.isOptional() ); if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && d.getSystemPath() != null ) { @@ -179,27 +178,6 @@ public Artifact createPluginArtifact( Plugin plugin ) return artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ); } - public ArtifactRepository buildArtifactRepository( Repository repo ) - throws InvalidRepositoryException - { - if ( repo != null ) - { - String id = repo.getId(); - - String url = repo.getUrl(); - - ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() ); - - ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() ); - - return artifactRepositoryFactory.createArtifactRepository( id, url, repo.getLayout(), snapshots, releases ); - } - else - { - return null; - } - } - public ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy policy ) { boolean enabled = true; @@ -224,38 +202,31 @@ public ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); } - + public ArtifactRepository createDefaultLocalRepository() throws InvalidRepositoryException { return createLocalRepository( RepositorySystem.defaultUserLocalRepository ); } - + public ArtifactRepository createLocalRepository( File localRepository ) throws InvalidRepositoryException { - return createRepository( "file://" + localRepository.toURI().getRawPath(), - RepositorySystem.DEFAULT_LOCAL_REPO_ID, true, - ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, - ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, - ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + return createRepository( "file://" + localRepository.toURI().getRawPath(), RepositorySystem.DEFAULT_LOCAL_REPO_ID, true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, + ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); } public ArtifactRepository createDefaultRemoteRepository() throws InvalidRepositoryException { - return createRepository( RepositorySystem.DEFAULT_REMOTE_REPO_URL, RepositorySystem.DEFAULT_REMOTE_REPO_ID, - true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, false, - ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, - ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); + return createRepository( RepositorySystem.DEFAULT_REMOTE_REPO_URL, RepositorySystem.DEFAULT_REMOTE_REPO_ID, true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, false, + ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); } - + public ArtifactRepository createLocalRepository( String url, String repositoryId ) throws IOException { - return createRepository( canonicalFileUrl( url ), repositoryId, true, - ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, - ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, + return createRepository( canonicalFileUrl( url ), repositoryId, true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); } @@ -288,22 +259,6 @@ else if ( url.startsWith( "file:" ) && !url.startsWith( "file://" ) ) return url; } - private ArtifactRepository createRepository( String url, String repositoryId, boolean releases, - String releaseUpdates, boolean snapshots, String snapshotUpdates, - String checksumPolicy ) - { - ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( snapshots, snapshotUpdates, checksumPolicy ); - - ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( releases, releaseUpdates, checksumPolicy ); - - return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy ); - } - - public ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) - { - return artifactRepositoryFactory.createArtifactRepository( id, url, repositoryLayout, snapshots, releases ); - } - public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) { /* @@ -372,23 +327,7 @@ public void addProxy( String protocol, String host, int port, String username, S } */ - /* - public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase ) - { - AuthenticationInfo authInfo = new AuthenticationInfo(); - authInfo.setUserName( username ); - authInfo.setPassword( password ); - authInfo.setPrivateKey( privateKey ); - authInfo.setPassphrase( passphrase ); - - authenticationInfoMap.put( repositoryId, authInfo ); - - wagonManager.addAuthenticationInfo( repositoryId, username, password, privateKey, passphrase ); - } - */ - // Mirror - public void addMirror( String id, String mirrorOf, String url ) { mirrorBuilder.addMirror( id, mirrorOf, url ); @@ -427,8 +366,7 @@ public List getEffectiveRepositories( List aliasedRepos : reposByKey.values() ) { - List releasePolicies = - new ArrayList( aliasedRepos.size() ); + List releasePolicies = new ArrayList( aliasedRepos.size() ); for ( ArtifactRepository aliasedRepo : aliasedRepos ) { @@ -437,8 +375,7 @@ public List getEffectiveRepositories( List snapshotPolicies = - new ArrayList( aliasedRepos.size() ); + List snapshotPolicies = new ArrayList( aliasedRepos.size() ); for ( ArtifactRepository aliasedRepo : aliasedRepos ) { @@ -449,10 +386,8 @@ public List getEffectiveRepositories( List artifacts, -// Artifact originatingArtifact, -// Map managedVersions, -// ArtifactRepository localRepository, -// List remoteRepositories, -// ArtifactMetadataSource source, -// ArtifactFilter filter, -// List listeners, -// List conflictResolvers ) - -// ArtifactResolutionResult result = artifactCollector. + // ArtifactResolutionResult collect( Set artifacts, + // Artifact originatingArtifact, + // Map managedVersions, + // ArtifactRepository localRepository, + // List remoteRepositories, + // ArtifactMetadataSource source, + // ArtifactFilter filter, + // List listeners, + // List conflictResolvers ) + + // ArtifactResolutionResult result = artifactCollector. return null; } @@ -558,4 +491,67 @@ public void publish( ArtifactRepository repository, File source, String remotePa { wagonManager.putRemoteFile( repository, source, remotePath, downloadMonitor ); } + + private Map authentications = new HashMap(); + + // + // serverId = repository id + // + public void addAuthenticationForArtifactRepository( String repositoryId, String username, String password ) + { + Authentication authentication = new Authentication( username, password ); + authentications.put( repositoryId, authentication ); + } + + // + // Artifact Repository Creation + // + public ArtifactRepository buildArtifactRepository( Repository repo ) + throws InvalidRepositoryException + { + if ( repo != null ) + { + String id = repo.getId(); + + String url = repo.getUrl(); + + ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() ); + + ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() ); + + return createArtifactRepository( id, url, layouts.get( repo.getLayout() ), snapshots, releases ); + } + else + { + return null; + } + } + + private ArtifactRepository createRepository( String url, String repositoryId, boolean releases, String releaseUpdates, boolean snapshots, String snapshotUpdates, String checksumPolicy ) + { + ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( snapshots, snapshotUpdates, checksumPolicy ); + + ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( releases, releaseUpdates, checksumPolicy ); + + return createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy ); + } + + public ArtifactRepository createArtifactRepository( String repositoryId, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) + { + if ( repositoryLayout == null ) + { + repositoryLayout = defaultArtifactRepositoryLayout; + } + + ArtifactRepository artifactRepository = artifactRepositoryFactory.createArtifactRepository( repositoryId, url, repositoryLayout, snapshots, releases ); + + Authentication authentication = authentications.get( repositoryId ); + + if ( authentication != null ) + { + artifactRepository.setAuthentication( authentication ); + } + + return artifactRepository; + } } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java index d58e7e52a1..365b52c0af 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -112,5 +112,7 @@ void publish( ArtifactRepository repository, File source, String remotePath, Tra throws TransferFailedException; void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor ) - throws TransferFailedException, ResourceDoesNotExistException; + throws TransferFailedException, ResourceDoesNotExistException; + + void addAuthenticationForArtifactRepository( String repositoryId, String username, String password ); } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java index f68ffbcdc5..fdd6dfdf68 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java @@ -32,9 +32,11 @@ import org.apache.maven.wagon.UnsupportedProtocolException; import org.apache.maven.wagon.Wagon; import org.apache.maven.wagon.authentication.AuthenticationException; +import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.observers.ChecksumObserver; +import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.repository.Repository; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; @@ -208,6 +210,38 @@ public void getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metada getRemoteFile( repository, destination, remotePath, null, checksumPolicy, true ); } + /** + * Deal with connecting to a wagon repository taking into account authentication and proxies. + * + * @param wagon + * @param repository + * @throws ConnectionException + * @throws AuthenticationException + */ + private void connectWagon( Wagon wagon, ArtifactRepository repository ) + throws ConnectionException, AuthenticationException + { + if ( repository.getAuthentication() != null ) + { + // + // We have authentication we have been asked to deal with. + // + AuthenticationInfo ai = new AuthenticationInfo(); + ai.setUserName( repository.getAuthentication().getUserName() ); + ai.setPassword( repository.getAuthentication().getPassword() ); + + wagon.connect( new Repository( repository.getId(), repository.getUrl() ), ai ); + } + else + { + wagon.connect( new Repository( repository.getId(), repository.getUrl() ) ); + } + + // + // ProxyInfo proxyInfo = new ProxyInfo(); + // + } + public void getRemoteFile( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor, String checksumPolicy, boolean force ) throws TransferFailedException, ResourceDoesNotExistException { @@ -237,8 +271,8 @@ public void getRemoteFile( ArtifactRepository repository, File destination, Stri try { - wagon.connect( new Repository( repository.getId(), repository.getUrl() ) ); - + connectWagon( wagon, repository ); + boolean firstRun = true; boolean retry = true; @@ -467,7 +501,7 @@ public void putRemoteFile( ArtifactRepository repository, File source, String re { try { - wagon.connect( new Repository( repository.getId(), repository.getUrl() ) ); + connectWagon( wagon, repository ); wagon.put( source, remotePath ); } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index 824403a317..92ff98623f 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -30,6 +30,7 @@ import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.MavenSettingsBuilder; import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.apache.maven.settings.SettingsUtils; import org.apache.maven.toolchain.ToolchainsBuilder; @@ -199,27 +200,14 @@ private void processRepositoriesInSettings( MavenExecutionRequest request ) repositorySystem.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts() ); } + */ for ( Server server : settings.getServers() ) { - String password; - String passPhrase; - - try - { - password = securityDispatcher.decrypt( server.getPassword() ); - passPhrase = securityDispatcher.decrypt( server.getPassphrase() ); - } - catch ( SecDispatcherException e ) - { - throw new MavenEmbedderException( "Error decrypting server password/passphrase.", e ); - } + repositorySystem.addAuthenticationForArtifactRepository( server.getId(), server.getUsername(), server.getPassword() ); - repositorySystem.addAuthenticationInfo( server.getId(), server.getUsername(), password, server.getPrivateKey(), passPhrase ); - - repositorySystem.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() ); + //repositorySystem.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() ); } - */ for ( Mirror mirror : settings.getMirrors() ) {