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 [14/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/core/ivy/IvyInstanceHelper.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/IvyInstanceHelper.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/IvyInstanceHelper.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/IvyInstanceHelper.java Tue Feb 22 15:55:55 2011
@@ -29,78 +29,78 @@ import org.apache.tools.ant.types.Refere
public class IvyInstanceHelper {
- /**
- * Get the project ivy instance name. This methods takes in consideration that project ivy instance name can be set through "project.ivy.instance" property
- * @param project a project instance
- * @return the project ivy instance name
- */
- public static String getProjectIvyInstanceName(Project project) {
- String projectIvyInstanceProp = project.getProperty(EasyAntMagicNames.PROJECT_IVY_INSTANCE);
- if (projectIvyInstanceProp == null) {
- projectIvyInstanceProp = EasyAntMagicNames.PROJECT_IVY_INSTANCE;
- }
- return projectIvyInstanceProp;
- }
+ /**
+ * Get the project ivy instance name. This methods takes in consideration that project ivy instance name can be set through "project.ivy.instance" property
+ * @param project a project instance
+ * @return the project ivy instance name
+ */
+ public static String getProjectIvyInstanceName(Project project) {
+ String projectIvyInstanceProp = project.getProperty(EasyAntMagicNames.PROJECT_IVY_INSTANCE);
+ if (projectIvyInstanceProp == null) {
+ projectIvyInstanceProp = EasyAntMagicNames.PROJECT_IVY_INSTANCE;
+ }
+ return projectIvyInstanceProp;
+ }
- /**
- * Build a project ivy reference.
- * @param project a project instance
- * @return a project ivy refrence
- */
- public static Reference buildProjectIvyReference(Project project) {
- return buildIvyReference(project,getProjectIvyInstanceName(project));
- }
-
- /**
- * Build an easyant ivy reference
- * @param project a project instance
- * @return an easyant ivy reference
- */
- public static Reference buildEasyAntIvyReference(Project project) {
- return buildIvyReference(project,EasyAntMagicNames.EASYANT_IVY_INSTANCE);
- }
-
- /**
- * Build an ivy instance reference based on a given instance name
- * @param project a project instance
- * @param instanceName an instance name
- * @return an ivy instance reference
- */
- public static Reference buildIvyReference (Project project,String instanceName) {
- return new Reference(project, instanceName);
- }
-
- /**
- * Get project {@link IvyAntSettings}
- * @param project a project instance
- * @return the project {@link IvyAntSettings}
- */
- public static IvyAntSettings getProjectIvyAntSettings(Project project) {
- return getIvyAntSettings(project, getProjectIvyInstanceName(project));
- }
-
- /**
- * Get easyant {@link IvyAntSettings}
- * @param project a project instance
- * @return the easyant {@link IvyAntSettings}
- */
- public static IvyAntSettings getEasyAntIvyAntSettings(Project project) {
- return getIvyAntSettings(project, EasyAntMagicNames.EASYANT_IVY_INSTANCE);
- }
-
- /**
- * Get an {@link IvyAntSettings} based on instance name
- * @param project a project instance
- * @param instanceName an {@link IvyAntSettings} name
- * @return the requested {@link IvyAntSettings}
- */
- public static IvyAntSettings getIvyAntSettings(Project project, String instanceName) {
- Object o = project.getReference(instanceName);
- if (o != null && o instanceof IvyAntSettings) {
- return (IvyAntSettings)o;
- } else {
- throw new IllegalStateException(instanceName + " is not a valid ivy instance");
- }
- }
+ /**
+ * Build a project ivy reference.
+ * @param project a project instance
+ * @return a project ivy refrence
+ */
+ public static Reference buildProjectIvyReference(Project project) {
+ return buildIvyReference(project,getProjectIvyInstanceName(project));
+ }
+
+ /**
+ * Build an easyant ivy reference
+ * @param project a project instance
+ * @return an easyant ivy reference
+ */
+ public static Reference buildEasyAntIvyReference(Project project) {
+ return buildIvyReference(project,EasyAntMagicNames.EASYANT_IVY_INSTANCE);
+ }
+
+ /**
+ * Build an ivy instance reference based on a given instance name
+ * @param project a project instance
+ * @param instanceName an instance name
+ * @return an ivy instance reference
+ */
+ public static Reference buildIvyReference (Project project,String instanceName) {
+ return new Reference(project, instanceName);
+ }
+
+ /**
+ * Get project {@link IvyAntSettings}
+ * @param project a project instance
+ * @return the project {@link IvyAntSettings}
+ */
+ public static IvyAntSettings getProjectIvyAntSettings(Project project) {
+ return getIvyAntSettings(project, getProjectIvyInstanceName(project));
+ }
+
+ /**
+ * Get easyant {@link IvyAntSettings}
+ * @param project a project instance
+ * @return the easyant {@link IvyAntSettings}
+ */
+ public static IvyAntSettings getEasyAntIvyAntSettings(Project project) {
+ return getIvyAntSettings(project, EasyAntMagicNames.EASYANT_IVY_INSTANCE);
+ }
+
+ /**
+ * Get an {@link IvyAntSettings} based on instance name
+ * @param project a project instance
+ * @param instanceName an {@link IvyAntSettings} name
+ * @return the requested {@link IvyAntSettings}
+ */
+ public static IvyAntSettings getIvyAntSettings(Project project, String instanceName) {
+ Object o = project.getReference(instanceName);
+ if (o != null && o instanceof IvyAntSettings) {
+ return (IvyAntSettings)o;
+ } else {
+ throw new IllegalStateException(instanceName + " is not a valid ivy instance");
+ }
+ }
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/repository/JarRepository.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/repository/JarRepository.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/repository/JarRepository.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/repository/JarRepository.java Tue Feb 22 15:55:55 2011
@@ -41,21 +41,21 @@ public class JarRepository extends URLRe
/** lazily cache jar file directories to speed up repository searches and reporting */
private HashMap<String, Directory> jarCache = new HashMap<String, Directory>();
- public List list(String parent) throws IOException {
- if (parent.startsWith("jar")) {
- //extract path in parent
- Matcher matcher = URL_PATTERN.matcher(parent);
- matcher.find();
+ public List list(String parent) throws IOException {
+ if (parent.startsWith("jar")) {
+ //extract path in parent
+ Matcher matcher = URL_PATTERN.matcher(parent);
+ matcher.find();
String baseUrl = matcher.group(1);
- String path = matcher.group(2);
-
+ String path = matcher.group(2);
+
//find the parent path in the directory.
Directory directory = getDirectory(baseUrl, parent).findEntry(path);
return new ArrayList<String>(directory.getChildren());
- }
- return super.list(parent);
- }
+ }
+ return super.list(parent);
+ }
@Override
public void put(File source, String destination, boolean overwrite) throws IOException {
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/resolvers/JarResolver.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/resolvers/JarResolver.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/resolvers/JarResolver.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ivy/resolvers/JarResolver.java Tue Feb 22 15:55:55 2011
@@ -25,11 +25,11 @@ import org.apache.ivy.plugins.resolver.U
* way to list files/directories inside a jar.
*/
public class JarResolver extends URLResolver {
- public JarResolver() {
- setRepository(new JarRepository());
- }
+ public JarResolver() {
+ setRepository(new JarRepository());
+ }
- public String getTypeName() {
- return "jar";
- }
+ public String getTypeName() {
+ return "jar";
+ }
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGenerator.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGenerator.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGenerator.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGenerator.java Tue Feb 22 15:55:55 2011
@@ -46,7 +46,7 @@ public interface MenuGenerator<M extends
* @param targetLink the target for the menu entry, e.g. a URL or file path
* @throws IOException if there are errors adding a new entry to the menu.
*/
- public void addEntry(String title, String targetLink) throws IOException;
+ public void addEntry(String title, String targetLink) throws IOException;
/**
* Add a submenu entry to the menu. It is <strong>not</strong> the responsibility
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGeneratorRegistry.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGeneratorRegistry.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGeneratorRegistry.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/menu/MenuGeneratorRegistry.java Tue Feb 22 15:55:55 2011
@@ -26,53 +26,53 @@ import java.util.List;
*
*/
public class MenuGeneratorRegistry {
- private List<MenuGenerator> menuGenerators = new ArrayList<MenuGenerator>();
- private final String context;
-
- /**
- * Default constructor
- * @param context the related context
- */
- public MenuGeneratorRegistry(String context) {
- this.context = context;
- }
-
-
- /**
- * Get a list of registred {@link MenuGenerator}s
- * @return a list of registred {@link MenuGenerator}
- */
- public List<MenuGenerator> getMenuGenerators() {
- return menuGenerators;
- }
+ private List<MenuGenerator> menuGenerators = new ArrayList<MenuGenerator>();
+ private final String context;
+
+ /**
+ * Default constructor
+ * @param context the related context
+ */
+ public MenuGeneratorRegistry(String context) {
+ this.context = context;
+ }
+
+
+ /**
+ * Get a list of registred {@link MenuGenerator}s
+ * @return a list of registred {@link MenuGenerator}
+ */
+ public List<MenuGenerator> getMenuGenerators() {
+ return menuGenerators;
+ }
- /**
- * Add a given {@link MenuGenerator}
- * @param menuGenerator a given {@link MenuGenerator}
- * @return true the element was added
- */
- public boolean addMenuGenerator(MenuGenerator menuGenerator) {
- return menuGenerators.add(menuGenerator);
- }
-
- /**
- * Remove a given {@link MenuGenerator}
- * @param menuGenerator a given {@link MenuGenerator}
- * @return true if the element was removed
- */
- public boolean removeMenuGenerator(MenuGenerator menuGenerator) {
- return menuGenerators.remove(menuGenerator);
- }
+ /**
+ * Add a given {@link MenuGenerator}
+ * @param menuGenerator a given {@link MenuGenerator}
+ * @return true the element was added
+ */
+ public boolean addMenuGenerator(MenuGenerator menuGenerator) {
+ return menuGenerators.add(menuGenerator);
+ }
+
+ /**
+ * Remove a given {@link MenuGenerator}
+ * @param menuGenerator a given {@link MenuGenerator}
+ * @return true if the element was removed
+ */
+ public boolean removeMenuGenerator(MenuGenerator menuGenerator) {
+ return menuGenerators.remove(menuGenerator);
+ }
- /**
- * Propagate the generation to all registered {@link MenuGenerator}
- * {@inheritDoc}
- */
- public void addEntry(String title, String targetLink) throws IOException {
- for (MenuGenerator menuGenerator : menuGenerators) {
- menuGenerator.addEntry(title, targetLink);
- }
- }
+ /**
+ * Propagate the generation to all registered {@link MenuGenerator}
+ * {@inheritDoc}
+ */
+ public void addEntry(String title, String targetLink) throws IOException {
+ for (MenuGenerator menuGenerator : menuGenerators) {
+ menuGenerator.addEntry(title, targetLink);
+ }
+ }
/**
* Call {@link org.apache.easyant.core.menu.MenuGenerator#endMenu()} on all registered
@@ -84,12 +84,12 @@ public class MenuGeneratorRegistry {
}
}
- /**
- * Get the context related to this registry
- * @return a string representing the context
- */
- public String getContext() {
- return context;
- }
+ /**
+ * Get the context related to this registry
+ * @return a string representing the context
+ */
+ public String getContext() {
+ return context;
+ }
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java Tue Feb 22 15:55:55 2011
@@ -54,589 +54,589 @@ import org.xml.sax.SAXException;
* Parses an easyant module descriptor and output an EasyAntModuleDescriptor
*/
public class DefaultEasyAntXmlModuleDescriptorParser extends
- XmlModuleDescriptorParser implements EasyAntModuleDescriptorParser {
+ XmlModuleDescriptorParser implements EasyAntModuleDescriptorParser {
- static final String[] PLUGIN_REGULAR_ATTRIBUTES = new String[] {
- "organisation", "org", "module", "revision", "rev", "mrid", "conf",
- "mode", "as", "inheritable", "inherit-scope" };
-
- public boolean accept(Resource res) {
- return res.getName().endsWith(".ivy");
- }
-
- protected Parser newParser(ParserSettings ivySettings) {
-
- return new EasyAntParser(this, ivySettings);
- }
-
- private EasyAntModuleDescriptor easyAntModuleDescriptor;
-
- private String activeBuildConfigurations;
-
- public void setActiveBuildConfigurations(String activeBuildConfigurations) {
- this.activeBuildConfigurations = activeBuildConfigurations;
- }
-
- public EasyAntModuleDescriptor getEasyAntModuleDescriptor() {
- return easyAntModuleDescriptor;
- }
-
- public ModuleDescriptor parseDescriptor(ParserSettings ivySettings,
- URL xmlURL, Resource res, boolean validate) throws ParseException,
- IOException {
-
- EasyAntParser parser = (EasyAntParser) newParser(ivySettings);
- parser.setValidate(validate);
- parser.setResource(res);
- parser.setInput(xmlURL);
- parser.parse();
- easyAntModuleDescriptor = parser.getEasyAntModuleDescriptor();
-
- return parser.getModuleDescriptor();
- }
-
- public class EasyAntParser extends Parser {
-
- public final class EasyAntState {
- public static final int NONE = 0;
- public static final int EASYANT = 1;
- public static final int PLUGIN = 2;
-
- private EasyAntState() {
- }
-
- }
-
- private int easyAntState;
-
- private DefaultEasyAntDescriptor easyAntModuleDescriptor;
-
- private String easyantPrefix;
-
- private PluginDescriptor currentPluginDescriptor;
-
- public EasyAntParser(ModuleDescriptorParser parser,
- ParserSettings ivySettings) {
- super(parser, ivySettings);
- easyAntState = EasyAntState.NONE;
- easyAntModuleDescriptor = new DefaultEasyAntDescriptor();
- easyantPrefix = "";
- }
-
- public void startElement(String uri, String localName, String name,
- Attributes attributes) throws SAXException {
- super.startElement(uri, localName, name, attributes);
- if (name.equals(easyantPrefix + ":build")
- && State.EXTRA_INFO == getState()) {
- eaBuildStarted(attributes);
- }
- if (name.equals(easyantPrefix + ":plugin")
- && State.EXTRA_INFO == getState()) {
- pluginStarted(attributes);
- }
- if (name.equals(easyantPrefix + ":property")
- && State.EXTRA_INFO == getState()) {
- easyantPropertyStarted(attributes);
- }
-
- if (name.equals(easyantPrefix + ":bindtarget")
- && State.EXTRA_INFO == getState()) {
- bindTargetStarted(attributes);
- }
-
- if ("easyant".equals(name)) {
- // TODO: add a reference to the documentation
- Message
- .warn("<easyant> tag is deprecated since easyant 0.6, we strongly recommend you to use <ea:build> instead");
- eaBuildStarted(attributes);
- }
- if (easyAntState == EasyAntState.EASYANT && "property".equals(name)) {
- // TODO: add a reference to the documentation
- Message
- .warn("<property> tag is deprecated since easyant 0.6, we strongly recommend you to use <ea:property> instead");
- easyantPropertyStarted(attributes);
- }
- if (easyAntState == EasyAntState.EASYANT && "plugin".equals(name)) {
- // TODO: add a reference to the documentation
- Message
- .warn("<plugin> tag is deprecated since easyant 0.6, we strongly recommend you to use <ea:plugin> instead");
- pluginStarted(attributes);
- }
- }
-
- @Override
- public void endElement(String uri, String localName, String name)
- throws SAXException {
- super.endElement(uri, localName, name);
- if (name.equals(easyantPrefix + ":plugin")
- && easyAntState == EasyAntState.PLUGIN) {
- endPlugin();
- }
- }
-
- protected void endPlugin() {
- currentPluginDescriptor = null;
- easyAntState = EasyAntState.NONE;
- }
-
- @Override
- protected void ivyModuleStarted(Attributes attributes)
- throws SAXException {
- super.ivyModuleStarted(attributes);
- // lookup easyant namespace
- for (Iterator iterator = getMd().getExtraAttributesNamespaces()
- .entrySet().iterator(); iterator.hasNext();) {
- Entry namespace = (Entry) iterator.next();
- if (EasyAntConstants.EASYANT_MD_NAMESPACE.equals(namespace
- .getValue())) {
- easyantPrefix = (String) namespace.getKey();
- }
- }
-
- }
-
- @Override
- public void endDocument() throws SAXException {
- super.endDocument();
-
- for (Configuration conf : getMd().getConfigurations()) {
- if ("profile".equals(conf.getExtraAttribute(easyantPrefix
- + ":type"))) {
- Message.debug("Adding build configuration named "
- + conf.getName());
- easyAntModuleDescriptor.addBuildConfiguration(conf
- .getName());
- }
- }
- try {
- easyAntModuleDescriptor.setIvyModuleDescriptor(super
- .getModuleDescriptor());
- } catch (ParseException e) {
- throw new SAXException(e);
- }
- }
-
- /**
- * Parsing the plugin tag
- *
- * @param attributes
- * reprensents the plugins attributes
- */
- protected void pluginStarted(Attributes attributes) {
- boolean mandatory = false;
-
- String mandatoryValue = getSettings().substitute(
- attributes.getValue("mandatory"));
- if (mandatoryValue != null && "true".equals(mandatoryValue)) {
- mandatory = true;
- }
- String conf = getSettings().substitute(attributes.getValue("conf"));
-
- easyAntState = EasyAntState.PLUGIN;
- PluginDescriptor plugin = new PluginDescriptor(getMd()
- .getModuleRevisionId());
-
- String mrid = getSettings().substitute(attributes.getValue("mrid"));
- if (mrid != null) {
- if (!mrid.matches(".*#.*")) {
- Message.debug("No organisation specified for plugin "
- + mrid + " using the default one");
- mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#"
- + mrid;
- }
- plugin.setMrid(mrid);
- } else {
- String org = attributes.getValue("org") != null ? attributes
- .getValue("org") : attributes.getValue("organisation");
- org = getSettings().substitute(org);
- if (org == null) {
- Message.debug("No organisation specified for plugin "
- + mrid + " using the default one");
- org = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION;
-
- }
- String module = getSettings().substitute(
- attributes.getValue("module"));
- String revision = attributes.getValue("rev") != null ? attributes
- .getValue("rev")
- : attributes.getValue("revision");
- revision = getSettings().substitute(revision);
- plugin.setOrganisation(org);
- plugin.setModule(module);
- plugin.setRevision(revision);
-
- }
- String mode = getSettings().substitute(attributes.getValue("mode"));
- // If no mode is defined in the module descriptor we use include
- // by default
- if (mode == null) {
- plugin.setMode("include");
- } else {
- plugin.setMode(mode);
- }
-
- plugin.setMandatory(mandatory);
- plugin.setAs(getSettings().substitute(attributes.getValue("as")));
- plugin.setBuildConfigurations(conf);
-
- handleInheritedScopeAttribute(attributes, plugin);
-
- currentPluginDescriptor = plugin;
- if (BuildConfigurationHelper.contains(conf,
- activeBuildConfigurations)) {
- easyAntModuleDescriptor.addPlugin(plugin);
- }
-
- handlePropertyAsAttribute(attributes, conf);
- }
-
- /**
- * handle properties as attribute
- *
- * @param attributes
- * a set of attributes
- * @param conf
- * build configurations where this property should be applied
- * (can be null)
- */
- protected void handlePropertyAsAttribute(Attributes attributes,
- String conf) {
- List<String> ignored = Arrays.asList(PLUGIN_REGULAR_ATTRIBUTES);
- for (int i = 0; i < attributes.getLength(); i++) {
- if (!ignored.contains(attributes.getQName(i))) {
- String propertyName = attributes.getQName(i);
- String value = IvyContext.getContext().getSettings()
- .substitute(attributes.getValue(i));
- PropertyDescriptor property = new PropertyDescriptor(
- propertyName);
- property.setValue(value);
- property.setBuildConfigurations(conf);
- applyInheritableItemAttributesFromPlugin(property);
- easyAntModuleDescriptor.getProperties().put(propertyName,
- property);
- }
- }
- }
-
- /**
- * Handle inherited scope specific attributes
- * @param attributes a set of attributes
- * @param inheritScopeElement an element supporting inherit scope attributes
- */
- private void handleInheritedScopeAttribute(Attributes attributes,
- AdvancedInheritableItem inheritScopeElement) {
- String inheritScopeValue=getSettings().substitute(
- attributes.getValue("inherit-scope"));
- if (inheritScopeValue != null) {
- InheritableScope scope = InheritableScope.valueOf(inheritScopeValue.toUpperCase());
- inheritScopeElement.setInheritScope(scope);
- }
-
- String inheritableValue = getSettings().substitute(
- attributes.getValue("inheritable"));
- if (inheritableValue != null) {
- inheritScopeElement.setInheritable("true".equalsIgnoreCase(inheritableValue));
- }
-
- }
-
- /**
- * Parsing the easyant tag
- *
- * @param attributes
- * reprensents the easyant attributes
- */
- protected void eaBuildStarted(Attributes attributes) {
- easyAntState = EasyAntState.EASYANT;
- String mrid = getSettings().substitute(attributes.getValue("mrid"));
- if (mrid != null) {
- if (!mrid.matches(".*#.*")) {
- Message.debug("No organisation specified for buildtype "
- + mrid + " using the default one");
- mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION
- + "#" + mrid;
- }
- easyAntModuleDescriptor.setBuildType(mrid);
- } else {
- String org = attributes.getValue("org") != null ? attributes
- .getValue("org") : attributes.getValue("organisation");
- org = getSettings().substitute(org);
- if (org == null) {
- Message.debug("No organisation specified for buildtype "
- + mrid + " using the default one");
- org = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION;
-
- }
- String module = getSettings().substitute(
- attributes.getValue("module"));
- String revision = attributes.getValue("rev") != null ? attributes
- .getValue("rev")
- : attributes.getValue("revision");
- revision = getSettings().substitute(revision);
- ModuleRevisionId moduleRevisionId = ModuleRevisionId
- .newInstance(org, module, revision);
-
- easyAntModuleDescriptor.setBuildType(moduleRevisionId
- .toString());
- }
-
- handlePropertyAsAttribute(attributes, null);
- }
-
- /**
- * Parsing the bindtarget tag
- *
- * @param attributes
- * reprensents the bindtarget attributes
- */
- protected void bindTargetStarted(Attributes attributes) {
- String target = getSettings().substitute(
- attributes.getValue("target"));
- String toPhase = getSettings().substitute(
- attributes.getValue("tophase"));
- String conf = getSettings().substitute(attributes.getValue("conf"));
- if (EasyAntState.PLUGIN == easyAntState && conf == null) {
- conf = currentPluginDescriptor.getBuildConfigurations();
- }
-
- if (BuildConfigurationHelper.contains(conf,
- activeBuildConfigurations)) {
- // if bindtarget tag is a subelement and look if an alias was
- // defined on the plugin
- if (EasyAntState.PLUGIN == easyAntState
- && currentPluginDescriptor.getAs() != null) {
- // check if the fully qualified name was defined, if not get
- // the alias defined on the plugin
- if (!target.startsWith(currentPluginDescriptor.getAs())) {
- target = currentPluginDescriptor.getAs() + target;
- }
-
- }
- // put this variable on the context
- PhaseMappingDescriptor phaseMappingDescriptor = new PhaseMappingDescriptor();
- phaseMappingDescriptor.setBuildConfigurations(conf);
- // TODO: add a facility to get plugin alias if this is a
- // declared as a subelement
- phaseMappingDescriptor.setTarget(target);
- phaseMappingDescriptor.setToPhase(toPhase);
- easyAntModuleDescriptor.addPhaseMapping(phaseMappingDescriptor);
- }
-
- }
-
- public EasyAntModuleDescriptor getEasyAntModuleDescriptor() {
- return easyAntModuleDescriptor;
- }
-
- /**
- * Parse the property tag
- *
- * @param attributes
- * reprensents the plugins attributes
- * @throws SAXException
- */
- protected void easyantPropertyStarted(Attributes attributes)
- throws SAXException {
- String conf = getSettings().substitute(attributes.getValue("conf"));
- // if property tag is a subelement and
- // no build configuration was defined looked at plugin build
- // configurations
- if (EasyAntState.PLUGIN == easyAntState && conf == null) {
- conf = currentPluginDescriptor.getBuildConfigurations();
- }
-
- if (attributes.getValue("file") != null) {
- String fileName = getSettings().substitute(
- attributes.getValue("file"));
- File file = new File(fileName);
- if (!file.exists()) {
- throw new SAXException(fileName + " doesn't exists !");
- }
- PropertiesFile props = new PropertiesFile(file,
- "project properties");
- Enumeration enumeration = props.propertyNames();
- while (enumeration.hasMoreElements()) {
- String key = (String) enumeration.nextElement();
- String value = getSettings().substitute(
- props.getProperty(key));
-
- if (BuildConfigurationHelper.contains(conf,
- activeBuildConfigurations)) {
- // put this variable on the context
- IvyContext.getContext().getSettings()
- .getVariableContainer().setVariable(key, value,
- true);
- PropertyDescriptor property = new PropertyDescriptor(
- key);
- property.setValue(value);
- property.setBuildConfigurations(conf);
-
- applyInheritableItemAttributesFromPlugin(property);
- //override with explicit inherited scope attributes
- handleInheritedScopeAttribute(attributes, property);
-
- easyAntModuleDescriptor.getProperties().put(key,
- property);
- }
-
- }
- } else {
- if (attributes.getValue("name") == null) {
- throw new SAXException("Can't set a null property!");
- }
- String propertyName = getSettings().substitute(
- attributes.getValue("name"));
- String value = getSettings().substitute(
- attributes.getValue("value"));
-
- if (BuildConfigurationHelper.contains(conf,
- activeBuildConfigurations)) {
- // put this variable on the context
- IvyContext.getContext().getSettings()
- .getVariableContainer().setVariable(propertyName,
- value, true);
- PropertyDescriptor property = new PropertyDescriptor(
- propertyName, getMd().getModuleRevisionId());
- property.setValue(value);
- property.setBuildConfigurations(conf);
-
- applyInheritableItemAttributesFromPlugin(property);
- //override with explicit inherited scope attributes
- handleInheritedScopeAttribute(attributes, property);
-
- easyAntModuleDescriptor.getProperties().put(propertyName,
- property);
-
- }
-
- }
- }
-
- /**
- * Apply {@link AdvancedInheritableItem} attributes from current plugin
- * @param property
- */
- private void applyInheritableItemAttributesFromPlugin(
- PropertyDescriptor property) {
- if (EasyAntState.PLUGIN == easyAntState) {
- property.setInheritable(currentPluginDescriptor.isInheritable());
- property.setInheritScope(currentPluginDescriptor.getInheritScope());
- }
- }
-
- /**
- * Merge all metadata with an other module descriptor
- *
- * @param parent
- * an other module descriptor
- */
- protected void mergeAll(ModuleDescriptor parent) {
- super.mergeAll(parent);
- if (parent.getParser() instanceof DefaultEasyAntXmlModuleDescriptorParser) {
- DefaultEasyAntXmlModuleDescriptorParser parser = (DefaultEasyAntXmlModuleDescriptorParser) parent
- .getParser();
- mergeEasyantProperties(parser.getEasyAntModuleDescriptor()
- .getProperties());
- mergeEasyantPlugins(parser.getEasyAntModuleDescriptor()
- .getPlugins());
- }
- }
-
- /**
- * Merge with other module descriptor
- *
- * @param extendTypes
- * a string that represents what we should extends
- * @param parent
- * an other module descriptor
- */
- protected void mergeWithOtherModuleDescriptor(List extendTypes,
- ModuleDescriptor parent) {
- super.mergeWithOtherModuleDescriptor(extendTypes, parent);
- if (parent.getParser() instanceof DefaultEasyAntXmlModuleDescriptorParser) {
- DefaultEasyAntXmlModuleDescriptorParser parser = (DefaultEasyAntXmlModuleDescriptorParser) parent
- .getParser();
-
- if (extendTypes.contains("properties")) {
-
- mergeEasyantProperties(parser.getEasyAntModuleDescriptor()
- .getProperties());
-
- }
- if (extendTypes.contains("plugins")) {
- mergeEasyantPlugins(parser.getEasyAntModuleDescriptor()
- .getPlugins());
- }
- }
-
- }
-
- /**
- * Merge easyant plugins
- *
- * @param plugins
- * a list of plugins that will be merged with current one
- */
- protected void mergeEasyantPlugins(List plugins) {
- for (Iterator iterator = plugins.iterator(); iterator.hasNext();) {
- PluginDescriptor plugin = (PluginDescriptor) iterator.next();
-
- if (plugin.isInheritable()
- && BuildConfigurationHelper.contains(plugin
- .getBuildConfigurations(),
- activeBuildConfigurations)) {
- StringBuilder sb = new StringBuilder("Merging plugin : ");
- sb.append(plugin.toString());
- if (plugin.getSourceModule() != null) {
- sb.append(" from ").append(
- plugin.getSourceModule().toString());
- }
- Message.debug(sb.toString());
-
- easyAntModuleDescriptor.addPlugin(plugin);
- }
- }
- }
-
- /**
- * Merge easyant properties
- *
- * @param properties
- * a map of properties that will be merged with current one
- */
- protected void mergeEasyantProperties(
- Map<String, PropertyDescriptor> properties) {
- for (Iterator<PropertyDescriptor> iterator = properties.values()
- .iterator(); iterator.hasNext();) {
- PropertyDescriptor prop = iterator.next();
- if (prop.isInheritable()
- && BuildConfigurationHelper.contains(prop
- .getBuildConfigurations(),
- activeBuildConfigurations)) {
- IvyContext.getContext().getSettings()
- .getVariableContainer().setVariable(prop.getName(),
- prop.getValue(), true);
- StringBuilder sb = new StringBuilder("Merging property");
- sb.append(prop.getName());
- if (prop.getSourceModule() != null) {
- sb.append(" from ").append(
- prop.getSourceModule().toString());
- }
- Message.debug(sb.toString());
- easyAntModuleDescriptor.getProperties().put(prop.getName(),
- prop);
- }
- }
- }
-
- /**
- * Get the default parent location
- *
- * @return a string that represents the default parent location
- */
- protected String getDefaultParentLocation() {
- return "../parent.ivy";
- }
- }
+ static final String[] PLUGIN_REGULAR_ATTRIBUTES = new String[] {
+ "organisation", "org", "module", "revision", "rev", "mrid", "conf",
+ "mode", "as", "inheritable", "inherit-scope" };
+
+ public boolean accept(Resource res) {
+ return res.getName().endsWith(".ivy");
+ }
+
+ protected Parser newParser(ParserSettings ivySettings) {
+
+ return new EasyAntParser(this, ivySettings);
+ }
+
+ private EasyAntModuleDescriptor easyAntModuleDescriptor;
+
+ private String activeBuildConfigurations;
+
+ public void setActiveBuildConfigurations(String activeBuildConfigurations) {
+ this.activeBuildConfigurations = activeBuildConfigurations;
+ }
+
+ public EasyAntModuleDescriptor getEasyAntModuleDescriptor() {
+ return easyAntModuleDescriptor;
+ }
+
+ public ModuleDescriptor parseDescriptor(ParserSettings ivySettings,
+ URL xmlURL, Resource res, boolean validate) throws ParseException,
+ IOException {
+
+ EasyAntParser parser = (EasyAntParser) newParser(ivySettings);
+ parser.setValidate(validate);
+ parser.setResource(res);
+ parser.setInput(xmlURL);
+ parser.parse();
+ easyAntModuleDescriptor = parser.getEasyAntModuleDescriptor();
+
+ return parser.getModuleDescriptor();
+ }
+
+ public class EasyAntParser extends Parser {
+
+ public final class EasyAntState {
+ public static final int NONE = 0;
+ public static final int EASYANT = 1;
+ public static final int PLUGIN = 2;
+
+ private EasyAntState() {
+ }
+
+ }
+
+ private int easyAntState;
+
+ private DefaultEasyAntDescriptor easyAntModuleDescriptor;
+
+ private String easyantPrefix;
+
+ private PluginDescriptor currentPluginDescriptor;
+
+ public EasyAntParser(ModuleDescriptorParser parser,
+ ParserSettings ivySettings) {
+ super(parser, ivySettings);
+ easyAntState = EasyAntState.NONE;
+ easyAntModuleDescriptor = new DefaultEasyAntDescriptor();
+ easyantPrefix = "";
+ }
+
+ public void startElement(String uri, String localName, String name,
+ Attributes attributes) throws SAXException {
+ super.startElement(uri, localName, name, attributes);
+ if (name.equals(easyantPrefix + ":build")
+ && State.EXTRA_INFO == getState()) {
+ eaBuildStarted(attributes);
+ }
+ if (name.equals(easyantPrefix + ":plugin")
+ && State.EXTRA_INFO == getState()) {
+ pluginStarted(attributes);
+ }
+ if (name.equals(easyantPrefix + ":property")
+ && State.EXTRA_INFO == getState()) {
+ easyantPropertyStarted(attributes);
+ }
+
+ if (name.equals(easyantPrefix + ":bindtarget")
+ && State.EXTRA_INFO == getState()) {
+ bindTargetStarted(attributes);
+ }
+
+ if ("easyant".equals(name)) {
+ // TODO: add a reference to the documentation
+ Message
+ .warn("<easyant> tag is deprecated since easyant 0.6, we strongly recommend you to use <ea:build> instead");
+ eaBuildStarted(attributes);
+ }
+ if (easyAntState == EasyAntState.EASYANT && "property".equals(name)) {
+ // TODO: add a reference to the documentation
+ Message
+ .warn("<property> tag is deprecated since easyant 0.6, we strongly recommend you to use <ea:property> instead");
+ easyantPropertyStarted(attributes);
+ }
+ if (easyAntState == EasyAntState.EASYANT && "plugin".equals(name)) {
+ // TODO: add a reference to the documentation
+ Message
+ .warn("<plugin> tag is deprecated since easyant 0.6, we strongly recommend you to use <ea:plugin> instead");
+ pluginStarted(attributes);
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String name)
+ throws SAXException {
+ super.endElement(uri, localName, name);
+ if (name.equals(easyantPrefix + ":plugin")
+ && easyAntState == EasyAntState.PLUGIN) {
+ endPlugin();
+ }
+ }
+
+ protected void endPlugin() {
+ currentPluginDescriptor = null;
+ easyAntState = EasyAntState.NONE;
+ }
+
+ @Override
+ protected void ivyModuleStarted(Attributes attributes)
+ throws SAXException {
+ super.ivyModuleStarted(attributes);
+ // lookup easyant namespace
+ for (Iterator iterator = getMd().getExtraAttributesNamespaces()
+ .entrySet().iterator(); iterator.hasNext();) {
+ Entry namespace = (Entry) iterator.next();
+ if (EasyAntConstants.EASYANT_MD_NAMESPACE.equals(namespace
+ .getValue())) {
+ easyantPrefix = (String) namespace.getKey();
+ }
+ }
+
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ super.endDocument();
+
+ for (Configuration conf : getMd().getConfigurations()) {
+ if ("profile".equals(conf.getExtraAttribute(easyantPrefix
+ + ":type"))) {
+ Message.debug("Adding build configuration named "
+ + conf.getName());
+ easyAntModuleDescriptor.addBuildConfiguration(conf
+ .getName());
+ }
+ }
+ try {
+ easyAntModuleDescriptor.setIvyModuleDescriptor(super
+ .getModuleDescriptor());
+ } catch (ParseException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ /**
+ * Parsing the plugin tag
+ *
+ * @param attributes
+ * reprensents the plugins attributes
+ */
+ protected void pluginStarted(Attributes attributes) {
+ boolean mandatory = false;
+
+ String mandatoryValue = getSettings().substitute(
+ attributes.getValue("mandatory"));
+ if (mandatoryValue != null && "true".equals(mandatoryValue)) {
+ mandatory = true;
+ }
+ String conf = getSettings().substitute(attributes.getValue("conf"));
+
+ easyAntState = EasyAntState.PLUGIN;
+ PluginDescriptor plugin = new PluginDescriptor(getMd()
+ .getModuleRevisionId());
+
+ String mrid = getSettings().substitute(attributes.getValue("mrid"));
+ if (mrid != null) {
+ if (!mrid.matches(".*#.*")) {
+ Message.debug("No organisation specified for plugin "
+ + mrid + " using the default one");
+ mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#"
+ + mrid;
+ }
+ plugin.setMrid(mrid);
+ } else {
+ String org = attributes.getValue("org") != null ? attributes
+ .getValue("org") : attributes.getValue("organisation");
+ org = getSettings().substitute(org);
+ if (org == null) {
+ Message.debug("No organisation specified for plugin "
+ + mrid + " using the default one");
+ org = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION;
+
+ }
+ String module = getSettings().substitute(
+ attributes.getValue("module"));
+ String revision = attributes.getValue("rev") != null ? attributes
+ .getValue("rev")
+ : attributes.getValue("revision");
+ revision = getSettings().substitute(revision);
+ plugin.setOrganisation(org);
+ plugin.setModule(module);
+ plugin.setRevision(revision);
+
+ }
+ String mode = getSettings().substitute(attributes.getValue("mode"));
+ // If no mode is defined in the module descriptor we use include
+ // by default
+ if (mode == null) {
+ plugin.setMode("include");
+ } else {
+ plugin.setMode(mode);
+ }
+
+ plugin.setMandatory(mandatory);
+ plugin.setAs(getSettings().substitute(attributes.getValue("as")));
+ plugin.setBuildConfigurations(conf);
+
+ handleInheritedScopeAttribute(attributes, plugin);
+
+ currentPluginDescriptor = plugin;
+ if (BuildConfigurationHelper.contains(conf,
+ activeBuildConfigurations)) {
+ easyAntModuleDescriptor.addPlugin(plugin);
+ }
+
+ handlePropertyAsAttribute(attributes, conf);
+ }
+
+ /**
+ * handle properties as attribute
+ *
+ * @param attributes
+ * a set of attributes
+ * @param conf
+ * build configurations where this property should be applied
+ * (can be null)
+ */
+ protected void handlePropertyAsAttribute(Attributes attributes,
+ String conf) {
+ List<String> ignored = Arrays.asList(PLUGIN_REGULAR_ATTRIBUTES);
+ for (int i = 0; i < attributes.getLength(); i++) {
+ if (!ignored.contains(attributes.getQName(i))) {
+ String propertyName = attributes.getQName(i);
+ String value = IvyContext.getContext().getSettings()
+ .substitute(attributes.getValue(i));
+ PropertyDescriptor property = new PropertyDescriptor(
+ propertyName);
+ property.setValue(value);
+ property.setBuildConfigurations(conf);
+ applyInheritableItemAttributesFromPlugin(property);
+ easyAntModuleDescriptor.getProperties().put(propertyName,
+ property);
+ }
+ }
+ }
+
+ /**
+ * Handle inherited scope specific attributes
+ * @param attributes a set of attributes
+ * @param inheritScopeElement an element supporting inherit scope attributes
+ */
+ private void handleInheritedScopeAttribute(Attributes attributes,
+ AdvancedInheritableItem inheritScopeElement) {
+ String inheritScopeValue=getSettings().substitute(
+ attributes.getValue("inherit-scope"));
+ if (inheritScopeValue != null) {
+ InheritableScope scope = InheritableScope.valueOf(inheritScopeValue.toUpperCase());
+ inheritScopeElement.setInheritScope(scope);
+ }
+
+ String inheritableValue = getSettings().substitute(
+ attributes.getValue("inheritable"));
+ if (inheritableValue != null) {
+ inheritScopeElement.setInheritable("true".equalsIgnoreCase(inheritableValue));
+ }
+
+ }
+
+ /**
+ * Parsing the easyant tag
+ *
+ * @param attributes
+ * reprensents the easyant attributes
+ */
+ protected void eaBuildStarted(Attributes attributes) {
+ easyAntState = EasyAntState.EASYANT;
+ String mrid = getSettings().substitute(attributes.getValue("mrid"));
+ if (mrid != null) {
+ if (!mrid.matches(".*#.*")) {
+ Message.debug("No organisation specified for buildtype "
+ + mrid + " using the default one");
+ mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION
+ + "#" + mrid;
+ }
+ easyAntModuleDescriptor.setBuildType(mrid);
+ } else {
+ String org = attributes.getValue("org") != null ? attributes
+ .getValue("org") : attributes.getValue("organisation");
+ org = getSettings().substitute(org);
+ if (org == null) {
+ Message.debug("No organisation specified for buildtype "
+ + mrid + " using the default one");
+ org = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION;
+
+ }
+ String module = getSettings().substitute(
+ attributes.getValue("module"));
+ String revision = attributes.getValue("rev") != null ? attributes
+ .getValue("rev")
+ : attributes.getValue("revision");
+ revision = getSettings().substitute(revision);
+ ModuleRevisionId moduleRevisionId = ModuleRevisionId
+ .newInstance(org, module, revision);
+
+ easyAntModuleDescriptor.setBuildType(moduleRevisionId
+ .toString());
+ }
+
+ handlePropertyAsAttribute(attributes, null);
+ }
+
+ /**
+ * Parsing the bindtarget tag
+ *
+ * @param attributes
+ * reprensents the bindtarget attributes
+ */
+ protected void bindTargetStarted(Attributes attributes) {
+ String target = getSettings().substitute(
+ attributes.getValue("target"));
+ String toPhase = getSettings().substitute(
+ attributes.getValue("tophase"));
+ String conf = getSettings().substitute(attributes.getValue("conf"));
+ if (EasyAntState.PLUGIN == easyAntState && conf == null) {
+ conf = currentPluginDescriptor.getBuildConfigurations();
+ }
+
+ if (BuildConfigurationHelper.contains(conf,
+ activeBuildConfigurations)) {
+ // if bindtarget tag is a subelement and look if an alias was
+ // defined on the plugin
+ if (EasyAntState.PLUGIN == easyAntState
+ && currentPluginDescriptor.getAs() != null) {
+ // check if the fully qualified name was defined, if not get
+ // the alias defined on the plugin
+ if (!target.startsWith(currentPluginDescriptor.getAs())) {
+ target = currentPluginDescriptor.getAs() + target;
+ }
+
+ }
+ // put this variable on the context
+ PhaseMappingDescriptor phaseMappingDescriptor = new PhaseMappingDescriptor();
+ phaseMappingDescriptor.setBuildConfigurations(conf);
+ // TODO: add a facility to get plugin alias if this is a
+ // declared as a subelement
+ phaseMappingDescriptor.setTarget(target);
+ phaseMappingDescriptor.setToPhase(toPhase);
+ easyAntModuleDescriptor.addPhaseMapping(phaseMappingDescriptor);
+ }
+
+ }
+
+ public EasyAntModuleDescriptor getEasyAntModuleDescriptor() {
+ return easyAntModuleDescriptor;
+ }
+
+ /**
+ * Parse the property tag
+ *
+ * @param attributes
+ * reprensents the plugins attributes
+ * @throws SAXException
+ */
+ protected void easyantPropertyStarted(Attributes attributes)
+ throws SAXException {
+ String conf = getSettings().substitute(attributes.getValue("conf"));
+ // if property tag is a subelement and
+ // no build configuration was defined looked at plugin build
+ // configurations
+ if (EasyAntState.PLUGIN == easyAntState && conf == null) {
+ conf = currentPluginDescriptor.getBuildConfigurations();
+ }
+
+ if (attributes.getValue("file") != null) {
+ String fileName = getSettings().substitute(
+ attributes.getValue("file"));
+ File file = new File(fileName);
+ if (!file.exists()) {
+ throw new SAXException(fileName + " doesn't exists !");
+ }
+ PropertiesFile props = new PropertiesFile(file,
+ "project properties");
+ Enumeration enumeration = props.propertyNames();
+ while (enumeration.hasMoreElements()) {
+ String key = (String) enumeration.nextElement();
+ String value = getSettings().substitute(
+ props.getProperty(key));
+
+ if (BuildConfigurationHelper.contains(conf,
+ activeBuildConfigurations)) {
+ // put this variable on the context
+ IvyContext.getContext().getSettings()
+ .getVariableContainer().setVariable(key, value,
+ true);
+ PropertyDescriptor property = new PropertyDescriptor(
+ key);
+ property.setValue(value);
+ property.setBuildConfigurations(conf);
+
+ applyInheritableItemAttributesFromPlugin(property);
+ //override with explicit inherited scope attributes
+ handleInheritedScopeAttribute(attributes, property);
+
+ easyAntModuleDescriptor.getProperties().put(key,
+ property);
+ }
+
+ }
+ } else {
+ if (attributes.getValue("name") == null) {
+ throw new SAXException("Can't set a null property!");
+ }
+ String propertyName = getSettings().substitute(
+ attributes.getValue("name"));
+ String value = getSettings().substitute(
+ attributes.getValue("value"));
+
+ if (BuildConfigurationHelper.contains(conf,
+ activeBuildConfigurations)) {
+ // put this variable on the context
+ IvyContext.getContext().getSettings()
+ .getVariableContainer().setVariable(propertyName,
+ value, true);
+ PropertyDescriptor property = new PropertyDescriptor(
+ propertyName, getMd().getModuleRevisionId());
+ property.setValue(value);
+ property.setBuildConfigurations(conf);
+
+ applyInheritableItemAttributesFromPlugin(property);
+ //override with explicit inherited scope attributes
+ handleInheritedScopeAttribute(attributes, property);
+
+ easyAntModuleDescriptor.getProperties().put(propertyName,
+ property);
+
+ }
+
+ }
+ }
+
+ /**
+ * Apply {@link AdvancedInheritableItem} attributes from current plugin
+ * @param property
+ */
+ private void applyInheritableItemAttributesFromPlugin(
+ PropertyDescriptor property) {
+ if (EasyAntState.PLUGIN == easyAntState) {
+ property.setInheritable(currentPluginDescriptor.isInheritable());
+ property.setInheritScope(currentPluginDescriptor.getInheritScope());
+ }
+ }
+
+ /**
+ * Merge all metadata with an other module descriptor
+ *
+ * @param parent
+ * an other module descriptor
+ */
+ protected void mergeAll(ModuleDescriptor parent) {
+ super.mergeAll(parent);
+ if (parent.getParser() instanceof DefaultEasyAntXmlModuleDescriptorParser) {
+ DefaultEasyAntXmlModuleDescriptorParser parser = (DefaultEasyAntXmlModuleDescriptorParser) parent
+ .getParser();
+ mergeEasyantProperties(parser.getEasyAntModuleDescriptor()
+ .getProperties());
+ mergeEasyantPlugins(parser.getEasyAntModuleDescriptor()
+ .getPlugins());
+ }
+ }
+
+ /**
+ * Merge with other module descriptor
+ *
+ * @param extendTypes
+ * a string that represents what we should extends
+ * @param parent
+ * an other module descriptor
+ */
+ protected void mergeWithOtherModuleDescriptor(List extendTypes,
+ ModuleDescriptor parent) {
+ super.mergeWithOtherModuleDescriptor(extendTypes, parent);
+ if (parent.getParser() instanceof DefaultEasyAntXmlModuleDescriptorParser) {
+ DefaultEasyAntXmlModuleDescriptorParser parser = (DefaultEasyAntXmlModuleDescriptorParser) parent
+ .getParser();
+
+ if (extendTypes.contains("properties")) {
+
+ mergeEasyantProperties(parser.getEasyAntModuleDescriptor()
+ .getProperties());
+
+ }
+ if (extendTypes.contains("plugins")) {
+ mergeEasyantPlugins(parser.getEasyAntModuleDescriptor()
+ .getPlugins());
+ }
+ }
+
+ }
+
+ /**
+ * Merge easyant plugins
+ *
+ * @param plugins
+ * a list of plugins that will be merged with current one
+ */
+ protected void mergeEasyantPlugins(List plugins) {
+ for (Iterator iterator = plugins.iterator(); iterator.hasNext();) {
+ PluginDescriptor plugin = (PluginDescriptor) iterator.next();
+
+ if (plugin.isInheritable()
+ && BuildConfigurationHelper.contains(plugin
+ .getBuildConfigurations(),
+ activeBuildConfigurations)) {
+ StringBuilder sb = new StringBuilder("Merging plugin : ");
+ sb.append(plugin.toString());
+ if (plugin.getSourceModule() != null) {
+ sb.append(" from ").append(
+ plugin.getSourceModule().toString());
+ }
+ Message.debug(sb.toString());
+
+ easyAntModuleDescriptor.addPlugin(plugin);
+ }
+ }
+ }
+
+ /**
+ * Merge easyant properties
+ *
+ * @param properties
+ * a map of properties that will be merged with current one
+ */
+ protected void mergeEasyantProperties(
+ Map<String, PropertyDescriptor> properties) {
+ for (Iterator<PropertyDescriptor> iterator = properties.values()
+ .iterator(); iterator.hasNext();) {
+ PropertyDescriptor prop = iterator.next();
+ if (prop.isInheritable()
+ && BuildConfigurationHelper.contains(prop
+ .getBuildConfigurations(),
+ activeBuildConfigurations)) {
+ IvyContext.getContext().getSettings()
+ .getVariableContainer().setVariable(prop.getName(),
+ prop.getValue(), true);
+ StringBuilder sb = new StringBuilder("Merging property");
+ sb.append(prop.getName());
+ if (prop.getSourceModule() != null) {
+ sb.append(" from ").append(
+ prop.getSourceModule().toString());
+ }
+ Message.debug(sb.toString());
+ easyAntModuleDescriptor.getProperties().put(prop.getName(),
+ prop);
+ }
+ }
+ }
+
+ /**
+ * Get the default parent location
+ *
+ * @return a string that represents the default parent location
+ */
+ protected String getDefaultParentLocation() {
+ return "../parent.ivy";
+ }
+ }
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java Tue Feb 22 15:55:55 2011
@@ -40,213 +40,215 @@ import org.xml.sax.SAXParseException;
public class EasyAntConfigParser {
- private boolean validate = true;
+ private boolean validate = true;
- public boolean isValidate() {
- return validate;
- }
-
- public void setValidate(boolean validate) {
- this.validate = validate;
- }
-
- public URL getEasyAntConfigSchema() {
- return getClass().getResource(
- "/org/apache/easyant/core/easyant-config.xsd");
- }
-
- public EasyAntConfiguration parseAndMerge(final URL configUrl,
- final EasyAntConfiguration easyAntConfiguration) throws Exception {
- ConfigParser parser = new ConfigParser();
-
- URL schemaURL = null;
-
- if (isValidate()) {
- schemaURL = getEasyAntConfigSchema();
- }
- try {
- parser.setConfigUrl(configUrl);
- parser.setEasyAntConfiguration(easyAntConfiguration);
- XMLHelper.parse(configUrl, schemaURL, parser, null);
- parser.checkErrors();
- } catch (ParserConfigurationException ex) {
- IllegalStateException ise = new IllegalStateException(ex
- .getMessage()
- + " in " + configUrl);
- ise.initCause(ex);
- throw ise;
-
- } catch (Exception e) {
-
- throw new Exception("Can't parse " + configUrl, e);
- }
- return easyAntConfiguration;
- }
-
- public EasyAntConfiguration parse(URL configUrl) throws Exception {
- EasyAntConfiguration easyAntConfiguration = new EasyAntConfiguration();
- return parseAndMerge(configUrl, easyAntConfiguration);
- }
-
- public static class ConfigParser extends ContextualSAXHandler {
- private List errors = new ArrayList();
- private URL configUrl;
- private EasyAntConfiguration easyAntConfiguration;
-
- public URL getConfigUrl() {
- return configUrl;
- }
-
- public void setConfigUrl(URL configUrl) {
- this.configUrl = configUrl;
- }
-
- public EasyAntConfiguration getEasyAntConfiguration() {
- return easyAntConfiguration;
- }
-
- public void setEasyAntConfiguration(
- EasyAntConfiguration easyAntConfiguration) {
- this.easyAntConfiguration = easyAntConfiguration;
- }
-
- protected void addError(String msg) {
- if (configUrl != null) {
- errors.add(msg + " in " + configUrl + "\n");
- } else {
- errors.add(msg + "\n");
- }
- }
-
- protected void checkErrors() throws ParseException {
- if (!errors.isEmpty()) {
- throw new ParseException(errors.toString(), 0);
- }
- }
-
- private String getLocationString(SAXParseException ex) {
- StringBuffer str = new StringBuffer();
-
- String systemId = ex.getSystemId();
- if (systemId != null) {
- int index = systemId.lastIndexOf('/');
- if (index != -1) {
- systemId = systemId.substring(index + 1);
- }
- str.append(systemId);
- } else if (configUrl != null) {
- str.append(configUrl.toString());
- }
- str.append(':');
- str.append(ex.getLineNumber());
- str.append(':');
- str.append(ex.getColumnNumber());
-
- return str.toString();
-
- }
-
- public void warning(SAXParseException ex) {
- Message.warn("xml parsing: " + getLocationString(ex) + ": "
- + ex.getMessage());
- }
-
- public void error(SAXParseException ex) {
- addError("xml parsing: " + getLocationString(ex) + ": "
- + ex.getMessage());
- }
-
- public void fatalError(SAXParseException ex) throws SAXException {
- addError("[Fatal Error] " + getLocationString(ex) + ": "
- + ex.getMessage());
- }
-
- public void startElement(String uri, String localName, String name,
- Attributes attributes) throws SAXException {
-
- super.startElement(uri, localName, name, attributes);
- if ("easyant-config/ivysettings".equals(getContext())) {
- if (attributes.getValue("url") != null
- && !attributes.getValue("url").equals("")) {
- easyAntConfiguration.setEasyantIvySettingsUrl(attributes
- .getValue("url"));
- }
- if (attributes.getValue("file") != null
- && !attributes.getValue("file").equals("")) {
- easyAntConfiguration.setEasyantIvySettingsFile(attributes
- .getValue("file"));
- }
- }
- if ("easyant-config/system-plugins/plugin".equals(getContext())) {
- PluginDescriptor pluginDescriptor = new PluginDescriptor();
- String org = attributes.getValue("org") != null ? attributes
- .getValue("org") : attributes.getValue("organisation");
- pluginDescriptor.setOrganisation(org);
- pluginDescriptor.setModule(attributes.getValue("module"));
- String rev = attributes.getValue("rev") != null ? attributes
- .getValue("rev") : attributes.getValue("revision");
- pluginDescriptor.setRevision(rev);
- pluginDescriptor.setMrid(attributes.getValue("mrid"));
- pluginDescriptor.setAs(attributes.getValue("as"));
- boolean mandatory = false;
- if (attributes.getValue("mandatory") != null
- && attributes.getValue("mandatory").equals("true"))
- mandatory = true;
- ;
- pluginDescriptor.setMandatory(mandatory);
- String mode = attributes.getValue("mode");
- if (mode != null) {
- pluginDescriptor.setMode(mode);
- } else
- pluginDescriptor.setMode("include");
- easyAntConfiguration.addSystemPlugin(pluginDescriptor);
- }
- if ("easyant-config/properties/property".equals(getContext())) {
- if (attributes.getValue("file") != null
- || attributes.getValue("url") != null) {
- Properties properties = new Properties();
-
- try {
- InputStream is = null;
- if (attributes.getValue("file") != null) {
- File f = new File(attributes.getValue("file"));
- is = new FileInputStream(f);
- properties.load(is);
- is.close();
- } else if (attributes.getValue("url") != null) {
- URL url = new URL(attributes.getValue("url"));
- is = url.openStream();
- properties.load(is);
- is.close();
- }
- for (Iterator iterator = properties.keySet().iterator(); iterator
- .hasNext();) {
- String key = (String) iterator.next();
- easyAntConfiguration.getDefinedProps().put(key,
- properties.get(key));
- }
-
- } catch (Exception e) {
- if (attributes.getValue("file") != null) {
- throw new SAXException(
- "can't read property file at : "
- + attributes.getValue("file"));
- } else if (attributes.getValue("url") != null) {
- throw new SAXException(
- "can't read property file at : "
- + attributes.getValue("url"));
- }
-
- }
- } else if (attributes.getValue("name") != null) {
- easyAntConfiguration.getDefinedProps().put(
- attributes.getValue("name"),
- attributes.getValue("value"));
- }
+ public boolean isValidate() {
+ return validate;
+ }
+
+ public void setValidate(boolean validate) {
+ this.validate = validate;
+ }
+
+ public URL getEasyAntConfigSchema() {
+ return getClass().getResource(
+ "/org/apache/easyant/core/easyant-config.xsd");
+ }
+
+ public EasyAntConfiguration parseAndMerge(final URL configUrl,
+ final EasyAntConfiguration easyAntConfiguration) throws Exception {
+ ConfigParser parser = new ConfigParser();
+
+ URL schemaURL = null;
+
+ if (isValidate()) {
+ schemaURL = getEasyAntConfigSchema();
+ }
+ try {
+ parser.setConfigUrl(configUrl);
+ parser.setEasyAntConfiguration(easyAntConfiguration);
+ XMLHelper.parse(configUrl, schemaURL, parser, null);
+ parser.checkErrors();
+ } catch (ParserConfigurationException ex) {
+ IllegalStateException ise = new IllegalStateException(ex
+ .getMessage()
+ + " in " + configUrl);
+ ise.initCause(ex);
+ throw ise;
+
+ } catch (Exception e) {
+
+ throw new Exception("Can't parse " + configUrl, e);
+ }
+ return easyAntConfiguration;
+ }
+
+ public EasyAntConfiguration parse(URL configUrl) throws Exception {
+ EasyAntConfiguration easyAntConfiguration = new EasyAntConfiguration();
+ return parseAndMerge(configUrl, easyAntConfiguration);
+ }
+
+ public static class ConfigParser extends ContextualSAXHandler {
+ private List errors = new ArrayList();
+ private URL configUrl;
+ private EasyAntConfiguration easyAntConfiguration;
+
+ public URL getConfigUrl() {
+ return configUrl;
+ }
+
+ public void setConfigUrl(URL configUrl) {
+ this.configUrl = configUrl;
+ }
+
+ public EasyAntConfiguration getEasyAntConfiguration() {
+ return easyAntConfiguration;
+ }
+
+ public void setEasyAntConfiguration(
+ EasyAntConfiguration easyAntConfiguration) {
+ this.easyAntConfiguration = easyAntConfiguration;
+ }
+
+ protected void addError(String msg) {
+ if (configUrl != null) {
+ errors.add(msg + " in " + configUrl + "
+");
+ } else {
+ errors.add(msg + "
+");
+ }
+ }
+
+ protected void checkErrors() throws ParseException {
+ if (!errors.isEmpty()) {
+ throw new ParseException(errors.toString(), 0);
+ }
+ }
+
+ private String getLocationString(SAXParseException ex) {
+ StringBuffer str = new StringBuffer();
+
+ String systemId = ex.getSystemId();
+ if (systemId != null) {
+ int index = systemId.lastIndexOf('/');
+ if (index != -1) {
+ systemId = systemId.substring(index + 1);
+ }
+ str.append(systemId);
+ } else if (configUrl != null) {
+ str.append(configUrl.toString());
+ }
+ str.append(':');
+ str.append(ex.getLineNumber());
+ str.append(':');
+ str.append(ex.getColumnNumber());
+
+ return str.toString();
+
+ }
+
+ public void warning(SAXParseException ex) {
+ Message.warn("xml parsing: " + getLocationString(ex) + ": "
+ + ex.getMessage());
+ }
+
+ public void error(SAXParseException ex) {
+ addError("xml parsing: " + getLocationString(ex) + ": "
+ + ex.getMessage());
+ }
+
+ public void fatalError(SAXParseException ex) throws SAXException {
+ addError("[Fatal Error] " + getLocationString(ex) + ": "
+ + ex.getMessage());
+ }
+
+ public void startElement(String uri, String localName, String name,
+ Attributes attributes) throws SAXException {
+
+ super.startElement(uri, localName, name, attributes);
+ if ("easyant-config/ivysettings".equals(getContext())) {
+ if (attributes.getValue("url") != null
+ && !attributes.getValue("url").equals("")) {
+ easyAntConfiguration.setEasyantIvySettingsUrl(attributes
+ .getValue("url"));
+ }
+ if (attributes.getValue("file") != null
+ && !attributes.getValue("file").equals("")) {
+ easyAntConfiguration.setEasyantIvySettingsFile(attributes
+ .getValue("file"));
+ }
+ }
+ if ("easyant-config/system-plugins/plugin".equals(getContext())) {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ String org = attributes.getValue("org") != null ? attributes
+ .getValue("org") : attributes.getValue("organisation");
+ pluginDescriptor.setOrganisation(org);
+ pluginDescriptor.setModule(attributes.getValue("module"));
+ String rev = attributes.getValue("rev") != null ? attributes
+ .getValue("rev") : attributes.getValue("revision");
+ pluginDescriptor.setRevision(rev);
+ pluginDescriptor.setMrid(attributes.getValue("mrid"));
+ pluginDescriptor.setAs(attributes.getValue("as"));
+ boolean mandatory = false;
+ if (attributes.getValue("mandatory") != null
+ && attributes.getValue("mandatory").equals("true"))
+ mandatory = true;
+ ;
+ pluginDescriptor.setMandatory(mandatory);
+ String mode = attributes.getValue("mode");
+ if (mode != null) {
+ pluginDescriptor.setMode(mode);
+ } else
+ pluginDescriptor.setMode("include");
+ easyAntConfiguration.addSystemPlugin(pluginDescriptor);
+ }
+ if ("easyant-config/properties/property".equals(getContext())) {
+ if (attributes.getValue("file") != null
+ || attributes.getValue("url") != null) {
+ Properties properties = new Properties();
+
+ try {
+ InputStream is = null;
+ if (attributes.getValue("file") != null) {
+ File f = new File(attributes.getValue("file"));
+ is = new FileInputStream(f);
+ properties.load(is);
+ is.close();
+ } else if (attributes.getValue("url") != null) {
+ URL url = new URL(attributes.getValue("url"));
+ is = url.openStream();
+ properties.load(is);
+ is.close();
+ }
+ for (Iterator iterator = properties.keySet().iterator(); iterator
+ .hasNext();) {
+ String key = (String) iterator.next();
+ easyAntConfiguration.getDefinedProps().put(key,
+ properties.get(key));
+ }
+
+ } catch (Exception e) {
+ if (attributes.getValue("file") != null) {
+ throw new SAXException(
+ "can't read property file at : "
+ + attributes.getValue("file"));
+ } else if (attributes.getValue("url") != null) {
+ throw new SAXException(
+ "can't read property file at : "
+ + attributes.getValue("url"));
+ }
+
+ }
+ } else if (attributes.getValue("name") != null) {
+ easyAntConfiguration.getDefinedProps().put(
+ attributes.getValue("name"),
+ attributes.getValue("value"));
+ }
- }
+ }
- }
- }
+ }
+ }
}
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntModuleDescriptorParser.java?rev=1073371&r1=1073370&r2=1073371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntModuleDescriptorParser.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntModuleDescriptorParser.java Tue Feb 22 15:55:55 2011
@@ -22,8 +22,8 @@ import org.apache.ivy.plugins.parser.Mod
public interface EasyAntModuleDescriptorParser extends ModuleDescriptorParser {
- void setActiveBuildConfigurations(String activeBuildConfigurations);
-
- EasyAntModuleDescriptor getEasyAntModuleDescriptor();
-
+ void setActiveBuildConfigurations(String activeBuildConfigurations);
+
+ EasyAntModuleDescriptor getEasyAntModuleDescriptor();
+
}