View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2010, 2014 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether.transfer;
12  
13  import org.eclipse.aether.RepositoryException;
14  import org.eclipse.aether.artifact.Artifact;
15  import org.eclipse.aether.repository.RemoteRepository;
16  
17  /**
18   * Thrown when an artifact could not be uploaded/downloaded to/from a particular remote repository.
19   */
20  public class ArtifactTransferException
21      extends RepositoryException
22  {
23  
24      private final transient Artifact artifact;
25  
26      private final transient RemoteRepository repository;
27  
28      private final boolean fromCache;
29  
30      static String getString( String prefix, RemoteRepository repository )
31      {
32          if ( repository == null )
33          {
34              return "";
35          }
36          else
37          {
38              return prefix + repository.getId() + " (" + repository.getUrl() + ")";
39          }
40      }
41  
42      /**
43       * Creates a new exception with the specified artifact, repository and detail message.
44       * 
45       * @param artifact The untransferable artifact, may be {@code null}.
46       * @param repository The involved remote repository, may be {@code null}.
47       * @param message The detail message, may be {@code null}.
48       */
49      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message )
50      {
51          this( artifact, repository, message, false );
52      }
53  
54      /**
55       * Creates a new exception with the specified artifact, repository and detail message.
56       * 
57       * @param artifact The untransferable artifact, may be {@code null}.
58       * @param repository The involved remote repository, may be {@code null}.
59       * @param message The detail message, may be {@code null}.
60       * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
61       *            exception actually just occurred.
62       */
63      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message, boolean fromCache )
64      {
65          super( message );
66          this.artifact = artifact;
67          this.repository = repository;
68          this.fromCache = fromCache;
69      }
70  
71      /**
72       * Creates a new exception with the specified artifact, repository and cause.
73       * 
74       * @param artifact The untransferable artifact, may be {@code null}.
75       * @param repository The involved remote repository, may be {@code null}.
76       * @param cause The exception that caused this one, may be {@code null}.
77       */
78      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, Throwable cause )
79      {
80          this( artifact, repository, "Could not transfer artifact " + artifact + getString( " from/to ", repository )
81              + getMessage( ": ", cause ), cause );
82      }
83  
84      /**
85       * Creates a new exception with the specified artifact, repository, detail message and cause.
86       * 
87       * @param artifact The untransferable artifact, may be {@code null}.
88       * @param repository The involved remote repository, may be {@code null}.
89       * @param message The detail message, may be {@code null}.
90       * @param cause The exception that caused this one, may be {@code null}.
91       */
92      public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message, Throwable cause )
93      {
94          super( message, cause );
95          this.artifact = artifact;
96          this.repository = repository;
97          this.fromCache = false;
98      }
99  
100     /**
101      * Gets the artifact that could not be transferred.
102      * 
103      * @return The troublesome artifact or {@code null} if unknown.
104      */
105     public Artifact getArtifact()
106     {
107         return artifact;
108     }
109 
110     /**
111      * Gets the remote repository involved in the transfer.
112      * 
113      * @return The involved remote repository or {@code null} if unknown.
114      */
115     public RemoteRepository getRepository()
116     {
117         return repository;
118     }
119 
120     /**
121      * Indicates whether this exception actually just occurred or was played back from the error cache.
122      * 
123      * @return {@code true} if the exception was played back from the error cache, {@code false} if the exception
124      *         actually occurred just now.
125      */
126     public boolean isFromCache()
127     {
128         return fromCache;
129     }
130 
131 }