View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.spi.connector;
20  
21  import java.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.eclipse.aether.RequestTrace;
26  import org.eclipse.aether.metadata.Metadata;
27  import org.eclipse.aether.repository.RemoteRepository;
28  import org.eclipse.aether.transfer.MetadataTransferException;
29  import org.eclipse.aether.transfer.TransferListener;
30  
31  /**
32   * A download of metadata from a remote repository. A repository connector processing this download has to use
33   * {@link #setException(MetadataTransferException)} to report the results of the transfer.
34   */
35  public final class MetadataDownload extends MetadataTransfer {
36  
37      private String checksumPolicy = "";
38  
39      private String context = "";
40  
41      private List<RemoteRepository> repositories = Collections.emptyList();
42  
43      /**
44       * Creates a new uninitialized download.
45       */
46      public MetadataDownload() {
47          // enables default constructor
48      }
49  
50      /**
51       * Creates a new download with the specified properties.
52       *
53       * @param metadata The metadata to download, may be {@code null}.
54       * @param context The context in which this download is performed, may be {@code null}.
55       * @param file The local file to download the metadata to, may be {@code null}.
56       * @param checksumPolicy The checksum policy, may be {@code null}.
57       */
58      public MetadataDownload(Metadata metadata, String context, File file, String checksumPolicy) {
59          setMetadata(metadata);
60          setFile(file);
61          setChecksumPolicy(checksumPolicy);
62          setRequestContext(context);
63      }
64  
65      @Override
66      public MetadataDownload setMetadata(Metadata metadata) {
67          super.setMetadata(metadata);
68          return this;
69      }
70  
71      @Override
72      public MetadataDownload setFile(File file) {
73          super.setFile(file);
74          return this;
75      }
76  
77      /**
78       * Gets the checksum policy for this transfer.
79       *
80       * @return The checksum policy, never {@code null}.
81       */
82      public String getChecksumPolicy() {
83          return checksumPolicy;
84      }
85  
86      /**
87       * Sets the checksum policy for this transfer.
88       *
89       * @param checksumPolicy The checksum policy, may be {@code null}.
90       * @return This transfer for chaining, never {@code null}.
91       */
92      public MetadataDownload setChecksumPolicy(String checksumPolicy) {
93          this.checksumPolicy = (checksumPolicy != null) ? checksumPolicy : "";
94          return this;
95      }
96  
97      /**
98       * Gets the context of this transfer.
99       *
100      * @return The context id, never {@code null}.
101      */
102     public String getRequestContext() {
103         return context;
104     }
105 
106     /**
107      * Sets the request context of this transfer.
108      *
109      * @param context The context id, may be {@code null}.
110      * @return This transfer for chaining, never {@code null}.
111      */
112     public MetadataDownload setRequestContext(String context) {
113         this.context = (context != null) ? context : "";
114         return this;
115     }
116 
117     /**
118      * Gets the remote repositories that are being aggregated by the physically contacted remote repository (i.e. a
119      * repository manager).
120      *
121      * @return The remote repositories being aggregated, never {@code null}.
122      */
123     public List<RemoteRepository> getRepositories() {
124         return repositories;
125     }
126 
127     /**
128      * Sets the remote repositories that are being aggregated by the physically contacted remote repository (i.e. a
129      * repository manager).
130      *
131      * @param repositories The remote repositories being aggregated, may be {@code null}.
132      * @return This transfer for chaining, never {@code null}.
133      */
134     public MetadataDownload setRepositories(List<RemoteRepository> repositories) {
135         if (repositories == null) {
136             this.repositories = Collections.emptyList();
137         } else {
138             this.repositories = repositories;
139         }
140         return this;
141     }
142 
143     @Override
144     public MetadataDownload setException(MetadataTransferException exception) {
145         super.setException(exception);
146         return this;
147     }
148 
149     @Override
150     public MetadataDownload setListener(TransferListener listener) {
151         super.setListener(listener);
152         return this;
153     }
154 
155     @Override
156     public MetadataDownload setTrace(RequestTrace trace) {
157         super.setTrace(trace);
158         return this;
159     }
160 
161     @Override
162     public String toString() {
163         return getMetadata() + " - " + getFile();
164     }
165 }