1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.project.artifact;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Files;
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
31
32
33
34
35
36 @Deprecated
37 public class ProjectArtifactMetadata extends AbstractArtifactMetadata {
38 private final File file;
39
40 public ProjectArtifactMetadata(Artifact artifact) {
41 this(artifact, null);
42 }
43
44 public ProjectArtifactMetadata(Artifact artifact, File file) {
45 super(artifact);
46 this.file = file;
47 }
48
49 public File getFile() {
50 return file;
51 }
52
53 public String getRemoteFilename() {
54 return getFilename();
55 }
56
57 public String getLocalFilename(ArtifactRepository repository) {
58 return getFilename();
59 }
60
61 private String getFilename() {
62 return getArtifactId() + "-" + artifact.getVersion() + ".pom";
63 }
64
65 public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactRepository remoteRepository)
66 throws RepositoryMetadataStoreException {
67 File destination = new File(
68 localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata(this, remoteRepository));
69
70
71
72
73
74
75
76
77 try {
78 Files.createDirectories(destination.toPath().getParent());
79 Files.copy(file.toPath(), destination.toPath());
80 } catch (IOException e) {
81 throw new RepositoryMetadataStoreException("Error copying POM to the local repository.", e);
82 }
83 }
84
85 public String toString() {
86 return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion();
87 }
88
89 public boolean storedInArtifactVersionDirectory() {
90 return true;
91 }
92
93 public String getBaseVersion() {
94 return artifact.getBaseVersion();
95 }
96
97 public Object getKey() {
98 return "project " + artifact.getGroupId() + ":" + artifact.getArtifactId();
99 }
100
101 public void merge(ArtifactMetadata metadata) {
102 ProjectArtifactMetadata m = (ProjectArtifactMetadata) metadata;
103 if (!m.file.equals(file)) {
104 throw new IllegalStateException("Cannot add two different pieces of metadata for: " + getKey());
105 }
106 }
107
108 public void merge(org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata) {
109 this.merge((ArtifactMetadata) metadata);
110 }
111 }