You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@apache.org on 2004/12/01 23:48:37 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs LibrariesTest.java

stevel      2004/12/01 14:48:37

  Modified:    src/main/org/apache/tools/ant/taskdefs/repository
                        HttpRepository.java Libraries.java Library.java
                        MavenRepository.java
               src/testcases/org/apache/tools/ant/taskdefs
                        LibrariesTest.java
  Log:
  Library flattens files
  
  Revision  Changes    Path
  1.4       +19 -19    ant/src/main/org/apache/tools/ant/taskdefs/repository/HttpRepository.java
  
  Index: HttpRepository.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/HttpRepository.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpRepository.java	22 Nov 2004 09:23:35 -0000	1.3
  +++ HttpRepository.java	1 Dec 2004 22:48:37 -0000	1.4
  @@ -31,6 +31,10 @@
    * can share this datatype, it is *not* thread safe; you can only use it in one
    * thread at at time
    *
  + * Although it is biased towards HTTP, because the underlying <get> task
  + * supports different protocols, one is actually able to use other protocols
  + * such as ftp: or file: to retrieve content. 
  + *
    * @since Ant1.7
    */
   public abstract class HttpRepository extends Repository {
  @@ -87,6 +91,21 @@
           this.url = url;
       }
   
  +    /**
  +     * set the base directory of the repository
  +     * This creates a URL of the <tt>file://</tt> type
  +     * and binds the URL of the repository to it.
  +     * @param basedir
  +     */
  +    public void setBaseDir(File basedir) {
  +        try {
  +            URL url=basedir.toURL();
  +            setUrl(url.toExternalForm());
  +        } catch (MalformedURLException e) {
  +            throw new BuildException(e);
  +        }
  +    }
  +
       public String getUsername() {
           return username;
       }
  @@ -112,26 +131,7 @@
       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;
  
  
  
  1.3       +31 -8     ant/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java
  
  Index: Libraries.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/Libraries.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Libraries.java	22 Nov 2004 09:23:35 -0000	1.2
  +++ Libraries.java	1 Dec 2004 22:48:37 -0000	1.3
  @@ -78,6 +78,12 @@
        */
       private boolean useTimestamp = false;
   
  +    /**
  +     * flag to indicate if the libraries should be stored
  +     * flat or in maven-style ($(project)/jars/) subdirectories.
  +     */
  +    private boolean flatten = 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";
  @@ -290,6 +296,21 @@
           this.useTimestamp = useTimestamp;
       }
   
  +    public boolean isFlatten() {
  +        return flatten;
  +    }
  +
  +    /**
  +     * Flatten flag.
  +     * Store downloaded libraries into a single directory if true,
  +     * store in project/jar subdirectores if false.
  +     * default: false
  +     * @param flatten
  +     */
  +    public void setFlatten(boolean flatten) {
  +        this.flatten = flatten;
  +    }
  +
       /**
        * get the current policy list
        * @return
  @@ -326,11 +347,8 @@
        */
       public void execute() throws BuildException {
           validate();
  -        if (isOffline()) {
  -            log("No retrieval, task is \"offline\"");
  -        } else {
  -            doExecute();
  -        }
  +        //execute
  +        doExecute();
           //validate the state
           verifyAllLibrariesPresent();
   
  @@ -378,6 +396,11 @@
               }
           }
   
  +        if (isOffline()) {
  +            log("No retrieval, task is \"offline\"");
  +            retrieve=false;
  +        }
  +
           //see if we need to do a download
           if (!retrieve) {
               //if not, log it
  @@ -393,7 +416,7 @@
               }
           }
   
  -        //now reverse iterate through all processed properties.
  +        //now reverse iterate through all processed policies.
           for (int i = processedPolicies.size() - 1; i >= 0; i--) {
               LibraryPolicy libraryPolicy = (LibraryPolicy) processedPolicies.get(i);
               //and call their post-processor
  @@ -408,7 +431,7 @@
        * @return number of failed retrievals.
        */
       private int connectAndRetrieve(Repository repo, boolean useTimestamp) {
  -        //connect the repository
  +        //connect to the repository
           int failures = 0;
           repo.connect(this);
           try {
  @@ -470,7 +493,7 @@
           Iterator it = libraries.iterator();
           while (it.hasNext()) {
               Library library = (Library) it.next();
  -            library.bind(destDir);
  +            library.bind(destDir, flatten);
           }
       }
   
  
  
  
  1.4       +11 -6     ant/src/main/org/apache/tools/ant/taskdefs/repository/Library.java
  
  Index: Library.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/Library.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Library.java	24 Nov 2004 23:10:47 -0000	1.3
  +++ Library.java	1 Dec 2004 22:48:37 -0000	1.4
  @@ -35,6 +35,8 @@
        */
       private boolean enabled = true;
   
  +    private static FileUtils FILE_UTILS = FileUtils.newFileUtils();
  +
       /**
        * turn policy on/off
        *
  @@ -241,18 +243,21 @@
        * calculate the destination file of a library; set {@link #libraryFile}
        * to the File thereof.
        *
  -     * @param baseDir dir that
  +     * @param baseDir dir that is used as the base for the operations
        *
  +     * @param flatten flag to indicate whether the directory path is 'flat' or not.
        * @throws BuildException if invalid
        */
  -    public void bind(File baseDir) {
  +    public void bind(File baseDir, boolean flatten) {
           validate();
  -        FileUtils fileUtils = FileUtils.newFileUtils();
  -
           if (destinationName == null) {
  -            destinationName = getMavenPath('/');
  +            if(flatten) {
  +                destinationName = getNormalFilename();
  +            } else {
  +                destinationName = getMavenPath('/');
  +            }
           }
  -        libraryFile = fileUtils.resolveFile(baseDir, destinationName);
  +        libraryFile = FILE_UTILS.resolveFile(baseDir, destinationName);
           if (libraryFile.isDirectory()) {
               throw new BuildException(ERROR_FILE_IS_A_DIR
                   + libraryFile);
  
  
  
  1.3       +1 -0      ant/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java
  
  Index: MavenRepository.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/MavenRepository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MavenRepository.java	22 Nov 2004 09:23:35 -0000	1.2
  +++ MavenRepository.java	1 Dec 2004 22:48:37 -0000	1.3
  @@ -56,6 +56,7 @@
           setUrl(MAVEN_URL);
       }
   
  +    
       /**
        * set this to check the MD5 signatures. SECURITY IS NOT YET FUNCTIONAL
        * @param checkMD5
  
  
  
  1.3       +3 -0      ant/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java
  
  Index: LibrariesTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/LibrariesTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LibrariesTest.java	24 Nov 2004 23:10:47 -0000	1.2
  +++ LibrariesTest.java	1 Dec 2004 22:48:37 -0000	1.3
  @@ -204,4 +204,7 @@
           execIfOnline("testNoSuffix");
       }
   
  +    public void testFlatten() {
  +        execIfOnline("testFlatten");
  +    }
   }
  
  
  

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