maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r709625 - in /maven/mercury/trunk/mercury-repo/mercury-repo-local-flat: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/ src/main/java/org/...
Date Sat, 01 Nov 2008 02:55:55 GMT
Author: ogusakov
Date: Fri Oct 31 19:55:54 2008
New Revision: 709625

URL: http://svn.apache.org/viewvc?rev=709625&view=rev
Log:
adding flat repo

Added:
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/pom.xml
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2Factory.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2Factory.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/resources/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/m2/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/pubring.gpg   (with props)
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/secring.gpg   (with props)
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/1/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/1/a-1.pom
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar   (with props)
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar.asc
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.pom
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.jar   (with props)
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.pom
    maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/maven-metadata.xml

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/pom.xml
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/pom.xml?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/pom.xml (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/pom.xml Fri Oct 31 19:55:54 2008
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.mercury</groupId>
+  <artifactId>mercury-repo-local-flat</artifactId>
+  <name>Mercury Local Flat Repository:  ${project.version}</name>
+  <description />
+  <parent>
+  	<groupId>org.apache.maven.mercury</groupId>
+  	<artifactId>mercury-repo</artifactId>
+  	<version>1.0.0-alpha-2-SNAPSHOT</version>
+  </parent>
+  <dependencies>
+  	<dependency>
+  		<groupId>org.apache.maven.mercury</groupId>
+  		<artifactId>mercury-repo-api</artifactId>
+  		<version>${project.version}</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>commons-digester</groupId>
+  		<artifactId>commons-digester</artifactId>
+  		<version>1.8</version>
+  		<scope>test</scope>
+  	</dependency>
+  	<dependency>
+  		<groupId>org.apache.maven.mercury</groupId>
+  		<artifactId>mercury-md-shared</artifactId>
+  		<version>${project.version}</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>org.apache.maven.mercury</groupId>
+  		<artifactId>mercury-util</artifactId>
+  		<version>${project.version}</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>org.apache.maven.mercury</groupId>
+  		<artifactId>mercury-crypto-basic</artifactId>
+  		<version>${project.version}</version>
+      <scope>test</scope>
+  	</dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,161 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
+import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
+import org.apache.maven.mercury.util.FileUtil;
+
+/**
+ * artifact relative location data object - used by repositories to hold on to intermediate path calculations 
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class ArtifactLocation
+{
+  public static final String POM_EXT = ".pom";
+
+  private String prefix;
+  
+  private String gaPath;
+  private String versionDir;
+  private String baseName;
+  private String version;
+  private String classifier;
+  private String type;
+  
+  private ArtifactBasicMetadata bmd;
+  
+  public ArtifactLocation( String prefix, ArtifactBasicMetadata bmd )
+  {
+    if( prefix == null || bmd == null || bmd.getGroupId() == null || bmd.getArtifactId() == null || bmd.getVersion() == null )
+      return;
+    
+    this.bmd = bmd;
+
+    this.prefix     = prefix;
+    this.gaPath     = bmd.getGroupId().replace( '.', FileUtil.SEP_CHAR ) + FileUtil.SEP + bmd.getArtifactId();
+    this.version    = bmd.getVersion();
+    this.baseName   = bmd.getArtifactId();
+    this.versionDir = this.version;
+    this.classifier = bmd.getClassifier();
+    this.type       = bmd.getType();
+  }
+  
+  public String getRelPath()
+  {
+    return gaPath+FileUtil.SEP+versionDir+FileUtil.SEP+baseName+FileUtil.DASH+version+getDashedClassifier()+'.'+type;
+  }
+  
+  public String getRelPomPath()
+  {
+    return gaPath+FileUtil.SEP+versionDir+FileUtil.SEP+baseName+FileUtil.DASH+version+POM_EXT;
+  }
+  
+  public String getAbsPath()
+  {
+    if( prefix == null )
+      return null;
+
+    return getSeparatedPrefix() + getRelPath();
+  }
+  
+  public String getAbsPomPath()
+  {
+    if( prefix == null )
+      return null;
+
+    return getSeparatedPrefix() + getRelPomPath();
+  }
+  
+  public String getGavPath()
+  {
+    return getGaPath()+FileUtil.SEP+versionDir;
+  }
+  
+  public String getBaseVersion()
+  {
+    if( version == null )
+      return null;
+    
+    DefaultArtifactVersion dav = new DefaultArtifactVersion( version );
+    return dav.getBase();
+  }
+  
+  //---------------------------------------------------------
+  public String getGaPath()
+  {
+    return gaPath;
+  }
+  public void setGaPath( String gaPath )
+  {
+    this.gaPath = gaPath;
+  }
+  public String getVersionDir()
+  {
+    return versionDir;
+  }
+  public void setVersionDir( String versionDir )
+  {
+    this.versionDir = versionDir;
+  }
+  public String getBaseName()
+  {
+    return baseName;
+  }
+  public void setBaseName( String baseName )
+  {
+    this.baseName = baseName;
+  }
+  public String getVersion()
+  {
+    return version;
+  }
+  public void setVersion( String version )
+  {
+    this.version = version;
+  }
+  public String getClassifier()
+  {
+    return classifier;
+  }
+  public String getDashedClassifier()
+  {
+    return (classifier == null||classifier.length()<1) ? "" : FileUtil.DASH+classifier;
+  }
+  public void setClassifier( String classifier )
+  {
+    this.classifier = classifier;
+  }
+  public String getType()
+  {
+    return type;
+  }
+  public void setType( String type )
+  {
+    this.type = type;
+  }
+  public String getPrefix()
+  {
+    return prefix;
+  }
+  public String getSeparatedPrefix()
+  {
+    if( prefix == null )
+      return null;
+
+    return prefix+(prefix.endsWith( FileUtil.SEP ) ? "" : FileUtil.SEP);
+  }
+  public void setPrefix( String prefix )
+  {
+    this.prefix = prefix;
+  }
+
+  @Override
+  public String toString()
+  {
+    return bmd == null ? "no ArtifactBasicMetadata" : bmd.toString();
+  }
+  
+}
\ No newline at end of file

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,94 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import java.io.File;
+
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.NonExistentProtocolException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.repository.api.RepositoryWriter;
+import org.apache.maven.mercury.transport.api.Server;
+
+public class LocalRepositoryM2
+extends AbstractRepository
+implements LocalRepository
+{
+    private File directory;
+    
+    private static final String METADATA_NAME = "maven-metadata-local.xml";
+
+    //----------------------------------------------------------------------------------
+    public LocalRepositoryM2( Server server )
+    {
+        super( server.getId(), DEFAULT_REPOSITORY_TYPE );
+        this.directory = new File( server.getURL().getFile() );
+        this.server = server;
+        this.metadataName = METADATA_NAME;
+    }
+    //----------------------------------------------------------------------------------
+    public LocalRepositoryM2( String id, File directory )
+    {
+        super( id, DEFAULT_REPOSITORY_TYPE );
+        this.directory = directory;
+        this.metadataName = METADATA_NAME;
+    }
+    //----------------------------------------------------------------------------------
+    public LocalRepositoryM2( String id, File directory, String type )
+    {
+        super( id, type );
+        this.directory = directory;
+        this.metadataName = METADATA_NAME;
+    }
+    //----------------------------------------------------------------------------------
+    public File getDirectory()
+    {
+        return directory;
+    }
+    //----------------------------------------------------------------------------------
+    public RepositoryReader getReader( DependencyProcessor processor ) 
+    {
+      if( reader == null )
+        reader = new LocalRepositoryReaderM2( this, processor );
+
+      return reader;
+    }
+    //----------------------------------------------------------------------------------
+    // TODO oleg: what happens in multi-threaded execution?? 
+    public RepositoryReader getReader( DependencyProcessor processor, String protocol )
+    {
+       return getReader(processor);
+    }
+    //----------------------------------------------------------------------------------
+    // TODO oleg: what happens in multi-threaded execution?? 
+    public RepositoryWriter getWriter()
+    {
+      if( writer == null )
+        writer = new LocalRepositoryWriterM2(this);
+      
+      return writer;
+    }
+    //----------------------------------------------------------------------------------
+    public RepositoryWriter getWriter( String protocol )
+        throws NonExistentProtocolException
+    {
+      return getWriter();
+    }
+    //----------------------------------------------------------------------------------
+    public boolean isLocal()
+    {
+      return true;
+    }
+    //----------------------------------------------------------------------------------
+    public boolean isReadOnly()
+    {
+      return false;
+    }
+    //----------------------------------------------------------------------------------
+    public String getType()
+    {
+      return DEFAULT_REPOSITORY_TYPE;
+    }
+    //----------------------------------------------------------------------------------
+    //----------------------------------------------------------------------------------
+}

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,576 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
+import org.apache.maven.mercury.artifact.DefaultArtifact;
+import org.apache.maven.mercury.artifact.Quality;
+import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
+import org.apache.maven.mercury.artifact.version.VersionException;
+import org.apache.maven.mercury.artifact.version.VersionRange;
+import org.apache.maven.mercury.artifact.version.VersionRangeFactory;
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.builder.api.MetadataReader;
+import org.apache.maven.mercury.builder.api.MetadataReaderException;
+import org.apache.maven.mercury.crypto.api.StreamObserverException;
+import org.apache.maven.mercury.crypto.api.StreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamVerifierException;
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+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.ArtifactBasicResults;
+import org.apache.maven.mercury.repository.api.ArtifactResults;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.util.FileUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+public class LocalRepositoryReaderM2
+extends AbstracRepositoryReader
+implements RepositoryReader, MetadataReader
+{
+  private static final org.slf4j.Logger _log = org.slf4j.LoggerFactory.getLogger( LocalRepositoryReaderM2.class ); 
+  private static final Language _lang = new DefaultLanguage( LocalRepositoryReaderM2.class );
+  //---------------------------------------------------------------------------------------------------------------
+  private static final String [] _protocols = new String [] { "file" };
+  
+  LocalRepository _repo;
+  File _repoDir;
+  //---------------------------------------------------------------------------------------------------------------
+  public LocalRepositoryReaderM2( LocalRepository repo, DependencyProcessor mdProcessor )
+  {
+    if( repo == null )
+      throw new IllegalArgumentException("localRepo cannot be null");
+    
+    _repoDir = repo.getDirectory();
+    if( _repoDir == null )
+      throw new IllegalArgumentException("localRepo directory cannot be null");
+    
+    if( !_repoDir.exists() )
+      throw new IllegalArgumentException("localRepo directory \""+_repoDir.getAbsolutePath()+"\" should exist");
+
+    _repo = repo;
+    
+    if( mdProcessor == null )
+      throw new IllegalArgumentException("MetadataProcessor cannot be null ");
+    
+    setDependencyProcessor(  mdProcessor );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public Repository getRepository()
+  {
+    return _repo;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private static ArtifactLocation calculateLocation( String root, ArtifactBasicMetadata bmd, AbstractRepOpResult res )
+  {
+    ArtifactLocation loc = new ArtifactLocation( root, bmd );
+
+    File   gaDir = new File( root, loc.getGaPath() );
+    
+    if( !gaDir.exists() )
+    {
+      res.addError( bmd, new RepositoryException( _lang.getMessage( "ga.not.found", bmd.toString(), loc.getGaPath() ) ) );
+      return null;
+    }
+    
+    Quality vq = new Quality( loc.getVersion() );
+    
+    // RELEASE = LATEST - SNAPSHOTs
+    if( Artifact.RELEASE_VERSION.equals( loc.getVersion() )
+        ||
+        Artifact.LATEST_VERSION.equals( loc.getVersion() ) 
+      )
+    {
+      boolean noSnapshots = Artifact.RELEASE_VERSION.equals( loc.getVersion() );
+      loc.setVersion( null );
+      DefaultArtifactVersion tempDav = null;
+      DefaultArtifactVersion tempDav2 = null;
+
+      File [] files = gaDir.listFiles();
+
+      // find latest
+      for( File vf : files )
+      {
+        if( vf.isFile() )
+          continue;
+        
+        String vn = vf.getName();
+        
+        // RELEASE?
+        if( noSnapshots && vn.endsWith( Artifact.SNAPSHOT_VERSION ))
+          continue;
+        
+        if( loc.getVersion() == null )
+        {
+          loc.setVersion( vn );
+          tempDav = new DefaultArtifactVersion( vn );
+          continue;
+        }
+        
+        tempDav2 = new DefaultArtifactVersion( vn );
+        if( tempDav2.compareTo( tempDav ) > 0 )
+        {
+          loc.setVersion( vn );
+          tempDav = tempDav2;
+        }
+        
+      }
+
+      if( loc.getVersion() == null )
+      {
+        res.addError( bmd, new RepositoryException( _lang.getMessage( "gav.not.found", bmd.toString(), loc.getGaPath() ) ) );
+        return null;
+      }
+      
+      // LATEST is a SNAPSHOT :(
+      if( loc.getVersion().endsWith( Artifact.SNAPSHOT_VERSION ) )
+      {
+        loc.setVersionDir( loc.getVersion() );
+
+        if( !findLatestSnapshot( bmd, loc, res ) )
+          return null;
+      }
+      else
+        // R or L found and actual captured in loc.version
+        loc.setVersionDir( loc.getVersion() );
+    }
+    // regular snapshot requested
+    else if( loc.getVersion().endsWith( Artifact.SNAPSHOT_VERSION ) )
+    {
+      File gavDir = new File( gaDir, loc.getVersion() );
+      if( !gavDir.exists() )
+      {
+        res.addError( bmd, new RepositoryException( _lang.getMessage( "gavdir.not.found", bmd.toString(), gavDir.getAbsolutePath() ) ) );
+        return null;
+      }
+      
+      if( !findLatestSnapshot( bmd, loc, res ) )
+        return null;
+        
+    }
+    // time stamped snapshot requested
+    else if( vq.equals( Quality.SNAPSHOT_TS_QUALITY ))
+    {
+      loc.setVersionDir( loc.getBaseVersion()+FileUtil.DASH+Artifact.SNAPSHOT_VERSION );
+    }
+    
+    return loc;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public ArtifactResults readArtifacts( Collection<ArtifactBasicMetadata> query )
+      throws RepositoryException,
+      IllegalArgumentException
+  {
+    if( query == null || query.isEmpty() )
+      throw new IllegalArgumentException( _lang.getMessage( "empty.query", query==null?"null":"empty" ) );
+    
+    ArtifactResults res = new ArtifactResults();
+    
+    Set<StreamVerifierFactory> vFacs = null;
+    
+    if( _repo.hasServer() && _repo.getServer().hasReaderStreamVerifierFactories() )
+      vFacs = _repo.getServer().getReaderStreamVerifierFactories();
+    
+    for( ArtifactBasicMetadata bmd : query )
+    {
+      DefaultArtifact da = bmd instanceof DefaultArtifact ? (DefaultArtifact)bmd : new DefaultArtifact( bmd );
+      
+      ArtifactLocation loc = calculateLocation( _repoDir.getAbsolutePath(), bmd, res );
+      
+      if( loc == null )
+        continue;
+      
+      File binary = new File( loc.getAbsPath() );
+      
+      // binary calculated 
+      if( ! binary.exists() )
+      {
+        res.addError( bmd, new RepositoryException( _lang.getMessage( "binary.not.found", bmd.toString(), binary.getAbsolutePath() ) ) );
+        continue;
+      }
+
+      try // reading pom if one exists
+      {
+        if( checkFile( binary, vFacs ) )
+          da.setFile( binary );
+
+        if( "pom".equals( bmd.getType() ) ) 
+        {
+            da.setPomBlob( FileUtil.readRawData( binary ) );
+        }
+        else
+        {
+          File pomFile = new File( loc.getAbsPomPath() );
+          if( pomFile.exists() )
+          {
+            if( checkFile( pomFile, vFacs ) )
+              da.setPomBlob( FileUtil.readRawData( pomFile ) );
+          }
+          else
+            _log.warn( _lang.getMessage( "pom.not.found", bmd.toString()) );
+        }
+
+        da.setVersion( loc.getVersion() );
+        res.add( bmd, da );
+      }
+      catch( Exception e )
+      {
+        throw new RepositoryException( e );
+      }
+    }
+    return res;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private static boolean checkFile( File f, Set<StreamVerifierFactory> vFacs )
+  throws RepositoryException, StreamVerifierException
+  {
+    if( vFacs != null )
+    {
+      String fileName = f.getAbsolutePath();
+      
+      HashSet<StreamVerifier> vs = new HashSet<StreamVerifier>( vFacs.size() );
+      
+      for( StreamVerifierFactory svf : vFacs )
+      {
+        StreamVerifier sv = svf.newInstance();
+        String ext = sv.getAttributes().getExtension();
+        String sigFileName = fileName+(ext.startsWith( "." )?"":".")+ext;
+        File sigFile = new File( sigFileName );
+        if( sigFile.exists() )
+        {
+          try
+          {
+            sv.initSignature( FileUtil.readRawDataAsString( sigFile ) );
+          }
+          catch( IOException e )
+          {
+            throw new RepositoryException( _lang.getMessage( "cannot.read.signature.file", sigFileName, e.getMessage() ) );
+          }
+          vs.add( sv );
+        }
+        else if( ! sv.getAttributes().isLenient() )
+        {
+          throw new RepositoryException( _lang.getMessage( "no.signature.file", ext, sigFileName ) );
+        }
+        // otherwise ignore absence of signature file, if verifier is lenient
+      }
+
+      FileInputStream fin = null;
+      try
+      {
+        fin = new FileInputStream( f );
+        byte [] buf = new byte[ 1024 ];
+        int n = -1;
+        while( (n = fin.read( buf )) != -1 )
+        {
+          for( StreamVerifier sv : vs )
+            try
+            {
+              sv.bytesReady( buf, 0, n );
+            }
+            catch( StreamObserverException e )
+            {
+              if( ! sv.getAttributes().isLenient() )
+                throw new RepositoryException(e);
+            }
+        }
+        
+        for( StreamVerifier sv : vs )
+        {
+          if( sv.verifySignature() )
+          {
+            if( sv.getAttributes().isSufficient() )
+              break;
+          }
+          else
+          {
+            if( !sv.getAttributes().isLenient() )
+              throw new RepositoryException( _lang.getMessage( "signature.failed", sv.getAttributes().getExtension(), fileName ) );
+          }
+        }
+      }
+      catch( IOException e )
+      {
+        throw new RepositoryException(e);
+      }
+      finally
+      {
+        if( fin != null ) try { fin.close(); } catch( Exception any ) {}
+      }
+    }
+    return true;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  /**
+   * 
+   */
+  public ArtifactBasicResults readDependencies( Collection<ArtifactBasicMetadata> query )
+      throws RepositoryException,
+      IllegalArgumentException
+  {
+    if( query == null || query.size() < 1 )
+      return null;
+
+    ArtifactBasicResults ror = null;
+    
+    File pomFile = null;
+    for( ArtifactBasicMetadata bmd : query )
+    {
+      String pomPath = bmd.getGroupId().replace( '.', '/' )
+                      + "/" + bmd.getArtifactId()
+                      + "/" + bmd.getVersion()
+                      + "/" + bmd.getArtifactId()+'-'+bmd.getVersion()
+                      + ".pom"
+                      ;
+      
+      pomFile = new File( _repoDir, pomPath );
+      if( ! pomFile.exists() )
+      {
+        _log.warn( "file \""+pomPath+"\" does not exist in local repo" );
+        continue;
+      }
+      
+      // TODO HIGH og: delegate POM processing to maven-project
+      // for testing purpose - I plug in my test processor
+      try
+      {
+        List<ArtifactBasicMetadata> deps = _mdProcessor.getDependencies( bmd, _mdReader == null ? this : _mdReader
+                                                                       , System.getenv()
+                                                                       , System.getProperties()
+                                                                       );
+        ror = ArtifactBasicResults.add( ror, bmd, deps );
+      }
+      catch( MetadataReaderException e )
+      {
+        _log.warn( "error reading "+bmd.toString()+" dependencies", e );
+        continue;
+      }
+      
+    }
+    
+    return ror;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private static boolean findLatestSnapshot( ArtifactBasicMetadata bmd, ArtifactLocation loc, AbstractRepOpResult res )
+  {
+    File binary = new File( loc.getAbsPath() );
+    
+    if( binary.exists() )
+      return true;
+
+    // no real SNAPSHOT file, let's try to find one
+    File gavDir = new File( loc.getGavPath() );
+    File [] files = gavDir.listFiles();
+    loc.setVersion( null );
+    DefaultArtifactVersion tempDav = null;
+    DefaultArtifactVersion tempDav2 = null;
+    
+    int aLen = loc.getBaseName().length();
+    
+    // find latest
+    for( File vf : files )
+    {
+      if( vf.isFile() )
+        continue;
+      
+      String vn = vf.getName().substring( aLen+1 );
+      
+      // no snapshots
+      if( vn.endsWith( Artifact.SNAPSHOT_VERSION ))
+        continue;
+
+      if( loc.getVersion() == null )
+      {
+        loc.setVersion( vn );
+        tempDav = new DefaultArtifactVersion( vn );
+        continue;
+      }
+      
+      tempDav2 = new DefaultArtifactVersion( vn );
+      if( tempDav2.compareTo( tempDav ) > 0 )
+      {
+        loc.setVersion( vn );
+        tempDav = tempDav2;
+      }
+    
+    }
+
+    if( loc.getVersion() == null )
+    {
+      res.addError( bmd, new RepositoryException( _lang.getMessage( "snapshot.not.found", bmd.toString(), gavDir.getAbsolutePath() ) ) );
+      return false;
+    }
+    
+    return true;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  /**
+   * direct disk search, no redirects - I cannot process pom files :(
+   */
+  public ArtifactBasicResults readVersions( Collection<ArtifactBasicMetadata> query )
+  throws RepositoryException, IllegalArgumentException
+  {
+    if( query == null || query.size() < 1 )
+      return null;
+    
+    ArtifactBasicResults res = new ArtifactBasicResults( query.size() );
+    
+    File gaDir = null;
+    for( ArtifactBasicMetadata bmd : query )
+    {
+      gaDir = new File( _repoDir, bmd.getGroupId().replace( '.', '/' )+"/"+bmd.getArtifactId() );
+      if( ! gaDir.exists() )
+        continue;
+      
+      File [] versionFiles = gaDir.listFiles();
+      
+      VersionRange versionQuery;
+      try
+      {
+        versionQuery = VersionRangeFactory.create( bmd.getVersion(), _repo.getVersionRangeQualityRange() );
+      }
+      catch( VersionException e )
+      {
+        res = ArtifactBasicResults.add( res, bmd, new RepositoryException(e) );
+        continue;
+      }
+      
+      Quality vq = new Quality( bmd.getVersion() );
+      
+      if(    vq.equals( Quality.FIXED_RELEASE_QUALITY ) 
+          || vq.equals( Quality.FIXED_LATEST_QUALITY )
+          || vq.equals( Quality.SNAPSHOT_QUALITY     )
+      )
+      {
+        ArtifactLocation loc = calculateLocation( _repoDir.getAbsolutePath(), bmd, res );
+        
+        if( loc == null )
+          continue;
+          
+        ArtifactBasicMetadata vmd = new ArtifactBasicMetadata();
+        vmd.setGroupId( bmd.getGroupId() );
+        vmd.setArtifactId(  bmd.getArtifactId() );
+        vmd.setClassifier( bmd.getClassifier() );
+        vmd.setType( bmd.getType() );
+        vmd.setVersion( loc.getVersion() );
+          
+        res = ArtifactBasicResults.add( res, bmd, vmd );
+        
+        continue;
+
+      }
+      
+      for( File vf : versionFiles )
+      {
+        if( !vf.isDirectory() )
+          continue;
+        
+        String version = vf.getName();
+        
+        Quality q = new Quality( version );
+        if( ! _repo.isAcceptedQuality( q ) )
+          continue;
+        
+        if( !versionQuery.includes(  vf.getName() )  )
+          continue;
+        
+        ArtifactBasicMetadata vmd = new ArtifactBasicMetadata();
+        vmd.setGroupId( bmd.getGroupId() );
+        vmd.setArtifactId(  bmd.getArtifactId() );
+        vmd.setClassifier( bmd.getClassifier() );
+        vmd.setType( bmd.getType() );
+        vmd.setVersion( vf.getName() );
+        
+        res = ArtifactBasicResults.add( res, bmd, vmd );
+      }
+    }
+    return res;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public byte[] readRawData( ArtifactBasicMetadata bmd, String classifier, String type )
+  throws MetadataReaderException
+  {
+    return readRawData( relPathOf(bmd, classifier, type, null ) );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private static String relPathOf( ArtifactBasicMetadata bmd, String classifier, String type, DefaultArtifactVersion inDav )
+  {
+    DefaultArtifactVersion dav = inDav;
+    if( inDav == null )
+      dav = new DefaultArtifactVersion( bmd.getVersion() );
+    Quality aq = dav.getQuality();
+    boolean isSnapshot = aq.equals( Quality.SNAPSHOT_QUALITY ) || aq.equals( Quality.SNAPSHOT_TS_QUALITY );
+    
+    String bmdPath = bmd.getGroupId().replace( '.', '/' )+'/'+bmd.getArtifactId()
+                +'/' + ( isSnapshot ? dav.getBase()+'-'+Artifact.SNAPSHOT_VERSION : bmd.getVersion() );
+    
+    String path = bmdPath+'/'+bmd.getBaseName(classifier)+'.' + (type == null ? bmd.getType() : type );
+    
+    return path ;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public byte[] readRawData( String path )
+  throws MetadataReaderException
+  {
+    File file = new File( _repoDir, path );
+    
+    if( ! file.exists() )
+      return null;
+    
+    FileInputStream fis = null;
+    
+    try
+    {
+      fis = new FileInputStream( file );
+      int len = (int)file.length();
+      byte [] pom = new byte [ len ];
+      fis.read( pom );
+      return pom;
+    }
+    catch( IOException e )
+    {
+      throw new MetadataReaderException(e);
+    }
+    finally
+    {
+      if( fis != null ) try { fis.close(); } catch( Exception any ) {}
+    }
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public String readStringData( String path )
+  throws MetadataReaderException
+  {
+    byte [] data = readRawData( path );
+    if( data == null )
+      return null;
+
+    return new String( data );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public boolean canHandle( String protocol )
+  {
+    return AbstractRepository.DEFAULT_LOCAL_READ_PROTOCOL.equals( protocol );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public String[] getProtocols()
+  {
+    return _protocols;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public void close()
+  {
+  }
+  //---------------------------------------------------------------------------------------------------------------
+}

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2Factory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2Factory.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2Factory.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2Factory.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,33 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.repository.api.RepositoryReaderFactory;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+public class LocalRepositoryReaderM2Factory
+implements RepositoryReaderFactory
+{
+  private static final Language lang = new DefaultLanguage( LocalRepositoryReaderM2Factory.class );
+  private static final LocalRepositoryReaderM2Factory factory = new LocalRepositoryReaderM2Factory();
+  
+  static 
+  {
+    AbstractRepository.register( AbstractRepository.DEFAULT_REPOSITORY_TYPE, factory  );
+  }
+  
+  public RepositoryReader getReader( Repository repo, DependencyProcessor mdProcessor)
+  throws RepositoryException
+  {
+    if( repo == null || !(repo instanceof LocalRepository) )
+      throw new RepositoryException( lang.getMessage( "bad.repository.type", repo == null ? "null" : repo.getClass().getName() ) );
+    
+    return new LocalRepositoryReaderM2( (LocalRepository)repo, mdProcessor );
+  }
+
+}

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,415 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.Quality;
+import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
+import org.apache.maven.mercury.crypto.api.StreamObserverException;
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.AbstractRepositoryWriter;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryWriter;
+import org.apache.maven.mercury.repository.metadata.AddVersionOperation;
+import org.apache.maven.mercury.repository.metadata.Metadata;
+import org.apache.maven.mercury.repository.metadata.MetadataBuilder;
+import org.apache.maven.mercury.repository.metadata.MetadataException;
+import org.apache.maven.mercury.repository.metadata.MetadataOperation;
+import org.apache.maven.mercury.repository.metadata.SetSnapshotOperation;
+import org.apache.maven.mercury.repository.metadata.Snapshot;
+import org.apache.maven.mercury.repository.metadata.SnapshotOperand;
+import org.apache.maven.mercury.repository.metadata.StringOperand;
+import org.apache.maven.mercury.transport.api.Server;
+import org.apache.maven.mercury.util.FileLockBundle;
+import org.apache.maven.mercury.util.FileUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+public class LocalRepositoryWriterM2
+extends AbstractRepositoryWriter
+implements RepositoryWriter
+{
+  public static final String SYSTEM_PROPERTY_PARALLEL_WORKERS = "mercury.local.repo.workers";
+  public static final int  PARALLEL_WORKERS = Integer.parseInt( System.getProperty( SYSTEM_PROPERTY_PARALLEL_WORKERS, "4" ) );
+  
+  public static final long SLEEP_FOR_WORKERS_TICK = 20l;
+
+  public static final String SYSTEM_PROPERTY_SLEEP_FOR_LOCK = "mercury.local.lock.wait.millis";
+  public static final long SLEEP_FOR_LOCK = Long.parseLong(  System.getProperty( SYSTEM_PROPERTY_SLEEP_FOR_LOCK, "5000" ) );
+  
+  public static final long SLEEP_FOR_LOCK_TICK = 5l;
+
+  private static final org.slf4j.Logger _log = org.slf4j.LoggerFactory.getLogger( LocalRepositoryWriterM2.class ); 
+  private static final Language _lang = new DefaultLanguage( LocalRepositoryWriterM2.class );
+  //---------------------------------------------------------------------------------------------------------------
+  private static final String [] _protocols = new String [] { "file" };
+  
+  private final LocalRepository _repo;
+  private final File _repoDir;
+  private final ArtifactQueue _aq;
+
+  private static final ArifactWriteData LAST_ARTIFACT = new ArifactWriteData( null, null );
+  //---------------------------------------------------------------------------------------------------------------
+  public LocalRepositoryWriterM2( LocalRepository repo )
+  {
+    if( repo == null )
+      throw new IllegalArgumentException("localRepo cannot be null");
+    
+    _repoDir = repo.getDirectory();
+    if( _repoDir == null )
+      throw new IllegalArgumentException("localRepo directory cannot be null");
+    
+    if( !_repoDir.exists() )
+      throw new IllegalArgumentException("localRepo directory \""+_repoDir.getAbsolutePath()+"\" should exist");
+
+    _repo = repo;
+    _aq = null;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private LocalRepositoryWriterM2( LocalRepository repo, File repoDir, ArtifactQueue aq )
+  {
+    _repo = repo;
+    _repoDir = repoDir;
+    _aq = aq;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  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()
+  {
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public void writeArtifacts( Collection<Artifact> artifacts )
+      throws RepositoryException
+  {
+    if( artifacts == null || artifacts.size() < 1 )
+      return;
+    
+    int nWorkers = PARALLEL_WORKERS;
+    if( artifacts.size() < nWorkers )
+      nWorkers = artifacts.size();
+    
+    ArtifactQueue aq = new ArtifactQueue();
+    LocalRepositoryWriterM2 [] workers = new LocalRepositoryWriterM2[ nWorkers ];
+    
+    for( int i=0; i<nWorkers; i++ )
+    {
+      workers[ i ] = new LocalRepositoryWriterM2( _repo, _repoDir, aq );
+      workers[ i ].start();
+    }
+    
+    for( Artifact artifact : artifacts )
+    {
+      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);
+
+      aq.addArtifact( new ArifactWriteData( artifact, vFacs ) );
+    }
+    aq.addArtifact( LAST_ARTIFACT );
+    
+    boolean alive = true;
+    while( alive )
+    {
+      alive = false;
+      for( int i=0; i<nWorkers; i++ )
+        if( workers[ i ].isAlive() )
+        {
+          alive = true;
+          try { sleep( SLEEP_FOR_WORKERS_TICK ); } catch( InterruptedException ie ) {}
+        }
+    }
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  /* (non-Javadoc)
+   * @see java.lang.Thread#run()
+   */
+  @Override
+  public void run()
+  {
+    try
+    {
+      for(;;)
+      {
+        ArifactWriteData awd = _aq.getArtifact();
+
+        if( awd == null || awd.artifact == null )
+            break;
+        
+        writeArtifact( awd.artifact, awd.vFacs );
+      }
+    }
+    catch (InterruptedException e)
+    {
+    }
+    catch( RepositoryException e )
+    {
+      throw new RuntimeException(e);
+    }
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public void writeArtifact( final Artifact artifact, final Set<StreamVerifierFactory> vFacs )
+      throws RepositoryException
+  {
+    if( artifact == null )
+      return;
+    
+    boolean isPom = "pom".equals( artifact.getType() );
+    
+    byte [] pomBlob = artifact.getPomBlob();
+    boolean hasPomBlob = pomBlob != null && pomBlob.length > 0;
+    
+    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( e );
+      }
+    }
+    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 versionDirName = isSnapshot ? (dav.getBase()+'-'+Artifact.SNAPSHOT_VERSION) : artifact.getVersion();
+    String relVersionPath = relGroupPath + '/' + versionDirName;
+    
+    String lockDir = null;
+    FileLockBundle fLock = null;
+
+    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;
+        }
+      }
+
+      // create folders
+      lockDir = _repoDir.getAbsolutePath()+'/'+relGroupPath;
+
+      File gav = new File( lockDir );
+      gav.mkdirs();
+
+//    haveLock = FileUtil.lockDir( lockDir, SLEEP_FOR_LOCK, SLEEP_FOR_LOCK_TICK );
+//    if( !haveLock )
+//      throw new RepositoryException( _lang.getMessage( "cannot.lock.gav", lockDir, ""+SLEEP_FOR_LOCK ) );
+      fLock = FileUtil.lockDir( lockDir, SLEEP_FOR_LOCK, SLEEP_FOR_LOCK_TICK );
+      if( fLock == null )
+        throw new RepositoryException( _lang.getMessage( "cannot.lock.gav", lockDir, ""+SLEEP_FOR_LOCK ) );
+
+      String fName = _repoDir.getAbsolutePath()+'/'+relVersionPath+'/'+artifact.getBaseName()+'.'+artifact.getType();
+      
+      if( !isPom ) // first - take care of the binary
+        FileUtil.writeAndSign( fName, in, vFacs );
+
+      // GA metadata
+      File mdFile = new File( _repoDir, relGroupPath+'/'+_repo.getMetadataName() );
+      updateGAMetadata( mdFile, artifact, versionDirName, aq, vFacs );
+
+      // now - GAV metadata
+      mdFile = new File( _repoDir, relVersionPath+'/'+_repo.getMetadataName() );
+      updateGAVMetadata( mdFile, artifact, aq, vFacs );
+
+      // if classier - nothing else to do :)
+      if( artifact.hasClassifier() )
+        return;
+      
+      if( hasPomBlob )
+      {
+        FileUtil.writeAndSign( _repoDir.getAbsolutePath()+'/'+relVersionPath
+                              +'/'+artifact.getArtifactId()+'-'+artifact.getVersion()+".pom", pomBlob, vFacs
+                              );
+      }
+        
+    }
+    catch( Exception e )
+    {
+      throw new RepositoryException( e );
+    }
+    finally
+    {
+      if( fLock != null )
+        fLock.release();
+    }
+    
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private void updateGAMetadata(  final File mdFile
+                                , final Artifact artifact
+                                , final String version
+                                , final Quality aq
+                                , final Set<StreamVerifierFactory> vFacs
+                              )
+  throws MetadataException, IOException, StreamObserverException
+  {
+    Metadata md = null;
+    
+    if( mdFile.exists() )
+    {
+      try
+      {
+        byte [] mdBytes = FileUtil.readRawData( mdFile );
+        
+        if( mdBytes == null )
+          throw new MetadataException( _lang.getMessage( "file.is.empty", mdFile.getAbsolutePath() ));
+        
+        md = MetadataBuilder.read( new ByteArrayInputStream(mdBytes) );
+      }
+      catch( MetadataException e )
+      {
+        throw e;
+      }
+    }
+    else
+    {
+      md = new Metadata();
+      md.setGroupId( artifact.getGroupId() );
+      md.setArtifactId( artifact.getArtifactId() );
+    }
+    
+    MetadataOperation mdOp = new AddVersionOperation( new StringOperand( version ) ); 
+    
+    byte [] resBytes = MetadataBuilder.changeMetadata( md, mdOp );
+
+    FileUtil.writeAndSign( mdFile.getAbsolutePath(), resBytes, vFacs );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  private void updateGAVMetadata( final File mdFile
+                                , final Artifact artifact
+                                , final Quality aq
+                                , final Set<StreamVerifierFactory> vFacs
+                              )
+  throws MetadataException, IOException, StreamObserverException
+  {
+    Metadata md = null;
+    
+    if( mdFile.exists() )
+    {
+      byte [] mdBytes = FileUtil.readRawData( mdFile );
+      md = MetadataBuilder.read( new ByteArrayInputStream(mdBytes) );
+    }
+    else
+    {
+      md = new Metadata();
+      md.setGroupId( artifact.getGroupId() );
+      md.setArtifactId( artifact.getArtifactId() );
+      md.setVersion( artifact.getVersion() );
+    }
+    List<MetadataOperation> mdOps = new ArrayList<MetadataOperation>(2);
+    
+    if( aq.equals( Quality.SNAPSHOT_TS_QUALITY ) )
+    {
+      Snapshot sn = MetadataBuilder.createSnapshot( artifact.getVersion() );
+      sn.setLocalCopy( true );
+      mdOps.add( new SetSnapshotOperation( new SnapshotOperand(sn) ) );
+    }
+    
+    mdOps.add( new AddVersionOperation( new StringOperand(artifact.getVersion()) ) ); 
+ 
+//System.out.println("added "+artifact.getVersion());
+//System.out.flush();
+    byte [] resBytes = MetadataBuilder.changeMetadata( md, mdOps );
+    FileUtil.writeAndSign( mdFile.getAbsolutePath(), resBytes, vFacs );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  //---------------------------------------------------------------------------------------------------------------
+}
+//=================================================================================================================
+class ArifactWriteData
+{
+  Artifact artifact;
+  Set<StreamVerifierFactory> vFacs;
+  
+  public ArifactWriteData(Artifact artifact, Set<StreamVerifierFactory> vFacs)
+  {
+    this.artifact = artifact;
+    this.vFacs = vFacs;
+  }
+}
+//=================================================================================================================
+class ArtifactQueue
+{
+  LinkedList<ArifactWriteData> queue = new LinkedList<ArifactWriteData>();
+  boolean empty = false;
+  
+  public synchronized void addArtifact( ArifactWriteData awd )
+  {
+    queue.addLast( awd );
+    empty = false;
+    notify();
+  }
+
+  public synchronized ArifactWriteData getArtifact()
+  throws InterruptedException
+  {
+    if( empty )
+      return null;
+
+    while( queue.isEmpty() )
+      wait();
+    
+    ArifactWriteData res = queue.removeFirst();
+    
+    if( res.artifact == null )
+    {
+      empty = true;
+      return null;
+    }
+
+    return res;
+  }
+}
+//=================================================================================================================

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2Factory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2Factory.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2Factory.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryWriterM2Factory.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,32 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryWriter;
+import org.apache.maven.mercury.repository.api.RepositoryWriterFactory;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+public class LocalRepositoryWriterM2Factory
+implements RepositoryWriterFactory
+{
+  private static final Language lang = new DefaultLanguage( LocalRepositoryWriterM2Factory.class );
+  private static final LocalRepositoryWriterM2Factory factory = new LocalRepositoryWriterM2Factory();
+  
+  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 LocalRepositoryWriterM2( (LocalRepository)repo );
+  }
+
+}

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties Fri Oct 31 19:55:54 2008
@@ -0,0 +1,15 @@
+bad.repository.type=repository should implement LocalRepository, instead got {0}
+empty.query=received empty query - {0}
+binary.not.found=Artifact {0} binary at not found {1} 
+ga.not.found=Artifact {0} version group not found at {1} 
+gav.not.found=No artifact version for {0} found in {1}
+snapshot.not.found=No snapshot version for {0} found in {1}
+gavdir.not.found=No directory {1} for artifact {0} 
+pom.not.found=Artifact {0} - binary exists, but POM not found in the repository 
+artifact.no.stream=Cannot find either input stream or file, associated with artifact {0}
+pom.artifact.no.stream=Cannot find either pom blob, input stream or file, associated with artifact {0}
+no.signature.file=Verifier for {0} is mandatory, but file {1} does not exist
+signature.failed=Signature "{0}": verification failed for file {1}
+cannot.read.signature.file=Cannot read signature file {0}, error: {1}
+cannot.lock.gav=Cannot lock GAV folder {0} in {1} millis
+file.is.empty=File {0} exists, but is empty. Data corruption somewhere - please repair metadata.
\ No newline at end of file

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java Fri Oct 31 19:55:54 2008
@@ -0,0 +1,92 @@
+package org.apache.maven.mercury.repository.local.m2;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.digester.Digester;
+import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.builder.api.MetadataReader;
+import org.apache.maven.mercury.builder.api.MetadataReaderException;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * a temporary thing to be replaced with real projectBuilder implementation
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MetadataProcessorMock
+implements DependencyProcessor
+{
+
+  public List<ArtifactBasicMetadata> getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map env, Map sysProps )
+  throws MetadataReaderException
+  {
+    List<ArtifactBasicMetadata> deps = null;
+    
+    try
+    {
+      byte [] pomBytes = mdReader.readMetadata( bmd );
+      if( pomBytes == null )
+      {
+        throw new MetadataReaderException("no metadata found for "+bmd);
+      }
+      deps = getDeps(  pomBytes );
+      
+      return deps;
+    }
+    catch( Exception e )
+    {
+      throw new MetadataReaderException( e );
+    }
+  }
+  
+  private static final List<ArtifactBasicMetadata> getDeps( byte [] pom )
+  throws IOException, SAXException
+  {
+    if( pom == null )
+      return null;
+    
+    DependencyCreator dc = new DependencyCreator();
+    Digester digester = new Digester();
+    digester.push( dc );
+    
+    digester.addCallMethod("project/dependencies/dependency", "addMD", 6 );
+    digester.addCallParam("project/dependencies/dependency/groupId",0);
+    digester.addCallParam("project/dependencies/dependency/artifactId",1);
+    digester.addCallParam("project/dependencies/dependency/version",2);
+    digester.addCallParam("project/dependencies/dependency/type",3);
+    digester.addCallParam("project/dependencies/dependency/scope",4);
+    digester.addCallParam("project/dependencies/dependency/optional",5);
+    
+    digester.parse( new ByteArrayInputStream(pom) );
+    
+    return dc.mds;
+  }
+
+}
+//==============================================================================================
+class DependencyCreator
+{
+  List<ArtifactBasicMetadata> mds = new ArrayList<ArtifactBasicMetadata>(8);
+  
+  public void addMD( String g, String a, String v, String t, String s, String o)
+  {
+    ArtifactBasicMetadata md = new ArtifactBasicMetadata();
+    md.setGroupId(g);
+    md.setArtifactId(a);
+    md.setVersion(v);
+    md.setType(t);
+    md.setScope(s);
+    md.setOptional(o);
+
+    mds.add(md);
+  }
+}
+//==============================================================================================

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/pubring.gpg
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/pubring.gpg?rev=709625&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/pubring.gpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/secring.gpg
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/secring.gpg?rev=709625&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/pgp/secring.gpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/1/a-1.pom
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/1/a-1.pom?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/1/a-1.pom (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/1/a-1.pom Fri Oct 31 19:55:54 2008
@@ -0,0 +1,19 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>a</groupId>
+  <artifactId>a</artifactId>
+  <version>1</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>b</groupId>
+      <artifactId>b</artifactId>
+      <version>1</version>
+    </dependency>
+    <dependency>
+      <groupId>c</groupId>
+      <artifactId>c</artifactId>
+      <version>1</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar?rev=709625&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar.asc
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar.asc?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar.asc (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.jar.asc Fri Oct 31 19:55:54 2008
@@ -0,0 +1,7 @@
+-----BEGIN PGP SIGNATURE-----
+Version: BCPG v1.40
+
+iEYEABECAAYFAkitxHsACgkQDttdkRQbxPI7ywCdHDfUKblJaNRHID0S4yuhXCGO
+oi8An2QRvn7A3KnrUq1v92t6bM4IKkMl
+=khMy
+-----END PGP SIGNATURE-----

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.pom
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.pom?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.pom (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/2/a-2.pom Fri Oct 31 19:55:54 2008
@@ -0,0 +1,23 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>a</groupId>
+  <artifactId>a</artifactId>
+  <version>2</version>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>b</groupId>
+      <artifactId>b</artifactId>
+      <version>[1,2]</version>
+    </dependency>
+
+    <dependency>
+      <groupId>c</groupId>
+      <artifactId>c</artifactId>
+      <version>[2,3)</version>
+    </dependency>
+  </dependencies>
+
+
+</project>
\ No newline at end of file

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.jar
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.jar?rev=709625&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.pom
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.pom?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.pom (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/3/a-3.pom Fri Oct 31 19:55:54 2008
@@ -0,0 +1,19 @@
+<project>
+	<modelVersion>4.0.0</modelVersion>
+  <groupId>a</groupId>
+  <artifactId>a</artifactId>
+  <version>3</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>b</groupId>
+      <artifactId>b</artifactId>
+      <version>2</version>
+    </dependency>
+    <dependency>
+      <groupId>c</groupId>
+      <artifactId>c</artifactId>
+      <version>(1,)</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/maven-metadata.xml
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/maven-metadata.xml?rev=709625&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/maven-metadata.xml (added)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-flat/src/test/resources/repo/a/a/maven-metadata.xml Fri Oct 31 19:55:54 2008
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><metadata>
+  <groupId>a</groupId>
+  <artifactId>a</artifactId>
+  <version>4</version>
+  <versioning>
+    <release>4</release>
+    <versions>
+      <version>1</version>
+      <version>2</version>
+      <version>3</version>
+      <version>4</version>
+      <version>5-SNAPSHOT</version>
+     </versions>
+    <lastUpdated>20080424212921</lastUpdated>
+  </versioning>
+</metadata>
\ No newline at end of file



Mime
View raw message