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 | |
public class AscArtifactMetadata |
33 | |
extends AbstractArtifactMetadata |
34 | |
{ |
35 | |
|
36 | |
File file; |
37 | |
|
38 | |
boolean isPom; |
39 | |
|
40 | |
public AscArtifactMetadata( Artifact artifact, File file, boolean isPom ) |
41 | |
{ |
42 | 0 | super( artifact ); |
43 | 0 | this.file = file; |
44 | 0 | this.isPom = isPom; |
45 | 0 | } |
46 | |
|
47 | |
public String getBaseVersion() |
48 | |
{ |
49 | 0 | return artifact.getBaseVersion(); |
50 | |
} |
51 | |
|
52 | |
public Object getKey() |
53 | |
{ |
54 | 0 | return "gpg signature " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() |
55 | |
+ ":" + artifact.getClassifier() + ( isPom ? ":pom" : "" ); |
56 | |
} |
57 | |
|
58 | |
private String getFilename() |
59 | |
{ |
60 | 0 | StringBuffer buf = new StringBuffer( 128 ); |
61 | 0 | buf.append( getArtifactId() ); |
62 | 0 | buf.append( "-" ).append( artifact.getVersion() ); |
63 | 0 | if ( isPom ) |
64 | |
{ |
65 | 0 | buf.append( ".pom" ); |
66 | |
} |
67 | |
else |
68 | |
{ |
69 | 0 | if ( artifact.getClassifier() != null && !"".equals( artifact.getClassifier() ) ) |
70 | |
{ |
71 | 0 | buf.append( "-" ).append( artifact.getClassifier() ); |
72 | |
} |
73 | 0 | buf.append( "." ).append( artifact.getArtifactHandler().getExtension() ); |
74 | |
} |
75 | 0 | buf.append( ".asc" ); |
76 | 0 | return buf.toString(); |
77 | |
} |
78 | |
|
79 | |
public String getLocalFilename( ArtifactRepository repository ) |
80 | |
{ |
81 | 0 | return getFilename(); |
82 | |
} |
83 | |
|
84 | |
public String getRemoteFilename() |
85 | |
{ |
86 | 0 | return getFilename(); |
87 | |
} |
88 | |
|
89 | |
public void merge( ArtifactMetadata metadata ) |
90 | |
{ |
91 | 0 | AscArtifactMetadata m = (AscArtifactMetadata) metadata; |
92 | 0 | if ( !m.file.equals( file ) ) |
93 | |
{ |
94 | 0 | throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() ); |
95 | |
} |
96 | 0 | } |
97 | |
|
98 | |
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository ) |
99 | |
throws RepositoryMetadataStoreException |
100 | |
{ |
101 | 0 | File destination = |
102 | |
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( this, |
103 | |
remoteRepository ) ); |
104 | |
|
105 | |
try |
106 | |
{ |
107 | 0 | FileUtils.copyFile( file, destination ); |
108 | |
} |
109 | 0 | catch ( IOException e ) |
110 | |
{ |
111 | 0 | throw new RepositoryMetadataStoreException( "Error copying ASC to the local repository.", e ); |
112 | 0 | } |
113 | 0 | } |
114 | |
|
115 | |
public boolean storedInArtifactVersionDirectory() |
116 | |
{ |
117 | 0 | return true; |
118 | |
} |
119 | |
|
120 | |
public String toString() |
121 | |
{ |
122 | 0 | return getFilename(); |
123 | |
} |
124 | |
|
125 | |
} |