remoteFile from the maven remote repositories
+ * and store it at destinationFile
+ *
+ * @param destinationFile the destination file in the local repository
+ * @param relativePath the relative path to the dependency
+ * @return true if the retrieval succeeds, false otherwise.
+ */
+ private boolean getRemoteArtifact( File destinationFile, String relativePath, Dependency relatedDependency )
+ {
+
+ // The directory structure for the project this dependency belongs to
+ // may not exists so attempt to create the project directory structure
+ // before attempting to download the dependency.
+ File directory = destinationFile.getParentFile();
+
+ if ( !directory.exists() )
+ {
+ directory.mkdirs();
+ }
+
+ log.info( "Attempting to download javadocs for " + relatedDependency.getArtifact());
+
+ boolean artifactFound = false;
+
+ for ( Iterator i = getProject().getContext().getMavenRepoRemote().iterator(); i.hasNext(); )
+ {
+ String remoteRepo = (String) i.next();
+
+ if ( remoteRepo.endsWith( "/" ) )
+ {
+ remoteRepo = remoteRepo.substring( 0, remoteRepo.length() - 1 );
+ }
+
+ // The username and password parameters are not being
+ // used here. Those are the "" parameters you see below.
+ String url = remoteRepo + "/" + relativePath;
+ url = StringUtils.replace( url, "//", "/" );
+
+ if ( !url.startsWith( "file" ) )
+ {
+ if ( url.startsWith( "https" ) )
+ {
+ url = StringUtils.replace( url, "https:/", "https://" );
+ }
+ else
+ {
+ url = StringUtils.replace( url, "http:/", "http://" );
+ }
+ }
+ log.debug("Trying to download source at " + url);
+
+ // Attempt to retrieve the artifact and set the checksum if retrieval
+ // of the checksum file was successful.
+ try
+ {
+ String loginHost = (String) getProject().getContext().getVariable( PROXY_LOGINHOST );
+ String loginDomain = (String) getProject().getContext().getVariable( PROXY_LOGINDOMAIN );
+ HttpUtils.getFile( url, destinationFile, false, true, getProject().getContext().getProxyHost(),
+ getProject().getContext().getProxyPort(),
+ getProject().getContext().getProxyUserName(),
+ getProject().getContext().getProxyPassword(), loginHost, loginDomain, true );
+
+ // Artifact was found, continue checking additional remote repos (if any)
+ // in case there is a newer version (i.e. snapshots) in another repo
+ artifactFound = true;
+
+ if ( !isSnapshot() )
+ {
+ break;
+ }
+ }
+ catch ( FileNotFoundException e )
+ {
+ // Multiple repositories may exist, and if the file is not found
+ // in just one of them, it's no problem, and we don't want to
+ // even print out an error.
+ // if it's not found at all, artifactFound will be false, and the
+ // build _will_ break, and the user will get an error message
+ log.debug( "File not found on one of the repos", e );
+ }
+ catch ( Exception e )
+ {
+ // If there are additional remote repos, then ignore exception
+ // as artifact may be found in another remote repo. If there
+ // are no more remote repos to check and the artifact wasn't found in
+ // a previous remote repo, then artifactFound is false indicating
+ // that the artifact could not be found in any of the remote repos
+ //
+ // arguably, we need to give the user better control (another command-
+ // line switch perhaps) of what to do in this case? Maven already has
+ // a command-line switch to work in offline mode, but what about when
+ // one of two or more remote repos is unavailable? There may be multiple
+ // remote repos for redundancy, in which case you probably want the build
+ // to continue. There may however be multiple remote repos because some
+ // artifacts are on one, and some are on another. In this case, you may
+ // want the build to break.
+ //
+ // print a warning, in any case, so user catches on to mistyped
+ // hostnames, or other snafus
+ // FIXME: localize this message
+ String[] parsedUrl = HttpUtils.parseUrl( url );
+ log.warn( "Error retrieving artifact from [" + parsedUrl[2] + "]: " + e );
+ if ( parsedUrl[0] != null )
+ {
+ log.debug( "Username was '" + parsedUrl[0] + "', password hidden" );
+ }
+ log.debug( "Error details", e );
+ }
+ }
+
+ return artifactFound;
+ }
+
+}
Index: xdocs/changes.xml
===================================================================
--- xdocs/changes.xml (revision 421191)
+++ xdocs/changes.xml (working copy)
@@ -23,6 +23,9 @@
true)
Note that you will need to defined a MAVEN_REPO Java