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