stevel      2004/11/18 08:25:05

  Modified:    src/main/org/apache/tools/ant/taskdefs defaults.properties
               src/main/org/apache/tools/ant/taskdefs/repository
                        AbsentFilesPolicy.java AssertDownloaded.java
                        BaseLibraryPolicy.java ForceUpdatePolicy.java
                        LibraryPolicy.java NoUpdatePolicy.java
                        ScheduledUpdatePolicy.java TimestampPolicy.java
               src/main/org/apache/tools/ant/types defaults.properties
  Added:       src/main/org/apache/tools/ant/taskdefs/repository
                        HttpRepository.java Libraries.java Library.java
                        MavenRepository.java Repository.java
                        RepositoryRef.java
               src/etc/testcases/taskdefs libraries.xml
               src/testcases/org/apache/tools/ant/taskdefs
                        LibrariesTest.java
  Removed:     src/main/org/apache/tools/ant/taskdefs/optional/repository
                        GetLibraries.java HttpRepository.java Library.java
                        MavenRepository.java Repository.java
                        RepositoryRef.java
               src/etc/testcases/taskdefs/optional getlibraries.xml
               src/testcases/org/apache/tools/ant/taskdefs/optional/repository
                        GetLibrariesTest.java
  Log:
  1. Move from optional.repository to tasks.repository
  2. rename <libraries>
  
  Revision  Changes    Path
  1.160     +1 -1      
ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.159
  retrieving revision 1.160
  diff -u -r1.159 -r1.160
  --- defaults.properties       25 Oct 2004 23:13:38 -0000      1.159
  +++ defaults.properties       18 Nov 2004 16:25:03 -0000      1.160
  @@ -80,6 +80,7 @@
   presetdef=org.apache.tools.ant.taskdefs.PreSetDef
   macrodef=org.apache.tools.ant.taskdefs.MacroDef
   nice=org.apache.tools.ant.taskdefs.Nice
  +libraries=org.apache.tools.ant.taskdefs.repository.Libraries
   
   # optional tasks
   image=org.apache.tools.ant.taskdefs.optional.image.Image
  @@ -203,7 +204,6 @@
   scriptdef=org.apache.tools.ant.taskdefs.optional.script.ScriptDef
   ildasm=org.apache.tools.ant.taskdefs.optional.dotnet.Ildasm
   apt=org.apache.tools.ant.taskdefs.Apt
  -getlibraries=org.apache.tools.ant.taskdefs.optional.repository.GetLibraries
   
   # deprecated ant tasks (kept for back compatibility)
   starteam=org.apache.tools.ant.taskdefs.optional.scm.AntStarTeamCheckOut
  
  
  
  1.2       +1 -3      
ant/src/main/org/apache/tools/ant/taskdefs/repository/AbsentFilesPolicy.java
  
  Index: AbsentFilesPolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/AbsentFilesPolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbsentFilesPolicy.java    18 Nov 2004 16:00:18 -0000      1.1
  +++ AbsentFilesPolicy.java    18 Nov 2004 16:25:03 -0000      1.2
  @@ -16,8 +16,6 @@
    */
   package org.apache.tools.ant.taskdefs.repository;
   
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -
   import java.util.ListIterator;
   
   /**
  @@ -36,7 +34,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
           owner.markMissingLibrariesForFetch();
           return true;
       }
  
  
  
  1.2       +2 -3      
ant/src/main/org/apache/tools/ant/taskdefs/repository/AssertDownloaded.java
  
  Index: AssertDownloaded.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/AssertDownloaded.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AssertDownloaded.java     18 Nov 2004 16:00:18 -0000      1.1
  +++ AssertDownloaded.java     18 Nov 2004 16:25:03 -0000      1.2
  @@ -17,7 +17,6 @@
   package org.apache.tools.ant.taskdefs.repository;
   
   import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
   
   import java.util.ListIterator;
   
  @@ -54,7 +53,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
           if(count==null) {
               throw new BuildException(ERROR_NO_COUNT);
           }
  @@ -70,7 +69,7 @@
        * @throws org.apache.tools.ant.BuildException
        *
        */
  -    public void afterFetched(GetLibraries owner, ListIterator libraries) {
  +    public void afterFetched(Libraries owner, ListIterator libraries) {
           int fetched=owner.calculateDownloadedCount();
           if(fetched!=count.intValue()) {
               throw new BuildException(ERROR_DOWNLOAD_FAILURE
  
  
  
  1.2       +2 -4      
ant/src/main/org/apache/tools/ant/taskdefs/repository/BaseLibraryPolicy.java
  
  Index: BaseLibraryPolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/BaseLibraryPolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseLibraryPolicy.java    18 Nov 2004 16:00:18 -0000      1.1
  +++ BaseLibraryPolicy.java    18 Nov 2004 16:25:03 -0000      1.2
  @@ -16,8 +16,6 @@
    */
   package org.apache.tools.ant.taskdefs.repository;
   
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -
   import java.util.ListIterator;
   
   /**
  @@ -57,7 +55,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
           return true;
       }
   
  @@ -70,7 +68,7 @@
        * @throws org.apache.tools.ant.BuildException
        *
        */
  -    public void afterFetched(GetLibraries owner, ListIterator libraries) {
  +    public void afterFetched(Libraries owner, ListIterator libraries) {
   
       }
   }
  
  
  
  1.2       +2 -4      
ant/src/main/org/apache/tools/ant/taskdefs/repository/ForceUpdatePolicy.java
  
  Index: ForceUpdatePolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/ForceUpdatePolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ForceUpdatePolicy.java    18 Nov 2004 16:00:18 -0000      1.1
  +++ ForceUpdatePolicy.java    18 Nov 2004 16:25:03 -0000      1.2
  @@ -17,8 +17,6 @@
   package org.apache.tools.ant.taskdefs.repository;
   
   import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -import org.apache.tools.ant.taskdefs.optional.repository.Library;
   
   import java.util.Iterator;
   import java.util.ListIterator;
  @@ -47,7 +45,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
           owner.markAllLibrariesForFetch(true);
           owner._setUseTimestamp(false);
           return true;
  @@ -62,7 +60,7 @@
        * @throws org.apache.tools.ant.BuildException
        *
        */
  -    public void afterFetched(GetLibraries owner, ListIterator libraries) {
  +    public void afterFetched(Libraries owner, ListIterator libraries) {
           //here verify that everything came in
           Iterator downloaded = owner.enabledLibrariesIterator();
           while (downloaded.hasNext()) {
  
  
  
  1.2       +4 -6      
ant/src/main/org/apache/tools/ant/taskdefs/repository/LibraryPolicy.java
  
  Index: LibraryPolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/LibraryPolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LibraryPolicy.java        18 Nov 2004 16:00:18 -0000      1.1
  +++ LibraryPolicy.java        18 Nov 2004 16:25:03 -0000      1.2
  @@ -17,8 +17,6 @@
   
   package org.apache.tools.ant.taskdefs.repository;
   
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -
   import java.util.ListIterator;
   
   /**
  @@ -29,14 +27,14 @@
    * Here is the use
    * <ol>
    * <li>Policies are executed in order of declaration.
  - * <li>The [EMAIL PROTECTED] 
#beforeConnect(org.apache.tools.ant.taskdefs.optional.repository.GetLibraries, 
java.util.ListIterator)} call,
  + * <li>The [EMAIL PROTECTED] 
#beforeConnect(org.apache.tools.ant.taskdefs.repository.Libraries, 
java.util.ListIterator)} call,
    * is called before any connection has been initiated; policies can 
manipulate
    * the library list, set/reset their toFetch list, rename destination files, 
etc.
    * <li>If any policy returns false from the method, the connection does not 
proceed.
    * This is not an error, provided the files are actually present.
    * <li>After running through the fetch of all files marked for download,
    * every policy implementation will again be called in order of declaration.
  - * <li>The [EMAIL PROTECTED] 
#afterFetched(org.apache.tools.ant.taskdefs.optional.repository.GetLibraries, 
java.util.ListIterator)} method
  + * <li>The [EMAIL PROTECTED] 
#afterFetched(org.apache.tools.ant.taskdefs.repository.Libraries, 
java.util.ListIterator)} method
    * does not return anything.
    * <li>Either method can throw a BuildException to indicate some kind of 
error.
    * </ol>
  @@ -57,7 +55,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries);
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries);
   
       /**
        * method called after a successful connection process.
  @@ -65,7 +63,7 @@
        * @param libraries
        * @throws org.apache.tools.ant.BuildException
        */
  -    public void afterFetched(GetLibraries owner,ListIterator libraries);
  +    public void afterFetched(Libraries owner,ListIterator libraries);
   
   
   }
  
  
  
  1.2       +1 -3      
ant/src/main/org/apache/tools/ant/taskdefs/repository/NoUpdatePolicy.java
  
  Index: NoUpdatePolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/NoUpdatePolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NoUpdatePolicy.java       18 Nov 2004 16:00:18 -0000      1.1
  +++ NoUpdatePolicy.java       18 Nov 2004 16:25:03 -0000      1.2
  @@ -16,8 +16,6 @@
    */
   package org.apache.tools.ant.taskdefs.repository;
   
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -
   import java.util.ListIterator;
   
   /**
  @@ -36,7 +34,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
               // mark all files as no Fetch
           owner.markAllLibrariesForFetch(false);
           return true;
  
  
  
  1.2       +2 -5      
ant/src/main/org/apache/tools/ant/taskdefs/repository/ScheduledUpdatePolicy.java
  
  Index: ScheduledUpdatePolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/ScheduledUpdatePolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScheduledUpdatePolicy.java        18 Nov 2004 16:00:18 -0000      1.1
  +++ ScheduledUpdatePolicy.java        18 Nov 2004 16:25:03 -0000      1.2
  @@ -18,9 +18,6 @@
   
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -import org.apache.tools.ant.taskdefs.optional.repository.Library;
  -import org.apache.tools.ant.taskdefs.optional.repository.Repository;
   import org.apache.tools.ant.util.FileUtils;
   
   import java.io.BufferedInputStream;
  @@ -118,7 +115,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
   
           Repository repository=owner.getRepository();
           if(markerFile==null) {
  @@ -161,7 +158,7 @@
        * @param owner
        * @param libraries
        */
  -    public void afterFetched(GetLibraries owner, ListIterator libraries) {
  +    public void afterFetched(Libraries owner, ListIterator libraries) {
   
           if(markerFileToSave!=null) {
               //if we get here, we need to save the file
  
  
  
  1.2       +1 -3      
ant/src/main/org/apache/tools/ant/taskdefs/repository/TimestampPolicy.java
  
  Index: TimestampPolicy.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/TimestampPolicy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TimestampPolicy.java      18 Nov 2004 16:00:18 -0000      1.1
  +++ TimestampPolicy.java      18 Nov 2004 16:25:03 -0000      1.2
  @@ -16,8 +16,6 @@
    */
   package org.apache.tools.ant.taskdefs.repository;
   
  -import org.apache.tools.ant.taskdefs.optional.repository.GetLibraries;
  -
   import java.util.ListIterator;
   
   /**
  @@ -38,7 +36,7 @@
        * @throws org.apache.tools.ant.BuildException
        *          if needed
        */
  -    public boolean beforeConnect(GetLibraries owner, ListIterator libraries) 
{
  +    public boolean beforeConnect(Libraries owner, ListIterator libraries) {
           owner.markAllLibrariesForFetch(true);
           owner._setUseTimestamp(true);
           return true;
  
  
  
  1.1                  
ant/src/main/org/apache/tools/ant/taskdefs/repository/HttpRepository.java
  
  Index: HttpRepository.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant.taskdefs.repository;
  
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.taskdefs.Get;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  /**
   * This is a base class for repositories that are built on URLs. Although you
   * can share this datatype, it is *not* thread safe; you can only use it in 
one
   * thread at at time
   *
   * @since Ant1.7
   */
  public abstract class HttpRepository extends Repository {
      /**
       * repositoryURL of repository
       */
      private String url;
  
      /**
       * username
       */
      private String username;
  
      /**
       * password
       */
      private String password;
  
      /**
       * auth realm; can be null
       */
  //    private String realm;
  
      /**
       * no repository URL
       */
      public static final String ERROR_NO_REPOSITORY_URL = "No repository URL";
  
      /**
       * owner class
       */
      private Libraries owner;
  
      /**
       * retry logic
       */
      public static final String ERROR_REENTRANT_USE = "Repository is already 
in use";
  
      /**
       * get the base URL of the repository
       *
       * @return
       */
      public String getUrl() {
          return url;
      }
  
      /**
       * Set the base URL of the repository
       *
       * @param url
       */
      public void setUrl(String url) {
          this.url = url;
      }
  
      public String getUsername() {
          return username;
      }
  
      /**
       * set the username for the remote repository
       *
       * @param username
       */
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      /**
       * set the password for the remote repository
       *
       * @param password
       */
      public void setPassword(String password) {
          this.password = password;
      }
  /*
  
      public String getRealm() {
          return realm;
      }
  */
  
      /**
       * set the realm for authentication; empty string is equivalent to "any
       * realm" (the default)
       *
       * @param realm
       */
  /*    public void setRealm(String realm) {
          if (realm != null) {
              this.realm = realm;
          } else {
              this.realm = null;
          }
      }*/
  
      public Libraries getOwner() {
          return owner;
      }
  
      /**
       * validate yourself
       *
       * @throws org.apache.tools.ant.BuildException
       *          if unhappy
       */
      public void validate() {
          super.validate();
          checkChildrenAllowed();
          checkAttributesAllowed();
          if (url == null || url.length() == 0) {
              throw new BuildException(ERROR_NO_REPOSITORY_URL);
          }
      }
  
      /**
       * override point: connection is called at the start of the retrieval
       * process
       *
       * @param newOwner
       *
       * @throws org.apache.tools.ant.BuildException
       *
       */
      public void connect(Libraries newOwner) {
          this.owner = newOwner;
          if (!url.endsWith("/")) {
              url = url + '/';
          }
  
          try {
              //validate the URL
              URL repository;
              repository = new URL(url);
          } catch (MalformedURLException e) {
              throw new BuildException(e);
          }
      }
  
      /**
       * override point: connection is called at the start of the retrieval
       * process
       *
       * @throws org.apache.tools.ant.BuildException
       *
       */
  
      public void disconnect() {
      }
  
      /**
       * Test for a repository being reachable. This method is called after 
[EMAIL PROTECTED]
       * #connect(org.apache.tools.ant.taskdefs.repository.GetLibraries)}
       * is called, before any files are to be retrieved.
       * <p/>
       * If it returns false the repository considers itself offline. Similarly,
       * any ioexception is interpreted as being offline.
       * <p/>
       * The Http implementation does nothing
       * @return true if the repository is online.
       *
       * @throws java.io.IOException
       */
      public boolean checkRepositoryReachable() throws IOException {
          return true;
      }
  
  
  
      /**
       * fetch a library from the repository
       *
       * @param library
       *
       * @param useTimestamp
       * @return true if we retrieved
       *
       * @throws org.apache.tools.ant.BuildException
       *
       */
      public boolean fetch(Library library, boolean useTimestamp) throws 
IOException {
  
          String path = getRemoteLibraryURL(library);
          logVerbose("Library URL=" + path);
          URL remoteURL=new URL(path);
          logVerbose("destination =" + library.getAbsolutePath());
          long start, finish;
          start = System.currentTimeMillis();
          boolean success=get(remoteURL, library.getLibraryFile(),useTimestamp,
                  username, password);
          finish = System.currentTimeMillis();
          long diff = finish - start;
          logVerbose("downloaded in " + diff / 1000 + " seconds");
  
          return success;
      }
  
      /**
       * get the
       * @param url
       * @param destFile
       * @param useTimestamp
       * @return
       */
      public boolean get(URL url,File destFile,boolean useTimestamp,String 
user,String passwd)
              throws IOException {
          //create the destination dir
          destFile.getParentFile().mkdirs();
          Get getTask = new Get();
          getTask.setProject(getProject());
          getTask.setTaskName(owner.getTaskName());
          getTask.setDest(destFile);
          getTask.setUsername(user);
          getTask.setPassword(passwd);
          getTask.setUseTimestamp(useTimestamp);
          getTask.setSrc(url);
          getTask.setIgnoreErrors(true);
          return getTask.doGet(Project.MSG_VERBOSE,null);
      }
  
      /**
       * log something at the verbose level
       *
       * @param message text to log
       */
      protected void logVerbose(String message) {
          getOwner().log(message,
                  Project.MSG_VERBOSE);
      }
  
      /**
       * log at debug level
       * @param message
       */
      protected void logDebug(String message) {
          getOwner().log(message,
                  Project.MSG_DEBUG);
      }
  
      /**
       * Get the path to a remote library. This is the full URL
       *
       * @param library
       *
       * @return URL to library
       */
      protected abstract String getRemoteLibraryURL(Library library);
  
      /**
       * Returns a string representation of the repository
       * Used for scheduled updates.
       * @return the base URL
       */
      public String toString() {
          return "Repository at " + getUrl();
      }
  
      /**
       * this is a string that uniquely describes the repository and can be used
       * for equality tests <i>across</i> instances.
       *
       * @return
       */
      public String getRepositoryURI() {
          return "HttpRepository://"+getUrl();
      }
  }
  
  
  
  1.1                  
ant/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java
  
  Index: Libraries.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant.taskdefs.repository;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.Path;
  import org.apache.tools.ant.types.Reference;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ListIterator;
  
  /**
   * This task will retrieve one or more libraries from a repository.
   * <ol>
   * <li>Users must declare a repository, either inline or by reference</li>
   * <li>Dependency checking is used (timestamps) unless forceDownload=true</li>
   * <li>It is an error if, at the end of the task, a library is missing.
   * </ol>
   *
   * @ant.task
   * @since Ant 1.7
   */
  public final class Libraries extends Task {
  
      /**
       * destination
       */
      private File destDir;
  
      /**
       * flag to force offline
       */
      private boolean offline = false;
  
      /**
       * list of libraries
       */
      private EnabledLibraryElementList libraries = new 
EnabledLibraryElementList();
  
      /**
       * helper list
       */
      private EnabledLibraryElementList policies=new 
EnabledLibraryElementList();
  
      /**
       * repository for retrieval
       */
  
      private Repository repository;
  
      /**
       * Optional. A name for a path to define from the dependencies specified.
       */
      private String pathid;
  
      /**
       * should we be timestamp aware in downloads?
       */
      private boolean useTimestamp = false;
  
      public static final String ERROR_ONE_REPOSITORY_ONLY = "Only one 
repository is allowed";
      public static final String ERROR_NO_DEST_DIR = "No destination directory";
      public static final String ERROR_NO_REPOSITORY = "No repository defined";
      public static final String ERROR_NO_LIBRARIES = "No libraries declared";
      public static final String ERROR_REPO_PROBE_FAILED = "Repository probe 
failed with ";
      public static final String ERROR_LIBRARY_FETCH_FAILED = "Failed to 
retrieve ";
      public static final String ERROR_INCOMPLETE_RETRIEVAL = "Missing 
Libraries :";
      public static final String MSG_NO_RETRIEVE = "Connections disabled";
      public static final String MSG_NO_LIBRARIES_TO_FETCH = "No libraries 
marked for retrieval";
  
  
      /**
       * Init the task
       *
       * @throws org.apache.tools.ant.BuildException
       *          if something goes wrong with the build
       */
      public void init() throws BuildException {
          super.init();
          //set our default polocy
          add(new AbsentFilesPolicy());
      }
  
      /**
       * add a repository. Only one is (currently) supported
       *
       * @param repo
       */
      public void add(Repository repo) {
          if (repository != null) {
              throw new BuildException(ERROR_ONE_REPOSITORY_ONLY);
          }
          repository = repo;
      }
  
  
      /**
       * add a repository. Unless there is explicit support for a subclass
       *
       * @param repo
       */
      public void addRepository(RepositoryRef repo) {
          add(repo);
      }
  
      /**
       * bind to a repository.
       */
      public void setRepositoryRef(final Reference ref) {
          //create a special repository that can only
          //resolve references.
          Repository r = new RepositoryRef(getProject(), ref);
          add(r);
      }
  
      /**
       * add anything that implements the library policy interface
       * @param policy
       */
      public void add(LibraryPolicy policy) {
          policies.add(policy);
      }
  
      /**
       * add a schedule
       * @param update
       */
      public void addSchedule(ScheduledUpdatePolicy update) {
          add(update);
      }
  
      /**
       * Declare that the update should be forced: everything
       * must be fetched; it will be a failure if any are not
       * @param policy
       */
      public void addForce(ForceUpdatePolicy policy) {
          add(policy);
      }
  
      /**
       * Declare that no files should be fetched
       * @param policy
       */
      public void addNoupdate(NoUpdatePolicy policy) {
          add(policy);
      }
  
      /**
       * declare that the update should be timestamp driven
       * @param policy
       */
      public void addTimestamp(TimestampPolicy policy) {
          add(policy);
      }
  
      /**
       * declare that only absent files are to be fetched
       * @param policy
       */
      public void addAbsentfiles(AbsentFilesPolicy policy) {
          add(policy);
      }
  
  
      /**
       * make a declaration about the number of files to fetch
       *
       * @param policy
       */
      public void addAssertDownloaded(AssertDownloaded policy) {
          add(policy);
      }
  
      /**
       * add a library for retrieval
       *
       * @param lib
       */
      public void addLibrary(Library lib) {
          libraries.add(lib);
      }
  
      /**
       * destination directory for all library files
       *
       * @param destDir
       */
      public void setDestDir(File destDir) {
          this.destDir = destDir;
      }
  
  
      /**
       * test for being offline
       *
       * @return true if the offline flag is set
       */
      public boolean isOffline() {
          return offline;
      }
  
      /**
       * declare the system offline. This disables any attempt to retrieve 
files.
       * In this mode, only the presence of files is verified. If forceDownload 
is
       * true, or there is a missing library, then an error will be raised.
       *
       * @param offline
       */
      public void setOffline(boolean offline) {
          this.offline = offline;
      }
  
  
      /**
       * get the destination directory
       * @return
       */
      public File getDestDir() {
          return destDir;
      }
  
  
      /**
       * get the list of libraries
       * @return
       */
      public List getLibraries() {
          return libraries;
      }
  
      /**
       * get our repository
       * @return
       */
      public Repository getRepository() {
          return repository;
      }
  
      /**
       * get the pathID if defined
       * @return
       */
      public String getPathid() {
          return pathid;
      }
  
      /**
       * the name of a path reference to be created referring
       * to the libraries.
       * @param pathid
       */
      public void setPathid(String pathid) {
          this.pathid = pathid;
      }
  
      /**
       * get the current timestamp flag
       * @return
       */
      public boolean isUseTimestamp() {
          return useTimestamp;
      }
  
      /**
       * set the timestamp flag. Not for export into XML
       * @param useTimestamp
       */
      public void _setUseTimestamp(boolean useTimestamp) {
          this.useTimestamp = useTimestamp;
      }
  
      /**
       * get the current policy list
       * @return
       */
      public List getPolicies() {
          return policies;
      }
  
      /**
       * validate ourselves
       *
       * @throws BuildException
       */
      public void validate() {
          if (destDir == null
          //        || !destDir.isDirectory()
          ) {
              throw new BuildException(ERROR_NO_DEST_DIR);
          }
          if (repository == null) {
              throw new BuildException(ERROR_NO_REPOSITORY);
          }
          Iterator it = libraries.iterator();
          while (it.hasNext()) {
              Library library = (Library) it.next();
              library.validate();
          }
      }
      /**
       * Called by the project to let the task do its work.
       *
       * @throws org.apache.tools.ant.BuildException
       *          if something goes wrong with the build
       */
      public void execute() throws BuildException {
          validate();
          if (isOffline()) {
              log("No retrieval, task is \"offline\"");
          } else {
              doExecute();
          }
          //validate the state
          verifyAllLibrariesPresent();
  
          //create the path
          if (pathid != null) {
              createPath();
          }
      }
      /**
       * This is the real worker method
       *
       * @throws org.apache.tools.ant.BuildException
       *          if something goes wrong with the build
       */
      private void doExecute() throws BuildException {
          destDir.mkdirs();
          Repository repo = repository.resolve();
          repo.validate();
          if (libraries.size() == 0) {
              throw new BuildException(ERROR_NO_LIBRARIES);
          }
          log("Getting libraries from " + repo.toString(), Project.MSG_VERBOSE);
          log("Saving libraries to " + destDir.toString(), Project.MSG_VERBOSE);
  
          //map libraries to files
          bindAllLibraries();
  
  
          //flag to indicate whether the download should go ahead
          boolean retrieve = true;
          List processedPolicies = new ArrayList(policies.size());
          //iterate through all policies and execute their preload task
          Iterator policyIterator = policies.enabledIterator();
          while (retrieve && policyIterator.hasNext()) {
              LibraryPolicy libraryPolicy = (LibraryPolicy) 
policyIterator.next();
              retrieve=libraryPolicy.beforeConnect(this, libraryIterator());
              if(retrieve) {
                  //add all processed properties to the list, 'cept for 
anything that
                  //broke the chain
                  processedPolicies.add(libraryPolicy);
              } else {
                  log("Policy "+libraryPolicy.getClass().getName()
                          + " disabled retrieval",
                          Project.MSG_VERBOSE);
              }
          }
  
          //see if we need to do a download
          if(!retrieve) {
              //if not, log it
              log(MSG_NO_RETRIEVE);
          } else {
              int downloads = calculateFetchCount();
              if(downloads>0) {
                  //get the files
                  connectAndRetrieve(repo, useTimestamp);
              } else {
                  //nothing to fetch
                  log(MSG_NO_LIBRARIES_TO_FETCH,Project.MSG_VERBOSE);
              }
          }
  
          //now reverse iterate through all processed properties.
          for(int i=processedPolicies.size()-1;i>=0;i--) {
              LibraryPolicy libraryPolicy = 
(LibraryPolicy)processedPolicies.get(i);
              //and call their post-processor
              libraryPolicy.afterFetched(this,libraryIterator() );
          }
      }
  
      /**
       * connect to the remote system, retrieve files
       * @param repo
       * @param useTimestamp
       * @return number of failed retrievals.
       */
      private int connectAndRetrieve(Repository repo, boolean useTimestamp) {
          //connect the repository
          int failures = 0;
          repo.connect(this);
          try {
  
              //check for reachability.
              //it is up to each repository to decide that.
              boolean reachable;
              try {
                  log("Checking repository for reachability", 
Project.MSG_DEBUG);
                  reachable = repo.checkRepositoryReachable();
              } catch (IOException e) {
  
                  log(ERROR_REPO_PROBE_FAILED + e.getMessage(),
                          Project.MSG_VERBOSE);
                  reachable = false;
              }
              if(!reachable) {
                  log("repository is not reachable", Project.MSG_INFO);
                  return 0;
              }
  
              //iterate through the libs we have enabled
              Iterator it = enabledLibrariesIterator();
              while (it.hasNext()) {
                  Library library = (Library) it.next();
                  //check to see if it is for fetching
                  if(library.isToFetch()) {
                      log("Fetching "+library.getNormalFilename(), 
Project.MSG_VERBOSE);
                      try {
                          //fetch it
                          boolean fetched=repo.fetch(library, useTimestamp) ;
                          //record the fact in the library
                          log("success; marking as fetched",
                                  Project.MSG_DEBUG);
                          library._setFetched(fetched);
                      } catch (IOException e) {
                          log(ERROR_LIBRARY_FETCH_FAILED + library);
                          log(e.getMessage());
                          //add failures
                          failures++;
                      }
                  } else {
                      //no fetch
                      log("Skipping " + library.getNormalFilename(), 
Project.MSG_VERBOSE);
                  }
              }
          } finally {
  
              log("disconnecting",Project.MSG_VERBOSE);
              repo.disconnect();
          }
          return failures;
      }
  
      /**
       * bind all libraries to our destination
       */
      public  void bindAllLibraries() {
          Iterator it = libraries.iterator();
          while (it.hasNext()) {
              Library library = (Library) it.next();
              library.bind(destDir);
          }
      }
  
      /**
       * set/clear the fetch flag on all libraries.
       * @param fetch
       */
      public void markAllLibrariesForFetch(boolean fetch) {
          Iterator it = libraryIterator();
          while (it.hasNext()) {
              Library library = (Library) it.next();
              library._setToFetch(fetch);
          }
      }
  
      /**
       * set the fetch flag on all libraries that are absent; clear
       * it from all those that exist
       *
       */
      public void markMissingLibrariesForFetch() {
          Iterator it = libraryIterator();
          while (it.hasNext()) {
              Library library = (Library) it.next();
              library._setToFetch(!library.exists());
          }
      }
  
      /**
       * work out how many libraries to fetch
       * @return count of enabled libraries with the to fetch bit set
       */
      public  int calculateFetchCount() {
          int count=0;
          Iterator it = enabledLibrariesIterator();
          while (it.hasNext()) {
              Library library = (Library) it.next();
              if(library.isToFetch()) {
                  count++;
              };
          }
          return count;
      }
  
      /**
       * work out how many libraries were fetched
       * @return number of libraries that are enabled with the
       * [EMAIL PROTECTED] Library#wasFetched()} flag true.
       */
      public int calculateDownloadedCount() {
          int count = 0;
          //here verify that everything came in
          Iterator downloaded = enabledLibrariesIterator();
          while (downloaded.hasNext()) {
              Library library = (Library) downloaded.next();
              if (library.wasFetched()) {
                  count++;
              }
          }
          return count;
      }
  
  
      /**
       * verify that all libraries are present
       */
      protected void verifyAllLibrariesPresent() {
          //iterate through the libs we have
          boolean missing = false;
          StringBuffer buffer=new StringBuffer();
          Iterator it = enabledLibrariesIterator();
          while (it.hasNext()) {
              Library library = (Library) it.next();
              //check for the library existing
              if (!library.exists()) {
                  //and log if one is missing
                  buffer.append(library.toString()+"; ");
                  log("Missing: " + library.toString(),
                          Project.MSG_ERR);
                  missing = true;
              }
          }
          if (missing) {
              throw new BuildException(ERROR_INCOMPLETE_RETRIEVAL+buffer);
          }
      }
  
      /**
       * create a path; requires pathID!=null
       */
      private void createPath() {
          Path path = new Path(getProject());
          for (Iterator iterator = enabledLibrariesIterator();
               iterator.hasNext();) {
              ((Library) iterator.next()).appendToPath(path);
          }
          getProject().addReference(pathid, path);
      }
  
      /**
       * get a filtered iterator of the dependencies
       * @return a new iterator that ignores disabled libraries
       */
      public Iterator enabledLibrariesIterator() {
          return libraries.enabledIterator();
      }
  
      /**
       * get a list iterator for the files
       * This gives you more power
       * @return
       */
      public ListIterator libraryIterator() {
          return libraries.listIterator();
      }
  
  }
  
  
  
  1.1                  
ant/src/main/org/apache/tools/ant/taskdefs/repository/Library.java
  
  Index: Library.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant.taskdefs.repository;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.types.Path;
  import org.apache.tools.ant.util.FileUtils;
  
  import java.io.File;
  
  /**
   * How we represent libraries
   *
   * @since Ant1.7
   */
  public class Library implements EnabledLibraryElement {
  
      /**
       * enabled flag
       */
      private boolean enabled = true;
  
      /**
       * turn policy on/off
       *
       * @param enabled
       */
      public void setEnabled(boolean enabled) {
          this.enabled = enabled;
      }
  
      /**
       * are we enabled
       *
       * @return true if [EMAIL PROTECTED] #enabled} is set
       */
      public boolean getEnabled() {
          return enabled;
      }
  
      //project "ant"
      private String project;
  
      //version "1.5"
      private String version;
  
      //archive prefix "ant-optional"
      private String archive;
  
      /**
       * very optional attribute; name of the destination. Autocalculated if not
       * set.
       */
  
      private String destinationName;
  
      /**
       * file mapped to this one
       */
      private File libraryFile;
  
      /**
       * we fetch every library by default; note the enabled/disabled
       * flag has precedence, and this flag is not visible in the XML
       */
      private boolean toFetch=true;
  
      private boolean fetched=false;
  
      public static final String ERROR_NO_ARCHIVE = "No archive defined";
      public static final String ERROR_NO_PROJECT = "No project defined";
      public static final String ERROR_NO_VERSION = "No version defined";
      public static final String ERROR_NO_SUFFIX = "No version defined";
  
      /**
       * suffix
       */
      private String suffix = "jar";
      public static final String ERROR_FILE_IS_A_DIR = "Library file is a 
directory:";
  
  
      /**
       * the project that provides this library
       * @return the project or null
       */
      public String getProject() {
          return project;
      }
  
      /**
       * the project that provides this library
       * @param project
       */
      public void setProject(String project) {
          this.project = project;
      }
  
      /**
       * Get the version string of this library
       * @return
       */
      public String getVersion() {
          return version;
      }
  
      /**
       * set the version string of this library
       * @param version
       */
      public void setVersion(String version) {
          this.version = version;
      }
  
      /**
       * get the base name of this library
       * @return
       */
      public String getArchive() {
          return archive;
      }
  
      /**
       * set the base name of this library
       * @param archive
       */
      public void setArchive(String archive) {
          this.archive = archive;
      }
  
      /**
       * get the destination name attribute.
       * @return
       */
      public String getDestinationName() {
          return destinationName;
      }
  
      /**
       * set the name of the library when downloaded,
       * relative to the base directory
       * @param destinationName
       */
      public void setDestinationName(String destinationName) {
          this.destinationName = destinationName;
      }
  
      /**
        * get the suffix for this file.
       *
       * @return
       */
      public String getSuffix() {
          return suffix;
      }
  
      /**
       * set the suffix for this file; default is "jar"
       * @param suffix
       */
      public void setSuffix(String suffix) {
          this.suffix = suffix;
      }
  
      /**
       * get the library file
       * (only non-null after binding)
       * @return library file or null
       */
      public File getLibraryFile() {
          return libraryFile;
      }
  
      /**
       * set the library file.
       * @param libraryFile
       */
      public void setLibraryFile(File libraryFile) {
          this.libraryFile = libraryFile;
      }
  
      /**
       * fault if the field is null or empty
       *
       * @param field
       * @param message text for fault
       *
       * @throws BuildException if the field is not set up
       */
      private void faultIfEmpty(String field, String message) {
          if (field == null || field.length() == 0) {
              throw new BuildException(message);
          }
      }
  
      /**
       * validate;
       *
       * @throws BuildException if invalid
       */
      public void validate() {
          faultIfEmpty(archive, ERROR_NO_ARCHIVE);
          faultIfEmpty(project, ERROR_NO_PROJECT);
          faultIfEmpty(version, ERROR_NO_VERSION);
          faultIfEmpty(version, ERROR_NO_SUFFIX);
      }
  
      /**
       * string is for debug
       * @return
       */
      public String toString() {
          return "Library " + getNormalFilename()
                  + " from project " + project
                  + " to " + getDestinationName();
      }
  
      /**
       * calculate the destination file of a library; set [EMAIL PROTECTED] 
#libraryFile}
       * to the File thereof.
       *
       * @param baseDir dir that
       *
       * @throws BuildException if invalid
       */
      public void bind(File baseDir) {
          validate();
          FileUtils fileUtils=FileUtils.newFileUtils();
  
          if (destinationName == null) {
              destinationName = getMavenPath('/');
          }
          libraryFile = fileUtils.resolveFile(baseDir, destinationName);
          if(libraryFile.isDirectory()) {
              throw new BuildException(ERROR_FILE_IS_A_DIR
                  +libraryFile);
          }
      }
  
      /**
       * Test for a library
       * only valid after binding
       *
       * @return
       */
      public boolean exists() {
          return libraryFile.exists();
      }
  
      /**
       * get the last modified date
       * only valid after binding
       * @return
       */
      public long getLastModified() {
          return libraryFile.lastModified();
      }
  
      /**
       * get the filename from the rule of archive+version+'.'+suffix. Clearly
       * only valid if all fields are defined.
       *
       * @return a string representing the expected name of the file at the
       *         source
       */
      public String getNormalFilename() {
          return archive + "-" + version + "." + suffix;
      }
  
      /**
       * get the filename of the destination; no path.
       *
       * @return
       */
      public String getDestFilename() {
          if (destinationName == null) {
              return getNormalFilename();
          } else {
              return destinationName;
          }
      }
  
      /**
       * get a maven path (project/filename)
       *
       * @param separator directory separator
       *
       * @return
       */
      public String getMavenPath(char separator) {
          return project + separator + "jars" + separator + getNormalFilename();
      }
  
      /**
       * get the absolute path of this library
       *
       * @return
       */
      public String getAbsolutePath() {
          return libraryFile.getAbsolutePath();
      }
  
  
      /**
       * prefixed to avoid ant picking up on it, this sets
       * the fetch/no-fetch flag.
       * @param toFetch
       */
      public void _setToFetch(boolean toFetch) {
          this.toFetch = toFetch;
      }
  
      /**
       * get the fetch flag.
       * @return
       */
      public boolean isToFetch() {
          return toFetch;
      }
  
      /**
       * get a flag that marks if a file is fetched
       * @return
       */
      public boolean wasFetched() {
          return fetched;
      }
  
      /**
       * another not-for-end-users attribute; a flag set to true if the
       * library has been fetched.
       * @param fetched
       */
      public void _setFetched(boolean fetched) {
          this.fetched = fetched;
      }
  
      /**
       * add our location to a filepath
       * @param path
       */
      public void appendToPath(Path path) {
          Path.PathElement pathElement = path.createPathElement();
          pathElement.setLocation(getLibraryFile());
      }
  
      /**
       * equality test uses archive, destinationName, project, suffix and 
version
       * fields (any of which can be null)
       * @param o
       * @return
       */
      public boolean equals(Object o) {
          if (this == o) {
              return true;
          }
          if (!(o instanceof Library)) {
              return false;
          }
  
          final Library library = (Library) o;
  
          if (archive != null ? !archive.equals(library.archive) : 
library.archive != null) {
              return false;
          }
          if (destinationName != null ? !destinationName.equals(
                  library.destinationName) : library.destinationName != null) {
              return false;
          }
          if (project != null ? !project.equals(library.project) : 
library.project != null) {
              return false;
          }
          if (suffix != null ? !suffix.equals(library.suffix) : library.suffix 
!= null) {
              return false;
          }
          if (version != null ? !version.equals(library.version) : 
library.version != null) {
              return false;
          }
  
          return true;
      }
  
      /**
       * Hash code uses the name fields as [EMAIL PROTECTED] #equals(Object)}
       * This sequence
       * @return
       */
      public int hashCode() {
          int result;
          result = (project != null ? project.hashCode() : 0);
          result = 29 * result + (version != null ? version.hashCode() : 0);
          result = 29 * result + (archive != null ? archive.hashCode() : 0);
          result = 29 * result + (destinationName != null ? 
destinationName.hashCode() : 0);
          result = 29 * result + (suffix != null ? suffix.hashCode() : 0);
          return result;
      }
  
  }
  
  
  
  1.1                  
ant/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java
  
  Index: MavenRepository.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant.taskdefs.repository;
  
  import org.apache.tools.ant.util.FileUtils;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.Reader;
  import java.net.URL;
  
  
  /**
   * A Maven repository knows about maven repository layout rules It also 
defaults
   * to http://www.ibiblio.org/maven/
   *
   * @link 
http://maven.apache.org/reference/user-guide.html#Remote_Repository_Layout
   * @link
   * @since Ant1.7
   */
  public class MavenRepository extends HttpRepository {
      public static final String MAVEN_URL = "http://www.ibiblio.org/maven/";;
  
  
      /**
       * check the MD5 flag
       */
      public boolean checkMD5;
  
      /**
       * this is what we think the MD5 type is
       */
      protected static final String MAVEN_MD5_FILE_TYPE = "US-ASCII";
  
      /**
       * bind to the main maven repository
       */
      public MavenRepository() {
          setUrl(MAVEN_URL);
      }
  
      /**
       * set this to check the MD5 signatures. SECURITY IS NOT YET FUNCTIONAL
       * @param checkMD5
       */
      public void setCheckMD5(boolean checkMD5) {
          this.checkMD5 = checkMD5;
      }
  
      /**
       * Get the path to a remote library. This is the full URL
       *
       * @param library
       *
       * @return URL to library
       */
      protected String getRemoteLibraryURL(Library library) {
          String base = getUrl();
          if (!base.endsWith("/")) {
              base = base + '/';
          }
  
          return base + library.getMavenPath('/');
      }
  
      /**
       * Returns a string representation of the repository
       *
       * @return the base URL
       */
      public String toString() {
          return "Maven Repository at " + getUrl();
      }
  
      /**
       * this is a string that uniquely describes the repository and can be used
       * for equality tests <i>across</i> instances.
       *
       * @return maven identifier
       */
      public String getRepositoryURI() {
          return "maven://" + getUrl();
      }
  
      /**
       * fetch a library from the repository
       *
       * @param library
       *
       * @param useTimestamp
       * @return true if we retrieved
       *
       * @throws org.apache.tools.ant.BuildException
       *
       */
      public boolean fetch(Library library, boolean useTimestamp) throws 
IOException {
          boolean  fetched=super.fetch(library, useTimestamp);
          if(fetched && checkMD5) {
              //we got here if there was a fetch. so we now get the MD5 info 
from the file,
              boolean successful=false;
              String md5path = getRemoteLibraryURL(library) + ".md5";
              File md5file = File.createTempFile(library.getArchive(),".md5");
              Reader in = null;
              try {
                  URL md5url=new URL(md5path);
                  logVerbose("getting md5 file from " + md5path +" to 
"+md5file.getAbsolutePath());
                  get(md5url,md5file, false,getUsername(), getPassword());
                  in = new InputStreamReader(new 
FileInputStream(md5file),MAVEN_MD5_FILE_TYPE);
                  char md5data[] =new char[32];
                  in.read(md5data);
                  logDebug("md5 data "+md5data);
                  //TODO: verify this against a <checksum> generated signature.
  
                  successful=true;
              } catch (IOException e) {
                  logVerbose("IO failure on MD5 fetch "+e.getMessage());
                  throw e;
              } finally {
                  FileUtils.close(in);
                  if(md5file.exists()) {
                      md5file.delete();
                  }
                  if(!successful) {
                      //if security checks failed for any reason,
                      //delete the library file
                      //brute force paranoia
                      library.getLibraryFile().delete();
                  }
              }
          }
          return fetched;
  
      }
  
  }
  
  
  
  1.1                  
ant/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java
  
  Index: Repository.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant.taskdefs.repository;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.types.DataType;
  
  import java.io.IOException;
  
  /**
   * This type represents a repository; a place that stores libraries for
   * retrieval. To use this type, you must use a non-abstract class, either one
   * that ships with Ant, or one you implement and declare yourself.
   * <p/>
   * The &lt;getlibraries&gt; task lets you supply a repository by reference
   * inline [EMAIL PROTECTED] Libraries#add(Repository)} or on the command line 
[EMAIL PROTECTED]
   * GetLibraries#setRepositoryRef(org.apache.tools.ant.types.Reference)}
   *
   * @since Ant1.7
   */
  public abstract class Repository extends DataType {
  
  
      /**
       * validate yourself
       *
       * @throws BuildException if unhappy
       */
      public void validate() {
      }
  
      /**
       * recursively resolve any references to get the real repository
       *
       * @return
       */
      public final Repository resolve() {
          if (getRefid() == null) {
              return this;
          } else {
              Repository repository = (Repository) 
getCheckedRef(Repository.class, 
                      "Repository");
              return repository;
          }
      }
  
      /**
       * override point: connection is called at the start of the retrieval
       * process
       *
       * @param owner owner of the libraries
       *
       * @throws BuildException
       */
      public void connect(Libraries owner) {
  
      }
  
      /**
       * override point: connection is called at the start of the retrieval
       * process
       *
       * @throws BuildException
       */
  
      public void disconnect() {
  
      }
  
  
      /**
       * Test for a repository being reachable. This method is called after 
[EMAIL PROTECTED]
       * #connect(GetLibraries)} is called, before any files are to be 
retrieved.
       * <p/>
       * If it returns false the repository considers itself offline. Similarly,
       * any ioexception is interpreted as being offline.
       *
       * @return true if the repository is online.
       *
       * @throws IOException
       */
      public abstract boolean checkRepositoryReachable() throws IOException;
  
      /**
       * fetch a library from the repository
       *
       * @param library library to fetch
       *
       * @param useTimestamp flag to indicate the timestamp of the lib should 
be used
       * @return
       */
      public abstract boolean fetch(Library library, boolean useTimestamp) 
throws IOException;
  
  
      /**
       * this is a string that uniquely describes the repository
       * and can be used for equality tests <i>across</i> instances. 
       * @return
       */
      public abstract String getRepositoryURI();
  }
  
  
  
  1.1                  
ant/src/main/org/apache/tools/ant/taskdefs/repository/RepositoryRef.java
  
  Index: RepositoryRef.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant.taskdefs.repository;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.types.Reference;
  
  import java.io.IOException;
  
  /**
   * not a real repository; one to paste a reference into the chain for
   * resolution.
   *
   * @since Ant1.7
   */
  public final class RepositoryRef extends Repository {
      /** this constant name is only funny to COM developers  
       */
      public static final String E_NOTIMPL = "Not Implemented";
  
  
      /**
       * create a repository reference
       *
       * @param reference
       */
      public RepositoryRef(Project project, Reference reference) {
          setRefid(reference);
          setProject(project);
      }
  
      /**
       * empty constructor
       */
      public RepositoryRef() {
      }
  
      /**
       * Test for a repository being reachable. This method is called after 
[EMAIL PROTECTED]
       * #connect(GetLibraries)} is called, before any files are to be 
retrieved.
       * <p/>
       * If it returns false the repository considers itself offline. Similarly,
       * any ioexception is interpreted as being offline.
       *
       * @return true if the repository is online.
       *
       * @throws java.io.IOException
       */
      public boolean checkRepositoryReachable() throws IOException {
          return false;
      }
  
      /**
       * fetch a library from the repository
       *
       * @param library
       *
       * @param useTimestamp
       * @return
       */
      public boolean fetch(Library library, boolean useTimestamp) throws 
IOException {
          throw new BuildException(E_NOTIMPL);
      }
  
      /**
       * this is a string that uniquely describes the repository and can be used
       * for equality tests <i>across</i> instances.
       *
       * @return
       */
      public String getRepositoryURI() {
          return "ref://"+getRefid();
      }
  }
  
  
  
  1.28      +1 -1      
ant/src/main/org/apache/tools/ant/types/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/types/defaults.properties,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- defaults.properties       25 Oct 2004 23:13:38 -0000      1.27
  +++ defaults.properties       18 Nov 2004 16:25:03 -0000      1.28
  @@ -34,4 +34,4 @@
   assertions=org.apache.tools.ant.types.Assertions
   concatfilter=org.apache.tools.ant.filters.ConcatFilter
   ispingable=org.apache.tools.ant.taskdefs.optional.condition.IsPingable
  
-mavenrepository=org.apache.tools.ant.taskdefs.optional.repository.MavenRepository
  \ No newline at end of file
  +mavenrepository=org.apache.tools.ant.taskdefs.repository.MavenRepository
  \ No newline at end of file
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/libraries.xml
  
  Index: libraries.xml
  ===================================================================
  <?xml version="1.0"?>
  <project name="getlibraries" basedir="." default="init">
  
  
    <!-- use the normal one at ibiblio-->
    <mavenrepository id="maven"/>
  
    <target name="init">
      <property name="lib.dir" value="getlib"/>
      
      <property name="commons.logging.project" value="commons-logging"/>
      <property name="commons.logging" 
        
value="${commons.logging.project}/jars/${commons.logging.project}-1.0.1.jar"/>
  
      <presetdef name="gl1">
        <libraries destDir="${lib.dir}">
        </libraries>
      </presetdef>
  
      <presetdef name="getlib">
        <gl1 destDir="${lib.dir}">
          <library archive="commons-logging" project="commons-logging" 
version="1.0.1"/>
        </gl1>
      </presetdef>
  
      <macrodef name="assert-downloaded">
        <attribute name="library" default="${commons.logging}"/>
        <sequential>
          <property name="@{library}.path" location="${lib.dir}/@{library}" />
          <available property="@{library}.exists"
            file="[EMAIL PROTECTED]"/>
          <fail unless="@{library}.exists">
            Not found: [EMAIL PROTECTED]
          </fail>
        </sequential>
      </macrodef>
  
      <macrodef name="assert-not-downloaded">
        <attribute name="library" default="${commons.logging}"/>
        <sequential>
          <property name="@{library}.path" location="${lib.dir}/@{library}" />
          <available property="@{library}.exists"
            file="[EMAIL PROTECTED]"/>
          <fail if="@{library}.exists">
            Found: [EMAIL PROTECTED]
          </fail>
        </sequential>
      </macrodef>
  
    </target>
  
    <target name="cleanup"  depends="init">
      <delete dir="${lib.dir}"/>
    </target>
  
    <target name="teardown"  depends="cleanup"/>
    
    <target name="testEmpty" depends="init">
      <libraries/>
    </target>
  
    <target name="testEmpty2" depends="init">
      <libraries destDir="${lib.dir}">
  
      </libraries>
    </target>
  
    <target name="testEmpty3" depends="init">
      <libraries destDir="${lib.dir}">
        <repository/>
      </libraries>
    </target>
  
    <target name="testNoRepo" depends="init">
      <getlib/>
    </target>
  
    <target name="testUnknownReference" depends="init">
      <getlib>
        <repository refid="unknown"/>
      </getlib>
    </target>
  
  
    <target name="testFunctionalInline" depends="init">
      <getlib repositoryref="maven">
      </getlib>
      <assert-downloaded/>
    </target>
  
    <target name="testMavenInline" depends="init">
      <getlib>
        <mavenrepository/>
      </getlib>
      <assert-downloaded/>
    </target>
  
    <target name="testTwoRepositories" depends="init">
      <getlib>
        <mavenrepository/>
        <mavenrepository/>
      </getlib>
    </target>
  
  
    <target name="testMavenInlineBadURL" depends="init">
      <getlib>
        <mavenrepository url="http://invalid.example.org"/>
      </getlib>
    </target>
  
    <target name="testRenaming" depends="init">
      <getlib>
        <mavenrepository/>
        <library archive="commons-logging" project="commons-logging" 
version="1.0.1"
          destinationName="renamed.jar"
          />
      </getlib>
      <assert-downloaded/>
      <assert-downloaded library="renamed.jar"/>
    </target>
  
  
    <target name="testOverwrite" depends="init">
      <getlib>
        <mavenrepository/>
        <assertdownloaded count="1" />
      </getlib>
      <getlib>
        <mavenrepository/>
        <assertdownloaded count="0" />
      </getlib>
    </target>
  
    <target name="testIf" depends="init">
      <gl1>
        <mavenrepository/>
        <library archive="commons-logging" project="commons-logging" 
version="1.0.1"
          enabled="true"/>
      </gl1>
      <assert-downloaded/>
    </target>
  
    <target name="testUnless" depends="init">
      <gl1>
        <mavenrepository/>
        <library archive="commons-logging" project="commons-logging" 
version="1.0.1"
          enabled="false"/>
      </gl1>
      <assert-not-downloaded/>
    </target>
  
    <target name="testPathID" depends="init">
      <getlib pathid="commons.logging">
        <mavenrepository/>
      </getlib>
      <available
        property="logging.found"
        classname="org.apache.commons.logging.Log"
        classpathref="commons.logging"
        ignoresystemclasses="true" />
      <fail unless="logging.found">
        Did not find commons logging in the path
      </fail>
    </target>
  
    <target name="testSecurity" depends="init">
      <getlib>
        <mavenrepository checkMD5="true"/>
      </getlib>
      <assert-downloaded/>
    </target>
    
    <target name="testSchedule" depends="init">
      <getlib >
        <mavenrepository/>
        <schedule days="1" markerFile="${lib.dir}/marker.txt"/>
        <assertdownloaded count="1" />
      </getlib>
      <getlib >
        <mavenrepository/>
        <schedule days="1" markerFile="${lib.dir}/marker.txt"/>
        <assertdownloaded count="0" />
      </getlib>
    </target>
  
    <target name="testForceEnabled" depends="init">
      <getlib>
        <mavenrepository/>
        <force enabled="true" />
        <assertdownloaded count="1" />
      </getlib>
      <getlib>
        <mavenrepository/>
        <force enabled="true" />
        <assertdownloaded count="1" />
      </getlib>    
    </target>
  
    <target name="testForceDisabled" depends="init">
      <getlib>
        <mavenrepository/>
        <force enabled="true" />
        <assertdownloaded count="1" />
      </getlib>
      <getlib >
        <mavenrepository/>
        <force enabled="false" />
        <assertdownloaded count="0" />
      </getlib>
    </target>
  
    <target name="testAbsentFiles" depends="init">
      <getlib >
        <mavenrepository/>
        <absentfiles enabled="true" />
        <assertdownloaded count="1" />
      </getlib>
    </target>
  
    <target name="testAbsentFilesTwice" depends="testAbsentFiles">
      <getlib >
        <mavenrepository/>
        <absentfiles enabled="true" />
        <assertdownloaded count="0" />
      </getlib>
    </target>
  
    <target name="testNoUpdate" depends="init">
      <getlib >
        <mavenrepository/>
        <force />
        <noupdate />
        <assertdownloaded count="0" />
      </getlib>
    </target>
  
    <target name="testTimestamp" depends="testAbsentFiles">
      <getlib >
        <mavenrepository/>
        <timestamp />
        <assertdownloaded count="0" />
      </getlib>
    </target>
  
    <target name="testAssertDownloadedCountSet" depends="init">
      <getlib>
        <mavenrepository/>
        <assertdownloaded />
      </getlib>
    </target>
  
    <target name="testAssertDownloadedCountTested" depends="init">
      <getlib>
        <mavenrepository/>
        <assertdownloaded count="152" />
      </getlib>
    </target>  
  </project>
  
  
  
  
  1.1                  
ant/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java
  
  Index: LibrariesTest.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.BuildFileTest;
  import org.apache.tools.ant.taskdefs.repository.AssertDownloaded;
  import org.apache.tools.ant.taskdefs.repository.Libraries;
  
  /**
   * test the test libraries stuff.
   * skip all the tests if we are offline
   */
  public class LibrariesTest extends BuildFileTest {
      private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/";
  
  
      public LibrariesTest(String name) {
          super(name);
      }
  
      public void setUp() {
          configureProject(TASKDEFS_DIR + "libraries.xml");
      }
  
  
      protected boolean offline() {
          return "true".equals(System.getProperty("offline"));
      }
  
      public void tearDown() {
          executeTarget("cleanup");
      }
  
      public void testEmpty() {
          expectBuildException("testEmpty",Libraries.ERROR_NO_DEST_DIR);
      }
  
      public void testEmpty2() {
          expectBuildException("testEmpty2", Libraries.ERROR_NO_REPOSITORY);
      }
  
      public void testEmpty3() {
          expectBuildException("testEmpty3", Libraries.ERROR_NO_LIBRARIES);
      }
  
      public void testNoRepo() {
          expectBuildException("testNoRepo", Libraries.ERROR_NO_REPOSITORY);
      }
  
      public void testUnknownReference() {
          expectBuildException("testUnknownReference", "Reference unknown not 
found.");
      }
  
      /**
       * refs are  broken
       * */
      public void testFunctionalInline() {
          execIfOnline("testFunctionalInline");
      }
      
      public void testMavenInline() {
          String targetName = "testMavenInline";
          execIfOnline(targetName);
      }
  
      /**
       * exec a target, but only if we are online
       * @param targetName
       */
      private void execIfOnline(String targetName) {
          if (offline()) {
              return;
          }
          executeTarget(targetName);
      }
  
      public void testTwoRepositories() {
          expectBuildException("testTwoRepositories",
                  Libraries.ERROR_ONE_REPOSITORY_ONLY);
      }
  
      public void testMavenInlineBadURL() {
          expectExceptionIfOnline("testMavenInlineBadURL",
                  "testMavenInlineBadURL",
                  Libraries.ERROR_INCOMPLETE_RETRIEVAL);
      }
  
      /**
       * exec a target if we are online; expect an eception
       * @param target
       * @param cause caue of the faule
       * @param message
       */
      private void expectExceptionIfOnline(String target, String cause,String 
message) {
          if (offline()) {
              return;
          }
          expectBuildExceptionContaining(target,cause,
                  message);
      }
  
      public void testRenaming() {
          execIfOnline("testRenaming");
  
      }
  
      public void testOverwrite() {
          execIfOnline("testOverwrite");
      }
  
      public void testIf() {
          execIfOnline("testIf");
      }
  
      public void testUnless() {
          execIfOnline("testUnless");
      }
  
      public void testPathID() {
          execIfOnline("testPathID");
      }
  
      public void testSecurity() {
          execIfOnline("testSecurity");
      }
  
      public void testSchedule() {
          execIfOnline("testSchedule");
      }
  
      public void testForceEnabled() {
          execIfOnline("testForceEnabled");
      }
  
      public void testForceDisabled() {
          execIfOnline("testForceDisabled");
      }
  
      public void testAbsentFiles() {
          execIfOnline("testAbsentFiles");
      }
  
      public void testAbsentFilesTwice() {
          execIfOnline("testAbsentFilesTwice");
      }
  
      public void testNoUpdate() {
          expectExceptionIfOnline("testNoUpdate",
                  "update disabled; dest file missing",
                  Libraries.ERROR_INCOMPLETE_RETRIEVAL);
      }
  
      public void testTimestamp() {
          execIfOnline("testTimestamp");
      }
  
      public void testAssertDownloadedCountSet() {
          expectExceptionIfOnline("testAssertDownloadedCountSet",
                  "No count in assertdownloaded",
                  AssertDownloaded.ERROR_NO_COUNT);
      }
  
      public void testAssertDownloadedCountTested() {
          expectExceptionIfOnline("testAssertDownloadedCountTested",
                  "Wrong count in assertdownloaded",
                  AssertDownloaded.ERROR_DOWNLOAD_FAILURE);
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to