michal      2004/05/11 13:13:14

  Added:       maven-project/src/main/java/org/apache/maven/artifact/snapshot
                        SnapshotUtils.java DefaultSnapshotResolver.java
                        SnapshotResolver.java
  Log:
  Early version of snapshot resolver. I would like to use .snapshot-version file 
locally and remotly for keeping time stamps.

  This will allow to use any local repository also as remote repository for other 
people but first of all release plugin will be able to use local .snapshot-version 
files while release will be made
  
  Revision  Changes    Path
  1.1                  
maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/SnapshotUtils.java
  
  Index: SnapshotUtils.java
  ===================================================================
  package org.apache.maven.artifact.snapshot;
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.TimeZone;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a> 
   * @version $Id: SnapshotUtils.java,v 1.1 2004/05/11 20:13:14 michal Exp $ 
   */
  public class SnapshotUtils
  {
      private final static SimpleDateFormat formatter = new SimpleDateFormat( 
"yyyyMMdd.HHmmss" );
  
      static
      {
          formatter.setTimeZone( TimeZone.getTimeZone( "GMT" ) );    
      }
      
      public static String createSnapshotVersion()
      {
          Date now = new Date();
          
          String retValue = formatter.format( now );
          
          return retValue;        
      }
      
      
      public static Date parseSnapshotVersion( String snapshotVersion ) throws 
ParseException
      {        
          Date retValue = formatter.parse( snapshotVersion );
          
          return retValue;       
      }
      
  }
  
  
  
  1.1                  
maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolver.java
  
  Index: DefaultSnapshotResolver.java
  ===================================================================
  package org.apache.maven.artifact.snapshot;
  
  import java.io.File;
  import java.util.Date;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.maven.artifact.MavenArtifact;
  import org.apache.maven.wagon.Wagon;
  import org.apache.maven.wagon.manager.WagonManager;
  import org.apache.maven.wagon.repository.Repository;
  import org.codehaus.plexus.util.FileUtils;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a> 
   * @version $Id: DefaultSnapshotResolver.java,v 1.1 2004/05/11 20:13:14 michal Exp $ 
   */
  public class DefaultSnapshotResolver implements SnapshotResolver
  {
  
      private WagonManager wagonManager;
  
      public void resolveSnapshotArtifact( MavenArtifact artifact,
              List repositories )
      {
  
          Date localVersion = getLocalVersion( artifact );
  
          for ( Iterator iter = repositories.iterator(); iter.hasNext(); )
          {
              Repository repository = ( Repository ) iter.next();
  
              // need to think how to handle excepion here and what they actually mean
              //Date remoteVersion =  getRemoteVersion( artifact, repository );
  
          }
  
      }
  
      private Date getRemoteVersion( MavenArtifact artifact, Repository repository )
              throws Exception
      {
          Date retValue = null;
  
          Wagon wagon = wagonManager.getWagon( repository.getProtocol() );
  
          wagon.connect( repository );
  
          // @todo - here I need to create temp file. 
          //I would prefer to have input stream from wagon and do not need to create/
          //delete file and handle all error which may appear.
          File file = null;
  
          wagon.get( artifact.getSnapshotVersionUrlPath(), file );
  
          String snapshotVersion = FileUtils.fileRead( file );
  
          retValue = SnapshotUtils.parseSnapshotVersion( snapshotVersion );
  
          return retValue;
  
      }
  
      private Date getLocalVersion( MavenArtifact artifact )
      {
  
          //assert artifact.exists();
  
          Date retValue = null;
  
          try
          {
              File file = artifact.getSnapshotVersionFile();
  
              if ( file.exists() )
              {
                  String snapshotVersion = FileUtils.fileRead( file );
  
                  retValue = SnapshotUtils.parseSnapshotVersion( snapshotVersion );
  
              }
  
          }
          catch ( Exception e )
          {
              // ignore
          }
  
          if ( retValue == null )
          {
              //try "traditional method"
  
              File file = artifact.getFile();
  
              if ( file.exists() )
              {
                  retValue = new Date( file.lastModified() );
              }
  
          }
  
          return retValue;
  
      }
  
  }
  
  
  1.1                  
maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/SnapshotResolver.java
  
  Index: SnapshotResolver.java
  ===================================================================
  package org.apache.maven.artifact.snapshot;
  
  import java.util.List;
  
  import org.apache.maven.artifact.MavenArtifact;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a> 
   * @version $Id: SnapshotResolver.java,v 1.1 2004/05/11 20:13:14 michal Exp $ 
   */
  public interface SnapshotResolver
  {
      
      String ROLE = SnapshotResolver.class.getName();
          
      void resolveSnapshotArtifact( MavenArtifact artifact, List repositories );
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to