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