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.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   * @deprecated since 4.0.0, use {@code maven-api-impl} jar instead
30   */
31  @Deprecated(since = "4.0.0")
32  public final class RelocatedArtifact extends AbstractArtifact {
33  
34      private final Artifact artifact;
35  
36      private final String groupId;
37  
38      private final String artifactId;
39  
40      private final String classifier;
41  
42      private final String extension;
43  
44      private final String version;
45  
46      private final String message;
47  
48      public RelocatedArtifact(
49              Artifact artifact,
50              String groupId,
51              String artifactId,
52              String classifier,
53              String extension,
54              String version,
55              String message) {
56          this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
57          this.groupId = (groupId != null && !groupId.isEmpty()) ? groupId : null;
58          this.artifactId = (artifactId != null && !artifactId.isEmpty()) ? artifactId : null;
59          this.classifier = (classifier != null && !classifier.isEmpty()) ? classifier : null;
60          this.extension = (extension != null && !extension.isEmpty()) ? extension : null;
61          this.version = (version != null && !version.isEmpty()) ? version : null;
62          this.message = (message != null && !message.isEmpty()) ? message : null;
63      }
64  
65      @Override
66      public String getGroupId() {
67          if (groupId != null) {
68              return groupId;
69          } else {
70              return artifact.getGroupId();
71          }
72      }
73  
74      @Override
75      public String getArtifactId() {
76          if (artifactId != null) {
77              return artifactId;
78          } else {
79              return artifact.getArtifactId();
80          }
81      }
82  
83      @Override
84      public String getClassifier() {
85          if (classifier != null) {
86              return classifier;
87          } else {
88              return artifact.getClassifier();
89          }
90      }
91  
92      @Override
93      public String getExtension() {
94          if (extension != null) {
95              return extension;
96          } else {
97              return artifact.getExtension();
98          }
99      }
100 
101     @Override
102     public String getVersion() {
103         if (version != null) {
104             return version;
105         } else {
106             return artifact.getVersion();
107         }
108     }
109 
110     // Revise these three methods when MRESOLVER-233 is delivered
111     @Override
112     public Artifact setVersion(String version) {
113         String current = getVersion();
114         if (current.equals(version) || (version == null && current.isEmpty())) {
115             return this;
116         }
117         return new RelocatedArtifact(artifact, groupId, artifactId, classifier, extension, version, message);
118     }
119 
120     @Override
121     public Artifact setFile(File file) {
122         File current = getFile();
123         if (Objects.equals(current, file)) {
124             return this;
125         }
126         return new RelocatedArtifact(
127                 artifact.setFile(file), groupId, artifactId, classifier, extension, version, message);
128     }
129 
130     @Override
131     public Artifact setProperties(Map<String, String> properties) {
132         Map<String, String> current = getProperties();
133         if (current.equals(properties) || (properties == null && current.isEmpty())) {
134             return this;
135         }
136         return new RelocatedArtifact(
137                 artifact.setProperties(properties), groupId, artifactId, classifier, extension, version, message);
138     }
139 
140     @Override
141     public File getFile() {
142         return artifact.getFile();
143     }
144 
145     @Override
146     public String getProperty(String key, String defaultValue) {
147         return artifact.getProperty(key, defaultValue);
148     }
149 
150     @Override
151     public Map<String, String> getProperties() {
152         return artifact.getProperties();
153     }
154 
155     public String getMessage() {
156         return message;
157     }
158 }