View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.internal;
20  
21  import java.io.File;
22  import java.nio.file.Path;
23  import java.util.Map;
24  import java.util.Objects;
25  
26  import org.eclipse.aether.artifact.AbstractArtifact;
27  import org.eclipse.aether.artifact.Artifact;
28  
29  /**
30   * @deprecated since 4.0.0, use {@code maven-api-impl} jar instead
31   */
32  @Deprecated(since = "4.0.0")
33  public final class RelocatedArtifact extends AbstractArtifact {
34  
35      private final Artifact artifact;
36  
37      private final String groupId;
38  
39      private final String artifactId;
40  
41      private final String classifier;
42  
43      private final String extension;
44  
45      private final String version;
46  
47      private final String message;
48  
49      public RelocatedArtifact(
50              Artifact artifact,
51              String groupId,
52              String artifactId,
53              String classifier,
54              String extension,
55              String version,
56              String message) {
57          this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
58          this.groupId = (groupId != null && !groupId.isEmpty()) ? groupId : null;
59          this.artifactId = (artifactId != null && !artifactId.isEmpty()) ? artifactId : null;
60          this.classifier = (classifier != null && !classifier.isEmpty()) ? classifier : null;
61          this.extension = (extension != null && !extension.isEmpty()) ? extension : null;
62          this.version = (version != null && !version.isEmpty()) ? version : null;
63          this.message = (message != null && !message.isEmpty()) ? message : null;
64      }
65  
66      @Override
67      public String getGroupId() {
68          if (groupId != null) {
69              return groupId;
70          } else {
71              return artifact.getGroupId();
72          }
73      }
74  
75      @Override
76      public String getArtifactId() {
77          if (artifactId != null) {
78              return artifactId;
79          } else {
80              return artifact.getArtifactId();
81          }
82      }
83  
84      @Override
85      public String getClassifier() {
86          if (classifier != null) {
87              return classifier;
88          } else {
89              return artifact.getClassifier();
90          }
91      }
92  
93      @Override
94      public String getExtension() {
95          if (extension != null) {
96              return extension;
97          } else {
98              return artifact.getExtension();
99          }
100     }
101 
102     @Override
103     public String getVersion() {
104         if (version != null) {
105             return version;
106         } else {
107             return artifact.getVersion();
108         }
109     }
110 
111     // Revise these three methods when MRESOLVER-233 is delivered
112     @Override
113     public Artifact setVersion(String version) {
114         String current = getVersion();
115         if (current.equals(version) || (version == null && current.isEmpty())) {
116             return this;
117         }
118         return new RelocatedArtifact(artifact, groupId, artifactId, classifier, extension, version, message);
119     }
120 
121     @Deprecated
122     @Override
123     public Artifact setFile(File file) {
124         File current = getFile();
125         if (Objects.equals(current, file)) {
126             return this;
127         }
128         return new RelocatedArtifact(
129                 artifact.setFile(file), groupId, artifactId, classifier, extension, version, message);
130     }
131 
132     @Override
133     public Artifact setPath(Path path) {
134         Path current = getPath();
135         if (Objects.equals(current, path)) {
136             return this;
137         }
138         return new RelocatedArtifact(
139                 artifact.setPath(path), groupId, artifactId, classifier, extension, version, message);
140     }
141 
142     @Override
143     public Artifact setProperties(Map<String, String> properties) {
144         Map<String, String> current = getProperties();
145         if (current.equals(properties) || (properties == null && current.isEmpty())) {
146             return this;
147         }
148         return new RelocatedArtifact(
149                 artifact.setProperties(properties), groupId, artifactId, classifier, extension, version, message);
150     }
151 
152     @Deprecated
153     @Override
154     public File getFile() {
155         return artifact.getFile();
156     }
157 
158     @Override
159     public Path getPath() {
160         return artifact.getPath();
161     }
162 
163     @Override
164     public String getProperty(String key, String defaultValue) {
165         return artifact.getProperty(key, defaultValue);
166     }
167 
168     @Override
169     public Map<String, String> getProperties() {
170         return artifact.getProperties();
171     }
172 
173     public String getMessage() {
174         return message;
175     }
176 }