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