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 jl...@apache.org on 2011/06/21 21:07:56 UTC
svn commit: r1138188 - in /incubator/easyant/core/trunk/src:
main/java/org/apache/easyant/core/ main/java/org/apache/easyant/core/ant/
main/java/org/apache/easyant/core/services/
main/java/org/apache/easyant/core/services/impl/ main/java/org/apache/eas...
Author: jlboudart
Date: Tue Jun 21 21:07:55 2011
New Revision: 1138188
URL: http://svn.apache.org/viewvc?rev=1138188&view=rev
Log:
refs EASYANT-29 : use ant api to generate easyant report
Added:
incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/
incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ant
incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ivy
Modified:
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/EasyAntProjectHelper.java
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ProjectMan.java
incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java Tue Jun 21 21:07:55 2011
@@ -91,7 +91,7 @@ public class EasyAntEngine {
* project instance
* @return a configured {@link Ivy} instance
*/
- protected Ivy configureEasyAntIvyInstance(Project project) {
+ public Ivy configureEasyAntIvyInstance(Project project) {
IvyConfigure easyantIvyConfigure = new IvyConfigure();
easyantIvyConfigure
.setSettingsId(EasyAntMagicNames.EASYANT_IVY_INSTANCE);
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java Tue Jun 21 21:07:55 2011
@@ -601,8 +601,11 @@ public class EasyAntMain implements AntM
} else if(projectMan) {
EasyAntEngine.configureAndInitProject(project, easyAntConfiguration);
File moduleDescriptor =new File(project.getProperty(EasyAntMagicNames.EASYANT_FILE));
- if (moduleDescriptor.exists()) {
- man.setContext(project, moduleDescriptor);
+ File optionalAntModule =new File(moduleDescriptor.getParent(),EasyAntConstants.DEFAULT_BUILD_FILE);
+ File overrideAntModule =new File(moduleDescriptor.getParent(),EasyAntConstants.DEFAULT_OVERRIDE_BUILD_FILE);
+
+ if (moduleDescriptor.exists()||optionalAntModule.exists()||overrideAntModule.exists()) {
+ man.setContext(project, moduleDescriptor,optionalAntModule,overrideAntModule);
man.execute();
} else {
project.log("Can't print project manual, there is no module descriptor available.");
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/EasyAntProjectHelper.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/EasyAntProjectHelper.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/EasyAntProjectHelper.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/EasyAntProjectHelper.java Tue Jun 21 21:07:55 2011
@@ -227,8 +227,9 @@ public class EasyAntProjectHelper extend
for (Iterator iter = Target.parseDepends(depends, name,
"depends").iterator(); iter.hasNext();) {
String curTarget = (String) iter.next();
- if (projectTargets.containsKey(curTarget) && (projectTargets.get(curTarget) instanceof Phase)) {
-
+ if (projectTargets.containsKey(curTarget)
+ && (projectTargets.get(curTarget) instanceof Phase)) {
+
target.addDependency(curTarget);
} else {
target.addDependency(prefix + sep + curTarget);
@@ -264,17 +265,25 @@ public class EasyAntProjectHelper extend
}
if (phase != null) {
if (!projectTargets.containsKey(phase)) {
- throw new BuildException("can't add target " + name
- + " to phase " + phase + " because the phase"
- + " is unknown.");
+ if (!Project.toBoolean(project.getProperty("audit.mode"))) {
+ throw new BuildException("can't add target " + name
+ + " to phase " + phase + " because the phase"
+ + " is unknown.");
+ } else {
+ Phase p = new Phase();
+ p.setName(phase);
+ project.addTarget(p);
+ }
}
- Target t = (Target) projectTargets.get(phase);
- if (!(t instanceof Phase)) {
- throw new BuildException("referenced target " + phase
- + " is not a phase");
+ Target t = (Target) projectTargets.get(phase);
+ if (t != null) {
+ if (!(t instanceof Phase)) {
+ throw new BuildException("referenced target " + phase
+ + " is not a phase");
+ }
+ t.addDependency(name);
}
- t.addDependency(name);
}
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java Tue Jun 21 21:07:55 2011
@@ -122,11 +122,26 @@ public interface PluginService {
*
* @param moduleDescriptor
* a file that represent the module descriptor
+ * @param optionalAntModule the optional build file
+ * @param overrideAntModule an optional override buildfile
+ * @return an easyantReport for a given moduleDescriptor
+ * @throws Exception
+ */
+ EasyAntReport generateEasyAntReport(File moduleDescriptor, File optionalAntModule, File overrideAntModule) throws Exception;
+
+ /**
+ * Generate an easyantReport for a given moduleDescriptor. Using this report
+ * you should have all properties / plugins / targets loaded in your module
+ * descriptor
+ *
+ * @param moduleDescriptor
+ * a file that represent the module descriptor
* @return an easyantReport for a given moduleDescriptor
* @throws Exception
*/
EasyAntReport generateEasyAntReport(File moduleDescriptor) throws Exception;
+
/**
* Return the EasyAnt model containing all data of the module described in
* given file.
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java Tue Jun 21 21:07:55 2011
@@ -18,22 +18,40 @@
package org.apache.easyant.core.services.impl;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
import org.apache.easyant.core.EasyAntConstants;
+import org.apache.easyant.core.EasyAntEngine;
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.ant.Phase;
import org.apache.easyant.core.descriptor.EasyAntModuleDescriptor;
import org.apache.easyant.core.descriptor.PluginDescriptor;
import org.apache.easyant.core.descriptor.PropertyDescriptor;
import org.apache.easyant.core.parser.DefaultEasyAntXmlModuleDescriptorParser;
import org.apache.easyant.core.parser.EasyAntModuleDescriptorParser;
import org.apache.easyant.core.report.EasyAntReport;
-import org.apache.easyant.core.report.EasyAntReportModuleParser;
import org.apache.easyant.core.report.ImportedModuleReport;
+import org.apache.easyant.core.report.ParameterReport;
+import org.apache.easyant.core.report.ParameterType;
+import org.apache.easyant.core.report.PhaseReport;
+import org.apache.easyant.core.report.TargetReport;
import org.apache.easyant.core.services.PluginService;
+import org.apache.easyant.tasks.Import;
+import org.apache.easyant.tasks.ParameterTask;
import org.apache.ivy.Ivy;
import org.apache.ivy.core.IvyContext;
import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.resolve.ResolveOptions;
import org.apache.ivy.core.resolve.ResolvedModuleRevision;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.matcher.PatternMatcher;
@@ -41,7 +59,14 @@ import org.apache.ivy.plugins.parser.Mod
import org.apache.ivy.plugins.repository.url.URLResource;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.util.Message;
-import org.xml.sax.SAXException;
+import org.apache.tools.ant.ComponentHelper;
+import org.apache.tools.ant.ExtensionPoint;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.Target;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Property;
public class DefaultPluginServiceImpl implements PluginService {
@@ -52,7 +77,9 @@ public class DefaultPluginServiceImpl im
/**
* This is the default constructor, the IvyContext should be the IvyContext
* configured to the easyant ivy instance
- * @param ivyInstance the easyant ivy instance
+ *
+ * @param ivyInstance
+ * the easyant ivy instance
*/
public DefaultPluginServiceImpl(final Ivy ivyInstance) {
this(ivyInstance, new DefaultEasyAntXmlModuleDescriptorParser());
@@ -60,10 +87,11 @@ public class DefaultPluginServiceImpl im
/**
* A custom constructor if you want to specify your own parser /
- * configuration service, you should use this constructor
- * the IvyContext should be the IvyContext
- * configured to the easyant ivy instance
- * @param ivyInstance the easyant ivy instance
+ * configuration service, you should use this constructor the IvyContext
+ * should be the IvyContext configured to the easyant ivy instance
+ *
+ * @param ivyInstance
+ * the easyant ivy instance
* @param parser
* a valid easyantModuleDescriptor
*/
@@ -80,16 +108,277 @@ public class DefaultPluginServiceImpl im
public EasyAntReport getPluginInfo(ModuleRevisionId moduleRevisionId,
String conf) throws Exception {
+
+ IvyContext.pushNewContext().setIvy(ivyInstance);
+ EasyAntReport eaReport = null;
try {
-
- IvyContext.pushNewContext().setIvy(ivyInstance);
- EasyAntReport eaReport = EasyAntReportModuleParser.parseEasyAntModule(
- moduleRevisionId, conf);
-
+
+ ResolveOptions resolveOptions = new ResolveOptions();
+ resolveOptions.setLog(ResolveOptions.LOG_QUIET);
+ resolveOptions.setConfs(conf.split(","));
+ ResolveReport report = IvyContext.getContext().getIvy()
+ .getResolveEngine()
+ .resolve(moduleRevisionId, resolveOptions, true);
+ eaReport = new EasyAntReport();
+ eaReport.setResolveReport(report);
+ Map<String, String> properties = new HashMap<String, String>();
+ File antFile = null;
+
+ 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())) {
+ antFile = 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");
+ properties.put(sb.toString(), artifact.getLocalFile()
+ .getAbsolutePath());
+ }
+ }
+
+ if (antFile != null) {
+ scanAntFile(conf, eaReport, properties, antFile);
+ }
+ } catch (Exception e) {
+ throw new Exception(
+ "An error occured while fetching plugin informations : "
+ + e.getMessage(), e);
+ } finally {
IvyContext.popContext();
- return eaReport;
- } catch (SAXException e) {
- throw new Exception("Impossible to parse " + moduleRevisionId, e);
+ }
+ return eaReport;
+
+ }
+
+ private void scanAntFile(String conf, EasyAntReport eaReport,
+ Map<String, String> properties, File antFile) throws IOException,
+ Exception {
+ Project project = new Project();
+ // FIXME: temporary to support phases report
+ project.setNewProperty("audit.mode", "true");
+ project.setNewProperty(EasyAntMagicNames.SKIP_CORE_REVISION_CHECKER,
+ "true");
+ EasyAntEngine eagAntEngine = new EasyAntEngine();
+ eagAntEngine.configureEasyAntIvyInstance(project);
+ if (properties != null) {
+ for (Entry<String, String> entry : properties.entrySet()) {
+ project.setNewProperty(entry.getKey(), entry.getValue());
+ }
+ }
+ project.init();
+ ProjectHelper.configureProject(project, antFile);
+
+ for (Iterator iterator = project.getTargets().values().iterator(); iterator
+ .hasNext();) {
+ Target target = (Target) iterator.next();
+ handleTarget(eaReport, target);
+ for (int i = 0; i < target.getTasks().length; i++) {
+ Task task = target.getTasks()[i];
+ Class taskClass = ComponentHelper.getComponentHelper(project)
+ .getComponentClass(task.getTaskType());
+ if (taskClass == null) {
+ continue;
+ }
+ if (ParameterTask.class.getName().equals(taskClass.getName())) {
+ handleParameterTask(eaReport, task);
+ }
+ if (Property.class.getName().equals(taskClass.getName())) {
+ handleProperty(eaReport, task);
+ }
+ if (Import.class.getName().equals(taskClass.getName())) {
+ handleImport(conf, eaReport, task);
+ }
+
+ }
+ }
+ }
+
+ private void handleImport(String conf, EasyAntReport eaReport, Task task)
+ throws Exception {
+ Map<String, String> attributes = task.getRuntimeConfigurableWrapper()
+ .getAttributeMap();
+ ImportedModuleReport importedModuleReport = new ImportedModuleReport();
+ importedModuleReport.setModuleMrid(attributes.get("mrid"));
+ importedModuleReport.setModule(attributes.get("module"));
+
+ String org = attributes.get("org") != null ? attributes.get("org")
+ : attributes.get("organisation");
+ importedModuleReport.setOrganisation(org);
+
+ String rev = attributes.get("rev") != null ? attributes.get("rev")
+ : attributes.get("revision");
+ importedModuleReport.setRevision(rev);
+
+ importedModuleReport.setType(attributes.get("type"));
+ importedModuleReport.setAs(attributes.get("as"));
+ if (attributes.get("mandatory") != null) {
+ importedModuleReport.setMandatory(Boolean.parseBoolean(attributes
+ .get("mandatory")));
+ }
+ // importedModuleReport.setEasyantReport(getPluginInfo(
+ // ModuleRevisionId.parse(PropertyHelper.getPropertyHelper(
+ // task.getProject()).replaceProperties(
+ // importedModuleReport.getModuleMrid())), conf));
+
+ eaReport.addImportedModuleReport(importedModuleReport);
+ Message.debug("Ant file import another module called : "
+ + importedModuleReport.getModuleMrid() + " with mode "
+ + importedModuleReport.getType());
+ }
+
+ /**
+ * @param eaReport
+ * @param task
+ * @throws IOException
+ */
+ private void handleProperty(EasyAntReport eaReport, Task task)
+ throws IOException {
+ Map<String, String> attributes = task.getRuntimeConfigurableWrapper()
+ .getAttributeMap();
+ if (attributes.get("file") != null
+ && !Project.toBoolean(attributes.get("optional"))) {
+ Properties propToLoad = new Properties();
+ File f = new File(PropertyHelper.getPropertyHelper(
+ task.getProject())
+ .replaceProperties(attributes.get("file")));
+ try {
+ propToLoad.load(new FileInputStream(f));
+ for (Iterator iter = propToLoad.keySet().iterator(); iter
+ .hasNext();) {
+ String key = (String) iter.next();
+ PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
+ key);
+ propertyDescriptor.setValue(propToLoad.getProperty(key));
+ eaReport.addPropertyDescriptor(
+ propertyDescriptor.getName(), propertyDescriptor);
+ }
+
+ } catch (IOException e) {
+ throw new IOException("Unable to parse the property file :"
+ + attributes.get("file"), e);
+ }
+ }
+ }
+
+ /**
+ * @param eaReport
+ * @param task
+ */
+ private void handleParameterTask(EasyAntReport eaReport, Task task) {
+ Map<String, String> attributes = task.getRuntimeConfigurableWrapper()
+ .getAttributeMap();
+ PropertyDescriptor propertyDescriptor = null;
+
+ if (attributes.get("property") != null) {
+ propertyDescriptor = new PropertyDescriptor(
+ attributes.get("property"));
+ propertyDescriptor.setDefaultValue(attributes.get("default"));
+ if (attributes.get("required") == null)
+ propertyDescriptor.setRequired(false);
+ else
+ propertyDescriptor.setRequired(new Boolean(attributes
+ .get("required")));
+ if (attributes.get("description") != null) {
+ propertyDescriptor
+ .setDescription(attributes.get("description"));
+ }
+ if (task.getRuntimeConfigurableWrapper().getText() != null
+ && task.getRuntimeConfigurableWrapper().getText().length() > 0) {
+ propertyDescriptor.setDescription(task
+ .getRuntimeConfigurableWrapper().getText().toString());
+ }
+ Message.debug("Ant file has a property called : "
+ + propertyDescriptor.getName());
+ eaReport.addPropertyDescriptor(propertyDescriptor.getName(),
+ propertyDescriptor);
+ } else if (attributes.get("path") != null) {
+ ParameterReport parameterReport = new ParameterReport(
+ ParameterType.PATH);
+ parameterReport.setName(attributes.get("path"));
+ parameterReport.setDefaultValue(attributes.get("default"));
+ parameterReport
+ .setRequired(new Boolean(attributes.get("required")));
+ eaReport.addParameterReport(parameterReport);
+ Message.debug("Ant file has a path called : "
+ + parameterReport.getName());
+ }
+ }
+
+ /**
+ * @param eaReport
+ * @param target
+ */
+ private void handleTarget(EasyAntReport eaReport, Target target) {
+ if (!"".equals(target.getName())) {
+ boolean isExtensionPoint = target instanceof ExtensionPoint
+ || target instanceof Phase;
+ if (!isExtensionPoint) {
+ TargetReport targetReport = new TargetReport();
+ targetReport.setName(target.getName());
+ StringBuilder sb = new StringBuilder();
+ Enumeration targetDeps = target.getDependencies();
+ while (targetDeps.hasMoreElements()) {
+ String t = (String) targetDeps.nextElement();
+ sb.append(t);
+ if (targetDeps.hasMoreElements()) {
+ sb.append(",");
+ }
+ }
+ targetReport.setDepends(sb.toString());
+ targetReport.setDescription(target.getDescription());
+ targetReport.setIfCase(target.getIf());
+ targetReport.setUnlessCase(target.getUnless());
+ for (Iterator iterator = target.getProject().getTargets()
+ .values().iterator(); iterator.hasNext();) {
+ Target currentTarget = (Target) iterator.next();
+ if (currentTarget instanceof ExtensionPoint
+ || currentTarget instanceof Phase) {
+ Enumeration dependencies = currentTarget
+ .getDependencies();
+ while (dependencies.hasMoreElements()) {
+ String dep = (String) dependencies.nextElement();
+ if (dep.equals(target.getName())) {
+ targetReport.setPhase(currentTarget.getName());
+ }
+ }
+
+ }
+ }
+
+ eaReport.addTargetReport(targetReport);
+
+ Message.debug("Ant file has a target called : "
+ + targetReport.getName());
+ } else {
+ PhaseReport extensionPoint = new PhaseReport(target.getName());
+ StringBuilder sb = new StringBuilder();
+ Enumeration targetDeps = target.getDependencies();
+ while (targetDeps.hasMoreElements()) {
+ String t = (String) targetDeps.nextElement();
+ sb.append(t);
+ if (targetDeps.hasMoreElements()) {
+ sb.append(",");
+ }
+ }
+ extensionPoint.setDepends(sb.toString());
+ extensionPoint.setDescription(target.getDescription());
+ eaReport.addPhaseReport(extensionPoint);
+ Message.debug("Ant file has an extensionPoint called : "
+ + extensionPoint.getName());
+ }
}
}
@@ -100,26 +389,15 @@ public class DefaultPluginServiceImpl im
public EasyAntReport getPluginInfo(String moduleRevisionId)
throws Exception {
- String mrid = moduleRevisionId;
- if (!mrid.matches(".*#.*")) {
- Message.debug("No organisation specified for plugin " + mrid
- + " using the default one");
- mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#" + mrid;
- }
- ModuleRevisionId module = ModuleRevisionId.parse(mrid);
+ ModuleRevisionId module = buildModuleRevisionId(moduleRevisionId,
+ PluginType.PLUGIN);
return getPluginInfo(module);
}
public EasyAntReport getBuildTypeInfo(String moduleRevisionId)
throws Exception {
- String mrid = moduleRevisionId;
- if (!mrid.matches(".*#.*")) {
- Message.debug("No organisation specified for buildtype " + mrid
- + " using the default one");
- mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION + "#"
- + mrid;
- }
- ModuleRevisionId module = ModuleRevisionId.parse(mrid);
+ ModuleRevisionId module = buildModuleRevisionId(moduleRevisionId,
+ PluginType.BUILDTYPE);
return getPluginInfo(module);
}
@@ -136,20 +414,22 @@ public class DefaultPluginServiceImpl im
// First we need to parse the specified file to retrieve all the easyant
// stuff
parser.parseDescriptor(ivyInstance.getSettings(),
- moduleDescriptor.toURL(), new URLResource(moduleDescriptor
- .toURL()), true);
+ moduleDescriptor.toURL(),
+ new URLResource(moduleDescriptor.toURL()), true);
EasyAntModuleDescriptor md = parser.getEasyAntModuleDescriptor();
IvyContext.popContext();
return md;
}
- public EasyAntReport generateEasyAntReport(File moduleDescriptor)
- throws Exception {
+ public EasyAntReport generateEasyAntReport(File moduleDescriptor,
+ File optionalAntModule, File overrideAntModule) throws Exception {
EasyAntReport eaReport = new EasyAntReport();
+
+ if (overrideAntModule != null && overrideAntModule.exists()) {
+ scanAntFile("default", eaReport, null, overrideAntModule);
+ }
try {
EasyAntModuleDescriptor md = getEasyAntModuleDescriptor(moduleDescriptor);
-
- // Then we can Store properties
for (Iterator<PropertyDescriptor> iterator = md.getProperties()
.values().iterator(); iterator.hasNext();) {
PropertyDescriptor property = iterator.next();
@@ -169,8 +449,13 @@ public class DefaultPluginServiceImpl im
PluginDescriptor plugin = (PluginDescriptor) iterator
.next();
ImportedModuleReport pluginReport = new ImportedModuleReport();
+ ModuleRevisionId mrid = ModuleRevisionId.parse(plugin.getMrid());
pluginReport.setModuleMrid(plugin.getMrid());
- pluginReport.setAs(plugin.getAs());
+ if (plugin.getAs() == null) {
+ pluginReport.setAs(mrid.getName());
+ } else {
+ pluginReport.setAs(plugin.getAs());
+ }
pluginReport.setType(plugin.getMode());
pluginReport
.setEasyantReport(getPluginInfo(ModuleRevisionId
@@ -183,11 +468,17 @@ public class DefaultPluginServiceImpl im
throw new Exception("problem while parsing Ivy module file: "
+ e.getMessage(), e);
}
+
+ if (optionalAntModule != null && optionalAntModule.exists()) {
+ scanAntFile("default", eaReport, null, optionalAntModule);
+ }
+
return eaReport;
}
public ModuleRevisionId[] search(String organisation, String moduleName,
- String revision, String branch, String matcher, String resolver) throws Exception {
+ String revision, String branch, String matcher, String resolver)
+ throws Exception {
IvySettings settings = ivyInstance.getSettings();
if (moduleName == null && PatternMatcher.EXACT.equals(matcher)) {
@@ -213,21 +504,24 @@ public class DefaultPluginServiceImpl im
PatternMatcher patternMatcher = settings.getMatcher(matcher);
if ("*".equals(resolver)) {
- //search in all resolvers. this can be quite slow for complex repository configurations
- //with ChainResolvers, since resolvers in chains will be searched multiple times.
+ // search in all resolvers. this can be quite slow for complex
+ // repository configurations
+ // with ChainResolvers, since resolvers in chains will be searched
+ // multiple times.
return ivyInstance.listModules(criteria, patternMatcher);
} else {
- //limit search to the specified resolver.
- DependencyResolver dependencyResolver =
- resolver == null ? settings.getDefaultResolver()
- : settings.getResolver(resolver);
+ // limit search to the specified resolver.
+ DependencyResolver dependencyResolver = resolver == null ? settings
+ .getDefaultResolver() : settings.getResolver(resolver);
if (dependencyResolver == null) {
- throw new IllegalArgumentException("Unknown dependency resolver for search: " + resolver);
+ throw new IllegalArgumentException(
+ "Unknown dependency resolver for search: " + resolver);
}
ivyInstance.pushContext();
try {
- return ivyInstance.getSearchEngine().listModules(dependencyResolver, criteria, patternMatcher);
+ return ivyInstance.getSearchEngine().listModules(
+ dependencyResolver, criteria, patternMatcher);
} finally {
ivyInstance.popContext();
}
@@ -249,35 +543,56 @@ public class DefaultPluginServiceImpl im
}
return result;
}
-
+
public String getDescription(ModuleRevisionId mrid) {
ResolvedModuleRevision rmr = ivyInstance.findModule(mrid);
return rmr.getDescriptor().getDescription();
}
-
-
- public String getPluginDescription(String moduleRevisionId) {
- String mrid = moduleRevisionId;
- if (!mrid.matches(".*#.*")) {
- Message.debug("No organisation specified for plugin " + mrid
- + " using the default one");
- mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#" + mrid;
- }
- ModuleRevisionId module = ModuleRevisionId.parse(mrid);
+ public String getPluginDescription(String moduleRevisionId) {
+ ModuleRevisionId module = buildModuleRevisionId(moduleRevisionId,
+ PluginType.PLUGIN);
return getDescription(module);
}
-
+
public String getBuildTypeDescription(String moduleRevisionId) {
+ ModuleRevisionId module = buildModuleRevisionId(moduleRevisionId,
+ PluginType.BUILDTYPE);
+
+ return getDescription(module);
+ }
+
+ private ModuleRevisionId buildModuleRevisionId(String moduleRevisionId,
+ PluginType pluginType) {
String mrid = moduleRevisionId;
if (!mrid.matches(".*#.*")) {
- Message.debug("No organisation specified for buildtype " + mrid
- + " using the default one");
- mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION + "#" + mrid;
+ if (pluginType.equals(PluginType.BUILDTYPE)) {
+ Message.debug("No organisation specified for buildtype " + mrid
+ + " using the default one");
+
+ mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION + "#"
+ + mrid;
+
+ } else {
+ Message.debug("No organisation specified for plugin " + mrid
+ + " using the default one");
+
+ mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#"
+ + mrid;
+ }
}
ModuleRevisionId module = ModuleRevisionId.parse(mrid);
+ return module;
+ }
+
+ public EasyAntReport generateEasyAntReport(File moduleDescriptor)
+ throws Exception {
+ return generateEasyAntReport(moduleDescriptor, null, null);
+ }
+
+ private enum PluginType {
+ BUILDTYPE, PLUGIN
- return getDescription(module);
}
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ProjectMan.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ProjectMan.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ProjectMan.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ProjectMan.java Tue Jun 21 21:07:55 2011
@@ -83,12 +83,14 @@ public class ProjectMan {
* @param moduleDescriptor
* The build module file. This MUST not be left unspecified.
* This value does not default to module.ivy in current directory.
+ * @param optionalAntModule The optional build file
+ * @param overrideAntModule The optional override build file.
*/
- public boolean setContext(Project p, File moduleDescriptor) {
+ public boolean setContext(Project p, File moduleDescriptor, File optionalAntModule, File overrideAntModule) {
project = p;
try {
PluginService pluginService = (PluginService)project.getReference(EasyAntMagicNames.PLUGIN_SERVICE_INSTANCE);
- earep = pluginService.generateEasyAntReport(moduleDescriptor);
+ earep = pluginService.generateEasyAntReport(moduleDescriptor,optionalAntModule,overrideAntModule);
inited = true;
} catch (Throwable t) {
project.log("EasyAntMan could not be initialized. Details: " + t.getMessage());
Modified: incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java?rev=1138188&r1=1138187&r2=1138188&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java (original)
+++ incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java Tue Jun 21 21:07:55 2011
@@ -49,13 +49,13 @@ public class PluginServiceTest {
public static void setUp() throws ParseException, IOException {
// configure the ivyinstance
Ivy ivy = IvyContext.pushNewContext().getIvy();
- ivy.setVariable(EasyAntMagicNames.EASYANT_CORE_REPO_URL,
+ ivy.setVariable(
+ EasyAntMagicNames.EASYANT_CORE_REPO_URL,
PluginServiceTest.class.getResource(
"/org/apache/easyant/core/repository/modules")
.toExternalForm());
- ivy
- .configure(PluginServiceTest.class
- .getResource("/org/apache/easyant/core/default-easyant-ivysettings.xml"));
+ ivy.configure(PluginServiceTest.class
+ .getResource("/org/apache/easyant/core/default-easyant-ivysettings.xml"));
pluginService = new DefaultPluginServiceImpl(ivy);
}
@@ -71,9 +71,10 @@ public class PluginServiceTest {
@Test
public void testSearchAllResolvers() throws Exception {
ModuleRevisionId[] mrids = pluginService.search(
- "org.apache.easyant.buildtypes", "build-std-java",
- null, null, PatternMatcher.EXACT, "*");
- // the module should be found once each in easyant repo and in chained resolver
+ "org.apache.easyant.buildtypes", "build-std-java", null, null,
+ PatternMatcher.EXACT, "*");
+ // the module should be found once each in easyant repo and in chained
+ // resolver
Assert.assertEquals(2, mrids.length);
Assert.assertEquals(mrids[0], mrids[1]);
}
@@ -86,10 +87,17 @@ public class PluginServiceTest {
Assert.assertEquals(1, mrids.length);
}
+ private EasyAntReport generateReport() throws Exception {
+ File module = new File(this.getClass().getResource("module.ivy")
+ .toURI());
+ File moduleAnt = new File(this.getClass().getResource("module.ant")
+ .toURI());
+ return pluginService.generateEasyAntReport(module, moduleAnt, null);
+ }
+
@Test
public void testGenerateReport() throws Exception {
- File module = new File("example/standard-java-app/module.ivy");
- EasyAntReport eaReport = pluginService.generateEasyAntReport(module);
+ EasyAntReport eaReport = generateReport();
Assert.assertNotNull(eaReport);
// the report should contain the run-java plugin
@@ -115,16 +123,15 @@ public class PluginServiceTest {
"run.main.classname");
Assert.assertNotNull(property);
// check the value of the property
- Assert.assertEquals("org.apache.easyant.example.Example", property
- .getValue());
+ Assert.assertEquals("org.apache.easyant.example.Example",
+ property.getValue());
// be sure that the property exist
PropertyDescriptor srcMainJava = eaReport.getAvailableProperties().get(
"src.main.java");
Assert.assertNotNull(srcMainJava);
// check the value of the property
- Assert.assertEquals("${basedir}/src/main/java", srcMainJava
- .getValue());
+ Assert.assertEquals("${basedir}/src/main/java", srcMainJava.getValue());
// the property should also be contained in getAvailableProperties which
// list all properties (those for the current module and those in
@@ -132,8 +139,8 @@ public class PluginServiceTest {
property = eaReport.getAvailableProperties().get("run.main.classname");
Assert.assertNotNull(property);
// check the value of the property
- Assert.assertEquals("org.apache.easyant.example.Example", property
- .getValue());
+ Assert.assertEquals("org.apache.easyant.example.Example",
+ property.getValue());
// check that package phase exists and that jar:jar target is bound to
// this phase
@@ -147,12 +154,31 @@ public class PluginServiceTest {
Assert.assertNotNull(packagePhase);
List<TargetReport> targets = packagePhase.getTargetReports();
- Set<String> expectedTargets = new HashSet<String>(Arrays.asList("jar:jar", "test-jar:jar"));
- Assert.assertEquals("test and main jars included in package phase", expectedTargets.size(), targets.size());
+ Set<String> expectedTargets = new HashSet<String>(Arrays.asList(
+ "jar:jar", "test-jar:jar"));
+ Assert.assertEquals("test and main jars included in package phase",
+ expectedTargets.size(), targets.size());
for (TargetReport target : packagePhase.getTargetReports()) {
- Assert.assertTrue("expected to find " + target.getName(), expectedTargets.remove(target.getName()));
+ Assert.assertTrue("expected to find " + target.getName(),
+ expectedTargets.remove(target.getName()));
+ }
+
+ }
+
+ @Test
+ public void shouldHaveModuleAntFile() throws Exception {
+ EasyAntReport eaReport = generateReport();
+ boolean hasHelloWorldTarget = false;
+ for (TargetReport targetReport : eaReport.getAvailableTargets()) {
+ if ("hello-world".equals(targetReport.getName())) {
+ Assert.assertTrue("process-sources".equals(targetReport
+ .getPhase()));
+ hasHelloWorldTarget = true;
+ break;
+ }
}
+ Assert.assertTrue(hasHelloWorldTarget);
}
@Test
Added: incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ant
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ant?rev=1138188&view=auto
==============================================================================
--- incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ant (added)
+++ incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ant Tue Jun 21 21:07:55 2011
@@ -0,0 +1,21 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project>
+ <target name="hello-world" phase="process-sources">
+ <echo>hello world</echo>
+ </target>
+</project>
\ No newline at end of file
Added: incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ivy
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ivy?rev=1138188&view=auto
==============================================================================
--- incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ivy (added)
+++ incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/services/module.ivy Tue Jun 21 21:07:55 2011
@@ -0,0 +1,29 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
+ <info organisation="org.apache.easyant" module="standard-java-app" status="integration" >
+ <ea:build module="build-std-java" revision="0.2">
+ <ea:property name="run.main.classname" value="org.apache.easyant.example.Example"/>
+ <ea:plugin module="run-java" revision="0.1"/>
+ <ea:plugin module="package-test-jar" revision="0.1" as="test-jar"/>
+ </ea:build>
+ </info>
+ <configurations>
+ <conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf"/>
+ <conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases."/>
+ </configurations>
+</ivy-module>