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.nio.file.Path;
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 extends MetadataTransfer {
37
38 private String checksumPolicy = "";
39
40 private String context = "";
41
42 private List<RemoteRepository> repositories = Collections.emptyList();
43
44 /**
45 * Creates a new uninitialized download.
46 */
47 public MetadataDownload() {
48 // enables default constructor
49 }
50
51 /**
52 * Creates a new download with the specified properties.
53 *
54 * @param metadata The metadata to download, may be {@code null}.
55 * @param context The context in which this download is performed, may be {@code null}.
56 * @param file The local file to download the metadata to, may be {@code null}.
57 * @param checksumPolicy The checksum policy, may be {@code null}.
58 * @deprecated Use {@link #MetadataDownload(Metadata, String, Path, String)} instead.
59 */
60 @Deprecated
61 public MetadataDownload(Metadata metadata, String context, File file, String checksumPolicy) {
62 this(metadata, context, file != null ? file.toPath() : null, checksumPolicy);
63 }
64
65 /**
66 * Creates a new download with the specified properties.
67 *
68 * @param metadata The metadata to download, may be {@code null}.
69 * @param context The context in which this download is performed, may be {@code null}.
70 * @param path The local file to download the metadata to, may be {@code null}.
71 * @param checksumPolicy The checksum policy, may be {@code null}.
72 * @since 2.0.0
73 */
74 public MetadataDownload(Metadata metadata, String context, Path path, String checksumPolicy) {
75 setMetadata(metadata);
76 setPath(path);
77 setChecksumPolicy(checksumPolicy);
78 setRequestContext(context);
79 }
80
81 @Override
82 public MetadataDownload setMetadata(Metadata metadata) {
83 super.setMetadata(metadata);
84 return this;
85 }
86
87 @Deprecated
88 @Override
89 public MetadataDownload setFile(File file) {
90 super.setFile(file);
91 return this;
92 }
93
94 @Override
95 public MetadataDownload setPath(Path path) {
96 super.setPath(path);
97 return this;
98 }
99
100 /**
101 * Gets the checksum policy for this transfer.
102 *
103 * @return The checksum policy, never {@code null}.
104 */
105 public String getChecksumPolicy() {
106 return checksumPolicy;
107 }
108
109 /**
110 * Sets the checksum policy for this transfer.
111 *
112 * @param checksumPolicy The checksum policy, may be {@code null}.
113 * @return This transfer for chaining, never {@code null}.
114 */
115 public MetadataDownload setChecksumPolicy(String checksumPolicy) {
116 this.checksumPolicy = (checksumPolicy != null) ? checksumPolicy : "";
117 return this;
118 }
119
120 /**
121 * Gets the context of this transfer.
122 *
123 * @return The context id, never {@code null}.
124 */
125 public String getRequestContext() {
126 return context;
127 }
128
129 /**
130 * Sets the request context of this transfer.
131 *
132 * @param context The context id, may be {@code null}.
133 * @return This transfer for chaining, never {@code null}.
134 */
135 public MetadataDownload setRequestContext(String context) {
136 this.context = (context != null) ? context : "";
137 return this;
138 }
139
140 /**
141 * Gets the remote repositories that are being aggregated by the physically contacted remote repository (i.e. a
142 * repository manager).
143 *
144 * @return The remote repositories being aggregated, never {@code null}.
145 */
146 public List<RemoteRepository> getRepositories() {
147 return repositories;
148 }
149
150 /**
151 * Sets the remote repositories that are being aggregated by the physically contacted remote repository (i.e. a
152 * repository manager).
153 *
154 * @param repositories The remote repositories being aggregated, may be {@code null}.
155 * @return This transfer for chaining, never {@code null}.
156 */
157 public MetadataDownload setRepositories(List<RemoteRepository> repositories) {
158 if (repositories == null) {
159 this.repositories = Collections.emptyList();
160 } else {
161 this.repositories = repositories;
162 }
163 return this;
164 }
165
166 @Override
167 public MetadataDownload setException(MetadataTransferException exception) {
168 super.setException(exception);
169 return this;
170 }
171
172 @Override
173 public MetadataDownload setListener(TransferListener listener) {
174 super.setListener(listener);
175 return this;
176 }
177
178 @Override
179 public MetadataDownload setTrace(RequestTrace trace) {
180 super.setTrace(trace);
181 return this;
182 }
183
184 @Override
185 public String toString() {
186 return getMetadata() + " - " + getPath();
187 }
188 }