ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs LibrariesTest.java
Date Thu, 20 Jan 2005 15:59:52 GMT
stevel      2005/01/20 07:59:52

  Modified:    docs/manual running.html
               docs/manual/CoreTasks libraries.html
               src/etc/testcases/taskdefs libraries.xml
               src/main/org/apache/tools/ant/taskdefs/repository
                        Libraries.java MavenRepository.java Repository.java
               src/testcases/org/apache/tools/ant/taskdefs
                        LibrariesTest.java
  Log:
  First updates to library
  -default dest, repository
  -override properties
  -changes to tests to keep working
  -enhancements to tests so they work behind a firewall if ~/.ant/proxy.properties contains
the settings
  
  Revision  Changes    Path
  1.31      +12 -0     ant/docs/manual/running.html
  
  Index: running.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/running.html,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- running.html	13 Jan 2005 23:09:32 -0000	1.30
  +++ running.html	20 Jan 2005 15:59:52 -0000	1.31
  @@ -277,6 +277,18 @@
     </td>
   </tr>
   <tr>
  +  <td><code>ant.maven.repository.dir</code></td>
  +  <td>directory e.g. ${user.home}/.maven/repository </td>
  +  <td>Override the default download location for <a href="CoreTasks/libraries.html">libraries</a>.
  +  </td>
  +</tr>
  +<tr>
  +  <td><code>ant.maven.repository.url</code></td>
  +  <td>URL e.g. <code>http://ibiblio.org/maven</code> </td>
  +  <td>Override the default source location for <a href="CoreTasks/libraries.html">libraries</a>.
  +  </td>
  +</tr>
  +<tr>
     <td><code>ant.netrexxc.*</code></td>
     <td>several formats</td>
     <td>Use specified values as defaults for <a href="OptionalTasks/netrexxc.html">netrexxc</a>.
  
  
  
  1.2       +21 -10    ant/docs/manual/CoreTasks/libraries.html
  
  Index: libraries.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/libraries.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- libraries.html	19 Jan 2005 23:15:26 -0000	1.1
  +++ libraries.html	20 Jan 2005 15:59:52 -0000	1.2
  @@ -42,7 +42,7 @@
       <td valign="top">destDir</td>
       <td valign="top">Destination directory for all downloads
       </td>
  -    <td valign="top" align="center">Yes</td>
  +    <td valign="top" align="center">No - default is ${user.home}/.maven/repository</td>
     </tr>
     <tr>
       <td valign="top">offline</td>
  @@ -68,10 +68,15 @@
       <td valign="top">repositoryRef</td>
       <td valign="top">Reference to a predefined repository
       </td>
  -    <td valign="top" align="center">Only if no repository is defined inline</td>
  +    <td valign="top" align="center">No</td>
     </tr>
   </table>
   
  +<p>
  +The default destination is that used by Maven,
  +${user.home}/.maven/repository . It can be overridden by setting the
  +property <code>ant.maven.repository.dir</code> to a new location. 
  +</p>
    
   </table>
   <h3>Nested Elements</h3>
  @@ -127,9 +132,12 @@
   </table>
   
   <h4>Repository</h4>
  -
  +<p>
   A repository is Ant datatype that extends the <code>Repository</code> type.
  -Ant only ships with one: the mavenrepository;  
  +Ant only ships with one: the mavenrepository. If no repository is
  +declared inline, and no repositoryref attribute set, the task
  +will default to the maven repository.
  +</p>
   
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  @@ -143,12 +151,6 @@
       </td>
       <td valign="top" align="center">No</td>
     </tr>
  -  <tr>
  -    <td valign="top"></td>
  -    <td valign="top">
  -    </td>
  -    <td valign="top" align="center">No</td>
  -  </tr>
   </table>
     
   <p>Example:</p>
  @@ -157,6 +159,15 @@
   </pre>    
   
   <h4>mavenrepository</h4>
  +
  +<p>
  +This connects to the Maven repository at ibiblio.org, or another 
  +chosen. Private repositories should copy the existing layout.
  +</p>
  +<p>
  +If no <code>url</code> is set, the default URL is 
  +<code>http://ibiblio.org/maven</code>, unless the property
  +<code>ant.maven.repository.url</code> is set to something else. 
   
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  
  
  
  1.4       +46 -13    ant/src/etc/testcases/taskdefs/libraries.xml
  
  Index: libraries.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/libraries.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- libraries.xml	1 Dec 2004 22:49:02 -0000	1.3
  +++ libraries.xml	20 Jan 2005 15:59:52 -0000	1.4
  @@ -2,10 +2,28 @@
   <project name="getlibraries" basedir="." default="init">
   
   
  +
  +
     <!-- use the normal one at ibiblio-->
     <mavenrepository id="maven"/>
   
  -  <target name="init">
  +  
  +    <!-- configure an HTTP proxy -->
  +  <target name="setproxy" unless="setproxy.disabled" >
  +    <!-- put your proxy settings here -->
  +    <property file="${user.home}/.ant/proxy.properties" />
  +    <property name="proxy.host" value="" />
  +    <property name="proxy.port" value="80" />
  +    <property name="proxy.user" value="" />
  +    <property name="proxy.pass" value="" />
  +    <echo level="verbose">
  +      proxy: ${proxy.host}:${proxy.port} [${proxy.user}/${proxy.pass}]
  +    </echo>
  +      <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
  +        proxyuser="${proxy.user}" proxypassword="${proxy.pass}" />
  +  </target> 
  +  
  +  <target name="init" depends="setproxy">
       <property name="lib.dir" value="getlib"/>
       
       <property name="commons.logging.project" value="commons-logging"/>
  @@ -15,6 +33,9 @@
       <property name="commons.logging"
         value="${commons.logging.project}/jars/${commons.logging.filename}"/>
   
  +    <property name="maven.repository.dir"
  +        location="${user.home}/.maven/repository" />      
  +      
       <presetdef name="gl1">
         <libraries destDir="${lib.dir}">
         </libraries>
  @@ -29,6 +50,21 @@
   
       <macrodef name="assert-downloaded">
         <attribute name="library" default="${commons.logging}"/>
  +      <attribute name="repository" default="${lib.dir}"/>
  +      <sequential>
  +        <fail >
  +          Not found: "@{repository}/@{library}"
  +          <condition>
  +            <not>
  +              <available file="@{repository}/@{library}"/>
  +            </not>
  +          </condition>
  +        </fail>
  +      </sequential>
  +    </macrodef>
  +    
  +<!--     <macrodef name="assert-downloaded">
  +      <attribute name="library" default="${commons.logging}"/>
         <sequential>
           <property name="@{library}.path" location="${lib.dir}/@{library}" />
           <available property="@{library}.exists"
  @@ -37,20 +73,21 @@
             Not found: ${@{library}.path}
           </fail>
         </sequential>
  -    </macrodef>
  +    </macrodef> -->
   
       <macrodef name="assert-not-downloaded">
         <attribute name="library" default="${commons.logging}"/>
  +      <attribute name="repository" default="${lib.dir}"/>
         <sequential>
  -        <property name="@{library}.path" location="${lib.dir}/@{library}" />
  -        <available property="@{library}.exists"
  -          file="${@{library}.path}"/>
  -        <fail if="@{library}.exists">
  -          Found: ${@{library}.path}
  +        <fail>
  +          Unexpectedly found: "@{repository}/@{library}"
  +          <condition>
  +            <available file="@{repository}/@{library}"/>
  +          </condition>
           </fail>
         </sequential>
       </macrodef>
  -
  +    
     </target>
   
     <target name="cleanup"  depends="init">
  @@ -77,6 +114,7 @@
   
     <target name="testNoRepo" depends="init">
       <getlib/>
  +    <assert-downloaded/>
     </target>
   
     <target name="testUnknownReference" depends="init">
  @@ -85,7 +123,6 @@
       </getlib>
     </target>
   
  -
     <target name="testFunctionalInline" depends="init">
       <getlib repositoryref="maven">
       </getlib>
  @@ -202,12 +239,10 @@
   
     <target name="testForceDisabled" depends="init">
       <getlib>
  -      <mavenrepository/>
         <force enabled="true" />
         <assertdownloaded count="1" />
       </getlib>
       <getlib >
  -      <mavenrepository/>
         <force enabled="false" />
         <assertdownloaded count="0" />
       </getlib>
  @@ -215,7 +250,6 @@
   
     <target name="testAbsentFiles" depends="init">
       <getlib >
  -      <mavenrepository/>
         <absentfiles enabled="true" />
         <assertdownloaded count="1" />
       </getlib>
  @@ -223,7 +257,6 @@
   
     <target name="testAbsentFilesTwice" depends="testAbsentFiles">
       <getlib >
  -      <mavenrepository/>
         <absentfiles enabled="true" />
         <assertdownloaded count="0" />
       </getlib>
  
  
  
  1.4       +41 -6     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Libraries.java	1 Dec 2004 22:48:37 -0000	1.3
  +++ Libraries.java	20 Jan 2005 15:59:52 -0000	1.4
  @@ -85,7 +85,7 @@
       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_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
";
  @@ -96,6 +96,22 @@
   
   
       /**
  +     * where maven stores stuff, and where we save stuff too, unless
  +     * declared otherwise.
  +     */
  +    public static final String MAVEN_LOCATION=".maven/repository";
  +
  +    /**
  +     * name of the property which can provide an override of the repository dir
  +     * from {@link #MAVEN_LOCATION}
  +     */
  +    public static final String REPOSITORY_DIR_PROPERTY="ant.maven.repository.dir";
  +    /**
  +     * name of the property which can provide an override of the repository URL
  +     */
  +    public static final String REPOSITORY_URL_PROPERTY = "ant.maven.repository.url";
  +
  +    /**
        * Init the task
        *
        * @throws org.apache.tools.ant.BuildException
  @@ -108,6 +124,23 @@
       }
   
       /**
  +     * locate the default directory, by looking for the property
  +     * {@link #REPOSITORY_DIR_PROPERTY}, and if not defined,
  +     * ${user.home}/.maven/repository
  +     * @return file for the default dest dir; may not exist yet.
  +     */
  +    private File locateDefaultDestDirectory() {
  +        //set the dest dir up to the default.
  +        File mavenDir
  +                = new File(System.getProperty("user.home"), MAVEN_LOCATION);
  +        String propertyDir = getProject().getProperty(REPOSITORY_DIR_PROPERTY);
  +        if(propertyDir!=null) {
  +            mavenDir=getProject().resolveFile(propertyDir);
  +        }
  +        return mavenDir;
  +    }
  +
  +    /**
        * add a repository. Only one is (currently) supported
        *
        * @param repo
  @@ -325,13 +358,12 @@
        * @throws BuildException
        */
       public void validate() {
  -        if (destDir == null
  -        //        || !destDir.isDirectory()
  -        ) {
  -            throw new BuildException(ERROR_NO_DEST_DIR);
  +        if (destDir == null) {
  +            destDir=locateDefaultDestDirectory();
           }
           if (repository == null) {
  -            throw new BuildException(ERROR_NO_REPOSITORY);
  +            MavenRepository maven=(MavenRepository)getProject().createDataType(MavenRepository.TYPE_NAME);
  +            repository=maven;
           }
           Iterator it = libraries.iterator();
           while (it.hasNext()) {
  @@ -365,9 +397,12 @@
        */
       private void doExecute() throws BuildException {
           destDir.mkdirs();
  +        //get the ultimate repository
           Repository repo = repository.resolve();
  +        //validate it
           repo.validate();
           if (libraries.size() == 0) {
  +            //bail out on an empty library
               throw new BuildException(ERROR_NO_LIBRARIES);
           }
           log("Getting libraries from " + repo.toString(), Project.MSG_VERBOSE);
  
  
  
  1.4       +25 -1     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MavenRepository.java	1 Dec 2004 22:48:37 -0000	1.3
  +++ MavenRepository.java	20 Jan 2005 15:59:52 -0000	1.4
  @@ -18,6 +18,7 @@
   package org.apache.tools.ant.taskdefs.repository;
   
   import org.apache.tools.ant.util.FileUtils;
  +import org.apache.tools.ant.BuildException;
   
   import java.io.File;
   import java.io.FileInputStream;
  @@ -48,12 +49,12 @@
        * this is what we think the MD5 type is
        */
       protected static final String MAVEN_MD5_FILE_TYPE = "US-ASCII";
  +    public static final String TYPE_NAME = "mavenrepository";
   
       /**
        * bind to the main maven repository
        */
       public MavenRepository() {
  -        setUrl(MAVEN_URL);
       }
   
       
  @@ -63,6 +64,29 @@
        */
       public void setCheckMD5(boolean checkMD5) {
           this.checkMD5 = checkMD5;
  +    }
  +
  +
  +    /**
  +     * Validation time is where the final fixup of repositories exist; this
  +     * is the last chance to examine properties to see if there is an override.
  +     *
  +     * @throws BuildException if unhappy
  +     */
  +    public void validate() {
  +        if(getUrl()==null) {
  +            //we have no URL yet; so use the maven one
  +            if(getProject()!=null) {
  +                String urlProperty=getProject()
  +                        .getProperty(Libraries.REPOSITORY_URL_PROPERTY);
  +                if(urlProperty!=null) {
  +                    setUrl(urlProperty);
  +                } else {
  +                    setUrl(MAVEN_URL);
  +                }
  +            }
  +        }
  +        super.validate();
       }
   
       /**
  
  
  
  1.3       +2 -2      ant/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java
  
  Index: Repository.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/repository/Repository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Repository.java	22 Nov 2004 09:23:35 -0000	1.2
  +++ Repository.java	20 Jan 2005 15:59:52 -0000	1.3
  @@ -27,9 +27,9 @@
    * 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
  + * The &lt;libraries&gt; task lets you supply a repository by reference
    * inline {@link Libraries#add(Repository)} or on the command line {@link
  - * GetLibraries#setRepositoryRef(org.apache.tools.ant.types.Reference)}
  + * Libraries#setRepositoryRef(org.apache.tools.ant.types.Reference)}
    *
    * @since Ant1.7
    */
  
  
  
  1.4       +3 -3      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LibrariesTest.java	1 Dec 2004 22:48:37 -0000	1.3
  +++ LibrariesTest.java	20 Jan 2005 15:59:52 -0000	1.4
  @@ -47,11 +47,11 @@
       }
   
       public void testEmpty() {
  -        expectBuildException("testEmpty",Libraries.ERROR_NO_DEST_DIR);
  +        expectBuildException("testEmpty", Libraries.ERROR_NO_LIBRARIES);
       }
   
       public void testEmpty2() {
  -        expectBuildException("testEmpty2", Libraries.ERROR_NO_REPOSITORY);
  +        expectBuildException("testEmpty2", Libraries.ERROR_NO_LIBRARIES);
       }
   
       public void testEmpty3() {
  @@ -59,7 +59,7 @@
       }
   
       public void testNoRepo() {
  -        expectBuildException("testNoRepo", Libraries.ERROR_NO_REPOSITORY);
  +        execIfOnline("testNoRepo");
       }
   
       public void testUnknownReference() {
  
  
  

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


Mime
View raw message