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