001    package org.apache.maven.project.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    
022    import org.apache.maven.artifact.Artifact;
023    import org.apache.maven.artifact.DefaultArtifact;
024    import org.apache.maven.artifact.InvalidArtifactRTException;
025    import org.apache.maven.artifact.handler.ArtifactHandler;
026    import org.apache.maven.artifact.metadata.ArtifactMetadata;
027    import org.apache.maven.artifact.repository.ArtifactRepository;
028    import org.apache.maven.artifact.versioning.ArtifactVersion;
029    import org.apache.maven.artifact.versioning.VersionRange;
030    
031    import java.util.Collection;
032    import java.util.Collections;
033    import java.util.List;
034    
035    /**
036     *<strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
037     * of the public API. In particular, this class can be changed or deleted without prior notice. Use
038     * {@link org.apache.maven.project.MavenProjectHelper#attachArtifact} instead.
039     */
040    @Deprecated
041    public class AttachedArtifact
042        extends DefaultArtifact
043    {
044    
045        private final Artifact parent;
046    
047        public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler )
048        {
049            super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
050                   classifier, artifactHandler, parent.isOptional() );
051    
052            setDependencyTrail( Collections.singletonList( parent.getId() ) );
053    
054            this.parent = parent;
055    
056            if ( getId().equals( parent.getId() ) )
057            {
058                throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(),
059                                                      parent.getType(), "An attached artifact must have a different ID"
060                                                          + " than its corresponding main artifact." );
061            }
062        }
063    
064        public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler )
065        {
066            this( parent, type, null, artifactHandler );
067        }
068    
069        public void setArtifactId( String artifactId )
070        {
071            throw new UnsupportedOperationException( "Cannot change the artifactId for an attached artifact."
072                + " It is derived from the main artifact." );
073        }
074    
075        public List<ArtifactVersion> getAvailableVersions()
076        {
077            return parent.getAvailableVersions();
078        }
079    
080        public void setAvailableVersions( List<ArtifactVersion> availableVersions )
081        {
082            throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
083                + " It is derived from the main artifact." );
084        }
085    
086        public String getBaseVersion()
087        {
088            return parent.getBaseVersion();
089        }
090    
091        public void setBaseVersion( String baseVersion )
092        {
093            throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
094                + " It is derived from the main artifact." );
095        }
096    
097        public String getDownloadUrl()
098        {
099            return parent.getDownloadUrl();
100        }
101    
102        public void setDownloadUrl( String downloadUrl )
103        {
104            throw new UnsupportedOperationException( "Cannot change the download information for an attached artifact."
105                + " It is derived from the main artifact." );
106        }
107    
108        public void setGroupId( String groupId )
109        {
110            throw new UnsupportedOperationException( "Cannot change the groupId for an attached artifact."
111                + " It is derived from the main artifact." );
112        }
113    
114        public ArtifactRepository getRepository()
115        {
116            return parent.getRepository();
117        }
118    
119        public void setRepository( ArtifactRepository repository )
120        {
121            throw new UnsupportedOperationException( "Cannot change the repository information for an attached artifact."
122                + " It is derived from the main artifact." );
123        }
124    
125        public String getScope()
126        {
127            return parent.getScope();
128        }
129    
130        public void setScope( String scope )
131        {
132            throw new UnsupportedOperationException( "Cannot change the scoping information for an attached artifact."
133                + " It is derived from the main artifact." );
134        }
135    
136        public String getVersion()
137        {
138            return parent.getVersion();
139        }
140    
141        public void setVersion( String version )
142        {
143            throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
144                + " It is derived from the main artifact." );
145        }
146    
147        public VersionRange getVersionRange()
148        {
149            return parent.getVersionRange();
150        }
151    
152        public void setVersionRange( VersionRange range )
153        {
154            throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
155                + " It is derived from the main artifact." );
156        }
157    
158        public boolean isRelease()
159        {
160            return parent.isRelease();
161        }
162    
163        public void setRelease( boolean release )
164        {
165            throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
166                + " It is derived from the main artifact." );
167        }
168    
169        public boolean isSnapshot()
170        {
171            return parent.isSnapshot();
172        }
173    
174        public void addMetadata( ArtifactMetadata metadata )
175        {
176            // ignore. The parent artifact will handle metadata.
177            // we must fail silently here to avoid problems with the artifact transformers.
178        }
179    
180        public Collection<ArtifactMetadata> getMetadataList()
181        {
182            return Collections.emptyList();
183        }
184    
185    }