Index: /trunk/src/main/java/org/apache/easyant/tasks/FindClasspath.java
===================================================================
--- /trunk/src/main/java/org/apache/easyant/tasks/FindClasspath.java (revision 401)
+++ /trunk/src/main/java/org/apache/easyant/tasks/FindClasspath.java (revision 401)
@@ -0,0 +1,260 @@
+package org.apache.easyant.tasks;
+
+import java.io.File;
+
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.ivy.ant.IvyCachePath;
+import org.apache.ivy.ant.IvyPostResolveTask;
+import org.apache.ivy.core.LogOptions;
+import org.apache.ivy.core.cache.ResolutionCacheManager;
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.ivy.plugins.report.XmlReportParser;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+/**
+ * This task provides a mechanism to build a plugin classpath depending on
+ * rules.
+ */
+public class FindClasspath extends EasyAntTask {
+	private String pathid;
+	private String organisation;
+	private String module;
+	private String revision;
+	private String conf = "default";
+	private String env;
+	private Path path;
+
+	/**
+	 * check if project dependencies matches with expected module
+	 * 
+	 * @return return true if project dependencies matches with expected module
+	 */
+	protected boolean checkProjectDependencies() {
+		log("Checking project dependencies ...", Project.MSG_DEBUG);
+		CheckProjectDependencies checkProjectDependencies = new CheckProjectDependencies();
+		checkProjectDependencies.setSettingsRef(getProjectIvyReference());
+		initTask(checkProjectDependencies);
+		return checkProjectDependencies.checkProjectDependencies();
+	}
+
+	/**
+	 * check environment variable
+	 * 
+	 * @return return true if the environment variable exist
+	 */
+	protected boolean checkEnvironmentVariable() {
+		log("Checking environment variable ...", Project.MSG_DEBUG);
+
+		if (getEnv() != null && System.getProperty(getEnv()) != null) {
+			log(getEnv() + " found !", Project.MSG_DEBUG);
+			File libDir = new File(System.getProperty(getEnv() + "/lib"));
+			FileSet fileSet = new FileSet();
+			fileSet.setDir(libDir);
+			// TODO: make this configurable
+			fileSet.setIncludes("**/*.jar");
+			fileSet.setProject(getProject());
+			fileSet.setLocation(getLocation());
+
+			getPath().addFileset(fileSet);
+			return true;
+		}
+		return false;
+
+	}
+
+	public void execute() throws BuildException {
+		// If the expected module was not found in project dependencies or using
+		// environment variable
+		// use the default one shipped with the plugin
+		if (!checkProjectDependencies() && !checkEnvironmentVariable()) {
+			checkPluginConfiguration();
+		}
+	}
+	
+	/**
+	 * check plugin configuration
+	 */
+	protected void checkPluginConfiguration() {
+		log("Checking plugin configuration ...");
+		loadCachePath(getOrganisation(), getModule(), getRevision(), getConf(),
+				new Reference(getProject(),
+						EasyAntMagicNames.EASYANT_IVY_INSTANCE));
+	}
+
+	/**
+	 * Utilitary method to load cachepath
+	 * 
+	 * @param organisation
+	 *            organisation name
+	 * @param module
+	 *            module name
+	 * @param revision
+	 *            revision number
+	 * @param conf
+	 *            configuration name
+	 * @param ivyRef
+	 *            ivy instance reference
+	 */
+	protected void loadCachePath(String organisation, String module,
+			String revision, String conf, Reference ivyRef) {
+		StringBuilder sb = new StringBuilder();
+		sb.append("Building classpath (").append(getPathid()).append(")");
+		sb.append(" with ");
+		sb.append(organisation).append("#").append(module).append(";").append(
+				revision);
+		sb.append(" conf=").append(conf);
+		log(sb.toString(), Project.MSG_DEBUG);
+		IvyCachePath pluginCachePath = new IvyCachePath();
+		pluginCachePath.setOrganisation(organisation);
+		pluginCachePath.setModule(module);
+		pluginCachePath.setRevision(revision);
+		pluginCachePath.setConf(conf);
+		pluginCachePath.setPathid(getPathid());
+		pluginCachePath.setLog(LogOptions.LOG_DOWNLOAD_ONLY);
+		pluginCachePath.setInline(true);
+
+		pluginCachePath.setSettingsRef(ivyRef);
+		initTask(pluginCachePath);
+
+	}
+	
+	/**
+	 * Utilitary method to build the classpath
+	 * 
+	 * @return a path
+	 */
+	protected Path getPath() {
+		if (path == null) {
+			Path path = new Path(getProject());
+			path.setPath(getPathid());
+			path.setLocation(getLocation());
+		}
+		return path;
+	}
+
+
+	public String getPathid() {
+		return pathid;
+	}
+
+	public void setPathid(String pathid) {
+		this.pathid = pathid;
+	}
+
+	public String getOrganisation() {
+		return organisation;
+	}
+
+	public void setOrganisation(String organisation) {
+		this.organisation = organisation;
+	}
+
+	public String getModule() {
+		return module;
+	}
+
+	public void setModule(String module) {
+		this.module = module;
+	}
+
+	public String getRevision() {
+		return revision;
+	}
+
+	public void setRevision(String revision) {
+		this.revision = revision;
+	}
+
+	public String getConf() {
+		return conf;
+	}
+
+	public void setConf(String conf) {
+		this.conf = conf;
+	}
+
+	public String getEnv() {
+		return env;
+	}
+
+	public void setEnv(String env) {
+		this.env = env;
+	}
+
+
+
+	private class CheckProjectDependencies extends IvyPostResolveTask {
+
+		@Override
+		public void doExecute() throws BuildException {
+			prepareAndCheck();
+		}
+
+		public boolean checkProjectDependencies() {
+			execute();
+			try {
+				ResolutionCacheManager cacheMgr = getIvyInstance()
+						.getResolutionCacheManager();
+				String[] confs = splitConfs(getConf());
+				String resolveId = getResolveId();
+				if (resolveId == null) {
+					resolveId = ResolveOptions
+							.getDefaultResolveId(getResolvedModuleId());
+				}
+				XmlReportParser parser = new XmlReportParser();
+				for (int i = 0; i < confs.length; i++) {
+					File report = cacheMgr
+							.getConfigurationResolveReportInCache(resolveId,
+									confs[i]);
+					parser.parse(report);
+
+					Artifact[] artifacts = parser.getArtifacts();
+					for (int j = 0; j < artifacts.length; j++) {
+						Artifact artifact = artifacts[j];
+						ModuleRevisionId mrid = artifact.getModuleRevisionId();
+						if (mrid.getOrganisation().equals(organisation)) {
+							if (mrid.getName().equals(module)) {
+								log(mrid.getOrganisation() + "#"
+										+ mrid.getName()
+										+ " found in project dependencies !",
+										Project.MSG_DEBUG);
+								// use this version
+								loadCachePath(mrid.getOrganisation(), mrid
+										.getName(), mrid.getRevision(), conf,
+										getProjectIvyReference());
+								return true;
+							} else {
+								// if only organization is found in project
+								// dependencies use the same version with the
+								// required module
+								log(
+										"Only organisation : "
+												+ mrid.getOrganisation()
+												+ " was found in project dependencies !",
+										Project.MSG_DEBUG);
+								loadCachePath(mrid.getOrganisation(), module,
+										mrid.getRevision(), conf,
+										getProjectIvyReference());
+								return true;
+
+							}
+						}
+
+					}
+				}
+			} catch (Exception ex) {
+				throw new BuildException(
+						"impossible to check project dependencies: " + ex, ex);
+			}
+			return false;
+		}
+
+	}
+
+}
Index: /trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
===================================================================
--- /trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java (revision 386)
+++ /trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java (revision 401)
@@ -363,12 +363,4 @@
 		}
 	}
-
-	private Task initTask(Task task) {
-		task.setLocation(getLocation());
-		task.setProject(getProject());
-		task.setTaskName(getTaskName());
-		task.setOwningTarget(getOwningTarget());
-		return task;
-	}
 	
 	/**
Index: /trunk/src/main/java/org/apache/easyant/tasks/EasyAntTask.java
===================================================================
--- /trunk/src/main/java/org/apache/easyant/tasks/EasyAntTask.java (revision 322)
+++ /trunk/src/main/java/org/apache/easyant/tasks/EasyAntTask.java (revision 401)
@@ -6,4 +6,5 @@
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Reference;
 
 /**
@@ -34,4 +35,26 @@
 		return getEasyAntIvyAntSettings().getConfiguredIvyInstance(this);
 	}
+	
+	/**
+	 * Utilitary method to configure a task with the current one
+	 * @param task task to configure
+	 * @return the configured task
+	 */
+	protected Task initTask(Task task) {
+		task.setLocation(getLocation());
+		task.setProject(getProject());
+		task.setTaskName(getTaskName());
+		task.setOwningTarget(getOwningTarget());
+		return task;
+	}
+
+	/**
+	 * Get a reference of the project ivy instance
+	 * @return a reference of the project ivy instance
+	 */
+	protected Reference getProjectIvyReference() {
+		return new Reference(getProject(), getProject().getProperty(
+				EasyAntMagicNames.PROJECT_IVY_INSTANCE));
+	}
 
 }
Index: /trunk/src/main/resources/org/apache/easyant/antlib.xml
===================================================================
--- /trunk/src/main/resources/org/apache/easyant/antlib.xml (revision 364)
+++ /trunk/src/main/resources/org/apache/easyant/antlib.xml (revision 401)
@@ -30,4 +30,5 @@
 	
 	<typedef name="configure-build-scoped-repository" classname="org.apache.easyant.tasks.ConfigureBuildScopedRepository"/> 
+	<typedef name="findclasspath" classname="org.apache.easyant.tasks.FindClasspath"/>
 
 	<presetdef name="include">
