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  
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.transfer.ArtifactTransferException;
25  
26  /**
27   * A download/upload of an artifact.
28   *
29   * @noextend This class is not intended to be extended by clients.
30   */
31  public abstract class ArtifactTransfer extends Transfer {
32  
33      private Artifact artifact;
34  
35      private File file;
36  
37      private ArtifactTransferException exception;
38  
39      ArtifactTransfer() {
40          // hide
41      }
42  
43      /**
44       * Gets the artifact being transferred.
45       *
46       * @return The artifact being transferred or {@code null} if not set.
47       */
48      public Artifact getArtifact() {
49          return artifact;
50      }
51  
52      /**
53       * Sets the artifact to transfer.
54       *
55       * @param artifact The artifact, may be {@code null}.
56       * @return This transfer for chaining, never {@code null}.
57       */
58      public ArtifactTransfer setArtifact(Artifact artifact) {
59          this.artifact = artifact;
60          return this;
61      }
62  
63      /**
64       * Gets the local file the artifact is downloaded to or uploaded from. In case of a download, a connector should
65       * first transfer the bytes to a temporary file and only overwrite the target file once the entire download is
66       * completed such that an interrupted/failed download does not corrupt the current file contents.
67       *
68       * @return The local file or {@code null} if not set.
69       */
70      public File getFile() {
71          return file;
72      }
73  
74      /**
75       * Sets the local file the artifact is downloaded to or uploaded from.
76       *
77       * @param file The local file, may be {@code null}.
78       * @return This transfer for chaining, never {@code null}.
79       */
80      public ArtifactTransfer setFile(File file) {
81          this.file = file;
82          return this;
83      }
84  
85      /**
86       * Gets the exception that occurred during the transfer (if any).
87       *
88       * @return The exception or {@code null} if the transfer was successful.
89       */
90      public ArtifactTransferException getException() {
91          return exception;
92      }
93  
94      /**
95       * Sets the exception that occurred during the transfer.
96       *
97       * @param exception The exception, may be {@code null} to denote a successful transfer.
98       * @return This transfer for chaining, never {@code null}.
99       */
100     public ArtifactTransfer setException(ArtifactTransferException exception) {
101         this.exception = exception;
102         return this;
103     }
104 }