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