1 package org.eclipse.aether.spi.connector;
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.Collections;
24 import java.util.List;
25
26 import org.eclipse.aether.RequestTrace;
27 import org.eclipse.aether.metadata.Metadata;
28 import org.eclipse.aether.repository.RemoteRepository;
29 import org.eclipse.aether.transfer.MetadataTransferException;
30 import org.eclipse.aether.transfer.TransferListener;
31
32 /**
33 * A download of metadata from a remote repository. A repository connector processing this download has to use
34 * {@link #setException(MetadataTransferException)} to report the results of the transfer.
35 */
36 public final class MetadataDownload
37 extends MetadataTransfer
38 {
39
40 private String checksumPolicy = "";
41
42 private String context = "";
43
44 private List<RemoteRepository> repositories = Collections.emptyList();
45
46 /**
47 * Creates a new uninitialized download.
48 */
49 public MetadataDownload()
50 {
51 // enables default constructor
52 }
53
54 /**
55 * Creates a new download with the specified properties.
56 *
57 * @param metadata The metadata to download, may be {@code null}.
58 * @param context The context in which this download is performed, may be {@code null}.
59 * @param file The local file to download the metadata to, may be {@code null}.
60 * @param checksumPolicy The checksum policy, may be {@code null}.
61 */
62 public MetadataDownload( Metadata metadata, String context, File file, String checksumPolicy )
63 {
64 setMetadata( metadata );
65 setFile( file );
66 setChecksumPolicy( checksumPolicy );
67 setRequestContext( context );
68 }
69
70 @Override
71 public MetadataDownload setMetadata( Metadata metadata )
72 {
73 super.setMetadata( metadata );
74 return this;
75 }
76
77 @Override
78 public MetadataDownload setFile( File file )
79 {
80 super.setFile( file );
81 return this;
82 }
83
84 /**
85 * Gets the checksum policy for this transfer.
86 *
87 * @return The checksum policy, never {@code null}.
88 */
89 public String getChecksumPolicy()
90 {
91 return checksumPolicy;
92 }
93
94 /**
95 * Sets the checksum policy for this transfer.
96 *
97 * @param checksumPolicy The checksum policy, may be {@code null}.
98 * @return This transfer for chaining, never {@code null}.
99 */
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 }