1-if you dont specify an archive name, use that of the project 2-its OK to specify suffix="" 3-you do need the "." in the suffix; this was not needed. (3) will break anything which set the suffix. I assumed the user base was small enough to avoid a compatibility hack. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277078 13f79535-47bb-0310-9956-ffa450edef68master
@@ -9,8 +9,9 @@ | |||
<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"/> | |||
<property name="version" value="1.0.4"/> | |||
<property name="commons.logging" | |||
value="${commons.logging.project}/jars/${commons.logging.project}-${version}.jar"/> | |||
<presetdef name="gl1"> | |||
<libraries destDir="${lib.dir}"> | |||
@@ -19,7 +20,8 @@ | |||
<presetdef name="getlib"> | |||
<gl1 destDir="${lib.dir}"> | |||
<library archive="commons-logging" project="commons-logging" version="1.0.1"/> | |||
<library archive="commons-logging" project="commons-logging" | |||
version="${version}"/> | |||
</gl1> | |||
</presetdef> | |||
@@ -112,7 +114,7 @@ | |||
<target name="testRenaming" depends="init"> | |||
<getlib> | |||
<mavenrepository/> | |||
<library archive="commons-logging" project="commons-logging" version="1.0.1" | |||
<library archive="commons-logging" project="commons-logging" version="${version}" | |||
destinationName="renamed.jar" | |||
/> | |||
</getlib> | |||
@@ -135,8 +137,7 @@ | |||
<target name="testIf" depends="init"> | |||
<gl1> | |||
<mavenrepository/> | |||
<library archive="commons-logging" project="commons-logging" version="1.0.1" | |||
enabled="true"/> | |||
<library archive="commons-logging" project="commons-logging" version="${version}" enabled="true"/> | |||
</gl1> | |||
<assert-downloaded/> | |||
</target> | |||
@@ -144,7 +145,7 @@ | |||
<target name="testUnless" depends="init"> | |||
<gl1> | |||
<mavenrepository/> | |||
<library archive="commons-logging" project="commons-logging" version="1.0.1" | |||
<library archive="commons-logging" project="commons-logging" version="${version}" | |||
enabled="false"/> | |||
</gl1> | |||
<assert-not-downloaded/> | |||
@@ -256,5 +257,55 @@ | |||
<assertdownloaded count="152" /> | |||
</getlib> | |||
</target> | |||
<target name="testNoArchiveName" depends="init"> | |||
<gl1 destDir="${lib.dir}" > | |||
<library project="commons-logging" version="${version}"/> | |||
<mavenrepository/> | |||
<assertdownloaded count="1"/> | |||
</gl1> | |||
</target> | |||
<target name="testNoVersion" depends="init"> | |||
<gl1 destDir="${lib.dir}" offline="true"> | |||
<library project="commons-logging" /> | |||
<mavenrepository/> | |||
</gl1> | |||
</target> | |||
<target name="testNoProject" depends="init"> | |||
<gl1 destDir="${lib.dir}" offline="true"> | |||
<library archive="commons-logging" version="${version}"/> | |||
<mavenrepository/> | |||
</gl1> | |||
</target> | |||
<target name="testNewSuffix" depends="init"> | |||
<gl1 destDir="${lib.dir}"> | |||
<library project="commons-logging" version="${version}" | |||
suffix=".jar.asc"/> | |||
<mavenrepository checkMD5="false"/> | |||
<assertdownloaded count="1"/> | |||
</gl1> | |||
</target> | |||
<target name="testNoSuffix" depends="init"> | |||
<gl1 destDir="${lib.dir}"> | |||
<library project="commons-logging" version="snapshot-version" suffix=""/> | |||
<assertdownloaded count="1"/> | |||
<mavenrepository checkMD5="false"/> | |||
</gl1> | |||
</target> | |||
<target name="testEmptyArchive" depends="init"> | |||
<gl1 destDir="${lib.dir}"> | |||
<library project="commons-logging" version="${version}" | |||
archive=""/> | |||
<assertdownloaded count="1"/> | |||
<mavenrepository/> | |||
</gl1> | |||
</target> | |||
</project> | |||
@@ -80,18 +80,20 @@ public class Library implements EnabledLibraryElement { | |||
*/ | |||
private boolean toFetch = true; | |||
/** | |||
* flag set after fetching | |||
*/ | |||
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"; | |||
public static final String ERROR_FILE_IS_A_DIR = "Library file is a directory:"; | |||
/** | |||
* suffix | |||
*/ | |||
private String suffix = "jar"; | |||
public static final String ERROR_FILE_IS_A_DIR = "Library file is a directory:"; | |||
private String suffix = ".jar"; | |||
/** | |||
@@ -169,7 +171,7 @@ public class Library implements EnabledLibraryElement { | |||
} | |||
/** | |||
* set the suffix for this file; default is "jar" | |||
* set the suffix for this file; default is ".jar" | |||
* @param suffix | |||
*/ | |||
public void setSuffix(String suffix) { | |||
@@ -213,10 +215,16 @@ public class Library implements EnabledLibraryElement { | |||
* @throws BuildException if invalid | |||
*/ | |||
public void validate() { | |||
faultIfEmpty(archive, ERROR_NO_ARCHIVE); | |||
faultIfEmpty(project, ERROR_NO_PROJECT); | |||
if(archive==null) { | |||
//adopt the name of the project if no archive is specced | |||
archive=project; | |||
} | |||
faultIfEmpty(archive, ERROR_NO_ARCHIVE); | |||
faultIfEmpty(version, ERROR_NO_VERSION); | |||
faultIfEmpty(version, ERROR_NO_SUFFIX); | |||
if(suffix==null) { | |||
suffix=""; | |||
} | |||
} | |||
/** | |||
@@ -278,7 +286,7 @@ public class Library implements EnabledLibraryElement { | |||
* source | |||
*/ | |||
public String getNormalFilename() { | |||
return archive + "-" + version + "." + suffix; | |||
return archive + "-" + version + suffix; | |||
} | |||
/** | |||
@@ -19,6 +19,7 @@ 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; | |||
import org.apache.tools.ant.taskdefs.repository.Library; | |||
/** | |||
* test the test libraries stuff. | |||
@@ -179,4 +180,28 @@ public class LibrariesTest extends BuildFileTest { | |||
"Wrong count in assertdownloaded", | |||
AssertDownloaded.ERROR_DOWNLOAD_FAILURE); | |||
} | |||
public void testNoVersion() { | |||
expectBuildException("testNoVersion", | |||
Library.ERROR_NO_PROJECT); | |||
} | |||
public void testNoProject() { | |||
expectBuildException("testNoProject", | |||
Library.ERROR_NO_PROJECT); | |||
} | |||
public void testNoArchiveName() { | |||
execIfOnline("testNoArchiveName"); | |||
} | |||
public void testEmptyArchive() { | |||
expectBuildException("testEmptyArchive", | |||
Library.ERROR_NO_ARCHIVE); | |||
} | |||
public void testNoSuffix() { | |||
execIfOnline("testNoSuffix"); | |||
} | |||
} |