1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.repository.internal;
20  
21  import java.io.File;
22  import java.util.Map;
23  import java.util.Objects;
24  
25  import org.eclipse.aether.artifact.AbstractArtifact;
26  import org.eclipse.aether.artifact.Artifact;
27  
28  
29  
30  
31  public final class RelocatedArtifact extends AbstractArtifact {
32  
33      private final Artifact artifact;
34  
35      private final String groupId;
36  
37      private final String artifactId;
38  
39      private final String version;
40  
41      private final String message;
42  
43      RelocatedArtifact(Artifact artifact, String groupId, String artifactId, String version, String message) {
44          this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
45          
46          this.groupId = (groupId != null && groupId.length() > 0) ? groupId : null;
47          this.artifactId = (artifactId != null && artifactId.length() > 0) ? artifactId : null;
48          this.version = (version != null && version.length() > 0) ? version : null;
49          this.message = (message != null && message.length() > 0) ? message : null;
50      }
51  
52      public String getGroupId() {
53          if (groupId != null) {
54              return groupId;
55          } else {
56              return artifact.getGroupId();
57          }
58      }
59  
60      public String getArtifactId() {
61          if (artifactId != null) {
62              return artifactId;
63          } else {
64              return artifact.getArtifactId();
65          }
66      }
67  
68      public String getVersion() {
69          if (version != null) {
70              return version;
71          } else {
72              return artifact.getVersion();
73          }
74      }
75  
76      
77      @Override
78      public Artifact setVersion(String version) {
79          String current = getVersion();
80          if (current.equals(version) || (version == null && current.length() <= 0)) {
81              return this;
82          }
83          return new RelocatedArtifact(artifact, groupId, artifactId, version, message);
84      }
85  
86      @Override
87      public Artifact setFile(File file) {
88          File current = getFile();
89          if (Objects.equals(current, file)) {
90              return this;
91          }
92          return new RelocatedArtifact(artifact.setFile(file), groupId, artifactId, version, message);
93      }
94  
95      @Override
96      public Artifact setProperties(Map<String, String> properties) {
97          Map<String, String> current = getProperties();
98          if (current.equals(properties) || (properties == null && current.isEmpty())) {
99              return this;
100         }
101         return new RelocatedArtifact(artifact.setProperties(properties), groupId, artifactId, version, message);
102     }
103 
104     public String getClassifier() {
105         return artifact.getClassifier();
106     }
107 
108     public String getExtension() {
109         return artifact.getExtension();
110     }
111 
112     public File getFile() {
113         return artifact.getFile();
114     }
115 
116     public String getProperty(String key, String defaultValue) {
117         return artifact.getProperty(key, defaultValue);
118     }
119 
120     public Map<String, String> getProperties() {
121         return artifact.getProperties();
122     }
123 
124     public String getMessage() {
125         return message;
126     }
127 }