001package org.eclipse.aether.util.artifact; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import java.util.Map; 024 025import org.eclipse.aether.artifact.AbstractArtifact; 026import org.eclipse.aether.artifact.Artifact; 027 028/** 029 * An artifact that delegates to another artifact instance. This class serves as a base for subclasses that want to 030 * carry additional data fields. 031 */ 032public abstract class DelegatingArtifact 033 extends AbstractArtifact 034{ 035 036 private final Artifact delegate; 037 038 /** 039 * Creates a new artifact instance that delegates to the specified artifact. 040 * 041 * @param delegate The artifact to delegate to, must not be {@code null}. 042 */ 043 protected DelegatingArtifact( Artifact delegate ) 044 { 045 if ( delegate == null ) 046 { 047 throw new IllegalArgumentException( "delegate artifact not specified" ); 048 } 049 this.delegate = delegate; 050 } 051 052 /** 053 * Creates a new artifact instance that delegates to the specified artifact. Subclasses should use this hook to 054 * instantiate themselves, taking along any data from the current instance that was added. 055 * 056 * @param delegate The artifact to delegate to, must not be {@code null}. 057 * @return The new delegating artifact, never {@code null}. 058 */ 059 protected abstract DelegatingArtifact newInstance( Artifact delegate ); 060 061 public String getGroupId() 062 { 063 return delegate.getGroupId(); 064 } 065 066 public String getArtifactId() 067 { 068 return delegate.getArtifactId(); 069 } 070 071 public String getVersion() 072 { 073 return delegate.getVersion(); 074 } 075 076 public Artifact setVersion( String version ) 077 { 078 Artifact artifact = delegate.setVersion( version ); 079 if ( artifact != delegate ) 080 { 081 return newInstance( artifact ); 082 } 083 return this; 084 } 085 086 public String getBaseVersion() 087 { 088 return delegate.getBaseVersion(); 089 } 090 091 public boolean isSnapshot() 092 { 093 return delegate.isSnapshot(); 094 } 095 096 public String getClassifier() 097 { 098 return delegate.getClassifier(); 099 } 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}