1 package org.apache.maven.artifact.resolver; 2 3 18 19 import org.apache.maven.artifact.Artifact; 20 import org.apache.maven.artifact.repository.ArtifactRepository; 21 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 32 public class AbstractArtifactResolutionException 33 extends Exception  34 { 35 private String groupId; 36 37 private String artifactId; 38 39 private String version; 40 41 private String type; 42 43 private List remoteRepositories; 44 45 private final String originalMessage; 46 47 private final String path; 48 49 static final String LS = System.getProperty( "line.separator" ); 50 51 protected AbstractArtifactResolutionException( String message, String groupId, String artifactId, String version, 52 String type, List remoteRepositories, List path ) 53 { 54 super( constructMessageBase( message, groupId, artifactId, version, type, remoteRepositories, path ) ); 55 56 this.originalMessage = message; 57 this.groupId = groupId; 58 this.artifactId = artifactId; 59 this.type = type; 60 this.version = version; 61 this.remoteRepositories = remoteRepositories; 62 this.path = constructArtifactPath( path, "" ); 63 } 64 65 protected AbstractArtifactResolutionException( String message, String groupId, String artifactId, String version, 66 String type, List remoteRepositories, List path, Throwable t ) 67 { 68 super( constructMessageBase( message, groupId, artifactId, version, type, remoteRepositories, path ), t ); 69 70 this.originalMessage = message; 71 this.groupId = groupId; 72 this.artifactId = artifactId; 73 this.type = type; 74 this.version = version; 75 this.remoteRepositories = remoteRepositories; 76 this.path = constructArtifactPath( path, "" ); 77 } 78 79 protected AbstractArtifactResolutionException( String message, Artifact artifact ) 80 { 81 this( message, artifact, null ); 82 } 83 84 protected AbstractArtifactResolutionException( String message, Artifact artifact, List remoteRepositories ) 85 { 86 this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), 87 remoteRepositories, artifact.getDependencyTrail() ); 88 } 89 90 protected AbstractArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, 91 Throwable t ) 92 { 93 this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), 94 remoteRepositories, artifact.getDependencyTrail(), t ); 95 } 96 97 public String getGroupId() 98 { 99 return groupId; 100 } 101 102 public String getArtifactId() 103 { 104 return artifactId; 105 } 106 107 public String getVersion() 108 { 109 return version; 110 } 111 112 public String getType() 113 { 114 return type; 115 } 116 117 public List getRemoteRepositories() 118 { 119 return remoteRepositories; 120 } 121 122 public String getOriginalMessage() 123 { 124 return originalMessage; 125 } 126 127 protected static String constructArtifactPath( List path, String indentation ) 128 { 129 StringBuffer sb = new StringBuffer (); 130 131 if ( path != null ) 132 { 133 sb.append( LS ); 134 sb.append( indentation ); 135 sb.append( "Path to dependency: " ); 136 sb.append( LS ); 137 int num = 1; 138 for ( Iterator i = path.iterator(); i.hasNext(); num++ ) 139 { 140 sb.append( indentation ); 141 sb.append( "\t" ); 142 sb.append( num ); 143 sb.append( ") " ); 144 sb.append( i.next() ); 145 sb.append( LS ); 146 } 147 } 148 149 return sb.toString(); 150 } 151 152 private static String constructMessageBase( String message, String groupId, String artifactId, String version, 153 String type, List remoteRepositories, List path ) 154 { 155 StringBuffer sb = new StringBuffer (); 156 157 sb.append( message ); 158 sb.append( LS ); 159 sb.append( " " + groupId + ":" + artifactId + ":" + type + ":" + version ); 160 sb.append( LS ); 161 if ( remoteRepositories != null && !remoteRepositories.isEmpty() ) 162 { 163 sb.append( LS ); 164 sb.append( "from the specified remote repositories:" ); 165 sb.append( LS + " " ); 166 167 for ( Iterator i = new HashSet ( remoteRepositories ).iterator(); i.hasNext(); ) 168 { 169 ArtifactRepository remoteRepository = (ArtifactRepository) i.next(); 170 171 sb.append( remoteRepository.getId() ); 172 sb.append( " (" ); 173 sb.append( remoteRepository.getUrl() ); 174 sb.append( ")" ); 175 if ( i.hasNext() ) 176 { 177 sb.append( ",\n " ); 178 } 179 } 180 } 181 182 sb.append( constructArtifactPath( path, "" ) ); 183 sb.append( LS ); 184 return sb.toString(); 185 } 186 187 protected static String constructMissingArtifactMessage( String message, String indentation, String groupId, String artifactId, String version, 188 String type, String downloadUrl, List path ) 189 { 190 StringBuffer sb = new StringBuffer ( message ); 191 192 if ( !"pom".equals( type ) ) 193 { 194 if ( downloadUrl != null ) 195 { 196 sb.append( LS ); 197 sb.append( LS ); 198 sb.append( indentation ); 199 sb.append( "Try downloading the file manually from: " ); 200 sb.append( LS ); 201 sb.append( indentation ); 202 sb.append( " " ); 203 sb.append( downloadUrl ); 204 } 205 else 206 { 207 sb.append( LS ); 208 sb.append( LS ); 209 sb.append( indentation ); 210 sb.append( "Try downloading the file manually from the project website." ); 211 } 212 213 sb.append( LS ); 214 sb.append( LS ); 215 sb.append( indentation ); 216 sb.append( "Then, install it using the command: " ); 217 sb.append( LS ); 218 sb.append( indentation ); 219 sb.append( " mvn install:install-file -DgroupId=" ); 220 sb.append( groupId ); 221 sb.append( " -DartifactId=" ); 222 sb.append( artifactId ); 223 sb.append( " \\\n"); 224 sb.append( indentation ); 225 sb.append( " " ); 226 sb.append( "-Dversion=" ); 227 sb.append( version ); 228 sb.append( " -Dpackaging=" ); 229 sb.append( type ); 230 sb.append( " -Dfile=/path/to/file" ); 231 sb.append( LS ); 232 } 233 234 sb.append( constructArtifactPath( path, indentation ) ); 235 sb.append( LS ); 236 237 return sb.toString(); 238 } 239 240 public String getArtifactPath() 241 { 242 return path; 243 } 244 } 245 | Popular Tags |