1 package org.apache.maven.plugin.gpg;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.metadata.AbstractArtifactMetadata;
27 import org.apache.maven.artifact.metadata.ArtifactMetadata;
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException;
30 import org.codehaus.plexus.util.FileUtils;
31
32
33
34
35
36 public class AscArtifactMetadata
37 extends AbstractArtifactMetadata
38 {
39
40 File file;
41
42 boolean isPom;
43
44 public AscArtifactMetadata( Artifact artifact, File file, boolean isPom )
45 {
46 super( artifact );
47 this.file = file;
48 this.isPom = isPom;
49 }
50
51 public String getBaseVersion()
52 {
53 return artifact.getBaseVersion();
54 }
55
56 public Object getKey()
57 {
58 return "gpg signature " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType()
59 + ":" + artifact.getClassifier() + ( isPom ? ":pom" : "" );
60 }
61
62 private String getFilename()
63 {
64 StringBuilder buf = new StringBuilder( 128 );
65 buf.append( getArtifactId() );
66 buf.append( "-" ).append( artifact.getVersion() );
67 if ( isPom )
68 {
69 buf.append( ".pom" );
70 }
71 else
72 {
73 if ( artifact.getClassifier() != null && !"".equals( artifact.getClassifier() ) )
74 {
75 buf.append( "-" ).append( artifact.getClassifier() );
76 }
77 buf.append( "." ).append( artifact.getArtifactHandler().getExtension() );
78 }
79 buf.append( ".asc" );
80 return buf.toString();
81 }
82
83 public String getLocalFilename( ArtifactRepository repository )
84 {
85 return getFilename();
86 }
87
88 public String getRemoteFilename()
89 {
90 return getFilename();
91 }
92
93 public void merge( ArtifactMetadata metadata )
94 {
95 AscArtifactMetadata m = (AscArtifactMetadata) metadata;
96 if ( !m.file.equals( file ) )
97 {
98 throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
99 }
100 }
101
102 public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
103 throws RepositoryMetadataStoreException
104 {
105 File destination =
106 new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( this,
107 remoteRepository ) );
108
109 try
110 {
111 FileUtils.copyFile( file, destination );
112 }
113 catch ( IOException e )
114 {
115 throw new RepositoryMetadataStoreException( "Error copying ASC to the local repository.", e );
116 }
117 }
118
119 public boolean storedInArtifactVersionDirectory()
120 {
121 return true;
122 }
123
124 public String toString()
125 {
126 return getFilename();
127 }
128
129 }