You are viewing a plain text version of this content. The canonical link for it is here.
Posted to easyant-commits@incubator.apache.org by hi...@apache.org on 2011/02/22 15:56:09 UTC

svn commit: r1073371 [18/28] - in /incubator/easyant/core/trunk: ./ bin/ example/build-configurations/ example/build-configurations/src/main/java/org/apache/easyant/example/ example/build-configurations/src/test/java/org/apache/easyant/example/ example...

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java Tue Feb 22 15:55:55 2011
@@ -71,483 +71,483 @@ import org.apache.tools.ant.types.Path;
  */
 public class Import extends AbstractEasyAntTask implements DynamicAttribute {
 
-	private String module;
-	private String organisation;
-	private String revision;
-
-	private String mrid;
-
-	private String file;
-	private String settingsRef;
-
-	private String as;
-	private String mode;
-	private boolean mandatory;
-	private String buildConfigurations;
-
-	private String mainConf = "default";
-	private String providedConf = "provided";
-
-	/**
-	 * Get the module name to import
-	 * 
-	 * @return the module name
-	 */
-	public String getModule() {
-		return module;
-	}
-
-	/**
-	 * Set the module name to import
-	 * 
-	 * @param module
-	 *            the module name
-	 */
-	public void setModule(String module) {
-		this.module = module;
-	}
-
-	/**
-	 * Get the organisation of the module to import
-	 * 
-	 * @return the organisation name
-	 */
-	public String getOrganisation() {
-		return organisation;
-	}
-
-	/**
-	 * Set the organisation of the module to import
-	 * 
-	 * @param organisation
-	 *            the organisation name
-	 */
-	public void setOrganisation(String organisation) {
-		this.organisation = organisation;
-	}
-
-	/**
-	 * Set the organisation of the module to import
-	 * 
-	 * @param organisation
-	 *            the organisation name
-	 */
-	public void setOrg(String org) {
-		this.organisation = org;
-	}
-
-	/**
-	 * Get the revision of the module to import
-	 * 
-	 * @return the revision
-	 */
-	public String getRevision() {
-		return revision;
-	}
-
-	/**
-	 * Set th revision of the module to import
-	 * 
-	 * @param revision
-	 *            the revision
-	 */
-	public void setRevision(String revision) {
-		this.revision = revision;
-	}
-
-	/**
-	 * Set th revision of the module to import
-	 * 
-	 * @param revision
-	 *            the revision
-	 */
-	public void setRev(String rev) {
-		this.revision = rev;
-	}
-
-	/**
-	 * Get the full mrid of the module to import
-	 * 
-	 * @return the mrid to import
-	 */
-	public String getMrid() {
-		return mrid;
-	}
-
-	/**
-	 * Set the full mrid of the module to import
-	 * 
-	 * @param mrid
-	 *            the mrid to import
-	 */
-	public void setMrid(String mrid) {
-		this.mrid = mrid;
-	}
-
-	/**
-	 * Get the alias name
-	 * 
-	 * @return a string that represents the alias name
-	 */
-	public String getAs() {
-		return as;
-	}
-
-	/**
-	 * Set the alias name
-	 * 
-	 * @param as
-	 *            a string that represents the alias name
-	 */
-	public void setAs(String as) {
-		this.as = as;
-	}
-
-	/**
-	 * Get the import mode
-	 * 
-	 * @return a string that represents the import mode (e.g. import / include)
-	 */
-	public String getMode() {
-		return mode;
-	}
-
-	/**
-	 * Set the import mode
-	 * 
-	 * @param mode
-	 *            a string that represents the import mode (e.g. import /
-	 *            include)
-	 */
-	public void setMode(String mode) {
-		this.mode = mode;
-	}
-
-	public String getBuildConfigurations() {
-		return buildConfigurations;
-	}
-
-	public void setBuildConfigurations(String conf) {
-		this.buildConfigurations = conf;
-	}
-
-	public void setConf(String conf) {
-		this.buildConfigurations = conf;
-	}
-
-	public String getFile() {
-		return file;
-	}
-
-	/**
-	 * Set the filesystem location of the module descriptor to load. This is an
-	 * alternative to specifying a repository location using
-	 * {@link #setMrid(String)} or {@link #setModule(String)}
-	 */
-	public void setFile(String file) {
-		this.file = file;
-	}
-
-	public String getSettingsRef() {
-		return settingsRef;
-	}
-
-	/**
-	 * Optionally specify the Ivy settings instance used to resolve module
-	 * dependencies and publications. If unspecified, the EasyAnt Ivy settings
-	 * are used.
-	 */
-	public void setSettingsRef(String settingsRef) {
-		this.settingsRef = settingsRef;
-	}
-
-	/**
-	 * Get the main configuration where plugin are resolved
-	 * 
-	 * @return a string representing the main configuration
-	 */
-	public String getMainConf() {
-		return mainConf;
-	}
-
-	/**
-	 * Set the main configuration where plugin are resolved
-	 * 
-	 * @param mainConf
-	 *            a string representing the main configuration
-	 */
-	public void setMainConf(String mainConf) {
-		this.mainConf = mainConf;
-	}
-
-	/**
-	 * Get the configuration that may contain dependency on easyant-core. This
-	 * configuration is used to check core compliance at resolve time. It should
-	 * not affect the plugin classpath
-	 * 
-	 * @return provided configuration
-	 */
-	public String getProvidedConf() {
-		return providedConf;
-	}
-
-	/**
-	 * Set the configuration that may contain dependency on easyant-core. This
-	 * configuration is used to check core compliance at resolve time. It should
-	 * not affect the plugin classpath
-	 * 
-	 * @return provided configuration
-	 */
-	public void setProvidedConf(String providedConf) {
-		this.providedConf = providedConf;
-	}
-
-	/**
-	 * Get resolve log settings
-	 * 
-	 * @return a string representing the log strategy
-	 */
-	public String getResolveLog() {
-		String downloadLog = getProject().getProperty(
-				EasyAntMagicNames.MODULE_DOWNLOAD_LOG);
-		return downloadLog != null ? downloadLog : LogOptions.LOG_DOWNLOAD_ONLY;
-	}
-
-	public void execute() throws BuildException {
-
-		ImportStrategy strategy = null;
-		if (mrid != null) {
-			strategy = new RepositoryImportStrategy(ModuleRevisionId
-					.parse(mrid));
-		} else if (organisation != null && module != null && revision != null) {
-			strategy = new RepositoryImportStrategy(ModuleRevisionId
-					.newInstance(organisation, module, revision));
-		} else if (file != null) {
-			strategy = new FileImportStrategy(new File(file));
-		} else {
-
-			throw new BuildException(
-					"You must specify exactly ONE of:  mrid, organisation + module + revision, or file");
-		}
-		String moduleName = strategy.getModuleName();
-		if (!BuildConfigurationHelper.isBuildConfigurationActive(
-				getBuildConfigurations(), getProject(), "module" + getModule())) {
-			log("no matching build configuration for module " + moduleName
-					+ " this module will be skipped ", Project.MSG_DEBUG);
-			return;
-		}
-		
-		//if no as attribute was given use module name
-		if (as==null && "include".equals(getMode())) {
-			//when using mrid style
-			if (mrid!=null) {
-				ModuleRevisionId moduleRevisionId=ModuleRevisionId.parse(mrid);
-				as = moduleRevisionId.getName();
-			//when using exploded style
-			} else if (getModule() != null) {
-				as=getModule();
-			}
-		}
-		
-		// check if a property skip.${module} or skip.${as} is set
-		boolean toBeSkipped = strategy.isSkipped()
-				|| getProject().getProperty("skip." + getAs()) != null;
-
-		if (mandatory && toBeSkipped) {
-			log("Impossible to skip a mandatory module : " + moduleName,
-					Project.MSG_WARN);
-		}
-
-		// a module can be skipped *only* if it is not mandatory
-		if (!mandatory && toBeSkipped) {
-			log(moduleName + " skipped !");
-		} else {
-			try {
-				ResolveOptions resolveOptions = new ResolveOptions();
-				// TODO: This should be configurable
-
-				resolveOptions.setLog(getResolveLog());
-
-				Boolean offline = Boolean.valueOf(getProject().getProperty(EasyAntMagicNames.EASYANT_OFFLINE));
-				resolveOptions.setUseCacheOnly(offline);
-
-				// Here we do not specify explicit configuration to resolve as
-				// we want to check multiple configurations.
-				// If we make specify explicitly configurations to resolve, the
-				// resolution could through exceptions when configuration does
-				// not exist in resolved modules.
-				// resolveOptions.setConfs(new String[] { mainConf,providedConf });
-				
-				// By default we consider that main conf is default.
-				// To verify core compliance we can have a dependency on
-				// easyant-core in a specific configuration.
-				// By default this configuration is provided.
-				
-				// An error can be thrown if module contains non-public configurations.
-				ResolveReport report = strategy.resolveModule(resolveOptions);
-				// Check dependency on core
-				checkCoreCompliance(report, providedConf);
-
-				ModuleRevisionId moduleRevisionId = strategy
-						.getModuleRevisionId(report);
-
-				Path path = new Path(getProject());
-				getProject().addReference(
-						moduleRevisionId.getModuleId().toString()
-								+ ".classpath", path);
-				File antFile = strategy.findAntScript(mainConf, report);
-				for (int j = 0; j < report.getConfigurationReport(mainConf)
-						.getAllArtifactsReports().length; j++) {
-					ArtifactDownloadReport artifact = report
-							.getConfigurationReport(mainConf)
-							.getAllArtifactsReports()[j];
-
-					if ("jar".equals(artifact.getType())) {
-						path.createPathElement().setLocation(
-								artifact.getLocalFile());
-					} else {
-						StringBuilder sb = new StringBuilder();
-						sb.append(moduleRevisionId.getOrganisation());
-						sb.append("#");
-						sb.append(moduleRevisionId.getName());
-						sb.append(".");
-						if (!moduleRevisionId.getName().equals(
-								artifact.getName())) {
-							sb.append(artifact.getName());
-							sb.append(".");
-						}
-						sb.append(artifact.getExt());
-						sb.append(".file");
-						getProject().setNewProperty(sb.toString(),
-								artifact.getLocalFile().getAbsolutePath());
-					}
-				}
-				if (antFile != null && antFile.exists()) {
-					ImportTask importTask = new ImportTask();
-					importTask.setProject(getProject());
-					importTask.setTaskName(getTaskName());
-					importTask.setOwningTarget(getOwningTarget());
-					importTask.setLocation(getLocation());
-					importTask.setFile(antFile.getAbsolutePath());
-					if (as != null) {
-						importTask.setAs(as);
-						importTask.setPrefixSeparator("");
-					}
-					if (mode != null && "include".equals(mode)) {
-						importTask.setTaskType(getMode());
-					}
-					importTask.execute();
-				}
-
-			} catch (Exception e) {
-				throw new BuildException(e);
-			}
-
-		}
-	}
-
-	/**
-	 * Check dependency on easyant core with a given configuration. If
-	 * dependency is found we'll check compliance with current core version. It
-	 * uses {@link CoreRevisionCheckerTask} internally.
-	 * 
-	 * @param report
-	 *            a {@link ResolveReport}
-	 * @param confToCheck
-	 *            configuration to check
-	 */
-	private void checkCoreCompliance(ResolveReport report, String confToCheck) {
-		if (report.getConfigurationReport(confToCheck) != null) {
-			log("checking module's provided dependencies ...",
-					Project.MSG_DEBUG);
-			for (Iterator iterator = report.getConfigurationReport(confToCheck)
-					.getModuleRevisionIds().iterator(); iterator.hasNext();) {
-				ModuleRevisionId currentmrid = (ModuleRevisionId) iterator
-						.next();
-				log("checking " + currentmrid.toString(), Project.MSG_DEBUG);
-				if (currentmrid.getOrganisation().equals("org.apache.easyant")
-						&& currentmrid.getName().equals("easyant-core")) {
-					CoreRevisionCheckerTask checker = new CoreRevisionCheckerTask();
-					checker.setRequiredRevision(currentmrid.getRevision());
-					initTask(checker).execute();
-				}
-			}
-		}
-	}
-
-	/**
-	 * Can we skip the load of this module?
-	 * 
-	 * @param mandatory
-	 *            true if the module can't be skipped
-	 */
-	public void setMandatory(boolean mandatory) {
-		this.mandatory = mandatory;
-
-	}
-
-	/**
-	 * Get the Ivy instance used to load the module artifacts.
-	 * 
-	 * @see #setSettingsRef(String)
-	 */
-	private Ivy getIvyInstance() {
-		if (settingsRef != null) {
-			IvyAntSettings settings = IvyInstanceHelper.getIvyAntSettings(getProject(),settingsRef);
-			if (settings == null) {
-				throw new BuildException("Unable to find Ivy settings named '"
-						+ settingsRef + "'");
-			}
-			return settings.getConfiguredIvyInstance(this);
-		} else {
-			return getEasyAntIvyInstance();
-		}
-	}
-
-	/**
-	 * Abstracts the mechanism used to locate a single module Ivy descriptor and
-	 * its artifacts.
-	 */
-	private static interface ImportStrategy {
-
-		/**
-		 * Resolve the module using the given resolution options.
-		 */
-		public ResolveReport resolveModule(ResolveOptions options)
-				throws ParseException, IOException;
-
-		public ModuleRevisionId getModuleRevisionId(ResolveReport report);
-
-		public File findAntScript(String conf, ResolveReport report);
-
-		/**
-		 * Get this module's name, for logging purposes.
-		 */
-		public String getModuleName();
-
-		/**
-		 * @return true if this module should not be imported.
-		 */
-		public boolean isSkipped();
-
-	}
-
-	/**
-	 * Load the requested module and its artifacts from an Ivy repository.
-	 */
-	private class RepositoryImportStrategy implements ImportStrategy {
-		private ModuleRevisionId mrid;
-
-		protected RepositoryImportStrategy(ModuleRevisionId mrid) {
-			this.mrid = mrid;
-		}
-
-		public ModuleRevisionId getModuleRevisionId(ResolveReport report) {
-			return mrid;
-		}
+    private String module;
+    private String organisation;
+    private String revision;
+
+    private String mrid;
+
+    private String file;
+    private String settingsRef;
+
+    private String as;
+    private String mode;
+    private boolean mandatory;
+    private String buildConfigurations;
+
+    private String mainConf = "default";
+    private String providedConf = "provided";
+
+    /**
+     * Get the module name to import
+     * 
+     * @return the module name
+     */
+    public String getModule() {
+        return module;
+    }
+
+    /**
+     * Set the module name to import
+     * 
+     * @param module
+     *            the module name
+     */
+    public void setModule(String module) {
+        this.module = module;
+    }
+
+    /**
+     * Get the organisation of the module to import
+     * 
+     * @return the organisation name
+     */
+    public String getOrganisation() {
+        return organisation;
+    }
+
+    /**
+     * Set the organisation of the module to import
+     * 
+     * @param organisation
+     *            the organisation name
+     */
+    public void setOrganisation(String organisation) {
+        this.organisation = organisation;
+    }
+
+    /**
+     * Set the organisation of the module to import
+     * 
+     * @param organisation
+     *            the organisation name
+     */
+    public void setOrg(String org) {
+        this.organisation = org;
+    }
+
+    /**
+     * Get the revision of the module to import
+     * 
+     * @return the revision
+     */
+    public String getRevision() {
+        return revision;
+    }
+
+    /**
+     * Set th revision of the module to import
+     * 
+     * @param revision
+     *            the revision
+     */
+    public void setRevision(String revision) {
+        this.revision = revision;
+    }
+
+    /**
+     * Set th revision of the module to import
+     * 
+     * @param revision
+     *            the revision
+     */
+    public void setRev(String rev) {
+        this.revision = rev;
+    }
+
+    /**
+     * Get the full mrid of the module to import
+     * 
+     * @return the mrid to import
+     */
+    public String getMrid() {
+        return mrid;
+    }
+
+    /**
+     * Set the full mrid of the module to import
+     * 
+     * @param mrid
+     *            the mrid to import
+     */
+    public void setMrid(String mrid) {
+        this.mrid = mrid;
+    }
+
+    /**
+     * Get the alias name
+     * 
+     * @return a string that represents the alias name
+     */
+    public String getAs() {
+        return as;
+    }
+
+    /**
+     * Set the alias name
+     * 
+     * @param as
+     *            a string that represents the alias name
+     */
+    public void setAs(String as) {
+        this.as = as;
+    }
+
+    /**
+     * Get the import mode
+     * 
+     * @return a string that represents the import mode (e.g. import / include)
+     */
+    public String getMode() {
+        return mode;
+    }
+
+    /**
+     * Set the import mode
+     * 
+     * @param mode
+     *            a string that represents the import mode (e.g. import /
+     *            include)
+     */
+    public void setMode(String mode) {
+        this.mode = mode;
+    }
+
+    public String getBuildConfigurations() {
+        return buildConfigurations;
+    }
+
+    public void setBuildConfigurations(String conf) {
+        this.buildConfigurations = conf;
+    }
+
+    public void setConf(String conf) {
+        this.buildConfigurations = conf;
+    }
+
+    public String getFile() {
+        return file;
+    }
+
+    /**
+     * Set the filesystem location of the module descriptor to load. This is an
+     * alternative to specifying a repository location using
+     * {@link #setMrid(String)} or {@link #setModule(String)}
+     */
+    public void setFile(String file) {
+        this.file = file;
+    }
+
+    public String getSettingsRef() {
+        return settingsRef;
+    }
+
+    /**
+     * Optionally specify the Ivy settings instance used to resolve module
+     * dependencies and publications. If unspecified, the EasyAnt Ivy settings
+     * are used.
+     */
+    public void setSettingsRef(String settingsRef) {
+        this.settingsRef = settingsRef;
+    }
+
+    /**
+     * Get the main configuration where plugin are resolved
+     * 
+     * @return a string representing the main configuration
+     */
+    public String getMainConf() {
+        return mainConf;
+    }
+
+    /**
+     * Set the main configuration where plugin are resolved
+     * 
+     * @param mainConf
+     *            a string representing the main configuration
+     */
+    public void setMainConf(String mainConf) {
+        this.mainConf = mainConf;
+    }
+
+    /**
+     * Get the configuration that may contain dependency on easyant-core. This
+     * configuration is used to check core compliance at resolve time. It should
+     * not affect the plugin classpath
+     * 
+     * @return provided configuration
+     */
+    public String getProvidedConf() {
+        return providedConf;
+    }
+
+    /**
+     * Set the configuration that may contain dependency on easyant-core. This
+     * configuration is used to check core compliance at resolve time. It should
+     * not affect the plugin classpath
+     * 
+     * @return provided configuration
+     */
+    public void setProvidedConf(String providedConf) {
+        this.providedConf = providedConf;
+    }
+
+    /**
+     * Get resolve log settings
+     * 
+     * @return a string representing the log strategy
+     */
+    public String getResolveLog() {
+        String downloadLog = getProject().getProperty(
+                EasyAntMagicNames.MODULE_DOWNLOAD_LOG);
+        return downloadLog != null ? downloadLog : LogOptions.LOG_DOWNLOAD_ONLY;
+    }
+
+    public void execute() throws BuildException {
+
+        ImportStrategy strategy = null;
+        if (mrid != null) {
+            strategy = new RepositoryImportStrategy(ModuleRevisionId
+                    .parse(mrid));
+        } else if (organisation != null && module != null && revision != null) {
+            strategy = new RepositoryImportStrategy(ModuleRevisionId
+                    .newInstance(organisation, module, revision));
+        } else if (file != null) {
+            strategy = new FileImportStrategy(new File(file));
+        } else {
+
+            throw new BuildException(
+                    "You must specify exactly ONE of:  mrid, organisation + module + revision, or file");
+        }
+        String moduleName = strategy.getModuleName();
+        if (!BuildConfigurationHelper.isBuildConfigurationActive(
+                getBuildConfigurations(), getProject(), "module" + getModule())) {
+            log("no matching build configuration for module " + moduleName
+                    + " this module will be skipped ", Project.MSG_DEBUG);
+            return;
+        }
+        
+        //if no as attribute was given use module name
+        if (as==null && "include".equals(getMode())) {
+            //when using mrid style
+            if (mrid!=null) {
+                ModuleRevisionId moduleRevisionId=ModuleRevisionId.parse(mrid);
+                as = moduleRevisionId.getName();
+            //when using exploded style
+            } else if (getModule() != null) {
+                as=getModule();
+            }
+        }
+        
+        // check if a property skip.${module} or skip.${as} is set
+        boolean toBeSkipped = strategy.isSkipped()
+                || getProject().getProperty("skip." + getAs()) != null;
+
+        if (mandatory && toBeSkipped) {
+            log("Impossible to skip a mandatory module : " + moduleName,
+                    Project.MSG_WARN);
+        }
+
+        // a module can be skipped *only* if it is not mandatory
+        if (!mandatory && toBeSkipped) {
+            log(moduleName + " skipped !");
+        } else {
+            try {
+                ResolveOptions resolveOptions = new ResolveOptions();
+                // TODO: This should be configurable
+
+                resolveOptions.setLog(getResolveLog());
+
+                Boolean offline = Boolean.valueOf(getProject().getProperty(EasyAntMagicNames.EASYANT_OFFLINE));
+                resolveOptions.setUseCacheOnly(offline);
+
+                // Here we do not specify explicit configuration to resolve as
+                // we want to check multiple configurations.
+                // If we make specify explicitly configurations to resolve, the
+                // resolution could through exceptions when configuration does
+                // not exist in resolved modules.
+                // resolveOptions.setConfs(new String[] { mainConf,providedConf });
+                
+                // By default we consider that main conf is default.
+                // To verify core compliance we can have a dependency on
+                // easyant-core in a specific configuration.
+                // By default this configuration is provided.
+                
+                // An error can be thrown if module contains non-public configurations.
+                ResolveReport report = strategy.resolveModule(resolveOptions);
+                // Check dependency on core
+                checkCoreCompliance(report, providedConf);
+
+                ModuleRevisionId moduleRevisionId = strategy
+                        .getModuleRevisionId(report);
+
+                Path path = new Path(getProject());
+                getProject().addReference(
+                        moduleRevisionId.getModuleId().toString()
+                                + ".classpath", path);
+                File antFile = strategy.findAntScript(mainConf, report);
+                for (int j = 0; j < report.getConfigurationReport(mainConf)
+                        .getAllArtifactsReports().length; j++) {
+                    ArtifactDownloadReport artifact = report
+                            .getConfigurationReport(mainConf)
+                            .getAllArtifactsReports()[j];
+
+                    if ("jar".equals(artifact.getType())) {
+                        path.createPathElement().setLocation(
+                                artifact.getLocalFile());
+                    } else {
+                        StringBuilder sb = new StringBuilder();
+                        sb.append(moduleRevisionId.getOrganisation());
+                        sb.append("#");
+                        sb.append(moduleRevisionId.getName());
+                        sb.append(".");
+                        if (!moduleRevisionId.getName().equals(
+                                artifact.getName())) {
+                            sb.append(artifact.getName());
+                            sb.append(".");
+                        }
+                        sb.append(artifact.getExt());
+                        sb.append(".file");
+                        getProject().setNewProperty(sb.toString(),
+                                artifact.getLocalFile().getAbsolutePath());
+                    }
+                }
+                if (antFile != null && antFile.exists()) {
+                    ImportTask importTask = new ImportTask();
+                    importTask.setProject(getProject());
+                    importTask.setTaskName(getTaskName());
+                    importTask.setOwningTarget(getOwningTarget());
+                    importTask.setLocation(getLocation());
+                    importTask.setFile(antFile.getAbsolutePath());
+                    if (as != null) {
+                        importTask.setAs(as);
+                        importTask.setPrefixSeparator("");
+                    }
+                    if (mode != null && "include".equals(mode)) {
+                        importTask.setTaskType(getMode());
+                    }
+                    importTask.execute();
+                }
+
+            } catch (Exception e) {
+                throw new BuildException(e);
+            }
+
+        }
+    }
 
-		public ResolveReport resolveModule(ResolveOptions options)
-				throws ParseException, IOException {
+    /**
+     * Check dependency on easyant core with a given configuration. If
+     * dependency is found we'll check compliance with current core version. It
+     * uses {@link CoreRevisionCheckerTask} internally.
+     * 
+     * @param report
+     *            a {@link ResolveReport}
+     * @param confToCheck
+     *            configuration to check
+     */
+    private void checkCoreCompliance(ResolveReport report, String confToCheck) {
+        if (report.getConfigurationReport(confToCheck) != null) {
+            log("checking module's provided dependencies ...",
+                    Project.MSG_DEBUG);
+            for (Iterator iterator = report.getConfigurationReport(confToCheck)
+                    .getModuleRevisionIds().iterator(); iterator.hasNext();) {
+                ModuleRevisionId currentmrid = (ModuleRevisionId) iterator
+                        .next();
+                log("checking " + currentmrid.toString(), Project.MSG_DEBUG);
+                if (currentmrid.getOrganisation().equals("org.apache.easyant")
+                        && currentmrid.getName().equals("easyant-core")) {
+                    CoreRevisionCheckerTask checker = new CoreRevisionCheckerTask();
+                    checker.setRequiredRevision(currentmrid.getRevision());
+                    initTask(checker).execute();
+                }
+            }
+        }
+    }
+
+    /**
+     * Can we skip the load of this module?
+     * 
+     * @param mandatory
+     *            true if the module can't be skipped
+     */
+    public void setMandatory(boolean mandatory) {
+        this.mandatory = mandatory;
+
+    }
+
+    /**
+     * Get the Ivy instance used to load the module artifacts.
+     * 
+     * @see #setSettingsRef(String)
+     */
+    private Ivy getIvyInstance() {
+        if (settingsRef != null) {
+            IvyAntSettings settings = IvyInstanceHelper.getIvyAntSettings(getProject(),settingsRef);
+            if (settings == null) {
+                throw new BuildException("Unable to find Ivy settings named '"
+                        + settingsRef + "'");
+            }
+            return settings.getConfiguredIvyInstance(this);
+        } else {
+            return getEasyAntIvyInstance();
+        }
+    }
+
+    /**
+     * Abstracts the mechanism used to locate a single module Ivy descriptor and
+     * its artifacts.
+     */
+    private static interface ImportStrategy {
+
+        /**
+         * Resolve the module using the given resolution options.
+         */
+        public ResolveReport resolveModule(ResolveOptions options)
+                throws ParseException, IOException;
+
+        public ModuleRevisionId getModuleRevisionId(ResolveReport report);
+
+        public File findAntScript(String conf, ResolveReport report);
+
+        /**
+         * Get this module's name, for logging purposes.
+         */
+        public String getModuleName();
+
+        /**
+         * @return true if this module should not be imported.
+         */
+        public boolean isSkipped();
+
+    }
+
+    /**
+     * Load the requested module and its artifacts from an Ivy repository.
+     */
+    private class RepositoryImportStrategy implements ImportStrategy {
+        private ModuleRevisionId mrid;
+
+        protected RepositoryImportStrategy(ModuleRevisionId mrid) {
+            this.mrid = mrid;
+        }
+
+        public ModuleRevisionId getModuleRevisionId(ResolveReport report) {
+            return mrid;
+        }
+
+        public ResolveReport resolveModule(ResolveOptions options)
+                throws ParseException, IOException {
             Ivy ivy = getIvyInstance();
             ivy.pushContext();
             try {
@@ -555,87 +555,87 @@ public class Import extends AbstractEasy
             } finally {
                 ivy.popContext();
             }
-		}
+        }
+
+        public String getModuleName() {
+            return mrid.toString();
+        }
+
+        public boolean isSkipped() {
+            return getProject().getProperty("skip." + getModuleName()) != null;
+        }
+
+        public File findAntScript(String conf, ResolveReport report) {
+            for (int j = 0; j < report.getConfigurationReport(conf)
+                    .getAllArtifactsReports().length; j++) {
+                ArtifactDownloadReport artifact = report
+                        .getConfigurationReport(conf).getAllArtifactsReports()[j];
+
+                if ("ant".equals(artifact.getType())
+                        && "ant".equals(artifact.getExt())) {
+                    return artifact.getLocalFile();
+                }
+            }
+            return null;
+        }
+    }
+
+    /**
+     * Load the requested module and its artifacts directly from the filesystem.
+     */
+    private class FileImportStrategy implements ImportStrategy {
+        private File descriptorFile;
+
+        private FileImportStrategy(File descriptorFile) {
+            this.descriptorFile = descriptorFile;
+        }
+
+        public ModuleRevisionId getModuleRevisionId(ResolveReport report) {
+            return report.getModuleDescriptor().getModuleRevisionId();
+        }
+
+        public ResolveReport resolveModule(ResolveOptions options)
+                throws ParseException, IOException {
+            return getIvyInstance().getResolveEngine().resolve(
+                    descriptorFile.toURL(), options);
+        }
+
+        public String getModuleName() {
+            return descriptorFile.getAbsolutePath();
+        }
+
+        public boolean isSkipped() {
+            return false;
+        }
+
+        public File findAntScript(String conf, ResolveReport report) {
+            ModuleDescriptor descriptor = report.getModuleDescriptor();
+            Artifact[] artifacts = descriptor.getArtifacts(conf);
+            for (int i = 0; i < artifacts.length; ++i) {
+                Artifact artifact = artifacts[i];
+                if ("ant".equals(artifact.getType())
+                        && "ant".equals(artifact.getExt())) {
+                    File file = getLocalArtifact(artifact.getName(), artifact
+                            .getExt());
+                    if (file.isFile()) {
+                        return file;
+                    }
+                }
+            }
+            return null;
+        }
 
-		public String getModuleName() {
-			return mrid.toString();
-		}
-
-		public boolean isSkipped() {
-			return getProject().getProperty("skip." + getModuleName()) != null;
-		}
-
-		public File findAntScript(String conf, ResolveReport report) {
-			for (int j = 0; j < report.getConfigurationReport(conf)
-					.getAllArtifactsReports().length; j++) {
-				ArtifactDownloadReport artifact = report
-						.getConfigurationReport(conf).getAllArtifactsReports()[j];
-
-				if ("ant".equals(artifact.getType())
-						&& "ant".equals(artifact.getExt())) {
-					return artifact.getLocalFile();
-				}
-			}
-			return null;
-		}
-	}
-
-	/**
-	 * Load the requested module and its artifacts directly from the filesystem.
-	 */
-	private class FileImportStrategy implements ImportStrategy {
-		private File descriptorFile;
-
-		private FileImportStrategy(File descriptorFile) {
-			this.descriptorFile = descriptorFile;
-		}
-
-		public ModuleRevisionId getModuleRevisionId(ResolveReport report) {
-			return report.getModuleDescriptor().getModuleRevisionId();
-		}
-
-		public ResolveReport resolveModule(ResolveOptions options)
-				throws ParseException, IOException {
-			return getIvyInstance().getResolveEngine().resolve(
-					descriptorFile.toURL(), options);
-		}
-
-		public String getModuleName() {
-			return descriptorFile.getAbsolutePath();
-		}
-
-		public boolean isSkipped() {
-			return false;
-		}
-
-		public File findAntScript(String conf, ResolveReport report) {
-			ModuleDescriptor descriptor = report.getModuleDescriptor();
-			Artifact[] artifacts = descriptor.getArtifacts(conf);
-			for (int i = 0; i < artifacts.length; ++i) {
-				Artifact artifact = artifacts[i];
-				if ("ant".equals(artifact.getType())
-						&& "ant".equals(artifact.getExt())) {
-					File file = getLocalArtifact(artifact.getName(), artifact
-							.getExt());
-					if (file.isFile()) {
-						return file;
-					}
-				}
-			}
-			return null;
-		}
-
-		private File getLocalArtifact(String name, String ext) {
-			return new File(descriptorFile.getParentFile(), name + "." + ext);
-		}
-	}
-
-	@Override
-	public void setDynamicAttribute(String attributeName, String value)
-			throws BuildException {
-		PropertyTask property = new PropertyTask();
-		property.setName(attributeName);
-		property.setValue(value);
-		initTask(property).execute();
-	}
+        private File getLocalArtifact(String name, String ext) {
+            return new File(descriptorFile.getParentFile(), name + "." + ext);
+        }
+    }
+
+    @Override
+    public void setDynamicAttribute(String attributeName, String value)
+            throws BuildException {
+        PropertyTask property = new PropertyTask();
+        property.setName(attributeName);
+        property.setValue(value);
+        initTask(property).execute();
+    }
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java Tue Feb 22 15:55:55 2011
@@ -61,479 +61,479 @@ import org.apache.tools.ant.taskdefs.Imp
  */
 public class LoadModule extends AbstractEasyAntTask {
 
-	private File buildFile;
-	private File buildModule;
-	private String easyAntMDParserClassName;
-	private Boolean useBuildRepository;
-
-	/**
-	 * Get the file name that will be loaded
-	 * 
-	 * @return a file that represents a module descriptor
-	 */
-	public File getBuildModule() {
-		return buildModule;
-	}
-
-	/**
-	 * set the file name that will be loaded
-	 * 
-	 * @param file
-	 *            represents a module descriptor
-	 */
-	public void setBuildModule(File file) {
-		this.buildModule = file;
-	}
-
-	public File getBuildFile() {
-		return buildFile;
-	}
-
-	public void setBuildFile(File buildFile) {
-		this.buildFile = buildFile;
-	}
-
-	public void setUseBuildRepository(boolean value) {
-		this.useBuildRepository = value;
-	}
-
-	/**
-	 * Set the classname of the easyant parser you want to use
-	 * 
-	 * @param easyAntMDParserClassName
-	 */
-	public void setEasyAntMDParserClassName(String easyAntMDParserClassName) {
-		this.easyAntMDParserClassName = easyAntMDParserClassName;
-	}
-
-	public void execute() throws BuildException {
-		if (buildModule != null && buildModule.exists()) {
-			IvyInfo info = new IvyInfo();
-			info.setFile(buildModule);
-			// Not sure we should bound IvyInfo to easyantIvyInstance
-			info.setSettingsRef(IvyInstanceHelper
-					.buildEasyAntIvyReference(getProject()));
-			initTask(info).execute();
-			getProject().setName(getProject().getProperty("ivy.module"));
-		}
-		if (buildModule != null && buildModule.exists()) {
-			// make sure it's not a directory (this falls into the ultra
-			// paranoid lets check everything category
-
-			if (buildModule.isDirectory()) {
-				System.out.println("What? buildModule: " + buildModule
-						+ " is a dir!");
-				throw new BuildException("Build failed");
-			}
-			// load override buildFile before buildModule to allow target/phase
-			// override
-			File f = new File(buildModule.getParent(),
-					EasyAntConstants.DEFAULT_OVERRIDE_BUILD_FILE);
-			if (f.exists()) {
-				log("Loading override build file : "
-						+ buildFile.getAbsolutePath());
-				loadBuildFile(f);
-			}
-
-			log("Loading build module : " + buildModule.getAbsolutePath());
-			loadBuildModule(buildModule);
-		}
-
-		// load buildFile before buildModule to allow target/phase override
-		if (buildFile != null && buildFile.exists()) {
-			// make sure it's not a directory (this falls into the ultra
-			// paranoid lets check everything category
-
-			if (buildFile.isDirectory()) {
-				System.out.println("What? buildFile: " + buildFile
-						+ " is a dir!");
-				throw new BuildException("Build failed");
-			}
-
-			log("Loading build file : " + buildFile.getAbsolutePath());
-			loadBuildFile(buildFile);
-		}
-
-		String projectIvyInstanceProp = IvyInstanceHelper
-				.getProjectIvyInstanceName(getProject());
-
-		// create project ivy instance except if project ivy instance is linked
-		// to easyant ivy instance
-		if (!EasyAntMagicNames.EASYANT_IVY_INSTANCE
-				.equals(projectIvyInstanceProp)) {
-			configureProjectIvyinstance(projectIvyInstanceProp);
-
-		}
-
-		if (shouldUseBuildRepository()) {
-			configureBuildRepository(IvyInstanceHelper
-					.getProjectIvyAntSettings(getProject()));
-		}
-
-		if (getProject().getDefaultTarget() == null
-				&& getProject().getTargets().containsKey(
-						EasyAntConstants.DEFAULT_TARGET)) {
-			getProject().setDefault(EasyAntConstants.DEFAULT_TARGET);
-		}
-	}
-
-	/**
-	 * 
-	 */
-	private void configureProjectIvyinstance(String projectIvyInstanceName) {
-		IvyConfigure projectIvyInstance = new IvyConfigure();
-		projectIvyInstance.setSettingsId(projectIvyInstanceName);
-		if (getProject()
-				.getProperty(EasyAntMagicNames.PROJECT_IVY_SETTING_FILE) != null) {
-			File projectIvyFile = new File(getProject().getProperty(
-					EasyAntMagicNames.PROJECT_IVY_SETTING_FILE));
-			projectIvyInstance.setFile(projectIvyFile);
-		}
-		if (getProject().getProperty(EasyAntMagicNames.PROJECT_IVY_SETTING_URL) != null) {
-			String url = getProject().getProperty(
-					EasyAntMagicNames.PROJECT_IVY_SETTING_URL);
-			try {
-				projectIvyInstance.setUrl(url);
-			} catch (MalformedURLException malformedUrl) {
-				throw new BuildException(
-						"Unable to parse project ivysettings from the following url : "
-								+ url, malformedUrl);
-			}
-		}
-		String defaultUrl = this.getClass().getResource(
-				"/org/apache/easyant/core/default-project-ivysettings.xml")
-				.toExternalForm();
-		getProject().setNewProperty(
-				EasyAntMagicNames.PROJECT_DEFAULT_IVYSETTINGS, defaultUrl);
-		if (getProject()
-				.getProperty(EasyAntMagicNames.PROJECT_IVY_SETTING_FILE) == null
-				&& getProject().getProperty(
-						EasyAntMagicNames.PROJECT_IVY_SETTING_URL) == null) {
-			File localSettings = new File(buildModule.getParent(),
-					"ivysettings.xml");
-			if (localSettings.exists()) {
-				getProject().log("loading local project settings file...",
-						Project.MSG_VERBOSE);
-				projectIvyInstance.setFile(localSettings);
-				getProject().setNewProperty(
-						EasyAntMagicNames.PROJECT_IVY_SETTING_FILE,
-						localSettings.getAbsolutePath());
-
-			} else {
-				getProject().log("no settings file found, using default...",
-						Project.MSG_VERBOSE);
-				getProject().setNewProperty(
-						EasyAntMagicNames.PROJECT_IVY_SETTING_URL,
-						defaultUrl.toString());
-				try {
-					projectIvyInstance.setUrl(defaultUrl);
-				} catch (MalformedURLException e) {
-					throw new BuildException(
-							"Unable to parse project ivysettings from the following url : "
-									+ defaultUrl, e);
-				}
-			}
-		}
-		initTask(projectIvyInstance).execute();
-	}
-
-	protected void loadBuildFile(File buildModule) {
-		ImportTask importTask = new ImportTask();
-		importTask.setFile(buildModule.getAbsolutePath());
-		importTask.setOptional(true);
-		initTask(importTask).execute();
-	}
-
-	protected void loadBuildModule(File buildModule) {
-		EasyAntModuleDescriptorParser parser = getEasyAntModuleDescriptorParser(buildModule);
-		log(
-				"Loading EasyAnt module descriptor :"
-						+ parser.getClass().getName(), Project.MSG_DEBUG);
-
-		try {
-			parser.setActiveBuildConfigurations(getProject().getProperty(
-					EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS));
-			parser.parseDescriptor(getEasyAntIvyInstance().getSettings(),
-					buildModule.toURL(), new URLResource(buildModule.toURL()),
-					true);
-			EasyAntModuleDescriptor md = parser.getEasyAntModuleDescriptor();
-			ModuleRevisionId currentModule = md.getIvyModuleDescriptor()
-					.getModuleRevisionId();
-
-			String buildConfigurations = null;
-			for (String conf : md.getBuildConfigurations()) {
-				if (buildConfigurations == null) {
-					buildConfigurations = conf;
-				} else {
-					buildConfigurations = buildConfigurations + "," + conf;
-				}
-			}
-			getProject().setProperty(
-					EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS,
-					buildConfigurations);
-			updateMainConfs();
-
-			for (Iterator<PropertyDescriptor> iterator = md.getProperties()
-					.values().iterator(); iterator.hasNext();) {
-				PropertyDescriptor property = iterator.next();
-				if (canInherit(property, currentModule)) {
-					PropertyTask propTask = new PropertyTask();
-					propTask.setName(property.getName());
-					propTask.setValue(property.getValue());
-					propTask.setBuildConfigurations(property
-							.getBuildConfigurations());
-					initTask(propTask).execute();
-				}
-			}
-			if (md.getBuildType() != null) {
-				Import importTask = new Import();
-				importTask.setMrid(md.getBuildType());
-				initTask(importTask).execute();
-			}
-			for (Iterator<?> iterator = md.getPlugins().iterator(); iterator
-					.hasNext();) {
-				PluginDescriptor plugin = (PluginDescriptor) iterator.next();
-
-				if (canInherit(plugin, currentModule)) {
-					Import importTask = new Import();
-					importTask.setMrid(plugin.getMrid());
-					importTask.setMode(plugin.getMode());
-					importTask.setAs(plugin.getAs());
-					importTask.setMandatory(plugin.isMandatory());
-					importTask.setBuildConfigurations(plugin
-							.getBuildConfigurations());
-					initTask(importTask).execute();
-				}
-			}
-			// Apply PhaseMapping
-			for (PhaseMappingDescriptor phaseMapping : md.getPhaseMappings()) {
-				BindTarget bindTarget = new BindTarget();
-				bindTarget.setTarget(phaseMapping.getTarget());
-				bindTarget.setToPhase(phaseMapping.getToPhase());
-				bindTarget.setBuildConfigurations(phaseMapping
-						.getBuildConfigurations());
-				initTask(bindTarget).execute();
-			}
-		} catch (Exception e) {
-			throw new BuildException("problem while parsing Ivy module file: "
-					+ e.getMessage(), e);
-		}
-	}
-
-	/**
-	 * Check if an inheritable item can be inherited by verifying
-	 * {@link InheritableScope}
-	 * 
-	 * @param inheritableItem
-	 *            a given {@link AdvancedInheritableItem}
-	 * @param currentModule
-	 *            current module
-	 * @return true if item can be inherited
-	 */
-	private boolean canInherit(AdvancedInheritableItem inheritableItem,
-			ModuleRevisionId currentModule) {
-		if (currentModule.equals(inheritableItem.getSourceModule())) {
-			return !InheritableScope.CHILD.equals(inheritableItem
-					.getInheritScope()); 
-		} else {
-			return true;
-		}
-	
-	}
-
-	/**
-	 * This method is in charge to update the main.confs property with all the
-	 * active build configuration for the current project.
-	 */
-	private void updateMainConfs() {
-		if (getProject().getProperty(
-				EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS) == null
-				|| getProject().getProperty(
-						EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS) == null) {
-			return;
-		}
-
-		List<String> availableBuildConfigurations = Arrays.asList(getProject()
-				.getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS)
-				.split(","));
-		// remove spaces in active confs
-		String activeConfs = getProject().getProperty(
-				EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS);
-		List<String> activeBuildConfigurations = BuildConfigurationHelper
-				.buildList(activeConfs);
-		List<String> mainConfsList = new ArrayList<String>();
-		for (String conf : activeBuildConfigurations) {
-			if (availableBuildConfigurations.contains(conf)) {
-				mainConfsList.add(conf);
-			} else {
-				log("removing unused configuration " + conf, Project.MSG_DEBUG);
-			}
-		}
-		if (mainConfsList.size() > 0) {
-			String mainConfs = StringUtils.join(mainConfsList
-					.toArray(new String[0]), ",");
-			log("updating main.confs with active profile for current project :"
-					+ mainConfs, Project.MSG_DEBUG);
-			getProject().setProperty(EasyAntMagicNames.MAIN_CONFS, mainConfs);
-		}
-
-	}
-
-	protected EasyAntModuleDescriptorParser getEasyAntModuleDescriptorParser(
-			File file) throws BuildException {
-		ModuleDescriptorParser mdp = null;
-		EasyAntModuleDescriptorParser parser = null;
-		try {
-			mdp = ModuleDescriptorParserRegistry.getInstance().getParser(
-					new URLResource(file.toURL()));
-		} catch (MalformedURLException e) {
-			throw new BuildException("Impossible to find a parser for "
-					+ file.getName());
-		}
-		// If valid easyant parser is defined use it
-		if (mdp != null
-				&& mdp.getClass().isInstance(
-						EasyAntModuleDescriptorParser.class)) {
-			return (EasyAntModuleDescriptorParser) mdp;
-		} else {
-			// if the user has customized the loadmodule task
-			if (easyAntMDParserClassName != null) {
-
-				try {
-					Class<? extends EasyAntModuleDescriptorParser> c = Class
-							.forName(easyAntMDParserClassName).asSubclass(
-									EasyAntModuleDescriptorParser.class);
-					log("Creating instance of " + easyAntMDParserClassName,
-							Project.MSG_DEBUG);
-					parser = c.newInstance();
-					ModuleDescriptorParserRegistry.getInstance().addParser(
-							parser);
-					return parser;
-				} catch (Exception e) {
-					throw new BuildException("Unable to load "
-							+ easyAntMDParserClassName, e);
-				}
-
-			}
-			// the default one
-			log("Creating instance of "
-					+ DefaultEasyAntXmlModuleDescriptorParser.class.getName(),
-					Project.MSG_DEBUG);
-			parser = new DefaultEasyAntXmlModuleDescriptorParser();
-
-			ModuleDescriptorParserRegistry.getInstance().addParser(parser);
-			return parser;
-
-		}
-	}
-
-	/**
-	 * @return true if this module should use a build-scoped repository and
-	 *         cache to find artifacts generated by other modules in the same
-	 *         build.
-	 */
-	private boolean shouldUseBuildRepository() {
-		// if a value has been provided by task attribute, return it
-		if (useBuildRepository != null) {
-			return useBuildRepository;
-		}
-		// otherwise, look for a value in property configuration, defaulting to
-		// false if no value.
-		return Project.toBoolean(getProject().getProperty(
-				EasyAntMagicNames.USE_BUILD_REPOSITORY));
-	}
-
-	/**
-	 * Change the given Ivy settings to use a local build-scoped repository and
-	 * cache by default. This allows submodules to access each others' artifacts
-	 * before they have been published to a shared repository.
-	 */
-	private void configureBuildRepository(IvyAntSettings projectSettings)
-			throws BuildException {
-		String target = getProject().getProperty(EasyAntMagicNames.META_TARGET);
-		if (target == null) {
-			target = getProject().getProperty(EasyAntMagicNames.TARGET);
-		}
-		if (target == null) {
-			target = getProject().getBaseDir() + "/target";
-		}
-
-		// be sure that we have an absolute path
-		File targetDir = new File(target);
-		target = targetDir.getAbsolutePath();
-
-		final String DEFAULT_BUILD_SCOPED_REPOSITORY_DIR = target
-				+ "/repository";
-		final String DEFAULT_CACHE_BUILD_SCOPED_REPO = target + "/cache";
-		getProject().log(
-				"Registering build scoped repository in "
-						+ DEFAULT_BUILD_SCOPED_REPOSITORY_DIR,
-				Project.MSG_DEBUG);
-		final String CACHENAME = "build-scoped-cache";
-		// Get the project ivy instance
-		Ivy ivy = projectSettings.getConfiguredIvyInstance(this);
-		IvySettings settings = ivy.getSettings();
-
-		// Search the default resolver after the build-scoped repo
-		DependencyResolver dr = settings.getDefaultResolver();
-		if (dr == null) {
-			throw new BuildException("Unable to find a default resolver");
-		}
-		resetDefaultResolver(settings);
-
-		// Create a cache for build scoped repository
-		File cacheDir = new File(DEFAULT_CACHE_BUILD_SCOPED_REPO);
-		DefaultRepositoryCacheManager rcm = new DefaultRepositoryCacheManager(
-				CACHENAME, settings, cacheDir);
-		rcm.setUseOrigin(true); // no need to copy temporary build artifacts
-		// into temporary cache.
-		// Register the repository cache
-		settings.addConfigured(rcm);
-
-		// Create the build scoped repository
-		FileSystemResolver buildRepository = new FileSystemResolver();
-		buildRepository.setName("build." + dr.getName());
-		buildRepository
-				.addArtifactPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR
-						+ "/[organisation]/[module]/[revision]/[artifact](-[classifier]).[ext]");
-		buildRepository.addIvyPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR
-				+ "/[organisation]/[module]/[revision]/[module].ivy");
-		// bind to the repocache
-		buildRepository.setCache(CACHENAME);
-
-		getProject().setProperty(EasyAntMagicNames.EASYANT_BUILD_REPOSITORY,
-				buildRepository.getName());
-
-		// replace the default resolver with a chain resolver, which first
-		// searches
-		// in the build repository, then in the old default.
-		ChainResolver resolver = new ChainResolver();
-		resolver.setName(dr.getName()); // same name as old default
-		resolver.setReturnFirst(true);
-		resolver.add(buildRepository);
-		resolver.add(dr);
-		dr.setName("delegate." + dr.getName()); // give old default a new name
-
-		settings.addResolver(buildRepository);
-		settings.addResolver(dr);
-		settings.addResolver(resolver);
-	}
-
-	/**
-	 * Clear the default resolver on the given IvySettings. This is a workaround
-	 * for <a href="http://issues.apache.org/jira/browse/IVY-1163">Ivy issue
-	 * 1163</a>. This code should be removed when the issue is resolved.
-	 */
-	private void resetDefaultResolver(IvySettings settings)
-			throws BuildException {
-		try {
-			Field cachedResolver = IvySettings.class
-					.getDeclaredField("defaultResolver");
-			cachedResolver.setAccessible(true);
-			cachedResolver.set(settings, null);
-		} catch (Exception e) {
-			throw new BuildException(
-					"Unable to reset default resolver on IvySettings", e);
-		}
-	}
+    private File buildFile;
+    private File buildModule;
+    private String easyAntMDParserClassName;
+    private Boolean useBuildRepository;
+
+    /**
+     * Get the file name that will be loaded
+     * 
+     * @return a file that represents a module descriptor
+     */
+    public File getBuildModule() {
+        return buildModule;
+    }
+
+    /**
+     * set the file name that will be loaded
+     * 
+     * @param file
+     *            represents a module descriptor
+     */
+    public void setBuildModule(File file) {
+        this.buildModule = file;
+    }
+
+    public File getBuildFile() {
+        return buildFile;
+    }
+
+    public void setBuildFile(File buildFile) {
+        this.buildFile = buildFile;
+    }
+
+    public void setUseBuildRepository(boolean value) {
+        this.useBuildRepository = value;
+    }
+
+    /**
+     * Set the classname of the easyant parser you want to use
+     * 
+     * @param easyAntMDParserClassName
+     */
+    public void setEasyAntMDParserClassName(String easyAntMDParserClassName) {
+        this.easyAntMDParserClassName = easyAntMDParserClassName;
+    }
+
+    public void execute() throws BuildException {
+        if (buildModule != null && buildModule.exists()) {
+            IvyInfo info = new IvyInfo();
+            info.setFile(buildModule);
+            // Not sure we should bound IvyInfo to easyantIvyInstance
+            info.setSettingsRef(IvyInstanceHelper
+                    .buildEasyAntIvyReference(getProject()));
+            initTask(info).execute();
+            getProject().setName(getProject().getProperty("ivy.module"));
+        }
+        if (buildModule != null && buildModule.exists()) {
+            // make sure it's not a directory (this falls into the ultra
+            // paranoid lets check everything category
+
+            if (buildModule.isDirectory()) {
+                System.out.println("What? buildModule: " + buildModule
+                        + " is a dir!");
+                throw new BuildException("Build failed");
+            }
+            // load override buildFile before buildModule to allow target/phase
+            // override
+            File f = new File(buildModule.getParent(),
+                    EasyAntConstants.DEFAULT_OVERRIDE_BUILD_FILE);
+            if (f.exists()) {
+                log("Loading override build file : "
+                        + buildFile.getAbsolutePath());
+                loadBuildFile(f);
+            }
+
+            log("Loading build module : " + buildModule.getAbsolutePath());
+            loadBuildModule(buildModule);
+        }
+
+        // load buildFile before buildModule to allow target/phase override
+        if (buildFile != null && buildFile.exists()) {
+            // make sure it's not a directory (this falls into the ultra
+            // paranoid lets check everything category
+
+            if (buildFile.isDirectory()) {
+                System.out.println("What? buildFile: " + buildFile
+                        + " is a dir!");
+                throw new BuildException("Build failed");
+            }
+
+            log("Loading build file : " + buildFile.getAbsolutePath());
+            loadBuildFile(buildFile);
+        }
+
+        String projectIvyInstanceProp = IvyInstanceHelper
+                .getProjectIvyInstanceName(getProject());
+
+        // create project ivy instance except if project ivy instance is linked
+        // to easyant ivy instance
+        if (!EasyAntMagicNames.EASYANT_IVY_INSTANCE
+                .equals(projectIvyInstanceProp)) {
+            configureProjectIvyinstance(projectIvyInstanceProp);
+
+        }
+
+        if (shouldUseBuildRepository()) {
+            configureBuildRepository(IvyInstanceHelper
+                    .getProjectIvyAntSettings(getProject()));
+        }
+
+        if (getProject().getDefaultTarget() == null
+                && getProject().getTargets().containsKey(
+                        EasyAntConstants.DEFAULT_TARGET)) {
+            getProject().setDefault(EasyAntConstants.DEFAULT_TARGET);
+        }
+    }
+
+    /**
+     * 
+     */
+    private void configureProjectIvyinstance(String projectIvyInstanceName) {
+        IvyConfigure projectIvyInstance = new IvyConfigure();
+        projectIvyInstance.setSettingsId(projectIvyInstanceName);
+        if (getProject()
+                .getProperty(EasyAntMagicNames.PROJECT_IVY_SETTING_FILE) != null) {
+            File projectIvyFile = new File(getProject().getProperty(
+                    EasyAntMagicNames.PROJECT_IVY_SETTING_FILE));
+            projectIvyInstance.setFile(projectIvyFile);
+        }
+        if (getProject().getProperty(EasyAntMagicNames.PROJECT_IVY_SETTING_URL) != null) {
+            String url = getProject().getProperty(
+                    EasyAntMagicNames.PROJECT_IVY_SETTING_URL);
+            try {
+                projectIvyInstance.setUrl(url);
+            } catch (MalformedURLException malformedUrl) {
+                throw new BuildException(
+                        "Unable to parse project ivysettings from the following url : "
+                                + url, malformedUrl);
+            }
+        }
+        String defaultUrl = this.getClass().getResource(
+                "/org/apache/easyant/core/default-project-ivysettings.xml")
+                .toExternalForm();
+        getProject().setNewProperty(
+                EasyAntMagicNames.PROJECT_DEFAULT_IVYSETTINGS, defaultUrl);
+        if (getProject()
+                .getProperty(EasyAntMagicNames.PROJECT_IVY_SETTING_FILE) == null
+                && getProject().getProperty(
+                        EasyAntMagicNames.PROJECT_IVY_SETTING_URL) == null) {
+            File localSettings = new File(buildModule.getParent(),
+                    "ivysettings.xml");
+            if (localSettings.exists()) {
+                getProject().log("loading local project settings file...",
+                        Project.MSG_VERBOSE);
+                projectIvyInstance.setFile(localSettings);
+                getProject().setNewProperty(
+                        EasyAntMagicNames.PROJECT_IVY_SETTING_FILE,
+                        localSettings.getAbsolutePath());
+
+            } else {
+                getProject().log("no settings file found, using default...",
+                        Project.MSG_VERBOSE);
+                getProject().setNewProperty(
+                        EasyAntMagicNames.PROJECT_IVY_SETTING_URL,
+                        defaultUrl.toString());
+                try {
+                    projectIvyInstance.setUrl(defaultUrl);
+                } catch (MalformedURLException e) {
+                    throw new BuildException(
+                            "Unable to parse project ivysettings from the following url : "
+                                    + defaultUrl, e);
+                }
+            }
+        }
+        initTask(projectIvyInstance).execute();
+    }
+
+    protected void loadBuildFile(File buildModule) {
+        ImportTask importTask = new ImportTask();
+        importTask.setFile(buildModule.getAbsolutePath());
+        importTask.setOptional(true);
+        initTask(importTask).execute();
+    }
+
+    protected void loadBuildModule(File buildModule) {
+        EasyAntModuleDescriptorParser parser = getEasyAntModuleDescriptorParser(buildModule);
+        log(
+                "Loading EasyAnt module descriptor :"
+                        + parser.getClass().getName(), Project.MSG_DEBUG);
+
+        try {
+            parser.setActiveBuildConfigurations(getProject().getProperty(
+                    EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS));
+            parser.parseDescriptor(getEasyAntIvyInstance().getSettings(),
+                    buildModule.toURL(), new URLResource(buildModule.toURL()),
+                    true);
+            EasyAntModuleDescriptor md = parser.getEasyAntModuleDescriptor();
+            ModuleRevisionId currentModule = md.getIvyModuleDescriptor()
+                    .getModuleRevisionId();
+
+            String buildConfigurations = null;
+            for (String conf : md.getBuildConfigurations()) {
+                if (buildConfigurations == null) {
+                    buildConfigurations = conf;
+                } else {
+                    buildConfigurations = buildConfigurations + "," + conf;
+                }
+            }
+            getProject().setProperty(
+                    EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS,
+                    buildConfigurations);
+            updateMainConfs();
+
+            for (Iterator<PropertyDescriptor> iterator = md.getProperties()
+                    .values().iterator(); iterator.hasNext();) {
+                PropertyDescriptor property = iterator.next();
+                if (canInherit(property, currentModule)) {
+                    PropertyTask propTask = new PropertyTask();
+                    propTask.setName(property.getName());
+                    propTask.setValue(property.getValue());
+                    propTask.setBuildConfigurations(property
+                            .getBuildConfigurations());
+                    initTask(propTask).execute();
+                }
+            }
+            if (md.getBuildType() != null) {
+                Import importTask = new Import();
+                importTask.setMrid(md.getBuildType());
+                initTask(importTask).execute();
+            }
+            for (Iterator<?> iterator = md.getPlugins().iterator(); iterator
+                    .hasNext();) {
+                PluginDescriptor plugin = (PluginDescriptor) iterator.next();
+
+                if (canInherit(plugin, currentModule)) {
+                    Import importTask = new Import();
+                    importTask.setMrid(plugin.getMrid());
+                    importTask.setMode(plugin.getMode());
+                    importTask.setAs(plugin.getAs());
+                    importTask.setMandatory(plugin.isMandatory());
+                    importTask.setBuildConfigurations(plugin
+                            .getBuildConfigurations());
+                    initTask(importTask).execute();
+                }
+            }
+            // Apply PhaseMapping
+            for (PhaseMappingDescriptor phaseMapping : md.getPhaseMappings()) {
+                BindTarget bindTarget = new BindTarget();
+                bindTarget.setTarget(phaseMapping.getTarget());
+                bindTarget.setToPhase(phaseMapping.getToPhase());
+                bindTarget.setBuildConfigurations(phaseMapping
+                        .getBuildConfigurations());
+                initTask(bindTarget).execute();
+            }
+        } catch (Exception e) {
+            throw new BuildException("problem while parsing Ivy module file: "
+                    + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Check if an inheritable item can be inherited by verifying
+     * {@link InheritableScope}
+     * 
+     * @param inheritableItem
+     *            a given {@link AdvancedInheritableItem}
+     * @param currentModule
+     *            current module
+     * @return true if item can be inherited
+     */
+    private boolean canInherit(AdvancedInheritableItem inheritableItem,
+            ModuleRevisionId currentModule) {
+        if (currentModule.equals(inheritableItem.getSourceModule())) {
+            return !InheritableScope.CHILD.equals(inheritableItem
+                    .getInheritScope()); 
+        } else {
+            return true;
+        }
+    
+    }
+
+    /**
+     * This method is in charge to update the main.confs property with all the
+     * active build configuration for the current project.
+     */
+    private void updateMainConfs() {
+        if (getProject().getProperty(
+                EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS) == null
+                || getProject().getProperty(
+                        EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS) == null) {
+            return;
+        }
+
+        List<String> availableBuildConfigurations = Arrays.asList(getProject()
+                .getProperty(EasyAntMagicNames.AVAILABLE_BUILD_CONFIGURATIONS)
+                .split(","));
+        // remove spaces in active confs
+        String activeConfs = getProject().getProperty(
+                EasyAntMagicNames.ACTIVE_BUILD_CONFIGURATIONS);
+        List<String> activeBuildConfigurations = BuildConfigurationHelper
+                .buildList(activeConfs);
+        List<String> mainConfsList = new ArrayList<String>();
+        for (String conf : activeBuildConfigurations) {
+            if (availableBuildConfigurations.contains(conf)) {
+                mainConfsList.add(conf);
+            } else {
+                log("removing unused configuration " + conf, Project.MSG_DEBUG);
+            }
+        }
+        if (mainConfsList.size() > 0) {
+            String mainConfs = StringUtils.join(mainConfsList
+                    .toArray(new String[0]), ",");
+            log("updating main.confs with active profile for current project :"
+                    + mainConfs, Project.MSG_DEBUG);
+            getProject().setProperty(EasyAntMagicNames.MAIN_CONFS, mainConfs);
+        }
+
+    }
+
+    protected EasyAntModuleDescriptorParser getEasyAntModuleDescriptorParser(
+            File file) throws BuildException {
+        ModuleDescriptorParser mdp = null;
+        EasyAntModuleDescriptorParser parser = null;
+        try {
+            mdp = ModuleDescriptorParserRegistry.getInstance().getParser(
+                    new URLResource(file.toURL()));
+        } catch (MalformedURLException e) {
+            throw new BuildException("Impossible to find a parser for "
+                    + file.getName());
+        }
+        // If valid easyant parser is defined use it
+        if (mdp != null
+                && mdp.getClass().isInstance(
+                        EasyAntModuleDescriptorParser.class)) {
+            return (EasyAntModuleDescriptorParser) mdp;
+        } else {
+            // if the user has customized the loadmodule task
+            if (easyAntMDParserClassName != null) {
+
+                try {
+                    Class<? extends EasyAntModuleDescriptorParser> c = Class
+                            .forName(easyAntMDParserClassName).asSubclass(
+                                    EasyAntModuleDescriptorParser.class);
+                    log("Creating instance of " + easyAntMDParserClassName,
+                            Project.MSG_DEBUG);
+                    parser = c.newInstance();
+                    ModuleDescriptorParserRegistry.getInstance().addParser(
+                            parser);
+                    return parser;
+                } catch (Exception e) {
+                    throw new BuildException("Unable to load "
+                            + easyAntMDParserClassName, e);
+                }
+
+            }
+            // the default one
+            log("Creating instance of "
+                    + DefaultEasyAntXmlModuleDescriptorParser.class.getName(),
+                    Project.MSG_DEBUG);
+            parser = new DefaultEasyAntXmlModuleDescriptorParser();
+
+            ModuleDescriptorParserRegistry.getInstance().addParser(parser);
+            return parser;
+
+        }
+    }
+
+    /**
+     * @return true if this module should use a build-scoped repository and
+     *         cache to find artifacts generated by other modules in the same
+     *         build.
+     */
+    private boolean shouldUseBuildRepository() {
+        // if a value has been provided by task attribute, return it
+        if (useBuildRepository != null) {
+            return useBuildRepository;
+        }
+        // otherwise, look for a value in property configuration, defaulting to
+        // false if no value.
+        return Project.toBoolean(getProject().getProperty(
+                EasyAntMagicNames.USE_BUILD_REPOSITORY));
+    }
+
+    /**
+     * Change the given Ivy settings to use a local build-scoped repository and
+     * cache by default. This allows submodules to access each others' artifacts
+     * before they have been published to a shared repository.
+     */
+    private void configureBuildRepository(IvyAntSettings projectSettings)
+            throws BuildException {
+        String target = getProject().getProperty(EasyAntMagicNames.META_TARGET);
+        if (target == null) {
+            target = getProject().getProperty(EasyAntMagicNames.TARGET);
+        }
+        if (target == null) {
+            target = getProject().getBaseDir() + "/target";
+        }
+
+        // be sure that we have an absolute path
+        File targetDir = new File(target);
+        target = targetDir.getAbsolutePath();
+
+        final String DEFAULT_BUILD_SCOPED_REPOSITORY_DIR = target
+                + "/repository";
+        final String DEFAULT_CACHE_BUILD_SCOPED_REPO = target + "/cache";
+        getProject().log(
+                "Registering build scoped repository in "
+                        + DEFAULT_BUILD_SCOPED_REPOSITORY_DIR,
+                Project.MSG_DEBUG);
+        final String CACHENAME = "build-scoped-cache";
+        // Get the project ivy instance
+        Ivy ivy = projectSettings.getConfiguredIvyInstance(this);
+        IvySettings settings = ivy.getSettings();
+
+        // Search the default resolver after the build-scoped repo
+        DependencyResolver dr = settings.getDefaultResolver();
+        if (dr == null) {
+            throw new BuildException("Unable to find a default resolver");
+        }
+        resetDefaultResolver(settings);
+
+        // Create a cache for build scoped repository
+        File cacheDir = new File(DEFAULT_CACHE_BUILD_SCOPED_REPO);
+        DefaultRepositoryCacheManager rcm = new DefaultRepositoryCacheManager(
+                CACHENAME, settings, cacheDir);
+        rcm.setUseOrigin(true); // no need to copy temporary build artifacts
+        // into temporary cache.
+        // Register the repository cache
+        settings.addConfigured(rcm);
+
+        // Create the build scoped repository
+        FileSystemResolver buildRepository = new FileSystemResolver();
+        buildRepository.setName("build." + dr.getName());
+        buildRepository
+                .addArtifactPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR
+                        + "/[organisation]/[module]/[revision]/[artifact](-[classifier]).[ext]");
+        buildRepository.addIvyPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR
+                + "/[organisation]/[module]/[revision]/[module].ivy");
+        // bind to the repocache
+        buildRepository.setCache(CACHENAME);
+
+        getProject().setProperty(EasyAntMagicNames.EASYANT_BUILD_REPOSITORY,
+                buildRepository.getName());
+
+        // replace the default resolver with a chain resolver, which first
+        // searches
+        // in the build repository, then in the old default.
+        ChainResolver resolver = new ChainResolver();
+        resolver.setName(dr.getName()); // same name as old default
+        resolver.setReturnFirst(true);
+        resolver.add(buildRepository);
+        resolver.add(dr);
+        dr.setName("delegate." + dr.getName()); // give old default a new name
+
+        settings.addResolver(buildRepository);
+        settings.addResolver(dr);
+        settings.addResolver(resolver);
+    }
+
+    /**
+     * Clear the default resolver on the given IvySettings. This is a workaround
+     * for <a href="http://issues.apache.org/jira/browse/IVY-1163">Ivy issue
+     * 1163</a>. This code should be removed when the issue is resolved.
+     */
+    private void resetDefaultResolver(IvySettings settings)
+            throws BuildException {
+        try {
+            Field cachedResolver = IvySettings.class
+                    .getDeclaredField("defaultResolver");
+            cachedResolver.setAccessible(true);
+            cachedResolver.set(settings, null);
+        } catch (Exception e) {
+            throw new BuildException(
+                    "Unable to reset default resolver on IvySettings", e);
+        }
+    }
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java Tue Feb 22 15:55:55 2011
@@ -27,170 +27,170 @@ import org.apache.tools.ant.types.Path;
 /**
  * parameter tasks is used to :
  * 
- * 			document properties / paths / phases 
- * 			check if properties /paths / phases are required 
- * 			set default values if properties are not set
+ *          document properties / paths / phases 
+ *          check if properties /paths / phases are required 
+ *          set default values if properties are not set
  * 
  * This could be usefull in precondition of each modules, to check if
  * property/phase/path are set. And much more usefull to document our modules.
  * 
  */
 public class ParameterTask extends Task {
-	private String property;
-	private String path;
-	private String phase;
-
-	private String description;
-	private String defaultValue;
-	private boolean required;
-
-	/**
-	 * Get a description to the property / path / phase
-	 * @return the description
-	 */
-	public String getDescription() {
-		return description;
-	}
-
-	/**
-	 * set a description to the property / path / phase
-	 * @param description the description
-	 */
-	public void setDescription(String description) {
-		this.description = description;
-	}
-	
-	/**
-	 * Appends CDATA text inside the Ant task to description
-	 * @see #setDescription(String)
-	 */
-	public void addText(String descriptionText) {
-		if (descriptionText.trim().length() > 0) {
-			descriptionText = getProject().replaceProperties(descriptionText);
-			if (getDescription() == null) {
-				setDescription(descriptionText);
-			} else {
-				setDescription(getDescription()+descriptionText);
-			}
-		}
-	}
-
-	/**
-	 * Get the property name to check
-	 * @return a property name
-	 */
-	public String getProperty() {
-		return property;
-	}
-
-	/**
-	 * Set the property name to check
-	 * @param property a property name
-	 */
-	public void setProperty(String property) {
-		this.property = property;
-	}
-
-	/**
-	 * Get the path to check
-	 * @return a pathId 
-	 */
-	public String getPath() {
-		return path;
-	}
-
-	/**
-	 * Set the path to check
-	 * @param path
-	 */
-	public void setPath(String path) {
-		this.path = path;
-	}
-
-	/**
-	 * Get a phase to check
-	 * @return a phase name
-	 */
-	public String getPhase() {
-		return phase;
-	}
-
-	/**
-	 * Set the path to check
-	 * @param phase a phase name 
-	 */
-	public void setPhase(String phase) {
-		this.phase = phase;
-	}
-
-	/**
-	 * Get the default value (only available for property)
-	 * @return a string that represents the default value
-	 */
-	public String getDefault() {
-		return defaultValue;
-	}
-
-	/**
-	 * Set the default value (only  available for property)
-	 * @param defaultValue a string that represents the default value
-	 */
-	public void setDefault(String defaultValue) {
-		this.defaultValue = defaultValue;
-	}
-
-	/**
-	 * Is the refererenced property / path required?
-	 * @return
-	 */
-	public boolean isRequired() {
-		return required;
-	}
-
-	/**
-	 * specify if the property / path is mandatory
-	 * @param required
-	 */
-	public void setRequired(boolean required) {
-		this.required = required;
-	}
-
-	public void execute() throws BuildException {
-		if (property != null) {
-			if (required && getProject().getProperty(property) == null) {
-				throw new BuildException("expected property '" + property
-						+ "': " + description);
-			}
-			if (defaultValue != null
-					&& getProject().getProperty(property) == null) {
-				Property propTask = new Property();
-				propTask.setProject(getProject());
-				propTask.setTaskName(getTaskName());
-				propTask.setName(property);
-				propTask.setValue(defaultValue);
-				propTask.execute();
-			}
-		} else if (phase != null) {
-			Target p = (Target) getProject().getTargets().get(phase);
-			if (p == null) {
-				throw new BuildException("expected phase '" + phase + "': "
-						+ description);
-			} else if (!(p instanceof Phase)) {
-				throw new BuildException("target '" + phase
-						+ "' must be a phase rather than a target");
-			}
-		} else if (path != null) {
-			Object p = getProject().getReference(path);
-			if (required && p == null) {
-				throw new BuildException("expected path '" + path + "': "
-						+ description);
-			} else if (!(p instanceof Path)) {
-				throw new BuildException("reference '" + path
-						+ "' must be a path");
-			}
-		} else {
-			throw new BuildException(
-					"at least one of these attributes is required: property, path, phase");
-		}
-	}
+    private String property;
+    private String path;
+    private String phase;
+
+    private String description;
+    private String defaultValue;
+    private boolean required;
+
+    /**
+     * Get a description to the property / path / phase
+     * @return the description
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * set a description to the property / path / phase
+     * @param description the description
+     */
+    public void setDescription(String description) {
+        this.description = description;
+    }
+    
+    /**
+     * Appends CDATA text inside the Ant task to description
+     * @see #setDescription(String)
+     */
+    public void addText(String descriptionText) {
+        if (descriptionText.trim().length() > 0) {
+            descriptionText = getProject().replaceProperties(descriptionText);
+            if (getDescription() == null) {
+                setDescription(descriptionText);
+            } else {
+                setDescription(getDescription()+descriptionText);
+            }
+        }
+    }
+
+    /**
+     * Get the property name to check
+     * @return a property name
+     */
+    public String getProperty() {
+        return property;
+    }
+
+    /**
+     * Set the property name to check
+     * @param property a property name
+     */
+    public void setProperty(String property) {
+        this.property = property;
+    }
+
+    /**
+     * Get the path to check
+     * @return a pathId 
+     */
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     * Set the path to check
+     * @param path
+     */
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    /**
+     * Get a phase to check
+     * @return a phase name
+     */
+    public String getPhase() {
+        return phase;
+    }
+
+    /**
+     * Set the path to check
+     * @param phase a phase name 
+     */
+    public void setPhase(String phase) {
+        this.phase = phase;
+    }
+
+    /**
+     * Get the default value (only available for property)
+     * @return a string that represents the default value
+     */
+    public String getDefault() {
+        return defaultValue;
+    }
+
+    /**
+     * Set the default value (only  available for property)
+     * @param defaultValue a string that represents the default value
+     */
+    public void setDefault(String defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+
+    /**
+     * Is the refererenced property / path required?
+     * @return
+     */
+    public boolean isRequired() {
+        return required;
+    }
+
+    /**
+     * specify if the property / path is mandatory
+     * @param required
+     */
+    public void setRequired(boolean required) {
+        this.required = required;
+    }
+
+    public void execute() throws BuildException {
+        if (property != null) {
+            if (required && getProject().getProperty(property) == null) {
+                throw new BuildException("expected property '" + property
+                        + "': " + description);
+            }
+            if (defaultValue != null
+                    && getProject().getProperty(property) == null) {
+                Property propTask = new Property();
+                propTask.setProject(getProject());
+                propTask.setTaskName(getTaskName());
+                propTask.setName(property);
+                propTask.setValue(defaultValue);
+                propTask.execute();
+            }
+        } else if (phase != null) {
+            Target p = (Target) getProject().getTargets().get(phase);
+            if (p == null) {
+                throw new BuildException("expected phase '" + phase + "': "
+                        + description);
+            } else if (!(p instanceof Phase)) {
+                throw new BuildException("target '" + phase
+                        + "' must be a phase rather than a target");
+            }
+        } else if (path != null) {
+            Object p = getProject().getReference(path);
+            if (required && p == null) {
+                throw new BuildException("expected path '" + path + "': "
+                        + description);
+            } else if (!(p instanceof Path)) {
+                throw new BuildException("reference '" + path
+                        + "' must be a path");
+            }
+        } else {
+            throw new BuildException(
+                    "at least one of these attributes is required: property, path, phase");
+        }
+    }
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PathTask.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PathTask.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PathTask.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PathTask.java Tue Feb 22 15:55:55 2011
@@ -30,117 +30,117 @@ import org.apache.tools.ant.types.Path.P
  * This task defines or contributes to an existing path. 
  * This task is similar to path task provided by ant but add 
  * an override attribute with these values:
- * 		true: new definition will take precedence over preceding one if any 
- * 		false: new definition will be discarded if any definition already exists 
- * 		append: new definition will be added to the existing one if any 
- * 		prepend: new definition will be added at the beginning of the existing one if any
+ *      true: new definition will take precedence over preceding one if any 
+ *      false: new definition will be discarded if any definition already exists 
+ *      append: new definition will be added to the existing one if any 
+ *      prepend: new definition will be added at the beginning of the existing one if any
  */
 public class PathTask extends Task {
-	public static final String OVERWRITE_TRUE = "true";
-	public static final String OVERWRITE_FALSE = "false";
-	public static final String OVERWRITE_PREPEND = "prepend";
-	public static final String OVERWRITE_APPEND = "append";
-
-	private String pathid;
-
-	private String overwrite;
-
-	private Path path;
-
-	public void setProject(Project project) {
-		super.setProject(project);
-		path = new Path(project);
-	}
-
-	public void execute() throws BuildException {
-		if (pathid == null) {
-			throw new BuildException("pathid is mandatory");
-		}
-		Object element = getProject().getReference(pathid);
-		if (element == null) {
-			if (OVERWRITE_PREPEND.equals(overwrite)
-					|| OVERWRITE_APPEND.equals(overwrite)) {
-				throw new BuildException("destination path not found: "
-						+ pathid);
-			}
-			getProject().addReference(pathid, path);
-		} else {
-			if (OVERWRITE_FALSE.equals(overwrite)) {
-				return;
-			}
-			if (!(element instanceof Path)) {
-				throw new BuildException("destination path is not a path: "
-						+ element.getClass());
-			}
-			if (OVERWRITE_TRUE.equals(overwrite)) {
-				getProject().addReference(pathid, path);
-			} else {
-				Path dest = (Path) element;
-				if (OVERWRITE_PREPEND.equals(overwrite)) {
-					// no way to add path elements at te beginning of the
-					// existing path: we do the opposite
-					// and replace the reference
-					path.append(dest);
-					getProject().addReference(pathid, path);
-				} else { // OVERWRITE_APPEND
-					dest.append(path);
-				}
-			}
-		}
-	}
-
-	public void add(Path path) throws BuildException {
-		this.path.add(path);
-	}
-
-	public void addDirset(DirSet dset) throws BuildException {
-		path.addDirset(dset);
-	}
-
-	public void addFilelist(FileList fl) throws BuildException {
-		path.addFilelist(fl);
-	}
-
-	public void addFileset(FileSet fs) throws BuildException {
-		path.addFileset(fs);
-	}
-
-	public Path createPath() throws BuildException {
-		return path.createPath();
-	}
-
-	public PathElement createPathElement() throws BuildException {
-		return path.createPathElement();
-	}
-
-	/**
-	 * Get a path id 
-	 * @return a pathId
-	 */
-	public String getPathid() {
-		return pathid;
-	}
-
-	/**
-	 * @param pathid a pathId 
-	 */
-	public void setPathid(String pathid) {
-		this.pathid = pathid;
-	}
-
-	/**
-	 * return a string which define if a path is overwritable (Possible values are true/false/append/prepend)
-	 * @return Possible values are true/false/append/prepend
-	 */
-	public String getOverwrite() {
-		return overwrite;
-	}
-
-	/**
-	 * specify if easyant should overwrite the path (Possible values are true/false/append/prepend)
-	 * @param overwrite Possible values are true/false/append/prepend
-	 */
-	public void setOverwrite(String overwrite) {
-		this.overwrite = overwrite;
-	}
+    public static final String OVERWRITE_TRUE = "true";
+    public static final String OVERWRITE_FALSE = "false";
+    public static final String OVERWRITE_PREPEND = "prepend";
+    public static final String OVERWRITE_APPEND = "append";
+
+    private String pathid;
+
+    private String overwrite;
+
+    private Path path;
+
+    public void setProject(Project project) {
+        super.setProject(project);
+        path = new Path(project);
+    }
+
+    public void execute() throws BuildException {
+        if (pathid == null) {
+            throw new BuildException("pathid is mandatory");
+        }
+        Object element = getProject().getReference(pathid);
+        if (element == null) {
+            if (OVERWRITE_PREPEND.equals(overwrite)
+                    || OVERWRITE_APPEND.equals(overwrite)) {
+                throw new BuildException("destination path not found: "
+                        + pathid);
+            }
+            getProject().addReference(pathid, path);
+        } else {
+            if (OVERWRITE_FALSE.equals(overwrite)) {
+                return;
+            }
+            if (!(element instanceof Path)) {
+                throw new BuildException("destination path is not a path: "
+                        + element.getClass());
+            }
+            if (OVERWRITE_TRUE.equals(overwrite)) {
+                getProject().addReference(pathid, path);
+            } else {
+                Path dest = (Path) element;
+                if (OVERWRITE_PREPEND.equals(overwrite)) {
+                    // no way to add path elements at te beginning of the
+                    // existing path: we do the opposite
+                    // and replace the reference
+                    path.append(dest);
+                    getProject().addReference(pathid, path);
+                } else { // OVERWRITE_APPEND
+                    dest.append(path);
+                }
+            }
+        }
+    }
+
+    public void add(Path path) throws BuildException {
+        this.path.add(path);
+    }
+
+    public void addDirset(DirSet dset) throws BuildException {
+        path.addDirset(dset);
+    }
+
+    public void addFilelist(FileList fl) throws BuildException {
+        path.addFilelist(fl);
+    }
+
+    public void addFileset(FileSet fs) throws BuildException {
+        path.addFileset(fs);
+    }
+
+    public Path createPath() throws BuildException {
+        return path.createPath();
+    }
+
+    public PathElement createPathElement() throws BuildException {
+        return path.createPathElement();
+    }
+
+    /**
+     * Get a path id 
+     * @return a pathId
+     */
+    public String getPathid() {
+        return pathid;
+    }
+
+    /**
+     * @param pathid a pathId 
+     */
+    public void setPathid(String pathid) {
+        this.pathid = pathid;
+    }
+
+    /**
+     * return a string which define if a path is overwritable (Possible values are true/false/append/prepend)
+     * @return Possible values are true/false/append/prepend
+     */
+    public String getOverwrite() {
+        return overwrite;
+    }
+
+    /**
+     * specify if easyant should overwrite the path (Possible values are true/false/append/prepend)
+     * @param overwrite Possible values are true/false/append/prepend
+     */
+    public void setOverwrite(String overwrite) {
+        this.overwrite = overwrite;
+    }
 }