View Javadoc
1   package org.eclipse.aether.transfer;
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 org.eclipse.aether.RepositoryException;
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.repository.RemoteRepository;
25  
26  /**
27   * Thrown when an artifact could not be uploaded/downloaded to/from a particular remote repository.
28   */
29  public class ArtifactTransferException
30      extends RepositoryException
31  {
32  
33      private final transient Artifact artifact;
34  
35      private final transient RemoteRepository repository;
36  
37      private final boolean fromCache;
38  
39      static String getString( String prefix, RemoteRepository repository )
40      {
41          if ( repository == null )
42          {
43              return "";
44          }
45          else
46          {
47              return prefix + repository.getId() + " (" + repository.getUrl() + ")";
48          }
49      }
50  
51      /**
52       * Creates a new exception with the specified artifact, repository and detail message.
53       * 
54       * @param artifact The untransferable artifact, may be {@code null}.
55       * @param repository The involved remote repository, may be {@code null}.
56       * @param message The detail message, may be {@code null}.
57       */
58      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message )
59      {
60          this( artifact, repository, message, false );
61      }
62  
63      /**
64       * Creates a new exception with the specified artifact, repository and detail message.
65       * 
66       * @param artifact The untransferable artifact, may be {@code null}.
67       * @param repository The involved remote repository, may be {@code null}.
68       * @param message The detail message, may be {@code null}.
69       * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
70       *            exception actually just occurred.
71       */
72      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message, boolean fromCache )
73      {
74          super( message );
75          this.artifact = artifact;
76          this.repository = repository;
77          this.fromCache = fromCache;
78      }
79  
80      /**
81       * Creates a new exception with the specified artifact, repository and cause.
82       * 
83       * @param artifact The untransferable artifact, may be {@code null}.
84       * @param repository The involved remote repository, may be {@code null}.
85       * @param cause The exception that caused this one, may be {@code null}.
86       */
87      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, Throwable cause )
88      {
89          this( artifact, repository, "Could not transfer artifact " + artifact + getString( " from/to ", repository )
90              + getMessage( ": ", cause ), cause );
91      }
92  
93      /**
94       * Creates a new exception with the specified artifact, repository, detail message and cause.
95       * 
96       * @param artifact The untransferable artifact, may be {@code null}.
97       * @param repository The involved remote repository, may be {@code null}.
98       * @param message The detail message, may be {@code null}.
99       * @param cause The exception that caused this one, may be {@code null}.
100      */
101     public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message, Throwable cause )
102     {
103         super( message, cause );
104         this.artifact = artifact;
105         this.repository = repository;
106         this.fromCache = false;
107     }
108 
109     /**
110      * Gets the artifact that could not be transferred.
111      * 
112      * @return The troublesome artifact or {@code null} if unknown.
113      */
114     public Artifact getArtifact()
115     {
116         return artifact;
117     }
118 
119     /**
120      * Gets the remote repository involved in the transfer.
121      * 
122      * @return The involved remote repository or {@code null} if unknown.
123      */
124     public RemoteRepository getRepository()
125     {
126         return repository;
127     }
128 
129     /**
130      * Indicates whether this exception actually just occurred or was played back from the error cache.
131      * 
132      * @return {@code true} if the exception was played back from the error cache, {@code false} if the exception
133      *         actually occurred just now.
134      */
135     public boolean isFromCache()
136     {
137         return fromCache;
138     }
139 
140 }