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