001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.spi.connector; 020 021import java.io.File; 022import java.nio.file.Path; 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 extends MetadataTransfer { 037 038 private String checksumPolicy = ""; 039 040 private String context = ""; 041 042 private List<RemoteRepository> repositories = Collections.emptyList(); 043 044 /** 045 * Creates a new uninitialized download. 046 */ 047 public MetadataDownload() { 048 // enables default constructor 049 } 050 051 /** 052 * Creates a new download with the specified properties. 053 * 054 * @param metadata The metadata to download, may be {@code null}. 055 * @param context The context in which this download is performed, may be {@code null}. 056 * @param file The local file to download the metadata to, may be {@code null}. 057 * @param checksumPolicy The checksum policy, may be {@code null}. 058 * @deprecated Use {@link #MetadataDownload(Metadata, String, Path, String)} instead. 059 */ 060 @Deprecated 061 public MetadataDownload(Metadata metadata, String context, File file, String checksumPolicy) { 062 this(metadata, context, file != null ? file.toPath() : null, checksumPolicy); 063 } 064 065 /** 066 * Creates a new download with the specified properties. 067 * 068 * @param metadata The metadata to download, may be {@code null}. 069 * @param context The context in which this download is performed, may be {@code null}. 070 * @param path The local file to download the metadata to, may be {@code null}. 071 * @param checksumPolicy The checksum policy, may be {@code null}. 072 * @since 2.0.0 073 */ 074 public MetadataDownload(Metadata metadata, String context, Path path, String checksumPolicy) { 075 setMetadata(metadata); 076 setPath(path); 077 setChecksumPolicy(checksumPolicy); 078 setRequestContext(context); 079 } 080 081 @Override 082 public MetadataDownload setMetadata(Metadata metadata) { 083 super.setMetadata(metadata); 084 return this; 085 } 086 087 @Deprecated 088 @Override 089 public MetadataDownload setFile(File file) { 090 super.setFile(file); 091 return this; 092 } 093 094 @Override 095 public MetadataDownload setPath(Path path) { 096 super.setPath(path); 097 return this; 098 } 099 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}