001package org.eclipse.aether.spi.connector;
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.Collections;
024import java.util.List;
025
026import org.eclipse.aether.RequestTrace;
027import org.eclipse.aether.metadata.Metadata;
028import org.eclipse.aether.repository.RemoteRepository;
029import org.eclipse.aether.transfer.MetadataTransferException;
030import org.eclipse.aether.transfer.TransferListener;
031
032/**
033 * A download of metadata from a remote repository. A repository connector processing this download has to use
034 * {@link #setException(MetadataTransferException)} to report the results of the transfer.
035 */
036public final class MetadataDownload
037    extends MetadataTransfer
038{
039
040    private String checksumPolicy = "";
041
042    private String context = "";
043
044    private List<RemoteRepository> repositories = Collections.emptyList();
045
046    /**
047     * Creates a new uninitialized download.
048     */
049    public MetadataDownload()
050    {
051        // enables default constructor
052    }
053
054    /**
055     * Creates a new download with the specified properties.
056     * 
057     * @param metadata The metadata to download, may be {@code null}.
058     * @param context The context in which this download is performed, may be {@code null}.
059     * @param file The local file to download the metadata to, may be {@code null}.
060     * @param checksumPolicy The checksum policy, may be {@code null}.
061     */
062    public MetadataDownload( Metadata metadata, String context, File file, String checksumPolicy )
063    {
064        setMetadata( metadata );
065        setFile( file );
066        setChecksumPolicy( checksumPolicy );
067        setRequestContext( context );
068    }
069
070    @Override
071    public MetadataDownload setMetadata( Metadata metadata )
072    {
073        super.setMetadata( metadata );
074        return this;
075    }
076
077    @Override
078    public MetadataDownload setFile( File file )
079    {
080        super.setFile( file );
081        return this;
082    }
083
084    /**
085     * Gets the checksum policy for this transfer.
086     * 
087     * @return The checksum policy, never {@code null}.
088     */
089    public String getChecksumPolicy()
090    {
091        return checksumPolicy;
092    }
093
094    /**
095     * Sets the checksum policy for this transfer.
096     * 
097     * @param checksumPolicy The checksum policy, may be {@code null}.
098     * @return This transfer for chaining, never {@code null}.
099     */
100    public MetadataDownload setChecksumPolicy( String checksumPolicy )
101    {
102        this.checksumPolicy = ( checksumPolicy != null ) ? checksumPolicy : "";
103        return this;
104    }
105
106    /**
107     * Gets the context of this transfer.
108     * 
109     * @return The context id, never {@code null}.
110     */
111    public String getRequestContext()
112    {
113        return context;
114    }
115
116    /**
117     * Sets the request context of this transfer.
118     * 
119     * @param context The context id, may be {@code null}.
120     * @return This transfer for chaining, never {@code null}.
121     */
122    public MetadataDownload setRequestContext( String context )
123    {
124        this.context = ( context != null ) ? context : "";
125        return this;
126    }
127
128    /**
129     * Gets the remote repositories that are being aggregated by the physically contacted remote repository (i.e. a
130     * repository manager).
131     * 
132     * @return The remote repositories being aggregated, never {@code null}.
133     */
134    public List<RemoteRepository> getRepositories()
135    {
136        return repositories;
137    }
138
139    /**
140     * Sets the remote repositories that are being aggregated by the physically contacted remote repository (i.e. a
141     * repository manager).
142     * 
143     * @param repositories The remote repositories being aggregated, may be {@code null}.
144     * @return This transfer for chaining, never {@code null}.
145     */
146    public MetadataDownload setRepositories( List<RemoteRepository> repositories )
147    {
148        if ( repositories == null )
149        {
150            this.repositories = Collections.emptyList();
151        }
152        else
153        {
154            this.repositories = repositories;
155        }
156        return this;
157    }
158
159    @Override
160    public MetadataDownload setException( MetadataTransferException exception )
161    {
162        super.setException( exception );
163        return this;
164    }
165
166    @Override
167    public MetadataDownload setListener( TransferListener listener )
168    {
169        super.setListener( listener );
170        return this;
171    }
172
173    @Override
174    public MetadataDownload setTrace( RequestTrace trace )
175    {
176        super.setTrace( trace );
177        return this;
178    }
179
180    @Override
181    public String toString()
182    {
183        return getMetadata() + " - " + getFile();
184    }
185
186}