You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2003/05/02 11:05:17 UTC

cvs commit: maven-new/core/src/java/org/apache/maven/artifact DependencySatisfier.java ArtifactProcessor.java ArtifactDownloader.java DefaultArtifactProcessor.java DefaultArtifactDownloader.java DefaultDependencySatisfier.java

michal      2003/05/02 02:05:17

  Added:       core/src/java/org/apache/maven/artifact
                        DependencySatisfier.java ArtifactProcessor.java
                        ArtifactDownloader.java
                        DefaultArtifactProcessor.java
                        DefaultArtifactDownloader.java
                        DefaultDependencySatisfier.java
  Log:
  Those classes are the result of decomposition of DependecyVerifier class
  
  Revision  Changes    Path
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/DependencySatisfier.java
  
  Index: DependencySatisfier.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.maven.artifact;
  
  import org.apache.maven.project.Project;
  import org.apache.maven.verifier.UnsatisfiedDependencyException;
  
  /**
   * Make sure that everything that is required for the project to build
   * successfully is present. We will start by looking at the dependencies
   * and make sure they are all here before trying to compile.
   * 
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
   * @version $Id: DependencySatisfier.java,v 1.1 2003/05/02 09:05:16 michal Exp $
   */
  public interface DependencySatisfier
  {
     /** Component Role name. */
     static String ROLE = DependencySatisfier.class.getName();
  
     /**
      *
      * @param project
      * @throws RepoConfigException
      * @throws UnsatisfiedDependencyException
      * @throws ChecksumVerificationException
      */
     void satisfyDependencies(Project project)
        throws UnsatisfiedDependencyException;
  }
  
  
  
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/ArtifactProcessor.java
  
  Index: ArtifactProcessor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.maven.artifact;
  
  import org.apache.maven.project.Project;
  
  /**
   * Main starting point for all the 
   * artifact related operations.     
   *   
   * <p>
   * The processing order is following: 
   * <nl>
   *   <li>{@link ArtifactFactory</code> is used 
   *       for creating artifact list for <code>Project</code>
   *   <li>{@link ArtifactSatisfier} takes care of downloading missing artifacts</li>
   *   <li>{@link ArtifactVerification} verifies the artifacts</li>
   *   <li>When artifact has associated {@link ArtifactHandler} this handler is applied<li>
   * </nl>
   *
   * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: ArtifactProcessor.java,v 1.1 2003/05/02 09:05:16 michal Exp $
   */
  public interface ArtifactProcessor
  {
     /** Component role name */
     public static final String ROLE = ArtifactProcessor.class.getName();
  
     /**
      * Process all the project's artifacts 
      * 
      * @param project The project of which artifact list will proceessed     
      */
     public void processArtifacts(Project project) throws Exception;
  
  }
  
  
  
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/ArtifactDownloader.java
  
  Index: ArtifactDownloader.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.maven.artifact;
  
  import org.apache.maven.project.Project;
  
  /**
   * Class resposible to download {@link Artifact} from
   * remote repository (repositories) to local repository
   *
   * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: ArtifactDownloader.java,v 1.1 2003/05/02 09:05:16 michal Exp $
   */
  public interface ArtifactDownloader
  {
  
     /** Component role name*/
     public static final String ROLE = ArtifactDownloader.class.getName();
  
     /**
     	* Retrieve a <code>remoteFile</code> from the maven remote repositories
     	* and store it at <code>localFile</code>
     	* @param artifact the artifact to retrieve from the repositories.
     	* @return true if the retrieval succeeds, false otherwise.
     	*/
     public boolean getRemoteArtifact(Artifact artifact, Project project);
  
  }
  
  
  
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/DefaultArtifactProcessor.java
  
  Index: DefaultArtifactProcessor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  F* SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.maven.artifact;
  
  import java.io.File;
  import java.io.InputStream;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Properties;
  
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.maven.MavenConstants;
  import org.apache.maven.MavenException;
  import org.apache.maven.project.Project;
  
  /**
   * Default implementation of ArtifactProcessor
   * 
   * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: DefaultArtifactProcessor.java,v 1.1 2003/05/02 09:05:16 michal Exp $
   */
  public class DefaultArtifactProcessor
     implements Initializable, Serviceable, ArtifactProcessor
  {
  
     /**
      * Maps type to its handler Object
      */
     private Map cachedGlobalHandlers = new HashMap();
  
     /**
      * Configuraation file.
      * We will lazy load handlers. Once we need one
      * for given type we will instattiate it 
      * and put to cachedGlobalHandlers map
      */
     private Properties globalHandlers = null;
  
     /** */
     private ArtifactFactory artifactFactory = null;
  
     /** */
     private DependencySatisfier dependencySatisfier = null;
  
     /** */
     private ArtifactVerifier artifactVerifier = null;
  
     // ----------------------------------------------------------------------
     // Lifecycle Management
     // ----------------------------------------------------------------------
  
     /**
      * Reads artifact-handler.properties file
      * 
      * @throws Exception if any error occures
      */
     public void initialize() throws Exception
     {
        InputStream inputStream = null;
        File configFile = null;
        try
        {
           Class clazz = DefaultArtifactProcessor.class;
           inputStream =
              clazz.getResourceAsStream(
                 MavenConstants.ARTIFACT_HANDLER_PROPERTIES);
           globalHandlers = new Properties();
           globalHandlers.load(inputStream);
        }
        catch (Exception e)
        {
           String message = "Cannot read global layout.properties file";
           throw new MavenException(message, e);
        }
        finally
        {
           if (inputStream != null)
           {
              try
              {
                 inputStream.close();
              }
              catch (Exception e)
              {
              }
           }
        }
     }
  
     /**
      * @see org.apache.maven.artifact.ArtifactListProcessor#processArtifacts(org.apache.maven.project.Project)
      */
     public void processArtifacts(Project project) throws Exception
     {
  
        //1.
        artifactFactory.createArtifacts(project);
  
        //2. download all missing artifacts
        dependencySatisfier.satisfyDependencies(project);
  
        //3.  verify artifacts
        artifactVerifier.verify(project);
  
        //4.  applay artifact's handlers
        List artifacts = project.getArtifacts();
        for (Iterator iter = artifacts.iterator(); iter.hasNext();)
        {
           Artifact artifact = (Artifact) iter.next();
           String type = artifact.getType();
           ArtifactHandler artifactHandler = getHandler(type);
           if (artifactHandler != null)
           {
              artifactHandler.process(artifact, project);
           }
        }
     }
  
     /**
      * @param type
      * @return
      */
     private ArtifactHandler getHandler(String type) throws Exception
     {
        if (cachedGlobalHandlers.containsKey(type))
        {
           return (ArtifactHandler) cachedGlobalHandlers.get(type);
        }
        String handlerClassname = globalHandlers.getProperty(type);
        if (handlerClassname == null)
        {
           return null;
        }
        Class clazz = Class.forName(handlerClassname);
        ArtifactHandler artifactHandler = (ArtifactHandler) clazz.newInstance();
        cachedGlobalHandlers.put(type, artifactHandler);
        return artifactHandler;
     }
  
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
     public void service(ServiceManager serviceManager) throws ServiceException
     {
        artifactFactory =
           (ArtifactFactory) serviceManager.lookup(ArtifactFactory.ROLE);
        dependencySatisfier =
           (DependencySatisfier) serviceManager.lookup(DependencySatisfier.ROLE);
        artifactVerifier =
           (ArtifactVerifier) serviceManager.lookup(ArtifactVerifier.ROLE);
     }
  
  }
  
  
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/DefaultArtifactDownloader.java
  
  Index: DefaultArtifactDownloader.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.maven.artifact;
  
  import java.io.FileNotFoundException;
  import java.util.Iterator;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.commons.lang.StringUtils;
  import org.apache.maven.project.Project;
  import org.apache.maven.util.HttpUtils;
  import org.apache.plexus.logging.AbstractLogEnabled;
  
  /**
   * Class resposible to download {@link Artifact} from
   * remote repository (repositories) to local repository
   *
   * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: DefaultArtifactDownloader.java,v 1.1 2003/05/02 09:05:16 michal Exp $
   */
  public class DefaultArtifactDownloader
     extends AbstractLogEnabled
     implements Configurable, ArtifactDownloader
  {
     /** Control the use of timestamp comparison when downloading missing resources. */
     private boolean useTimestamp = true;
  
     /** Control continuation upon errors during the downloading of missing resources. */
     private boolean ignoreErrors;
  
  
  
     //	----------------------------------------------------------------------
     // Lifecylce Management
     // ----------------------------------------------------------------------
  
     public void configure(Configuration configuration)
        throws ConfigurationException
     {
        ignoreErrors =
           configuration.getChild("ignoreErrors").getValueAsBoolean(true);      
     }
  
     /**
      * @see org.apache.maven.artifact.ArtifactDownloader#getRemoteArtifact(org.apache.maven.artifact.Artifact, org.apache.maven.project.Project)
      */
     public boolean getRemoteArtifact(Artifact artifact, Project project)
     {
        boolean artifactFound = false;
  
        for (Iterator i = project.getMavenRepoRemote().iterator(); i.hasNext();)
        {
           String remoteRepo = (String) i.next();
  
           // The username and password parameters are not being
           // used here. Those are the "" parameters you see below.
           String url = remoteRepo + "/" + artifact.getUrlPath();
           url = StringUtils.replace(url, "//", "/");
           url = StringUtils.replace(url, "http:/", "http://");
  
           // Attempt to retrieve the artifact and set the checksum if retrieval
           // of the checksum file was successful.
           try
           {
              HttpUtils.getFile(
                 url,
                 artifact.getFile(),
                 ignoreErrors,
                 useTimestamp,
                 project.getProxyHost(),
                 project.getProxyPort(),
                 project.getProxyUserName(),
                 project.getProxyPassword(),
                 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;
           }
           catch (FileNotFoundException e)
           {
              // Multiple repositories may exist, and if the file is not found
              // in just one of them, it's no problem.
              // if it's not found at all, artifactFound will be false.
           }
           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
              System.out.println(
                 "Error retrieving artifact from [" + url + "]: " + e);
           }
        }
  
        return artifactFound;
     }
  
  }
  
  
  
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/DefaultDependencySatisfier.java
  
  Index: DefaultDependencySatisfier.java
  ===================================================================
  package org.apache.maven.artifact;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.maven.project.Project;
  import org.apache.maven.util.I18NUtils;
  import org.apache.maven.verifier.UnsatisfiedDependencyException;
  import org.apache.plexus.logging.AbstractLogEnabled;
  
  /**
   * Make sure that everything that is required for the project to build
   * successfully is present. We will start by looking at the dependencies
   * and make sure they are all here before trying to compile.
   *
   * @author <a href="jason@zenplex.com">Jason van Zyl</a>
   * @author <a href="vmassol@apache.org">Vincent Massol</a>
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
   *
   * @version $Id: DefaultDependencySatisfier.java,v 1.1 2003/05/02 09:05:16 michal Exp $
   *
   */
  public class DefaultDependencySatisfier
     extends AbstractLogEnabled
     implements Serviceable, DependencySatisfier
  {
     /** Control the use of timestamp comparison when downloading missing resources. */
     private boolean useTimestamp = true;
  
    
     /** ArtifactDownloader whicj will download artifacts */
     private ArtifactDownloader artifactDownloader;
  
     // ----------------------------------------------------------------------
     // Lifecyclce Management
     // ----------------------------------------------------------------------  
  
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
     public void service(ServiceManager serviceManager) throws ServiceException
     {
        artifactDownloader =
           (ArtifactDownloader) serviceManager.lookup(ArtifactDownloader.ROLE);
     }
  
     /**
      * Check to see that all dependencies are present and if they are
      * not then download them.
      *
      * @throws UnsatisfiedDependencyException If there are unsatisfied dependencies.
      */
     public void satisfyDependencies(Project project)
        throws UnsatisfiedDependencyException
     {
  
        List failedDependencies = new ArrayList();
  
        // Is the remote repository enabled?
        boolean remoteRepoEnabled =
           project.getRemoteRepositoryEnabled().booleanValue();
  
        // Is the user online?
        boolean online = project.getOnline().booleanValue();
  
        if (remoteRepoEnabled == false)
        {
           System.out.println(
              I18NUtils.getMessage("remote.repository.disabled.warning"));
        }
  
        for (Iterator i = project.getArtifacts().iterator(); i.hasNext();)
        {
           Artifact artifact = (Artifact) i.next();
  
           // The artifact plain doesn't exist so chalk it up as a failed dependency.
           if (artifact.exists() == false)
           {
              failedDependencies.add(artifact);
           }
           else
           {
              // The artifact exists but we need to take into account the user
              // being online and whether the artifact is a snapshot. If the user
              // is online then snapshots are added to the list of failed dependencies
              // so that a newer version can be retrieved if one exists. We make
              // an exception when the user is working offline and let them
              // take their chances with a strong warning that they could possibly
              // be using an out-of-date artifact. We don't want to cripple users
              // when working offline.
              if (online && artifact.isSnapshot())
              {
                 failedDependencies.add(artifact);
              }
              else
                 if (online == false && artifact.isSnapshot())
                 {
                    System.out.println(
                       I18NUtils.getMessage(
                          "offline.snapshot.warning",
                          artifact.getId()));
                 }
           }
        }
  
        // If we have any failed dependencies then we will attempt to download
        // them for the user if the remote repository is enabled.
        if (failedDependencies.isEmpty() == false && remoteRepoEnabled && online)
        {
           getDependencies(failedDependencies, project);
        }
  
        // If we still have failed dependencies after we have tried to
        // satisfy all dependencies then we have a problem. There might
        // also be a problem if the use of the remote repository has
        // been disabled and dependencies just aren't present. In any
        // case we have a problem.
        if (failedDependencies.isEmpty() == false)
        {
           throw new UnsatisfiedDependencyException(
              createUnsatisfiedDependenciesMessage(failedDependencies));
        }
     }
  
     /**
      * Create a message for the user stating the dependencies that are unsatisfied.
      *
      * @return The unsatisfied dependency message.
      */
     private String createUnsatisfiedDependenciesMessage(List failedDependencies)
     {
        StringBuffer message = new StringBuffer();
  
        if (failedDependencies.size() == 1)
        {
           message.append(
              I18NUtils.getMessage("single.unsatisfied.dependency.error"));
        }
        else
        {
           message.append(
              I18NUtils.getMessage("multiple.unsatisfied.dependency.error"));
        }
  
        message.append("\n\n");
  
        for (Iterator i = failedDependencies.iterator(); i.hasNext();)
        {
           Artifact artifact = (Artifact) i.next();
           message.append(artifact.getId()).append("\n");
        }
        return message.toString();
     }
  
  
     /**
      *  Try and retrieve the dependencies from the remote repository in
      *  order to satisfy the dependencies of the project.
      */
     private void getDependencies(List failedDependencies, Project project)
     {
        for (Iterator i = failedDependencies.iterator(); i.hasNext();)
        {
           Artifact artifact = (Artifact) i.next();
  
           // 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 = artifact.getFile().getParentFile();
  
           if (directory.exists() == false)
           {
              directory.mkdirs();
           }
  
           System.out.println(
              I18NUtils.getMessage("download.message", artifact.getId()));
  
           if (artifactDownloader.getRemoteArtifact(artifact, project))
           {
              // The dependency has been successfully downloaded so lets remove
              // it from the failed dependency list.
              i.remove();
           }
           else
           {
              String warning =
                 I18NUtils.getMessage(
                    "failed.download.warning",
                    artifact.getId());
              System.err.println(warning);
           }
        }
     }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org