You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/28 01:12:32 UTC

svn commit: r769199 [8/19] - in /maven/mercury/trunk: mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/ mercury-core/src/main/java/org/apache/maven/mercury/artifact/ ...

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java Mon Apr 27 23:12:25 2009
@@ -52,11 +52,11 @@
 import org.apache.maven.mercury.repository.api.AbstracRepositoryReader;
 import org.apache.maven.mercury.repository.api.AbstractRepOpResult;
 import org.apache.maven.mercury.repository.api.AbstractRepository;
-import org.apache.maven.mercury.repository.api.MetadataResults;
 import org.apache.maven.mercury.repository.api.ArtifactResults;
 import org.apache.maven.mercury.repository.api.LocalRepository;
 import org.apache.maven.mercury.repository.api.MetadataCacheException;
 import org.apache.maven.mercury.repository.api.MetadataCorruptionException;
+import org.apache.maven.mercury.repository.api.MetadataResults;
 import org.apache.maven.mercury.repository.api.RemoteRepository;
 import org.apache.maven.mercury.repository.api.Repository;
 import org.apache.maven.mercury.repository.api.RepositoryException;
@@ -100,6 +100,7 @@
     private static final String[] _protocols = new String[] { "http", "https", "dav", "webdav" };
 
     private HashSet<Server> _servers;
+
     // ---------------------------------------------------------------------------------------------------------------
     RemoteRepository _repo;
 
@@ -141,8 +142,8 @@
             _defaultRoot.delete();
             _defaultRoot.mkdirs();
             _defaultRoot.deleteOnExit();
-            
-            if( LOG.isDebugEnabled() )
+
+            if ( LOG.isDebugEnabled() )
                 LOG.debug( LANG.getMessage( "default.root", _defaultRoot.getCanonicalPath() ) );
         }
         catch ( IOException e )
@@ -354,9 +355,9 @@
 
         for ( ArtifactMetadata md : query )
         {
-            if( ! _repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
+            if ( !_repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
                 continue;
-            
+
             try
             {
                 readArtifact( md, res );
@@ -432,91 +433,93 @@
         }
         else
         {
-            if( LOG.isInfoEnabled() )
+            if ( LOG.isInfoEnabled() )
                 LOG.info( LANG.getMessage( "read.artifact", loc.getAbsPath(), Util.convertLength( binFile.length() ) ) );
 
             da.setFile( binFile );
-            
+
             da.setPomBlob( FileUtil.readRawData( isPom ? binFile : pomFile ) );
-            
+
             res.add( md, da );
         }
     }
+
     // ---------------------------------------------------------------------------------------------------------------
     /**
      * this is an extended call, specific to Remote M2 repository for now
      */
     public void readQualifiedArtifacts( Collection<ArtifactMetadata> mds, ArtifactResults res )
-    throws IOException, RepositoryException, MetadataReaderException, MetadataException
+        throws IOException, RepositoryException, MetadataReaderException, MetadataException
     {
-        if( Util.isEmpty( mds ) )
+        if ( Util.isEmpty( mds ) )
             throw new IllegalArgumentException( LANG.getMessage( "no.md.list" ) );
-        
+
         Map<ArtifactMetadata, DefaultArtifact> artifacts = new HashMap<ArtifactMetadata, DefaultArtifact>( mds.size() );
-        
+
         DefaultRetrievalRequest request = new DefaultRetrievalRequest();
-        
+
         long start = 0;
 
-        if( LOG.isInfoEnabled() )
+        if ( LOG.isInfoEnabled() )
         {
             start = System.currentTimeMillis();
-            
-            LOG.info( LANG.getMessage( "read.artifacts", mds.size()+"" ) );
+
+            LOG.info( LANG.getMessage( "read.artifacts", mds.size() + "" ) );
         }
-        
-        TreeSet<Server> servers = new TreeSet<Server>(
-                        new Comparator<Server>()
-                        {
 
-                            public int compare( Server s1, Server s2 )
-                            {
-                                return s1.getId().compareTo( s2.getId() );
-                            }
-            
-                        }
-                                                     );
-        for( ArtifactMetadata md : mds )
+        TreeSet<Server> servers = new TreeSet<Server>( new Comparator<Server>()
+        {
+
+            public int compare( Server s1, Server s2 )
+            {
+                return s1.getId().compareTo( s2.getId() );
+            }
+
+        } );
+        for ( ArtifactMetadata md : mds )
         {
             DefaultArtifact da = md instanceof DefaultArtifact ? (DefaultArtifact) md : new DefaultArtifact( md );
-            
+
             artifacts.put( md, da );
-            
-            Server server = ( (RemoteRepositoryReaderM2)md.getTracker() ).getRepository().getServer();
-    
-            ArtifactLocation loc = new ArtifactLocation( server.getURL().toString(), md ); //calculateLocation( server.getURL().toString(), md, res );
-            
+
+            Server server = ( (RemoteRepositoryReaderM2) md.getTracker() ).getRepository().getServer();
+
+            ArtifactLocation loc = new ArtifactLocation( server.getURL().toString(), md ); // calculateLocation(
+                                                                                           // server.getURL().toString(),
+                                                                                           // md, res );
+
             servers.add( server );
-    
+
             da.setVersion( loc.getVersion() );
-    
+
             Quality vq = da.getRequestedQuality();
-    
+
             File root = findLocalRoot( vq );
-    
+
             File binFile = new File( root, loc.getRelPath() );
             File pomFile = null;
-    
+
             Binding binBinding = new Binding( new URL( loc.getAbsPath() ), binFile );
             request.addBinding( binBinding );
-            
+
             da.setFile( binFile );
-    
+
             if ( !md.isPom() )
             {
                 pomFile = new File( root, loc.getRelPomPath() );
                 Binding pomBinding = new Binding( new URL( loc.getAbsPomPath() ), pomFile );
                 request.addBinding( pomBinding );
-                
+
                 da.setPomFile( pomFile );
             }
 
             Object tracker = md.getTracker();
-            
-            if( tracker == null )
-                throw new RepositoryNonQualifiedArtifactException( LANG.getMessage( "non.qualified.artifact", md.toString() ));
 
-            servers.add( ((RemoteRepositoryReaderM2)tracker).getRepository().getServer() );
+            if ( tracker == null )
+                throw new RepositoryNonQualifiedArtifactException( LANG.getMessage( "non.qualified.artifact",
+                                                                                    md.toString() ) );
+
+            servers.add( ( (RemoteRepositoryReaderM2) tracker ).getRepository().getServer() );
         }
 
         DefaultRetriever retriever;
@@ -526,23 +529,24 @@
         }
         catch ( HttpClientException e )
         {
-            throw new RepositoryException(e);
+            throw new RepositoryException( e );
         }
-        
+
         retriever.setServers( servers );
-        
+
         RetrievalResponse response = retriever.retrieve( request );
-        
+
         retriever.stop();
-        
+
         if ( response.hasExceptions() )
         {
-            // record all bugs on the first artifact as jetty transport does not 
-            res.addError( (ArtifactMetadata) mds.toArray()[0], new RepositoryException( response.getExceptions().toString() ) );
+            // record all bugs on the first artifact as jetty transport does not
+            res.addError( (ArtifactMetadata) mds.toArray()[0],
+                          new RepositoryException( response.getExceptions().toString() ) );
         }
         else
         {
-            for( Map.Entry<ArtifactMetadata, DefaultArtifact> e : artifacts.entrySet() )
+            for ( Map.Entry<ArtifactMetadata, DefaultArtifact> e : artifacts.entrySet() )
             {
                 DefaultArtifact da = e.getValue();
                 da.setPomBlob( FileUtil.readRawData( da.isPom() ? da.getFile() : da.getPomFile() ) );
@@ -550,10 +554,10 @@
             }
         }
 
-        if( LOG.isInfoEnabled() )
+        if ( LOG.isInfoEnabled() )
         {
             long diff = System.currentTimeMillis() - start;
-            LOG.info( LANG.getMessage( "read.artifacts.time", mds.size()+"", (diff/1000L)+"" ) );
+            LOG.info( LANG.getMessage( "read.artifacts.time", mds.size() + "", ( diff / 1000L ) + "" ) );
         }
     }
 
@@ -571,9 +575,9 @@
 
         for ( ArtifactMetadata md : query )
         {
-            if( ! _repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
+            if ( !_repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
                 continue;
-            
+
             try
             {
                 List<ArtifactMetadata> deps =
@@ -599,7 +603,7 @@
         ArtifactCoordinates coord = null;
         TreeSet<String> gaVersions = null;
         String ver = bmd.getVersion();
-        
+
         // check the cache first
         if ( _mdCache != null )
         {
@@ -609,7 +613,7 @@
                 coord.setVersion( loc.getVersion() );
 
                 gam = _mdCache.findGA( _repo.getId(), _repo.getUpdatePolicy(), coord );
-                
+
                 if ( gam != null && !gam.isExpired() )
                 {
                     gaVersions = gam.getVersions();
@@ -628,14 +632,16 @@
                     String binPath =
                         loc.getGaPath() + FileUtil.SEP + versionDir + FileUtil.SEP + bmd.getArtifactId() + "-"
                             + bmd.getVersion() + ".pom";
-                    
-                    byte [] pom = null;
-                    
+
+                    byte[] pom = null;
+
                     try
                     {
                         pom = readRawData( binPath, true );
                     }
-                    catch( Exception e ) {}
+                    catch ( Exception e )
+                    {
+                    }
 
                     if ( pom != null && pom.length > 1 )
                     {
@@ -666,15 +672,12 @@
         byte[] mavenMetadata = readRawData( mdPath, true );
 
         Metadata mmd = null;
-        
-        if( mavenMetadata != null )
+
+        if ( mavenMetadata != null )
             mmd = MetadataBuilder.getMetadata( mavenMetadata );
 
-        if ( mmd == null
-            || mmd.getVersioning() == null
-            || mmd.getVersioning().getVersions() == null
-            || ( bmd.isSingleton() && ! mmd.getVersioning().getVersions().contains( ver ) )
-        )
+        if ( mmd == null || mmd.getVersioning() == null || mmd.getVersioning().getVersions() == null
+            || ( bmd.isSingleton() && !mmd.getVersioning().getVersions().contains( ver ) ) )
         {
             if ( ( (RemoteRepositoryM2) _repo )._workAroundBadMetadata )
             {
@@ -682,33 +685,33 @@
                 String versionDir = ArtifactLocation.calculateVersionDir( bmd.getVersion() );
 
                 String binPath =
-                    loc.getGaPath() + FileUtil.SEP + versionDir + FileUtil.SEP + bmd.getArtifactId() + "-"
-                        + ver + ".pom";
+                    loc.getGaPath() + FileUtil.SEP + versionDir + FileUtil.SEP + bmd.getArtifactId() + "-" + ver
+                        + ".pom";
 
                 byte[] pom = readRawData( binPath, true );
 
                 if ( pom != null ) // version exists
                 {
-                    if( mmd == null )
+                    if ( mmd == null )
                     {
                         mavenMetadata =
-                            ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<metadata>" + "<groupId>" + bmd.getGroupId()
-                                + "</groupId>" + "<artifactId>" + bmd.getArtifactId() + "</artifactId>" + "<version>"
-                                + ArtifactLocation.calculateVersionDir( ver ) + "</version>" + "<versioning>"
-                                + "<versions>" + "<version>" + ver + "</version>" + "</versions>"
-                                + "</versioning>" + "</metadata>" ).getBytes();
+                            ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<metadata>" + "<groupId>"
+                                + bmd.getGroupId() + "</groupId>" + "<artifactId>" + bmd.getArtifactId()
+                                + "</artifactId>" + "<version>" + ArtifactLocation.calculateVersionDir( ver )
+                                + "</version>" + "<versioning>" + "<versions>" + "<version>" + ver + "</version>"
+                                + "</versions>" + "</versioning>" + "</metadata>" ).getBytes();
                         mmd = MetadataBuilder.getMetadata( mavenMetadata );
                     }
                     else
                     {
                         Versioning v = mmd.getVersioning();
-                        
-                        if( v == null )
+
+                        if ( v == null )
                         {
                             v = new Versioning();
                             mmd.setVersioning( v );
                         }
-                        
+
                         v.addVersion( ver );
                     }
                 }
@@ -732,8 +735,8 @@
         {
             LOG.warn( LANG.getMessage( "maven.metadata.no.versions", loc.getGaPath() + FileUtil.SEP
                 + _repo.getMetadataName(), _repo.getId() ) );
-            
-            if( gam != null && _mdCache != null )
+
+            if ( gam != null && _mdCache != null )
             {
                 gam.setNegativeResult( true );
                 // cache negative result
@@ -840,9 +843,9 @@
 
         for ( ArtifactMetadata md : query )
         {
-            if( ! _repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
+            if ( !_repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
                 continue;
-            
+
             ArtifactLocation loc = new ArtifactLocation( root, md );
 
             TreeSet<String> versions = null;
@@ -924,7 +927,7 @@
                     vmd.setClassifier( md.getClassifier() );
                     vmd.setType( md.getType() );
                     vmd.setVersion( found );
-                    
+
                     vmd.setTracker( this );
 
                     res = MetadataResults.add( res, md, vmd );
@@ -960,7 +963,7 @@
                 vmd.setClassifier( md.getClassifier() );
                 vmd.setType( md.getType() );
                 vmd.setVersion( version );
-                
+
                 vmd.setTracker( this );
 
                 res = MetadataResults.add( res, md, vmd );
@@ -982,7 +985,7 @@
     public byte[] readRawData( ArtifactMetadata md, String classifier, String type, boolean exempt )
         throws MetadataReaderException
     {
-        if( ! _repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
+        if ( !_repo.getRepositoryQualityRange().isAcceptedQuality( md.getRequestedQuality() ) )
             return null;
 
         byte[] res = null;
@@ -994,7 +997,7 @@
         mod = new ArtifactMetadata( md );
         mod.setClassifier( classifier );
         mod.setType( type );
-        
+
         // only cache poms at the moment
         if ( _mdCache != null && "pom".equals( type ) )
         {
@@ -1016,11 +1019,11 @@
             }
         }
 
-//        mod =
-//            new ArtifactMetadata( md );
-//        new ArtifactMetadata( md.getGroupId() + ":" + md.getArtifactId() + ":" + md.getVersion() + ":"
-//                              + ( classifier == null ? "" : classifier ) + ":" + ( type == null ? md.getType() : type ) 
-//                              );
+        // mod =
+        // new ArtifactMetadata( md );
+        // new ArtifactMetadata( md.getGroupId() + ":" + md.getArtifactId() + ":" + md.getVersion() + ":"
+        // + ( classifier == null ? "" : classifier ) + ":" + ( type == null ? md.getType() : type )
+        // );
 
         // ArtifactLocation loc = new ArtifactLocation( "", mod );
 
@@ -1034,7 +1037,7 @@
         res = readRawData( mdPath, exempt );
 
         if ( LOG.isDebugEnabled() )
-            LOG.debug( "POM bytes not cached, read "+ (res == null ? 0:res.length) +" bytes from " + mdPath );
+            LOG.debug( "POM bytes not cached, read " + ( res == null ? 0 : res.length ) + " bytes from " + mdPath );
 
         if ( _mdCache != null && res != null && mod != null )
         {
@@ -1087,13 +1090,13 @@
 
             if ( response.hasExceptions() )
             {
-                if( LOG.isDebugEnabled() )
+                if ( LOG.isDebugEnabled() )
                     LOG.debug( LANG.getMessage( "read.raw.exceptions", path, response.getExceptions().toString() ) );
 
                 return null;
             }
-            
-            if( LOG.isInfoEnabled() )
+
+            if ( LOG.isInfoEnabled() )
                 LOG.info( LANG.getMessage( "read.raw.length", url, Util.convertLength( baos.size() ) ) );
 
             return baos.toByteArray();
@@ -1104,7 +1107,7 @@
         }
         catch ( HttpClientException e )
         {
-            throw new MetadataReaderException(e);
+            throw new MetadataReaderException( e );
         }
         finally
         {
@@ -1126,10 +1129,10 @@
 
     public void close()
     {
-//        if( _transport != null )
-//            _transport.stop();
-        
-        if( _defaultRoot != null )
+        // if( _transport != null )
+        // _transport.stop();
+
+        if ( _defaultRoot != null )
             FileUtil.delete( _defaultRoot );
         _defaultRoot = null;
     }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2Factory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2Factory.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2Factory.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2Factory.java Mon Apr 27 23:12:25 2009
@@ -29,23 +29,25 @@
 import org.codehaus.plexus.lang.Language;
 
 public class RemoteRepositoryReaderM2Factory
-implements RepositoryReaderFactory
+    implements RepositoryReaderFactory
 {
-  private static final Language LANG = new DefaultLanguage( RemoteRepositoryReaderM2Factory.class );
-  private static final RemoteRepositoryReaderM2Factory FACTORY = new RemoteRepositoryReaderM2Factory();
-  
-  static 
-  {
-    AbstractRepository.register( AbstractRepository.DEFAULT_REPOSITORY_TYPE, FACTORY  );
-  }
-  
-  public RepositoryReader getReader( Repository repo, DependencyProcessor mdProcessor )
-  throws RepositoryException
-  {
-    if( repo == null || !(repo instanceof RemoteRepository) )
-      throw new RepositoryException( LANG.getMessage( "bad.repository.type", repo == null ? "null" : repo.getClass().getName() ) );
-    
-    return new RemoteRepositoryReaderM2( (RemoteRepository)repo, mdProcessor );
-  }
+    private static final Language LANG = new DefaultLanguage( RemoteRepositoryReaderM2Factory.class );
+
+    private static final RemoteRepositoryReaderM2Factory FACTORY = new RemoteRepositoryReaderM2Factory();
+
+    static
+    {
+        AbstractRepository.register( AbstractRepository.DEFAULT_REPOSITORY_TYPE, FACTORY );
+    }
+
+    public RepositoryReader getReader( Repository repo, DependencyProcessor mdProcessor )
+        throws RepositoryException
+    {
+        if ( repo == null || !( repo instanceof RemoteRepository ) )
+            throw new RepositoryException( LANG.getMessage( "bad.repository.type", repo == null ? "null"
+                            : repo.getClass().getName() ) );
+
+        return new RemoteRepositoryReaderM2( (RemoteRepository) repo, mdProcessor );
+    }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2.java Mon Apr 27 23:12:25 2009
@@ -64,243 +64,259 @@
 import org.codehaus.plexus.lang.Language;
 
 public class RemoteRepositoryWriterM2
-extends AbstractRepositoryWriter
-implements RepositoryWriter
+    extends AbstractRepositoryWriter
+    implements RepositoryWriter
 {
-  private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( RemoteRepositoryWriterM2.class ); 
-  private static final Language LANG = new DefaultLanguage( RemoteRepositoryWriterM2.class );
-  //---------------------------------------------------------------------------------------------------------------
-  private static final String [] _protocols = new String [] { "http", "https", "dav", "webdav" };
-  
-  RemoteRepository _repo;
-  Server _server;
-  RepositoryReader _reader;
-  
-  // TODO og: 2008-08-22 should be replaced with real transport implementation
-  DefaultDeployer _transport;
-  //---------------------------------------------------------------------------------------------------------------
-  public RemoteRepositoryWriterM2( RemoteRepository repo )
-  throws RepositoryException
-  {
-    if( repo == null )
-      throw new IllegalArgumentException("localRepo cannot be null");
-    
-    _server = repo.getServer();
-    if( _server == null )
-      throw new IllegalArgumentException( LANG.getMessage( "bad.repository.server.null" ) );
-    
-    if( _server.getURL() == null )
-      throw new IllegalArgumentException(LANG.getMessage( "bad.repository.server.url.null" ));
-
-    _repo = repo;
-    
-    _reader = _repo.getReader();
-
-    try
-    {
-      _transport = new DefaultDeployer();
-      HashSet<Server> servers = new HashSet<Server>(1);
-      servers.add( _server );
-      _transport.setServers( servers );
-    }
-    catch( HttpClientException e )
-    {
-      throw new RepositoryException(e);
-    }
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  public Repository getRepository()
-  {
-    return _repo;
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  public boolean canHandle( String protocol )
-  {
-    return AbstractRepository.DEFAULT_LOCAL_READ_PROTOCOL.equals( protocol );
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  public String[] getProtocols()
-  {
-    return _protocols;
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  public void close()
-  {
-      if( _transport != null )
-          _transport.stop();
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  public void writeArtifacts( Collection<Artifact> artifacts )
-      throws RepositoryException
-  {
-    if( artifacts == null || artifacts.size() < 1 )
-      return;
-    
-    Set<StreamVerifierFactory> vFacs = null;
-    Server server = _repo.getServer();
-    if( server != null && server.hasWriterStreamVerifierFactories() )
-      vFacs = server.getWriterStreamVerifierFactories();
-    
-    if( vFacs == null ) // let it be empty, but not null
-      vFacs = new HashSet<StreamVerifierFactory>(1);
-      
-    for( Artifact artifact : artifacts )
-    {
-      writeArtifact( artifact, vFacs );
-    }
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  public void writeArtifact( Artifact artifact, Set<StreamVerifierFactory> vFacs )
-  throws RepositoryException
-  {
-    if( artifact == null )
-      throw new RepositoryException( LANG.getMessage( "null.artifact") );
-    
-    if( artifact.getFile() == null || !artifact.getFile().exists() )
-      throw new RepositoryException( LANG.getMessage( "bad.artifact.file", artifact.toString(), (artifact.getFile() == null ? "null" : artifact.getFile().getAbsolutePath()) ) );
-    
-    boolean isPom = "pom".equals( artifact.getType() );
-    
-    byte [] pomBlob = artifact.getPomBlob();
-    boolean hasPomBlob = pomBlob != null && pomBlob.length > 0;
-    
-    if( !artifact.hasClassifier() && !hasPomBlob )
-      throw new RepositoryException( LANG.getMessage( "no.pom.in.primary.artifact", artifact.toString() ) );
-    
-    InputStream in = artifact.getStream();
-    if( in == null )
-    {
-      File aFile = artifact.getFile();
-      if( aFile == null && !isPom )
-      {
-        throw new RepositoryException( LANG.getMessage( "artifact.no.stream", artifact.toString() ) );
-      }
-
-      try
-      {
-        in = new FileInputStream( aFile );
-      }
-      catch( FileNotFoundException e )
-      {
-        if( !isPom )
-          throw new RepositoryException( LANG.getMessage( "artifact.no.file", artifact.toString(), aFile.getAbsolutePath(), e.getMessage() ) );
-      }
-    }
-    DefaultArtifactVersion dav = new DefaultArtifactVersion( artifact.getVersion() );
-    Quality aq = dav.getQuality();
-    boolean isSnapshot = aq.equals( Quality.SNAPSHOT_QUALITY ) || aq.equals( Quality.SNAPSHOT_TS_QUALITY );
-
-    String relGroupPath = artifact.getGroupId().replace( '.', '/' )+"/"+artifact.getArtifactId();
-    String versionFolder = (isSnapshot ? (dav.getBase()+'-'+Artifact.SNAPSHOT_VERSION) : artifact.getVersion() );
-    String relVersionPath = relGroupPath + '/' + versionFolder;
-
-    try
-    {
-      if( isPom )
-      {
-        if( in == null && !hasPomBlob )
-          throw new RepositoryException( LANG.getMessage( "pom.artifact.no.stream", artifact.toString() ) );
-        
-        if( in != null )
-        {
-          byte [] pomBlobBytes = FileUtil.readRawData( in );
-          hasPomBlob = pomBlobBytes != null && pomBlobBytes.length > 0;
-          if( hasPomBlob )
-            pomBlob = pomBlobBytes;
-        }
-          
-      }
-      
-      String url = _server.getURL().toString(); 
-      
-      // read metadata
-      String gaMdUrl    = url+'/'+relGroupPath+'/'+_repo.getMetadataName();
-      byte [] gaMdBytes = _reader.readRawData( gaMdUrl, true );
-      
-      String gavMdUrl = url+'/'+relVersionPath+'/'+_repo.getMetadataName();
-      byte [] gavMdBytes = _reader.readRawData( gavMdUrl, true );
-
-      HashSet<Binding> bindings = new HashSet<Binding>(4);
-      
-      // first - take care of the binary
-      String binUrl = url+'/'+relVersionPath+'/'+artifact.getBaseName()+'.'+artifact.getType();
-      bindings.add( new Binding( new URL(binUrl), artifact.getFile() ) );
-      
-      // GA metadata
-      Metadata md = gaMdBytes == null ? null :  MetadataBuilder.getMetadata( gaMdBytes );
-      
-      if( md == null )
-      {
-        md = new Metadata();
-        md.setGroupId( artifact.getGroupId() );
-        md.setArtifactId( artifact.getArtifactId() );
-      }
-      
-      List<MetadataOperation> ops = new ArrayList<MetadataOperation>(2); 
-      
-      if( isSnapshot )
-      {
-        Snapshot sn = MetadataBuilder.createSnapshot( artifact.getVersion() );
-        sn.setLocalCopy( true );
-        ops.add( new SetSnapshotOperation( new SnapshotOperand(sn) ) );
-        ops.add( new AddVersionOperation( new StringOperand(versionFolder) ) );
-      }
-      else
-          ops.add( new AddVersionOperation( new StringOperand(artifact.getVersion()) ) ); 
-      
-      byte [] gaResBytes = MetadataBuilder.changeMetadata( md, ops );
-      Metadata gaMd = MetadataBuilder.getMetadata( gaResBytes );
-      
-      bindings.add( new Binding(new URL(gaMdUrl), new ByteArrayInputStream(gaResBytes)) );
-
-      // now - GAV metadata
-      md = gavMdBytes == null ? null : MetadataBuilder.getMetadata( gavMdBytes );
-      
-      if( md == null )
-      {
-        md = new Metadata();
-        md.setGroupId( artifact.getGroupId() );
-        md.setArtifactId( artifact.getArtifactId() );
-        md.setVersion( artifact.getVersion() );
-      }
-      
-      MetadataOperation mdOp = new AddVersionOperation( new StringOperand(artifact.getVersion()) );
-      byte [] gavResBytes = MetadataBuilder.changeMetadata( md, mdOp );
-      Metadata gavMd = MetadataBuilder.getMetadata( gavResBytes );
-      
-      bindings.add( new Binding( new URL(gavMdUrl), new ByteArrayInputStream(gavResBytes)) );
-      
-      if( !isPom && hasPomBlob )
-      {
-        String pomUrl = url+'/'+relVersionPath+'/'+artifact.getArtifactId()+'-'+artifact.getVersion()+".pom";
-        bindings.add( new Binding( new URL(pomUrl), new ByteArrayInputStream(pomBlob) ) );
-      }
-      
-      DefaultDeployRequest request = new DefaultDeployRequest();
-      request.setBindings( bindings );
-      
-      DeployResponse response = _transport.deploy( request );
-      
-      if( response.hasExceptions() )
-        throw new RepositoryException( response.getExceptions().toString() );
-      
-      if( _mdCache != null )
-      {
-        // cache metadata
-// don't cache a single version on the GA level !!
-//        _mdCache.updateGA( _repo.getId(), new RepositoryGAMetadata(gaMd) );
-        _mdCache.updateGAV( _repo.getId(), new RepositoryGAVMetadata(gavMd) );
-        if( hasPomBlob && DefaultArtifact.class.isAssignableFrom( artifact.getClass() ) )
-          _mdCache.saveRaw( (DefaultArtifact)artifact, pomBlob );
-      }
-        
-    }
-    catch( Exception e )
-    {
-      throw new RepositoryException( e );
-    }
-    
-  }
-  //---------------------------------------------------------------------------------------------------------------
-  //---------------------------------------------------------------------------------------------------------------
+    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( RemoteRepositoryWriterM2.class );
+
+    private static final Language LANG = new DefaultLanguage( RemoteRepositoryWriterM2.class );
+
+    // ---------------------------------------------------------------------------------------------------------------
+    private static final String[] _protocols = new String[] { "http", "https", "dav", "webdav" };
+
+    RemoteRepository _repo;
+
+    Server _server;
+
+    RepositoryReader _reader;
+
+    // TODO og: 2008-08-22 should be replaced with real transport implementation
+    DefaultDeployer _transport;
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public RemoteRepositoryWriterM2( RemoteRepository repo )
+        throws RepositoryException
+    {
+        if ( repo == null )
+            throw new IllegalArgumentException( "localRepo cannot be null" );
+
+        _server = repo.getServer();
+        if ( _server == null )
+            throw new IllegalArgumentException( LANG.getMessage( "bad.repository.server.null" ) );
+
+        if ( _server.getURL() == null )
+            throw new IllegalArgumentException( LANG.getMessage( "bad.repository.server.url.null" ) );
+
+        _repo = repo;
+
+        _reader = _repo.getReader();
+
+        try
+        {
+            _transport = new DefaultDeployer();
+            HashSet<Server> servers = new HashSet<Server>( 1 );
+            servers.add( _server );
+            _transport.setServers( servers );
+        }
+        catch ( HttpClientException e )
+        {
+            throw new RepositoryException( e );
+        }
+    }
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public Repository getRepository()
+    {
+        return _repo;
+    }
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public boolean canHandle( String protocol )
+    {
+        return AbstractRepository.DEFAULT_LOCAL_READ_PROTOCOL.equals( protocol );
+    }
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public String[] getProtocols()
+    {
+        return _protocols;
+    }
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public void close()
+    {
+        if ( _transport != null )
+            _transport.stop();
+    }
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public void writeArtifacts( Collection<Artifact> artifacts )
+        throws RepositoryException
+    {
+        if ( artifacts == null || artifacts.size() < 1 )
+            return;
+
+        Set<StreamVerifierFactory> vFacs = null;
+        Server server = _repo.getServer();
+        if ( server != null && server.hasWriterStreamVerifierFactories() )
+            vFacs = server.getWriterStreamVerifierFactories();
+
+        if ( vFacs == null ) // let it be empty, but not null
+            vFacs = new HashSet<StreamVerifierFactory>( 1 );
+
+        for ( Artifact artifact : artifacts )
+        {
+            writeArtifact( artifact, vFacs );
+        }
+    }
+
+    // ---------------------------------------------------------------------------------------------------------------
+    public void writeArtifact( Artifact artifact, Set<StreamVerifierFactory> vFacs )
+        throws RepositoryException
+    {
+        if ( artifact == null )
+            throw new RepositoryException( LANG.getMessage( "null.artifact" ) );
+
+        if ( artifact.getFile() == null || !artifact.getFile().exists() )
+            throw new RepositoryException( LANG.getMessage( "bad.artifact.file", artifact.toString(),
+                                                            ( artifact.getFile() == null ? "null"
+                                                                            : artifact.getFile().getAbsolutePath() ) ) );
+
+        boolean isPom = "pom".equals( artifact.getType() );
+
+        byte[] pomBlob = artifact.getPomBlob();
+        boolean hasPomBlob = pomBlob != null && pomBlob.length > 0;
+
+        if ( !artifact.hasClassifier() && !hasPomBlob )
+            throw new RepositoryException( LANG.getMessage( "no.pom.in.primary.artifact", artifact.toString() ) );
+
+        InputStream in = artifact.getStream();
+        if ( in == null )
+        {
+            File aFile = artifact.getFile();
+            if ( aFile == null && !isPom )
+            {
+                throw new RepositoryException( LANG.getMessage( "artifact.no.stream", artifact.toString() ) );
+            }
+
+            try
+            {
+                in = new FileInputStream( aFile );
+            }
+            catch ( FileNotFoundException e )
+            {
+                if ( !isPom )
+                    throw new RepositoryException( LANG.getMessage( "artifact.no.file", artifact.toString(),
+                                                                    aFile.getAbsolutePath(), e.getMessage() ) );
+            }
+        }
+        DefaultArtifactVersion dav = new DefaultArtifactVersion( artifact.getVersion() );
+        Quality aq = dav.getQuality();
+        boolean isSnapshot = aq.equals( Quality.SNAPSHOT_QUALITY ) || aq.equals( Quality.SNAPSHOT_TS_QUALITY );
+
+        String relGroupPath = artifact.getGroupId().replace( '.', '/' ) + "/" + artifact.getArtifactId();
+        String versionFolder =
+            ( isSnapshot ? ( dav.getBase() + '-' + Artifact.SNAPSHOT_VERSION ) : artifact.getVersion() );
+        String relVersionPath = relGroupPath + '/' + versionFolder;
+
+        try
+        {
+            if ( isPom )
+            {
+                if ( in == null && !hasPomBlob )
+                    throw new RepositoryException( LANG.getMessage( "pom.artifact.no.stream", artifact.toString() ) );
+
+                if ( in != null )
+                {
+                    byte[] pomBlobBytes = FileUtil.readRawData( in );
+                    hasPomBlob = pomBlobBytes != null && pomBlobBytes.length > 0;
+                    if ( hasPomBlob )
+                        pomBlob = pomBlobBytes;
+                }
+
+            }
+
+            String url = _server.getURL().toString();
+
+            // read metadata
+            String gaMdUrl = url + '/' + relGroupPath + '/' + _repo.getMetadataName();
+            byte[] gaMdBytes = _reader.readRawData( gaMdUrl, true );
+
+            String gavMdUrl = url + '/' + relVersionPath + '/' + _repo.getMetadataName();
+            byte[] gavMdBytes = _reader.readRawData( gavMdUrl, true );
+
+            HashSet<Binding> bindings = new HashSet<Binding>( 4 );
+
+            // first - take care of the binary
+            String binUrl = url + '/' + relVersionPath + '/' + artifact.getBaseName() + '.' + artifact.getType();
+            bindings.add( new Binding( new URL( binUrl ), artifact.getFile() ) );
+
+            // GA metadata
+            Metadata md = gaMdBytes == null ? null : MetadataBuilder.getMetadata( gaMdBytes );
+
+            if ( md == null )
+            {
+                md = new Metadata();
+                md.setGroupId( artifact.getGroupId() );
+                md.setArtifactId( artifact.getArtifactId() );
+            }
+
+            List<MetadataOperation> ops = new ArrayList<MetadataOperation>( 2 );
+
+            if ( isSnapshot )
+            {
+                Snapshot sn = MetadataBuilder.createSnapshot( artifact.getVersion() );
+                sn.setLocalCopy( true );
+                ops.add( new SetSnapshotOperation( new SnapshotOperand( sn ) ) );
+                ops.add( new AddVersionOperation( new StringOperand( versionFolder ) ) );
+            }
+            else
+                ops.add( new AddVersionOperation( new StringOperand( artifact.getVersion() ) ) );
+
+            byte[] gaResBytes = MetadataBuilder.changeMetadata( md, ops );
+            Metadata gaMd = MetadataBuilder.getMetadata( gaResBytes );
+
+            bindings.add( new Binding( new URL( gaMdUrl ), new ByteArrayInputStream( gaResBytes ) ) );
+
+            // now - GAV metadata
+            md = gavMdBytes == null ? null : MetadataBuilder.getMetadata( gavMdBytes );
+
+            if ( md == null )
+            {
+                md = new Metadata();
+                md.setGroupId( artifact.getGroupId() );
+                md.setArtifactId( artifact.getArtifactId() );
+                md.setVersion( artifact.getVersion() );
+            }
+
+            MetadataOperation mdOp = new AddVersionOperation( new StringOperand( artifact.getVersion() ) );
+            byte[] gavResBytes = MetadataBuilder.changeMetadata( md, mdOp );
+            Metadata gavMd = MetadataBuilder.getMetadata( gavResBytes );
+
+            bindings.add( new Binding( new URL( gavMdUrl ), new ByteArrayInputStream( gavResBytes ) ) );
+
+            if ( !isPom && hasPomBlob )
+            {
+                String pomUrl =
+                    url + '/' + relVersionPath + '/' + artifact.getArtifactId() + '-' + artifact.getVersion() + ".pom";
+                bindings.add( new Binding( new URL( pomUrl ), new ByteArrayInputStream( pomBlob ) ) );
+            }
+
+            DefaultDeployRequest request = new DefaultDeployRequest();
+            request.setBindings( bindings );
+
+            DeployResponse response = _transport.deploy( request );
+
+            if ( response.hasExceptions() )
+                throw new RepositoryException( response.getExceptions().toString() );
+
+            if ( _mdCache != null )
+            {
+                // cache metadata
+                // don't cache a single version on the GA level !!
+                // _mdCache.updateGA( _repo.getId(), new RepositoryGAMetadata(gaMd) );
+                _mdCache.updateGAV( _repo.getId(), new RepositoryGAVMetadata( gavMd ) );
+                if ( hasPomBlob && DefaultArtifact.class.isAssignableFrom( artifact.getClass() ) )
+                    _mdCache.saveRaw( (DefaultArtifact) artifact, pomBlob );
+            }
+
+        }
+        catch ( Exception e )
+        {
+            throw new RepositoryException( e );
+        }
+
+    }
+    // ---------------------------------------------------------------------------------------------------------------
+    // ---------------------------------------------------------------------------------------------------------------
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2Factory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2Factory.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2Factory.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryWriterM2Factory.java Mon Apr 27 23:12:25 2009
@@ -29,23 +29,25 @@
 import org.codehaus.plexus.lang.Language;
 
 public class RemoteRepositoryWriterM2Factory
-implements RepositoryWriterFactory
+    implements RepositoryWriterFactory
 {
-  private static final Language LANG = new DefaultLanguage( RemoteRepositoryWriterM2Factory.class );
-  private static final RemoteRepositoryWriterM2Factory FACTORY = new RemoteRepositoryWriterM2Factory();
-  
-  static 
-  {
-    AbstractRepository.register( AbstractRepository.DEFAULT_REPOSITORY_TYPE, FACTORY );
-  }
-  
-  public RepositoryWriter getWriter( Repository repo )
-  throws RepositoryException
-  {
-    if( repo == null || !(repo instanceof LocalRepository) )
-      throw new RepositoryException( LANG.getMessage( "bad.repository.type", repo == null ? "null" : repo.getClass().getName() ) );
-    
-    return new RemoteRepositoryWriterM2( (RemoteRepository)repo );
-  }
+    private static final Language LANG = new DefaultLanguage( RemoteRepositoryWriterM2Factory.class );
+
+    private static final RemoteRepositoryWriterM2Factory FACTORY = new RemoteRepositoryWriterM2Factory();
+
+    static
+    {
+        AbstractRepository.register( AbstractRepository.DEFAULT_REPOSITORY_TYPE, FACTORY );
+    }
+
+    public RepositoryWriter getWriter( Repository repo )
+        throws RepositoryException
+    {
+        if ( repo == null || !( repo instanceof LocalRepository ) )
+            throw new RepositoryException( LANG.getMessage( "bad.repository.type", repo == null ? "null"
+                            : repo.getClass().getName() ) );
+
+        return new RemoteRepositoryWriterM2( (RemoteRepository) repo );
+    }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryNonQualifiedArtifactException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryNonQualifiedArtifactException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryNonQualifiedArtifactException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryNonQualifiedArtifactException.java Mon Apr 27 23:12:25 2009
@@ -15,19 +15,15 @@
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-*/
+ */
 
 package org.apache.maven.mercury.repository.remote.m2;
 
 import org.apache.maven.mercury.repository.api.RepositoryException;
 
-
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class RepositoryNonQualifiedArtifactException
     extends RepositoryException

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryUtilM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryUtilM2.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryUtilM2.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/remote/m2/RepositoryUtilM2.java Mon Apr 27 23:12:25 2009
@@ -40,141 +40,142 @@
 import org.codehaus.plexus.lang.Language;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class RepositoryUtilM2
 {
-  private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( RepositoryUtilM2.class ); 
-  private static final Language LANG = new DefaultLanguage( RepositoryUtilM2.class );
-  //----------------------------------------------------------------------------------
-  public static void flip( LocalRepositoryM2 repo, File dest )
-  {
-    if( repo == null )
-      throw new IllegalArgumentException( LANG.getMessage( "lrepo.null" ) );
-
-    File lDir = repo.getDirectory();
-    
-    if( lDir == null )
-      throw new IllegalArgumentException( LANG.getMessage( "lrepo.no.dir" ) );
-    
-    if( !lDir.exists() || !lDir.isDirectory() )
-      throw new IllegalArgumentException( LANG.getMessage( "lrepo.dir.not.exists", lDir.toString() ) );
-    
-    if( dest.exists() && !dest.isFile() )
-      throw new IllegalArgumentException( LANG.getMessage( "dest.is.file", dest.toString() ) );
-    
-    
-  }
-
-  public static void flipLocalFolderToRemoteRepository( File repoDir )
-  {
-    
-    if( !repoDir.exists() || !repoDir.isDirectory() )
-      throw new IllegalArgumentException( LANG.getMessage( "lrepo.dir.not.exists", repoDir.toString() ) );
-
-    // temporary solution: just rename metadata, hoping it is correct
-    // ideally - will use metadata correction utility
-    FileUtil.renameFile( repoDir, LocalRepositoryM2.METADATA_FILE_NAME, RemoteRepositoryM2.METADATA_FILE_NAME );
-  }
-  
-  private static final void findGA( File dir )
-  throws MetadataException, IOException
-  {
-    if( dir.isFile() )
-      return;
-    
-    File [] files = dir.listFiles();
-    
-    if( files == null || files.length < 1 )
-      return;
-    
-    int dep = FileUtil.depth( dir );
-    
-    List<MetadataOperation> vo = null;
-    
-    if( dep <= 1 )
-      vo = new ArrayList<MetadataOperation>();
-    
-    for( File f : files )
+    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( RepositoryUtilM2.class );
+
+    private static final Language LANG = new DefaultLanguage( RepositoryUtilM2.class );
+
+    // ----------------------------------------------------------------------------------
+    public static void flip( LocalRepositoryM2 repo, File dest )
     {
-      if( f.isFile() )
-        return;
-      
-      if( dep == 1 )
-      {
-        vo.add( new AddVersionOperation( new StringOperand(f.getName()) ) );
-      }
-      else 
-        findGA( f );
+        if ( repo == null )
+            throw new IllegalArgumentException( LANG.getMessage( "lrepo.null" ) );
+
+        File lDir = repo.getDirectory();
+
+        if ( lDir == null )
+            throw new IllegalArgumentException( LANG.getMessage( "lrepo.no.dir" ) );
+
+        if ( !lDir.exists() || !lDir.isDirectory() )
+            throw new IllegalArgumentException( LANG.getMessage( "lrepo.dir.not.exists", lDir.toString() ) );
+
+        if ( dest.exists() && !dest.isFile() )
+            throw new IllegalArgumentException( LANG.getMessage( "dest.is.file", dest.toString() ) );
+
     }
-    
-    if( dep == 1 )
+
+    public static void flipLocalFolderToRemoteRepository( File repoDir )
     {
-      Metadata md = new Metadata();
-      
-      byte [] mdBytes = MetadataBuilder.changeMetadata( md, vo );
-      
-      FileUtil.writeRawData( new File( dir, RemoteRepositoryM2.METADATA_FILE_NAME ), mdBytes );
+
+        if ( !repoDir.exists() || !repoDir.isDirectory() )
+            throw new IllegalArgumentException( LANG.getMessage( "lrepo.dir.not.exists", repoDir.toString() ) );
+
+        // temporary solution: just rename metadata, hoping it is correct
+        // ideally - will use metadata correction utility
+        FileUtil.renameFile( repoDir, LocalRepositoryM2.METADATA_FILE_NAME, RemoteRepositoryM2.METADATA_FILE_NAME );
     }
-    else if( dep == 0 )
+
+    private static final void findGA( File dir )
+        throws MetadataException, IOException
     {
-      
+        if ( dir.isFile() )
+            return;
+
+        File[] files = dir.listFiles();
+
+        if ( files == null || files.length < 1 )
+            return;
+
+        int dep = FileUtil.depth( dir );
+
+        List<MetadataOperation> vo = null;
+
+        if ( dep <= 1 )
+            vo = new ArrayList<MetadataOperation>();
+
+        for ( File f : files )
+        {
+            if ( f.isFile() )
+                return;
+
+            if ( dep == 1 )
+            {
+                vo.add( new AddVersionOperation( new StringOperand( f.getName() ) ) );
+            }
+            else
+                findGA( f );
+        }
+
+        if ( dep == 1 )
+        {
+            Metadata md = new Metadata();
+
+            byte[] mdBytes = MetadataBuilder.changeMetadata( md, vo );
+
+            FileUtil.writeRawData( new File( dir, RemoteRepositoryM2.METADATA_FILE_NAME ), mdBytes );
+        }
+        else if ( dep == 0 )
+        {
+
+        }
     }
-  }
-  //----------------------------------------------------------------------------------
-  //----------------------------------------------------------------------------------
+    // ----------------------------------------------------------------------------------
+    // ----------------------------------------------------------------------------------
 }
-//=====================================================================================
+
+// =====================================================================================
 class copyGa
-implements Runnable
+    implements Runnable
 {
-  ConcurrentLinkedQueue<ArtifactCoordinates> _q;
-  File _root;
-  File _dest;
-  
-  public copyGa( ConcurrentLinkedQueue<ArtifactCoordinates> q, File from, File to )
-  {
-    this._q = q;
-    this._root = from;
-    this._dest = to;
-  }
-
-  // copy GAV to it's final dest
-  public void run()
-  {
-    try
+    ConcurrentLinkedQueue<ArtifactCoordinates> _q;
+
+    File _root;
+
+    File _dest;
+
+    public copyGa( ConcurrentLinkedQueue<ArtifactCoordinates> q, File from, File to )
     {
-      for(;;)
-      {
-        ArtifactCoordinates ga = _q.remove();
-        
-//        File gaDir = new File( _root );
-//        File gaDest = new File( _dest );
-//        
-//        gaDest.mkdirs();
-//        
-//        Metadata gaMd = new Metadata();
-//        gaMd.setGroupId( groupId )
-//        
-//        File [] versions = gaDir.listFiles(); 
-//        
-//        for( File v : versions )
-//        {
-//          if( v.isFile() )
-//            continue;
-//        }
-        
-      }
+        this._q = q;
+        this._root = from;
+        this._dest = to;
     }
-    catch( NoSuchElementException e )
+
+    // copy GAV to it's final dest
+    public void run()
     {
+        try
+        {
+            for ( ;; )
+            {
+                ArtifactCoordinates ga = _q.remove();
+
+                // File gaDir = new File( _root );
+                // File gaDest = new File( _dest );
+                //        
+                // gaDest.mkdirs();
+                //        
+                // Metadata gaMd = new Metadata();
+                // gaMd.setGroupId( groupId )
+                //        
+                // File [] versions = gaDir.listFiles();
+                //        
+                // for( File v : versions )
+                // {
+                // if( v.isFile() )
+                // continue;
+                // }
+
+            }
+        }
+        catch ( NoSuchElementException e )
+        {
+        }
     }
-  }
-  //-------------------------------------
+    // -------------------------------------
 }
-//=====================================================================================
+// =====================================================================================
 

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java Mon Apr 27 23:12:25 2009
@@ -64,7 +64,7 @@
 /**
  * this helper class hides the necessity to talk to localRepo and a bunch of remoteRepos. It also adds discrete
  * convenience methods, hiding batch nature of RepositoryReader
- *
+ * 
  * @author Oleg Gusakov
  * @version $Id$
  */
@@ -109,7 +109,7 @@
     private LocalRepository _localRepository;
 
     private RepositoryWriter _localRepositoryWriter;
-    
+
     private RemoteRepositoryReaderM2 _idleReader;
 
     private RepositoryMetadataCache _mdCache;
@@ -267,30 +267,32 @@
 
             _repositoryReaders[i++] = rr;
         }
-        
+
         try
         {
-            _idleReader = (RemoteRepositoryReaderM2) new RemoteRepositoryM2( "http://localhost", DependencyProcessor.NULL_PROCESSOR ).getReader();
+            _idleReader =
+                (RemoteRepositoryReaderM2) new RemoteRepositoryM2( "http://localhost",
+                                                                   DependencyProcessor.NULL_PROCESSOR ).getReader();
         }
         catch ( MalformedURLException e )
         {
             throw new RepositoryException( e );
         }
-        
+
         _initialized = true;
     }
-    
+
     /**
      * close all readers is they are started
      */
     public void close()
     {
-        if( ! _initialized )
+        if ( !_initialized )
             return;
-        
+
         try
         {
-            for( RepositoryReader rr : _repositoryReaders )
+            for ( RepositoryReader rr : _repositoryReaders )
                 rr.close();
         }
         finally
@@ -392,14 +394,11 @@
                             {
                                 res.add( key, rorRes );
                             }
-                            
-                            if ( 
-                                  ( !key.isVirtual() && key.isSingleton() )
-                                  ||
-                                  ( key.isVirtual() && rr.getRepository().isSufficient() )
-                               )
+
+                            if ( ( !key.isVirtual() && key.isSingleton() )
+                                || ( key.isVirtual() && rr.getRepository().isSufficient() ) )
                             {
-                                // fixed release is found or virtual is found 
+                                // fixed release is found or virtual is found
                                 // in a sufficient repo - no more scanning
                                 qList.remove( key );
                             }
@@ -445,7 +444,7 @@
             return;
         }
 
-        Map<ArtifactMetadata, List<ArtifactMetadata> > m = res.getResults();
+        Map<ArtifactMetadata, List<ArtifactMetadata>> m = res.getResults();
 
         for ( ArtifactMetadata key : m.keySet() )
         {
@@ -461,48 +460,45 @@
             return;
         }
 
-        TreeSet<ArtifactMetadata> ts = new TreeSet<ArtifactMetadata>(
-                        new Comparator<ArtifactMetadata>()
-                        {
-                            public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
-                            {
-                                String v1 = o1.getVersion();
-                                String v2 = o2.getVersion();
-                                
-                                if( o1.isVirtualSnapshot() && o1.getTimeStamp() != null )
-                                    v1 = v1.replace( Artifact.SNAPSHOT_VERSION, o1.getTimeStamp()+"-00" );
-                                
-                                if( o2.isVirtualSnapshot() && o2.getTimeStamp() != null )
-                                    v2 = v2.replace( Artifact.SNAPSHOT_VERSION, o2.getTimeStamp()+"-00" );
-                                
-                                  DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1 );
-                                  DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2 );
+        TreeSet<ArtifactMetadata> ts = new TreeSet<ArtifactMetadata>( new Comparator<ArtifactMetadata>()
+        {
+            public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
+            {
+                String v1 = o1.getVersion();
+                String v2 = o2.getVersion();
 
-                                  return av1.compareTo( av2 );
-                            }
+                if ( o1.isVirtualSnapshot() && o1.getTimeStamp() != null )
+                    v1 = v1.replace( Artifact.SNAPSHOT_VERSION, o1.getTimeStamp() + "-00" );
 
-                        }
-                                                                      );
+                if ( o2.isVirtualSnapshot() && o2.getTimeStamp() != null )
+                    v2 = v2.replace( Artifact.SNAPSHOT_VERSION, o2.getTimeStamp() + "-00" );
+
+                DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1 );
+                DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2 );
+
+                return av1.compareTo( av2 );
+            }
+
+        } );
         ts.addAll( res );
 
         ArtifactMetadata single = ts.last();
-        
-        // Oleg: -SNAPSHOT should always win        
-//        if( key.isVirtualSnapshot() )
-//        {
-//            ArtifactMetadata first = ts.first();
-//            
-//            if( first.isVirtualSnapshot() )
-//                single = first;
-//        }
-            
+
+        // Oleg: -SNAPSHOT should always win
+        // if( key.isVirtualSnapshot() )
+        // {
+        // ArtifactMetadata first = ts.first();
+        //            
+        // if( first.isVirtualSnapshot() )
+        // single = first;
+        // }
 
         res.clear();
 
         res.add( single );
     }
 
-    //----------------------------------------------------------------------------------------------------------------------------
+    // ----------------------------------------------------------------------------------------------------------------------------
     public ArtifactMetadata readDependencies( ArtifactMetadata bmd )
         throws IllegalArgumentException, RepositoryException
     {
@@ -555,29 +551,29 @@
 
                     if ( res != null )
                     {
-                        if( res.hasExceptions() )
+                        if ( res.hasExceptions() )
                         {
                             if ( LOG.isWarnEnabled() )
                             {
                                 LOG.warn( bmd + " dependecies: error : " + res.getExceptions().toString() );
                             }
                         }
-                        
-                        if( res.hasResults( bmd ) )
+
+                        if ( res.hasResults( bmd ) )
                         {
                             md.setDependencies( res.getResult( bmd ) );
                             md.setTracker( rr );
-    
+
                             if ( _eventManager != null )
                             {
                                 eventRead.setInfo( eventRead.getInfo() + ", found: " + md.getDependencies() );
                             }
-    
+
                             if ( LOG.isDebugEnabled() )
                             {
                                 LOG.debug( bmd + " dependecies found : " + md.getDependencies() );
                             }
-    
+
                             return md;
                         }
                     }
@@ -669,10 +665,10 @@
     }
 
     // ----------------------------------------------------------------------------------------------------------------------------
-    // TODO: Oleg: this is a copy of readArtifacts - optimize for the particular 
-    //             purpose - reading non-qualified virtuals, remove
+    // TODO: Oleg: this is a copy of readArtifacts - optimize for the particular
+    // purpose - reading non-qualified virtuals, remove
     //
-    // Now this can also be used to read artifacts without pooling them if there is such 
+    // Now this can also be used to read artifacts without pooling them if there is such
     //
     public ArtifactResults readArtifactsNoBatch( Collection<? extends ArtifactMetadata> query )
         throws RepositoryException
@@ -734,8 +730,8 @@
                     if ( rrRes.hasExceptions() )
                     {
                         throw new RepositoryException( LANG.getMessage( "error.reading.existing.artifact",
-                                                                         rrRes.getExceptions().toString(),
-                                                                         rr.getRepository().getId() ) );
+                                                                        rrRes.getExceptions().toString(),
+                                                                        rr.getRepository().getId() ) );
                     }
 
                     if ( rrRes.hasResults() )
@@ -787,10 +783,9 @@
                     }
                 }
 
-
                 if ( virtuals != null )
                 {
-                    // this makes them qualified because tracker will point to 
+                    // this makes them qualified because tracker will point to
                     // the repository
                     MetadataResults virtRes = readVersions( virtuals );
 
@@ -802,7 +797,8 @@
                     {
                         if ( virtRes.hasResults() )
                         {
-                            Map<ArtifactMetadata, ArtifactMetadata> sMap = new HashMap<ArtifactMetadata, ArtifactMetadata>();
+                            Map<ArtifactMetadata, ArtifactMetadata> sMap =
+                                new HashMap<ArtifactMetadata, ArtifactMetadata>();
 
                             for ( ArtifactMetadata md : virtRes.getResults().keySet() )
                             {
@@ -943,29 +939,26 @@
             {
                 return res;
             }
-            
+
             int qSize = query.size();
-            
+
             List<ArtifactMetadata> qualified = new ArrayList<ArtifactMetadata>( qSize );
-            
+
             List<ArtifactMetadata> leftovers = new ArrayList<ArtifactMetadata>( qSize );
-            
-            for( ArtifactMetadata md : query )
+
+            for ( ArtifactMetadata md : query )
             {
                 Object tracker = md.getTracker();
-    
+
                 // do we know where this metadata came from ?
-                if ( tracker != null 
-                     && RemoteRepositoryReaderM2.class.isAssignableFrom( tracker.getClass() )
-                     && !md.isVirtual()
-                     && md.isSingleton()
-                )
+                if ( tracker != null && RemoteRepositoryReaderM2.class.isAssignableFrom( tracker.getClass() )
+                    && !md.isVirtual() && md.isSingleton() )
                     qualified.add( md );
                 else
                     leftovers.add( md );
             }
 
-            if ( qualified.isEmpty()  && leftovers.isEmpty() )
+            if ( qualified.isEmpty() && leftovers.isEmpty() )
             {
                 throw new RepositoryException( LANG.getMessage( "internal.error.sorting.query", query.toString() ) );
             }
@@ -977,50 +970,52 @@
             // first read repository-qualified Artifacts
             GenericEvent eventRead = null;
 
-            if( qualified.size() > 0 )
-            try
-            {
-                if ( _eventManager != null )
-                    eventRead = new GenericEvent( EventTypeEnum.virtualRepositoryReader, EVENT_READ_ARTIFACTS, ""+qualified );
-                
-                ArtifactResults rrRes = new ArtifactResults();
-                
-                _idleReader.readQualifiedArtifacts( qualified, rrRes );
-
-                if ( rrRes.hasExceptions() )
+            if ( qualified.size() > 0 )
+                try
                 {
-                    throw new RepositoryException( LANG.getMessage( "error.reading.existing.artifact",
-                                                                     rrRes.getExceptions().toString(),
-                                                                     "multiple.server.internal.repo" ) );
-                }
+                    if ( _eventManager != null )
+                        eventRead =
+                            new GenericEvent( EventTypeEnum.virtualRepositoryReader, EVENT_READ_ARTIFACTS, ""
+                                + qualified );
 
-                if ( rrRes.hasResults() )
-                {
-                    for ( ArtifactMetadata bm : rrRes.getResults().keySet() )
-                    {
-                        List<Artifact> al = rrRes.getResults( bm );
+                    ArtifactResults rrRes = new ArtifactResults();
 
-                        res.addAll( bm, al );
+                    _idleReader.readQualifiedArtifacts( qualified, rrRes );
+
+                    if ( rrRes.hasExceptions() )
+                    {
+                        throw new RepositoryException( LANG.getMessage( "error.reading.existing.artifact",
+                                                                        rrRes.getExceptions().toString(),
+                                                                        "multiple.server.internal.repo" ) );
+                    }
 
-                        if ( _localRepositoryWriter != null )
+                    if ( rrRes.hasResults() )
+                    {
+                        for ( ArtifactMetadata bm : rrRes.getResults().keySet() )
                         {
-                            _localRepositoryWriter.writeArtifacts( al );
+                            List<Artifact> al = rrRes.getResults( bm );
+
+                            res.addAll( bm, al );
+
+                            if ( _localRepositoryWriter != null )
+                            {
+                                _localRepositoryWriter.writeArtifacts( al );
+                            }
                         }
                     }
                 }
-            }
-            catch ( Exception e )
-            {
-                throw new RepositoryException( e );
-            }
-            finally
-            {
-                if ( _eventManager != null )
+                catch ( Exception e )
                 {
-                    eventRead.stop();
-                    _eventManager.fireEvent( eventRead );
+                    throw new RepositoryException( e );
+                }
+                finally
+                {
+                    if ( _eventManager != null )
+                    {
+                        eventRead.stop();
+                        _eventManager.fireEvent( eventRead );
+                    }
                 }
-            }
 
             // then process unqualified virtuals
             if ( !Util.isEmpty( leftovers ) )
@@ -1040,7 +1035,6 @@
                     }
                 }
 
-
                 if ( virtuals != null )
                 {
                     MetadataResults virtRes = readVersions( virtuals );
@@ -1053,7 +1047,8 @@
                     {
                         if ( virtRes.hasResults() )
                         {
-                            Map<ArtifactMetadata, ArtifactMetadata> sMap = new HashMap<ArtifactMetadata, ArtifactMetadata>();
+                            Map<ArtifactMetadata, ArtifactMetadata> sMap =
+                                new HashMap<ArtifactMetadata, ArtifactMetadata>();
 
                             for ( ArtifactMetadata md : virtRes.getResults().keySet() )
                             {
@@ -1181,17 +1176,17 @@
         return readMetadata( bmd, false );
     }
 
-    public byte[] readMetadata( ArtifactMetadata bmd, boolean exempt  )
+    public byte[] readMetadata( ArtifactMetadata bmd, boolean exempt )
         throws MetadataReaderException
     {
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Asking for pom: " + bmd );
         }
-        
-        byte [] res = readRawData( bmd, "", "pom", exempt ); 
 
-        return res; 
+        byte[] res = readRawData( bmd, "", "pom", exempt );
+
+        return res;
     }
 
     // ----------------------------------------------------------------------------------------------------------------------------
@@ -1230,13 +1225,13 @@
                 event = new GenericEvent( EventTypeEnum.virtualRepositoryReader, EVENT_READ_RAW, eventTag );
             }
 
-            ArtifactMetadata bmdQuery = new ArtifactMetadata(bmd);
-            
-            if( !Util.isEmpty( type ))
+            ArtifactMetadata bmdQuery = new ArtifactMetadata( bmd );
+
+            if ( !Util.isEmpty( type ) )
                 bmdQuery.setType( type );
-            
+
             // pom cannot have classifiers
-            if( "pom".equals( bmdQuery.getType() ) )
+            if ( "pom".equals( bmdQuery.getType() ) )
                 bmdQuery.setClassifier( null );
 
             try
@@ -1253,18 +1248,18 @@
 
             if ( LOG.isDebugEnabled() )
             {
-                LOG.debug( "quality calculated as " + (vq.getQuality() == null ? "null" : vq.getQuality().name()) );
+                LOG.debug( "quality calculated as " + ( vq.getQuality() == null ? "null" : vq.getQuality().name() ) );
             }
 
             if ( Quality.SNAPSHOT_QUALITY.equals( vq ) )
             {
                 List<ArtifactMetadata> query = new ArrayList<ArtifactMetadata>( 1 );
-                
+
                 ArtifactMetadata nBmd = new ArtifactMetadata( bmdQuery );
-                
-                if( !Util.isEmpty( type ))
+
+                if ( !Util.isEmpty( type ) )
                     nBmd.setType( type );
-                
+
                 query.add( nBmd );
 
                 try
@@ -1277,22 +1272,22 @@
                             LOG.debug( "no snapshots found - throw exception" );
                         }
 
-                        throw new MetadataReaderException( LANG.getMessage( "no.snapshots", bmd.toString(),
-                                                                             classifier, type ) );
+                        throw new MetadataReaderException( LANG.getMessage( "no.snapshots", bmd.toString(), classifier,
+                                                                            type ) );
                     }
 
                     if ( vRes.hasResults( nBmd ) )
                     {
                         List<ArtifactMetadata> versions = vRes.getResult( nBmd );
-                        
+
                         processSingletons( nBmd, versions );
 
-//                        TreeSet<ArtifactMetadata> snapshots =
-//                            new TreeSet<ArtifactMetadata>( new MetadataVersionComparator() );
-//                        snapshots.addAll( versions );
-//
-//                        bmdQuery = snapshots.last();
-                        
+                        // TreeSet<ArtifactMetadata> snapshots =
+                        // new TreeSet<ArtifactMetadata>( new MetadataVersionComparator() );
+                        // snapshots.addAll( versions );
+                        //
+                        // bmdQuery = snapshots.last();
+
                         bmdQuery = versions.get( 0 );
                     }
                     else
@@ -1302,8 +1297,8 @@
                             LOG.debug( "no snapshots found - throw exception" );
                         }
 
-                        throw new MetadataReaderException( LANG.getMessage( "no.snapshots", bmd.toString(),
-                                                                             classifier, type ) );
+                        throw new MetadataReaderException( LANG.getMessage( "no.snapshots", bmd.toString(), classifier,
+                                                                            type ) );
                     }
                 }
                 catch ( Exception e )
@@ -1372,11 +1367,13 @@
             }
         }
     }
+
     // ----------------------------------------------------------------------------------------------------------------------------
     public RepositoryMetadataCache getCache()
     {
         return _mdCache;
     }
+
     // ----------------------------------------------------------------------------------------------------------------------------
     public void register( MercuryEventListener listener )
     {

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DestinationRealmResolver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DestinationRealmResolver.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DestinationRealmResolver.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DestinationRealmResolver.java Mon Apr 27 23:12:25 2009
@@ -32,101 +32,96 @@
 import org.mortbay.jetty.client.security.RealmResolver;
 
 /**
- * DestinationRealmResolver
- *
- * Resolve a security realm based on the Server instance
- * which matches an async Destination.
+ * DestinationRealmResolver Resolve a security realm based on the Server instance which matches an async Destination.
  */
-public class DestinationRealmResolver implements RealmResolver
+public class DestinationRealmResolver
+    implements RealmResolver
 {
-    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger(DestinationRealmResolver.class);
-    
+    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( DestinationRealmResolver.class );
+
     protected Set<Server> _servers = new HashSet<Server>();
-    
-    
-    
-    public DestinationRealmResolver (Set<Server> servers)
+
+    public DestinationRealmResolver( Set<Server> servers )
     {
-        _servers.addAll(servers);
+        _servers.addAll( servers );
     }
 
-    public Realm getRealm(String name, HttpDestination dest, String pathSpec)
-            throws IOException
+    public Realm getRealm( String name, HttpDestination dest, String pathSpec )
+        throws IOException
     {
-       Address address = dest.getAddress();
-       boolean secure = dest.isSecure();
+        Address address = dest.getAddress();
+        boolean secure = dest.isSecure();
 
-       if( LOG.isDebugEnabled() )
-       {
-         LOG.debug("Dest "+address.getHost()+":"+address.getPort()+"(secure="+secure+")" );
-         LOG.debug("Server list: "+_servers );
-         
-       }
-
-       //get a username and password appropriate for the destination. Usernames and passwords are
-       //associated with Server Credential objects.
-       Server server = null;
-       Iterator<Server> itor = _servers.iterator();
-       while (server==null && itor.hasNext())
-       {
-           Server s = itor.next();
-           if (s.getURL() != null)
-           {
-               String protocol = s.getURL().getProtocol();
-               String host = s.getURL().getHost();
-               int port = s.getURL().getPort();
-               if( port == -1 )
-               {
-                 port = "https".equalsIgnoreCase( protocol ) ? 443 : 80;
-               }
-
-               if( LOG.isDebugEnabled() )
-                 LOG.debug("Trying dest "+address.getHost()+":"+address.getPort()+"(secure="+dest.isSecure()
-                     +") against server "+protocol+"://"+host+":"+port );
-
-               if (((secure && "https".equalsIgnoreCase(protocol)) || (!secure && "http".equalsIgnoreCase(protocol)))
-                   &&
-                   (address.getPort() == port))
-               {
-                   if (address.getHost().equalsIgnoreCase(host) || address.getHost().equalsIgnoreCase(host))
-                   {
-                       server = s;
-                       if (LOG.isDebugEnabled())
-                           LOG.debug("Matched server "+address.getHost()+":"+address.getPort());
-                   }
-               }
-           }
-       }
-
-       if (server == null || server.getServerCredentials() == null)
-       {
-           if (LOG.isDebugEnabled())
-               LOG.debug("No server matching "+address.getHost()+":"+address.getPort()+" or no credentials");
-           return null;
-       }
-       
-       if (server.getServerCredentials().isCertificate())
-           throw new UnsupportedOperationException("Certificate not supported");
-       
-       final Server realmServer = server;
-       return new Realm ()
-       {
-           public String getCredentials()
-           {
-               return realmServer.getServerCredentials().getPass();
-           }
-
-           public String getId()
-           {
-               return realmServer.getId();
-           }
-
-           public String getPrincipal()
-           {
-               return realmServer.getServerCredentials().getUser();
-           }
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( "Dest " + address.getHost() + ":" + address.getPort() + "(secure=" + secure + ")" );
+            LOG.debug( "Server list: " + _servers );
+
+        }
+
+        // get a username and password appropriate for the destination. Usernames and passwords are
+        // associated with Server Credential objects.
+        Server server = null;
+        Iterator<Server> itor = _servers.iterator();
+        while ( server == null && itor.hasNext() )
+        {
+            Server s = itor.next();
+            if ( s.getURL() != null )
+            {
+                String protocol = s.getURL().getProtocol();
+                String host = s.getURL().getHost();
+                int port = s.getURL().getPort();
+                if ( port == -1 )
+                {
+                    port = "https".equalsIgnoreCase( protocol ) ? 443 : 80;
+                }
+
+                if ( LOG.isDebugEnabled() )
+                    LOG.debug( "Trying dest " + address.getHost() + ":" + address.getPort() + "(secure="
+                        + dest.isSecure() + ") against server " + protocol + "://" + host + ":" + port );
+
+                if ( ( ( secure && "https".equalsIgnoreCase( protocol ) ) || ( !secure && "http".equalsIgnoreCase( protocol ) ) )
+                    && ( address.getPort() == port ) )
+                {
+                    if ( address.getHost().equalsIgnoreCase( host ) || address.getHost().equalsIgnoreCase( host ) )
+                    {
+                        server = s;
+                        if ( LOG.isDebugEnabled() )
+                            LOG.debug( "Matched server " + address.getHost() + ":" + address.getPort() );
+                    }
+                }
+            }
+        }
+
+        if ( server == null || server.getServerCredentials() == null )
+        {
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "No server matching " + address.getHost() + ":" + address.getPort() + " or no credentials" );
+            return null;
+        }
+
+        if ( server.getServerCredentials().isCertificate() )
+            throw new UnsupportedOperationException( "Certificate not supported" );
+
+        final Server realmServer = server;
+        return new Realm()
+        {
+            public String getCredentials()
+            {
+                return realmServer.getServerCredentials().getPass();
+            }
+
+            public String getId()
+            {
+                return realmServer.getId();
+            }
+
+            public String getPrincipal()
+            {
+                return realmServer.getServerCredentials().getUser();
+            }
 
-       };
+        };
     }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java Mon Apr 27 23:12:25 2009
@@ -33,37 +33,42 @@
  * <p/>
  * Base class for asynchronously PUTting or GETting a file.
  */
-public abstract class FileExchange extends HttpExchange
+public abstract class FileExchange
+    extends HttpExchange
 {
 
-   
-
     public static final String __BATCH_HEADER = "Jetty-Batch-Id";
+
     public static final String __BATCH_SUPPORTED_HEADER = "Jetty-Batch-Supported";
+
     public static final String __BATCH_COMMIT_HEADER = "Jetty-Batch-Commit";
-    public static final String __BATCH_DISCARD_HEADER = "Jetty-Batch-Discard";
 
+    public static final String __BATCH_DISCARD_HEADER = "Jetty-Batch-Discard";
 
     protected HttpClient _httpClient;
+
     protected int _status;
+
     protected String _url;
+
     protected File _localFile;
+
     protected Binding _binding;
+
     protected Server _server;
 
     public abstract void onFileComplete( String url, File localFile );
 
     public abstract void onFileError( String url, Exception e );
 
-
     public FileExchange( Server server, Binding binding, File localFile, HttpClient client )
     {
         _server = server;
         _binding = binding;
-        if (_binding != null)
+        if ( _binding != null )
         {
             URL url = binding.getRemoteResource();
-            if (url != null)
+            if ( url != null )
                 _url = url.toString();
         }
 
@@ -76,7 +81,7 @@
     {
         try
         {
-            SecureSender.send(_server, _httpClient, this);
+            SecureSender.send( _server, _httpClient, this );
         }
         catch ( Exception e )
         {
@@ -98,10 +103,10 @@
     {
         onFileError( _url, new Exception( "Timeout occurred" ) );
     }
-    
-    protected void onConnectionFailed(Throwable ex)
+
+    protected void onConnectionFailed( Throwable ex )
     {
-        onFileError(_url, new Exception(ex));
+        onFileError( _url, new Exception( ex ) );
     }
-    
+
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HandshakeExchange.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HandshakeExchange.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HandshakeExchange.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HandshakeExchange.java Mon Apr 27 23:12:25 2009
@@ -28,15 +28,20 @@
 /**
  * HandshakeExchange
  * <p/>
- * Asychronous http message sending. Used to generate a commit or discard
- * message to the remote server after the mercury upload is finished.
+ * Asychronous http message sending. Used to generate a commit or discard message to the remote server after the mercury
+ * upload is finished.
  */
-public abstract class HandshakeExchange extends HttpExchange
+public abstract class HandshakeExchange
+    extends HttpExchange
 {
     private HttpClient _httpClient;
+
     private String _method;
+
     private String _url;
+
     private Map<String, String> _headers;
+
     private int _status;
 
     public abstract void onHandshakeComplete( String url );
@@ -78,7 +83,6 @@
         }
     }
 
-
     protected void onResponseStatus( Buffer version, int status, Buffer reason )
     {
         _status = status;

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientException.java Mon Apr 27 23:12:25 2009
@@ -30,15 +30,14 @@
 //See the License for the specific language governing permissions and
 //limitations under the License.
 //========================================================================
-
 package org.apache.maven.mercury.spi.http.client;
+
 import org.apache.maven.mercury.transport.api.Binding;
 
 /**
  * BatchException
  * <p/>
- * Exception that occurs whilst deploying or retrieving files
- * asynchronously.
+ * Exception that occurs whilst deploying or retrieving files asynchronously.
  */
 public class HttpClientException
     extends Exception
@@ -68,7 +67,6 @@
         return binding;
     }
 
-
     public String getMessage()
     {
         return super.getMessage() + " for " + binding;