jvanzyl     02/04/18 08:21:26

  Added:       src/java/org/apache/maven ProjectVerify.java
  Log:
  While working on the reactor I noticed that some jars were missing and
  it completely wrecks the process so this is the start of a safeguard
  mechansim to make sure the project is intact before attempting to do
  anything with it.
  
  First is a simple extension of the update-jars mechanism to compare
  what is available against what is required and retrieve the difference
  automatically.
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/ProjectVerify.java
  
  Index: ProjectVerify.java
  ===================================================================
  package org.apache.maven;
  
  /* ====================================================================
   * 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 Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", 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.net.URL;
  
  import java.util.Iterator;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.maven.executor.ProjectExecutor;
  import org.apache.maven.project.Dependency;
  import org.apache.maven.util.HttpUtils;
  
  /**
   * 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="[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: ProjectVerify.java,v 1.1 2002/04/18 15:21:26 jvanzyl Exp $
   */
  public class ProjectVerify
      extends ProjectExecutor
  {
      /**
       * Local repository property.
       */
      private String libRepo;
  
      /**
       * Base url where all resources live on the web.
       */
      private String baseUrl;
  
      /**
       * List of failed deps.
       */
      private List failedDependencies;
  
      /**
       * Default ctor.
       */
      public ProjectVerify()
      {
          failedDependencies = new ArrayList();
      }        
  
      /**
       * Sets the baseUrl attribute of the Get object
       */
      public void setBaseUrl(String baseUrl)
      {
          this.baseUrl = baseUrl;
      }
  
      /**
       * Execute the task.
       *
       * @throws BuildException
       */
      public void doExecute()
          throws Exception
      {
          // Grab the libRepo property.
          libRepo = getProject().getProperty("lib.repo");
          
          verifyDependencies();
      }
      
      public void verifyDependencies()
          throws Exception
      {        
          for (Iterator i = mavenProject.getDependencies().iterator(); i.hasNext();)
          {
              Dependency dependency = (Dependency)i.next();
              String jar = (String) dependency.getJar();
          
              File jarFile = new File(libRepo, jar);
              if (jarFile.exists() == false)
              {
                  // We are missing a dependency. Either the user didn't
                  // run update-jars or something else has gone wrong. So
                  // We'll add the jar to our list of failed dependencies
                  // and get them when we're done checking all the JARs.
                  failedDependencies.add(jar);
              }
          }
  
          // If we have any failed dependencies then we will download
          // them for the user.
          if (failedDependencies.size() > 0)
          {
              for (Iterator i = failedDependencies.iterator(); i.hasNext();)
              {
                  String dependency = (String) i.next();
                  log("Retrieving missing dependency: " + dependency);
                  URL url = new URL(baseUrl + dependency);
                  File destinationFile = new File(libRepo,dependency);
                  HttpUtils.getFile(url, destinationFile, dependency, false, true, 
true,"","");
              }
          }
      }
  }
  
  
  


Reply via email to