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 24 import org.eclipse.aether.metadata.Metadata; 25 import org.eclipse.aether.transfer.MetadataTransferException; 26 27 /** 28 * A download/upload of metadata. 29 * 30 * @noextend This class is not intended to be extended by clients. 31 */ 32 public abstract class MetadataTransfer extends Transfer { 33 34 private Metadata metadata; 35 36 private Path path; 37 38 private MetadataTransferException exception; 39 40 MetadataTransfer() { 41 // hide 42 } 43 44 /** 45 * Gets the metadata being transferred. 46 * 47 * @return The metadata being transferred or {@code null} if not set. 48 */ 49 public Metadata getMetadata() { 50 return metadata; 51 } 52 53 /** 54 * Sets the metadata to transfer. 55 * 56 * @param metadata The metadata, may be {@code null}. 57 * @return This transfer for chaining, never {@code null}. 58 */ 59 public MetadataTransfer setMetadata(Metadata metadata) { 60 this.metadata = metadata; 61 return this; 62 } 63 64 /** 65 * Gets the local file the metadata is downloaded to or uploaded from. In case of a download, a connector should 66 * first transfer the bytes to a temporary file and only overwrite the target file once the entire download is 67 * completed such that an interrupted/failed download does not corrupt the current file contents. 68 * 69 * @return The local file or {@code null} if not set. 70 * @deprecated Use {@link #getPath()} instead. 71 */ 72 @Deprecated 73 public File getFile() { 74 return path != null ? path.toFile() : null; 75 } 76 77 /** 78 * Gets the local file the metadata is downloaded to or uploaded from. In case of a download, a connector should 79 * first transfer the bytes to a temporary file and only overwrite the target file once the entire download is 80 * completed such that an interrupted/failed download does not corrupt the current file contents. 81 * 82 * @return The local file or {@code null} if not set. 83 * @since 2.0.0 84 */ 85 public Path getPath() { 86 return path; 87 } 88 89 /** 90 * Sets the local file the metadata is downloaded to or uploaded from. 91 * 92 * @param file The local file, may be {@code null}. 93 * @return This transfer for chaining, never {@code null}. 94 * @deprecated Use {@link #setPath(Path)} instead. 95 */ 96 @Deprecated 97 public MetadataTransfer setFile(File file) { 98 return setPath(file != null ? file.toPath() : null); 99 } 100 101 /** 102 * Sets the local file the metadata is downloaded to or uploaded from. 103 * 104 * @param path The local file, may be {@code null}. 105 * @return This transfer for chaining, never {@code null}. 106 * @since 2.0.0 107 */ 108 public MetadataTransfer setPath(Path path) { 109 this.path = path; 110 return this; 111 } 112 113 /** 114 * Gets the exception that occurred during the transfer (if any). 115 * 116 * @return The exception or {@code null} if the transfer was successful. 117 */ 118 public MetadataTransferException getException() { 119 return exception; 120 } 121 122 /** 123 * Sets the exception that occurred during the transfer. 124 * 125 * @param exception The exception, may be {@code null} to denote a successful transfer. 126 * @return This transfer for chaining, never {@code null}. 127 */ 128 public MetadataTransfer setException(MetadataTransferException exception) { 129 this.exception = exception; 130 return this; 131 } 132 }