View Javadoc
1   package org.eclipse.aether.util.artifact;
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  
25  import org.eclipse.aether.artifact.AbstractArtifact;
26  import org.eclipse.aether.artifact.Artifact;
27  
28  /**
29   * An artifact that delegates to another artifact instance. This class serves as a base for subclasses that want to
30   * carry additional data fields.
31   */
32  public abstract class DelegatingArtifact
33      extends AbstractArtifact
34  {
35  
36      private final Artifact delegate;
37  
38      /**
39       * Creates a new artifact instance that delegates to the specified artifact.
40       * 
41       * @param delegate The artifact to delegate to, must not be {@code null}.
42       */
43      protected DelegatingArtifact( Artifact delegate )
44      {
45          if ( delegate == null )
46          {
47              throw new IllegalArgumentException( "delegate artifact not specified" );
48          }
49          this.delegate = delegate;
50      }
51  
52      /**
53       * Creates a new artifact instance that delegates to the specified artifact. Subclasses should use this hook to
54       * instantiate themselves, taking along any data from the current instance that was added.
55       * 
56       * @param delegate The artifact to delegate to, must not be {@code null}.
57       * @return The new delegating artifact, never {@code null}.
58       */
59      protected abstract DelegatingArtifact newInstance( Artifact delegate );
60  
61      public String getGroupId()
62      {
63          return delegate.getGroupId();
64      }
65  
66      public String getArtifactId()
67      {
68          return delegate.getArtifactId();
69      }
70  
71      public String getVersion()
72      {
73          return delegate.getVersion();
74      }
75  
76      public Artifact setVersion( String version )
77      {
78          Artifact artifact = delegate.setVersion( version );
79          if ( artifact != delegate )
80          {
81              return newInstance( artifact );
82          }
83          return this;
84      }
85  
86      public String getBaseVersion()
87      {
88          return delegate.getBaseVersion();
89      }
90  
91      public boolean isSnapshot()
92      {
93          return delegate.isSnapshot();
94      }
95  
96      public String getClassifier()
97      {
98          return delegate.getClassifier();
99      }
100 
101     public String getExtension()
102     {
103         return delegate.getExtension();
104     }
105 
106     public File getFile()
107     {
108         return delegate.getFile();
109     }
110 
111     public Artifact setFile( File file )
112     {
113         Artifact artifact = delegate.setFile( file );
114         if ( artifact != delegate )
115         {
116             return newInstance( artifact );
117         }
118         return this;
119     }
120 
121     public String getProperty( String key, String defaultValue )
122     {
123         return delegate.getProperty( key, defaultValue );
124     }
125 
126     public Map<String, String> getProperties()
127     {
128         return delegate.getProperties();
129     }
130 
131     public Artifact setProperties( Map<String, String> properties )
132     {
133         Artifact artifact = delegate.setProperties( properties );
134         if ( artifact != delegate )
135         {
136             return newInstance( artifact );
137         }
138         return this;
139     }
140 
141     @Override
142     public boolean equals( Object obj )
143     {
144         if ( obj == this )
145         {
146             return true;
147         }
148 
149         if ( obj instanceof DelegatingArtifact )
150         {
151             return delegate.equals( ( (DelegatingArtifact) obj ).delegate );
152         }
153 
154         return delegate.equals( obj );
155     }
156 
157     @Override
158     public int hashCode()
159     {
160         return delegate.hashCode();
161     }
162 
163     @Override
164     public String toString()
165     {
166         return delegate.toString();
167     }
168 
169 }