maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r681187 - in /maven/sandbox/trunk/mercury/src: main/java/org/apache/maven/mercury/artifact/ main/java/org/apache/maven/mercury/repository/api/ main/java/org/apache/maven/mercury/repository/local/m2/ main/java/org/apache/maven/mercury/reposi...
Date Wed, 30 Jul 2008 20:07:28 GMT
Author: ogusakov
Date: Wed Jul 30 13:07:27 2008
New Revision: 681187

URL: http://svn.apache.org/viewvc?rev=681187&view=rev
Log:
MetadataReaderTest passes with RemoteRepositoryReader using jetty-client.

Exposed low-level readRawData(String) method in RepositoryReader

Modified:
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/artifact/ArtifactBasicMetadata.java
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/api/RepositoryReader.java
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
    maven/sandbox/trunk/mercury/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataReaderTest.java

Modified: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/artifact/ArtifactBasicMetadata.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/artifact/ArtifactBasicMetadata.java?rev=681187&r1=681186&r2=681187&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/artifact/ArtifactBasicMetadata.java
(original)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/artifact/ArtifactBasicMetadata.java
Wed Jul 30 13:07:27 2008
@@ -44,38 +44,50 @@
   transient RepositoryReader _reader;
   
   //------------------------------------------------------------------
+  public ArtifactBasicMetadata()
+  {
+  }
+  //------------------------------------------------------------------
   /**
    * create basic out of <b>group:artifact:version:classifier:type</b> string,
use 
    * empty string to specify missing component - for instance query for common-1.3.zip
    * can be specified as ":common:1.3::zip" - note missing groupId and classifier. 
    */
-  public static ArtifactBasicMetadata create( String query )
+  public ArtifactBasicMetadata( String query )
   {
-    ArtifactBasicMetadata mdq = new ArtifactBasicMetadata();
-    
     if( query == null )
-      return null;
+      return;
     
     String [] tokens = query.split(":");
     
     if( tokens == null || tokens.length < 1 )
-      return mdq;
+      return;
 
     int count = tokens.length;
     
-    mdq.groupId = nullify( tokens[0] );
+    this.groupId = nullify( tokens[0] );
   
     if( count > 1 )
-      mdq.artifactId = nullify( tokens[1] );
+      this.artifactId = nullify( tokens[1] );
     
     if( count > 2 )
-      mdq.version = nullify( tokens[2] );
+      this.version = nullify( tokens[2] );
     
     if( count > 3 )
-      mdq.classifier = nullify( tokens[3] );
+      this.classifier = nullify( tokens[3] );
     
     if( count > 4 )
-      mdq.type = nullify( tokens[4] );
+      this.type = nullify( tokens[4] );
+  }
+  //------------------------------------------------------------------
+  /**
+   * create basic out of <b>group:artifact:version:classifier:type</b> string,
use 
+   * empty string to specify missing component - for instance query for common-1.3.zip
+   * can be specified as ":common:1.3::zip" - note missing groupId and classifier. 
+   */
+  public static ArtifactBasicMetadata create( String query )
+  {
+    ArtifactBasicMetadata mdq = new ArtifactBasicMetadata( query );
     
     return mdq;
   }

Modified: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/api/RepositoryReader.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/api/RepositoryReader.java?rev=681187&r1=681186&r2=681187&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/api/RepositoryReader.java
(original)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/api/RepositoryReader.java
Wed Jul 30 13:07:27 2008
@@ -67,4 +67,15 @@
    */
   public void setMetadataProcessor( MetadataProcessor mdProcessor );
   public MetadataProcessor getMetadataProcessor();
+  
+  /**
+   * read content pointed by relative path. It will return content bytes
+   * 
+   * @param path - realative resource path in this repository
+   * @return byte [] of the resource content, pointed by the path
+   * @throws MetadataProcessingException
+   */
+  public byte [] readRawData( String path )
+  throws MetadataProcessingException;
+
 }

Modified: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java?rev=681187&r1=681186&r2=681187&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
(original)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
Wed Jul 30 13:07:27 2008
@@ -179,17 +179,25 @@
   {
     String bmdPath = bmd.getGroupId().replace( '.', '/' )+"/"+bmd.getArtifactId()+"/"+bmd.getVersion();
     
-    File pomFile = new File( _repoDir, bmdPath+"/"+bmd.getBaseName(classifier)+'.' + (type
== null ? bmd.getType() : type ) );
+    String path = bmdPath+"/"+bmd.getBaseName(classifier)+'.' + (type == null ? bmd.getType()
: type );
     
-    if( ! pomFile.exists() )
+    return readRawData( path );
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public byte[] readRawData( String path )
+  throws MetadataProcessingException
+  {
+    File file = new File( _repoDir, path );
+    
+    if( ! file.exists() )
       return null;
     
     FileInputStream fis = null;
     
     try
     {
-      fis = new FileInputStream( pomFile );
-      int len = (int)pomFile.length();
+      fis = new FileInputStream( file );
+      int len = (int)file.length();
       byte [] pom = new byte [ len ];
       fis.read( pom );
       return pom;

Modified: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java?rev=681187&r1=681186&r2=681187&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
(original)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
Wed Jul 30 13:07:27 2008
@@ -235,14 +235,22 @@
     return readRawData( bmdPath );
   }
   //---------------------------------------------------------------------------------------------------------------
-  private byte[] readRawData( String path )
+  public byte[] readRawData( String path )
   throws MetadataProcessingException
   {
+    if( path == null || path.length() < 1 )
+      return null;
+    
     FileInputStream fis = null;
     try
     {
       File tempFile = File.createTempFile( "mercury", "readraw" );
-      Binding binding = new Binding( new URL(_repo.getServer().getURL().toString()+'/'+path)
, tempFile);
+      
+      String separator = "/";
+      if( path.startsWith( separator ))
+        separator = "";
+      
+      Binding binding = new Binding( new URL(_repo.getServer().getURL().toString() + separator
+ path) , tempFile );
       DefaultRetrievalRequest request = new DefaultRetrievalRequest();
       request.addBinding( binding );
       

Modified: maven/sandbox/trunk/mercury/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataReaderTest.java?rev=681187&r1=681186&r2=681187&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataReaderTest.java
(original)
+++ maven/sandbox/trunk/mercury/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataReaderTest.java
Wed Jul 30 13:07:27 2008
@@ -1,5 +1,6 @@
 package org.apache.maven.mercury.repository.metadata;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -10,7 +11,9 @@
 
 import junit.framework.TestCase;
 
+import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
 import org.apache.maven.mercury.repository.MetadataProcessorMock;
+import org.apache.maven.mercury.repository.api.MetadataProcessingException;
 import org.apache.maven.mercury.repository.api.RepositoryException;
 import org.apache.maven.mercury.repository.api.RepositoryReader;
 import org.apache.maven.mercury.repository.metadata.io.xpp3.MetadataXpp3Reader;
@@ -88,30 +91,17 @@
   }
   //-------------------------------------------------------------------------
   public void testReadRemoteMdViaRepositoryReader()
-  throws FileNotFoundException, IOException, XmlPullParserException, RepositoryException
+  throws FileNotFoundException, IOException, XmlPullParserException, RepositoryException,
MetadataProcessingException
   {
-    File temp = File.createTempFile("maven", "metadata" );
-    RemoteRepositoryReaderM2Factory rf = new RemoteRepositoryReaderM2Factory();
-    
     Server server = new Server( "test", new URL("http://localhost:"+_port+"/repo") );
+
     RemoteRepositoryM2 rrm2 = new RemoteRepositoryM2( "testRepo", server );
     
-    RepositoryReader reader = rf.getReader( rrm2, new MetadataProcessorMock() );
-    
-    HashSet<Binding> bindings = new HashSet<Binding>();
-    
-    Binding aaMdBinding = new Binding( new URL("http://localhost:"+_port+"/repo/a/a/maven-metadata.xml"),
temp);
-    bindings.add( aaMdBinding );
-    
-    _request.setBindings(bindings);
-    
-    RetrievalResponse response = _retriever.retrieve(_request);
+    RepositoryReader reader = rrm2.getReader( new MetadataProcessorMock() );
     
-    if( response.hasExceptions() )
-      fail("retrieval exceptions: "+response.getExceptions()+"\nReading from "+aaMdBinding.getRemoteResource()
);
+    byte [] mmBuf = reader.readRawData( "a/a/maven-metadata.xml" );
     
-    Metadata mmd = _reader.read( new FileInputStream( temp ) );
-    temp.delete();
+    Metadata mmd = _reader.read( new ByteArrayInputStream( mmBuf ) );
     
     validateMmd( mmd );
     



Mime
View raw message