maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-artifact/src/main/java/org/apache/maven/artifact Artifact.java DefaultArtifact.java
Date Wed, 23 Mar 2005 14:55:15 GMT
brett       2005/03/23 06:55:15

  Modified:    maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager
                        DefaultArtifactHandlerManager.java
               maven-artifact/src/main/java/org/apache/maven/artifact/installer
                        DefaultArtifactInstaller.java
               maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout
                        AbstractArtifactRepositoryLayout.java
                        ArtifactRepositoryLayout.java
                        DefaultRepositoryLayout.java
                        LegacyRepositoryLayout.java
               maven-artifact/src/main/java/org/apache/maven/artifact/repository
                        ArtifactRepository.java
               maven-artifact/src/main/java/org/apache/maven/artifact/transform
                        SnapshotTransformation.java
               maven-artifact/src/main/java/org/apache/maven/artifact
                        Artifact.java DefaultArtifact.java
  Added:       maven-artifact/src/main/java/org/apache/maven/artifact/metadata
                        AbstractArtifactMetadata.java ArtifactMetadata.java
                        SnapshotArtifactMetadata.java
  Log:
  add artifact metadata on installation of snapshot in a local repository
  
  Revision  Changes    Path
  1.10      +1 -2      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
  
  Index: DefaultArtifactHandlerManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultArtifactHandlerManager.java	23 Mar 2005 08:42:56 -0000	1.9
  +++ DefaultArtifactHandlerManager.java	23 Mar 2005 14:55:15 -0000	1.10
  @@ -82,7 +82,6 @@
               // TODO: perform transformation
           }
   
  -        String artifactPath = localRepository.getBasedir() + "/" + localRepository.pathOf(
artifact );
  -        return artifactPath;
  +        return localRepository.getBasedir() + "/" + localRepository.pathOf( artifact );
       }
   }
  \ No newline at end of file
  
  
  
  1.9       +9 -0      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
  
  Index: DefaultArtifactInstaller.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultArtifactInstaller.java	23 Mar 2005 08:42:56 -0000	1.8
  +++ DefaultArtifactInstaller.java	23 Mar 2005 14:55:15 -0000	1.9
  @@ -19,6 +19,7 @@
   import org.apache.maven.artifact.Artifact;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
   import org.codehaus.plexus.logging.AbstractLogEnabled;
  @@ -26,6 +27,7 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.util.Iterator;
   
   public class DefaultArtifactInstaller
       extends AbstractLogEnabled
  @@ -65,6 +67,13 @@
               getLogger().info( "Installing " + source.getPath() + " to " + artifact.getPath()
);
   
               FileUtils.copyFile( source, artifact.getFile() );
  +
  +            // must be after the artifact is installed
  +            for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
  +            {
  +                ArtifactMetadata metadata = (ArtifactMetadata) i.next();
  +                metadata.storeInLocalRepository( localRepository );
  +            }
           }
           catch ( IOException e )
           {
  
  
  
  1.1                  maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java
  
  Index: AbstractArtifactMetadata.java
  ===================================================================
  package org.apache.maven.artifact.metadata;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.maven.artifact.Artifact;
  
  /**
   * Common elements of artifact metadata.
   *
   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   * @version $Id: AbstractArtifactMetadata.java,v 1.1 2005/03/23 14:55:15 brett Exp $
   */
  public abstract class AbstractArtifactMetadata
      implements ArtifactMetadata
  {
      protected final String filename;
  
      protected final Artifact artifact;
  
      protected AbstractArtifactMetadata( Artifact artifact, String filename )
      {
          this.artifact = artifact;
          this.filename = filename;
      }
  
      public Artifact getArtifact()
      {
          return artifact;
      }
  
      public String getFilename()
      {
          return filename;
      }
  }
  
  
  
  1.1                  maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java
  
  Index: ArtifactMetadata.java
  ===================================================================
  package org.apache.maven.artifact.metadata;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.repository.ArtifactRepository;
  import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
  
  import java.io.IOException;
  
  /**
   * Contains metadata about an artifact, and methods to retrieve/store it from an artifact
repository.
   *
   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   * @version $Id: ArtifactMetadata.java,v 1.1 2005/03/23 14:55:15 brett Exp $
   * @todo naming is too close to ArtifactMetadataSource which refers to a POM. A POM is sometimes
an artifact itself,
   * so that naming may no longer be appropriate.
   */
  public interface ArtifactMetadata
  {
      /**
       * Store the metadata in the local repository.
       *
       * @param localRepository the local repository
       */
      void storeInLocalRepository( ArtifactRepository localRepository )
          throws IOException, ArtifactPathFormatException;
  
      /**
       * Get the associated artifact.
       *
       * @return the artifact
       */
      Artifact getArtifact();
  
      /**
       * Get the filename of this metadata.
       *
       * @return the filename
       */
      String getFilename();
  }
  
  
  
  1.1                  maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java
  
  Index: SnapshotArtifactMetadata.java
  ===================================================================
  package org.apache.maven.artifact.metadata;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.repository.ArtifactRepository;
  import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
  import org.codehaus.plexus.util.FileUtils;
  
  import java.io.IOException;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.TimeZone;
  
  /**
   * Contains the information stored for a snapshot.
   *
   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   * @version $Id: SnapshotArtifactMetadata.java,v 1.1 2005/03/23 14:55:15 brett Exp $
   */
  public class SnapshotArtifactMetadata
      extends AbstractArtifactMetadata
  {
      private String timestamp = null;
  
      private int buildNumber = 1;
  
      private static final String SNAPSHOT_VERSION_LOCAL_FILE = "version-local.txt";
  
      private static final String SNAPSHOT_VERSION_FILE = "version.txt";
  
      private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
  
      private SnapshotArtifactMetadata( Artifact artifact, String filename )
      {
          super( artifact, filename );
      }
  
      public static SnapshotArtifactMetadata createLocalSnapshotMetadata( Artifact artifact
)
      {
          return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_LOCAL_FILE );
      }
  
      public void storeInLocalRepository( ArtifactRepository localRepository )
          throws IOException, ArtifactPathFormatException
      {
          FileUtils.fileWrite( localRepository.getBasedir() + "/" + localRepository.pathOfMetadata(
this ),
                               getTimestamp() + "-" + buildNumber );
      }
  
      public String getTimestamp()
      {
          if ( timestamp == null )
          {
              timestamp = getUtcDateFormatter().format( new Date() );
          }
          return timestamp;
      }
  
      public DateFormat getUtcDateFormatter()
      {
          DateFormat utcDateFormatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
          utcDateFormatter.setTimeZone( UTC_TIME_ZONE );
          return utcDateFormatter;
      }
  }
  
  
  
  1.5       +30 -13    maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
  
  Index: AbstractArtifactRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractArtifactRepositoryLayout.java	23 Mar 2005 04:53:30 -0000	1.4
  +++ AbstractArtifactRepositoryLayout.java	23 Mar 2005 14:55:15 -0000	1.5
  @@ -20,35 +20,27 @@
   import org.apache.maven.artifact.handler.ArtifactHandler;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
  -import org.codehaus.plexus.logging.AbstractLogEnabled;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
   import org.codehaus.plexus.util.StringUtils;
   
   /**
    * @author jdcasey
    */
   public abstract class AbstractArtifactRepositoryLayout
  -    extends AbstractLogEnabled
       implements ArtifactRepositoryLayout
   {
  -
       private ArtifactHandlerManager artifactHandlerManager;
   
       protected abstract String layoutPattern();
   
  +    protected abstract String metadataLayoutPattern();
  +
       protected abstract String groupIdAsPath( String groupId );
   
       public String pathOf( Artifact artifact )
           throws ArtifactPathFormatException
       {
  -        String path = layoutPattern();
  -
  -        String groupPath = groupIdAsPath( artifact.getGroupId() );
  -
  -        path = StringUtils.replace( path, "${groupPath}", groupPath );
  -
  -        path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
  -
  -        path = StringUtils.replace( path, "${version}", artifact.getVersion() );
  +        String path = basicPathOf( artifact, layoutPattern() );
   
           if ( artifact.hasClassifier() )
           {
  @@ -59,6 +51,32 @@
               path = StringUtils.replace( path, "-${classifier}", "" );
           }
   
  +        return path;
  +    }
  +
  +    public String pathOfMetadata( ArtifactMetadata metadata )
  +        throws ArtifactPathFormatException
  +    {
  +        String path = basicPathOf( metadata.getArtifact(), metadataLayoutPattern() );
  +
  +        path = StringUtils.replace( path, "${metadataFilename}", metadata.getFilename()
);
  +
  +        return path;
  +    }
  +
  +    private String basicPathOf( Artifact artifact, String pattern )
  +        throws ArtifactPathFormatException
  +    {
  +        String path = pattern;
  +
  +        String groupPath = groupIdAsPath( artifact.getGroupId() );
  +
  +        path = StringUtils.replace( path, "${groupPath}", groupPath );
  +
  +        path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
  +
  +        path = StringUtils.replace( path, "${version}", artifact.getVersion() );
  +
           ArtifactHandler artifactHandler = null;
           try
           {
  @@ -73,7 +91,6 @@
           path = StringUtils.replace( path, "${directory}", artifactHandler.directory() );
   
           path = StringUtils.replace( path, "${extension}", artifactHandler.extension() );
  -
           return path;
       }
   
  
  
  
  1.3       +3 -0      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
  
  Index: ArtifactRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArtifactRepositoryLayout.java	23 Mar 2005 03:40:12 -0000	1.2
  +++ ArtifactRepositoryLayout.java	23 Mar 2005 14:55:15 -0000	1.3
  @@ -17,6 +17,7 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
   
   /**
    * @author jdcasey
  @@ -29,4 +30,6 @@
       String pathOf( Artifact artifact )
           throws ArtifactPathFormatException;
   
  +    String pathOfMetadata( ArtifactMetadata metadata )
  +        throws ArtifactPathFormatException;
   }
  \ No newline at end of file
  
  
  
  1.4       +5 -0      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
  
  Index: DefaultRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultRepositoryLayout.java	23 Mar 2005 04:53:30 -0000	1.3
  +++ DefaultRepositoryLayout.java	23 Mar 2005 14:55:15 -0000	1.4
  @@ -28,6 +28,11 @@
           return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
       }
   
  +    protected String metadataLayoutPattern()
  +    {
  +        return "${groupPath}/${artifactId}/${version}/${metadataFilename}";
  +    }
  +
       protected String groupIdAsPath( String groupId )
       {
           return groupId.replace( '.', '/' );
  
  
  
  1.3       +5 -0      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
  
  Index: LegacyRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LegacyRepositoryLayout.java	23 Mar 2005 03:40:12 -0000	1.2
  +++ LegacyRepositoryLayout.java	23 Mar 2005 14:55:15 -0000	1.3
  @@ -28,6 +28,11 @@
           return "${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}";
       }
   
  +    protected String metadataLayoutPattern()
  +    {
  +        return "${groupPath}/${directory}/${artifactId}-${version}-${metadataFilename}";
  +    }
  +
       protected String groupIdAsPath( String groupId )
       {
           return groupId;
  
  
  
  1.8       +8 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
  
  Index: ArtifactRepository.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ArtifactRepository.java	23 Mar 2005 03:40:13 -0000	1.7
  +++ ArtifactRepository.java	23 Mar 2005 14:55:15 -0000	1.8
  @@ -17,6 +17,7 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
   import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
   import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
   import org.apache.maven.wagon.authentication.AuthenticationInfo;
  @@ -55,4 +56,10 @@
           return layout.pathOf( artifact );
       }
   
  +    public String pathOfMetadata( ArtifactMetadata artifactMetadata )
  +        throws ArtifactPathFormatException
  +    {
  +        return layout.pathOfMetadata( artifactMetadata );
  +    }
  +
   }
  \ No newline at end of file
  
  
  
  1.3       +13 -1     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
  
  Index: SnapshotTransformation.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SnapshotTransformation.java	23 Mar 2005 08:42:57 -0000	1.2
  +++ SnapshotTransformation.java	23 Mar 2005 14:55:15 -0000	1.3
  @@ -17,6 +17,8 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
  +import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   
   /**
  @@ -185,7 +187,17 @@
       */
       public Artifact transformLocalArtifact( Artifact artifact, ArtifactRepository localRepository
)
       {
  -        // TODO: implement
  +        if ( isSnapshot( artifact ) && "pom".equals( artifact.getType() ) )
  +        {
  +            // only store the snapshot-version-local.txt file for POMs as every file has
an associated POM
  +            ArtifactMetadata metadata = SnapshotArtifactMetadata.createLocalSnapshotMetadata(
artifact );
  +            artifact.addMetadata( metadata );
  +        }
           return artifact;
       }
  +
  +    private static boolean isSnapshot( Artifact artifact )
  +    {
  +        return artifact.getVersion().endsWith( "SNAPSHOT" );
  +    }
   }
  \ No newline at end of file
  
  
  
  1.7       +10 -0     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
  
  Index: Artifact.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Artifact.java	23 Mar 2005 03:40:13 -0000	1.6
  +++ Artifact.java	23 Mar 2005 14:55:15 -0000	1.7
  @@ -16,8 +16,14 @@
    * limitations under the License.
    */
   
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
  +
   import java.io.File;
  +import java.util.List;
   
  +/**
  + * Description of an artifact.
  + */
   public interface Artifact
   {
       // TODO: into scope handler
  @@ -61,4 +67,8 @@
       String getId();
   
       String getConflictId();
  +
  +    void addMetadata( ArtifactMetadata metadata );
  +
  +    List getMetadataList();
   }
  \ No newline at end of file
  
  
  
  1.17      +21 -1     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
  
  Index: DefaultArtifact.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DefaultArtifact.java	23 Mar 2005 03:40:13 -0000	1.16
  +++ DefaultArtifact.java	23 Mar 2005 14:55:15 -0000	1.17
  @@ -16,9 +16,13 @@
    * limitations under the License.
    */
   
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
   import org.codehaus.plexus.util.StringUtils;
   
   import java.io.File;
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.List;
   
   /**
    * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
  @@ -46,6 +50,8 @@
   
       private String path;
   
  +    private List metadataList;
  +
       /**
        * @todo this should be replaced by type handler
        * !!! WARNING !!! Never put <classifier/> in the POM. It is for mojo use
  @@ -161,6 +167,20 @@
           return getGroupId() + ":" + getArtifactId() + ":" + getType();
       }
   
  +    public void addMetadata( ArtifactMetadata metadata )
  +    {
  +        if ( metadataList == null )
  +        {
  +            metadataList = new ArrayList();
  +        }
  +        metadataList.add( metadata );
  +    }
  +
  +    public List getMetadataList()
  +    {
  +        return metadataList == null ? Collections.EMPTY_LIST : metadataList;
  +    }
  +
       // ----------------------------------------------------------------------
       // Object overrides
       // ----------------------------------------------------------------------
  
  
  

Mime
View raw message