git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277107 13f79535-47bb-0310-9956-ffa450edef68master
@@ -31,6 +31,10 @@ import java.net.URL; | |||
* 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 @@ public abstract class HttpRepository extends Repository { | |||
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 abstract class HttpRepository extends Repository { | |||
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; | |||
@@ -78,6 +78,12 @@ public final class Libraries extends Task { | |||
*/ | |||
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 @@ public final class Libraries extends Task { | |||
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 final class Libraries extends Task { | |||
*/ | |||
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 @@ public final class Libraries extends Task { | |||
} | |||
} | |||
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 @@ public final class Libraries extends Task { | |||
} | |||
} | |||
//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 @@ public final class Libraries extends Task { | |||
* @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 @@ public final class Libraries extends Task { | |||
Iterator it = libraries.iterator(); | |||
while (it.hasNext()) { | |||
Library library = (Library) it.next(); | |||
library.bind(destDir); | |||
library.bind(destDir, flatten); | |||
} | |||
} | |||
@@ -35,6 +35,8 @@ public class Library implements EnabledLibraryElement { | |||
*/ | |||
private boolean enabled = true; | |||
private static FileUtils FILE_UTILS = FileUtils.newFileUtils(); | |||
/** | |||
* turn policy on/off | |||
* | |||
@@ -241,18 +243,21 @@ public class Library implements EnabledLibraryElement { | |||
* 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); | |||
@@ -56,6 +56,7 @@ public class MavenRepository extends HttpRepository { | |||
setUrl(MAVEN_URL); | |||
} | |||
/** | |||
* set this to check the MD5 signatures. SECURITY IS NOT YET FUNCTIONAL | |||
* @param checkMD5 | |||
@@ -204,4 +204,7 @@ public class LibrariesTest extends BuildFileTest { | |||
execIfOnline("testNoSuffix"); | |||
} | |||
public void testFlatten() { | |||
execIfOnline("testFlatten"); | |||
} | |||
} |