gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r981122 - /gump/trunk/python/gump/core/model/builder.py
Date Sun, 01 Aug 2010 03:05:31 GMT
Author: bodewig
Date: Sun Aug  1 03:05:30 2010
New Revision: 981122

URL: http://svn.apache.org/viewvc?rev=981122&view=rev
Log:
The complete method is called while building the graph before any module has been updated
- this is too early to parse the POM which may be outdated or not even been checked out, yet.
 Move POM parsing logic to a the building phase.

Modified:
    gump/trunk/python/gump/core/model/builder.py

Modified: gump/trunk/python/gump/core/model/builder.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/model/builder.py?rev=981122&r1=981121&r2=981122&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/builder.py (original)
+++ gump/trunk/python/gump/core/model/builder.py Sun Aug  1 03:05:30 2010
@@ -33,7 +33,7 @@ from gump.util.domutils import domAttrib
 
 from gump.core.model.depend import INHERIT_NONE, ProjectDependency
 from gump.core.model.object import ModelObject
-from gump.core.model.property import PropertyContainer
+from gump.core.model.property import Property, PropertyContainer
 
 # represents a generic build (e.g. <ant/>) element
 class Builder(ModelObject, PropertyContainer):
@@ -200,7 +200,14 @@ class Builder(ModelObject, PropertyConta
         # Complete them all
         self.completeProperties(workspace)
 
-        self.resolve_basedir()
+        if self.hasDomAttribute('basedir'):
+            self.basedir = os.path.abspath(os.path.join(
+                    self.project.getModule().getWorkingDirectory()
+                    or dir.base,
+                    self.getDomAttributeValue('basedir')
+                    ))
+        else:
+            self.basedir = self.project.getBaseDirectory()
 
         # Check for debugging properties
         self.setDebug(self.domAttributeIsTrue('debug'))
@@ -219,19 +226,6 @@ class Builder(ModelObject, PropertyConta
     def getBaseDirectory(self):
         return self.basedir
 
-    def resolve_basedir(self):
-        """ Sets basedir based on the basedir attribute or the
-        project's configuration """
-        if not self.basedir:
-            if self.hasDomAttribute('basedir'):
-                self.basedir = os.path.abspath(os.path.join(
-                        self.project.getModule().getWorkingDirectory()
-                        or dir.base,
-                        self.getDomAttributeValue('basedir')
-                        ))
-            else:
-                self.basedir = self.project.getBaseDirectory()
-
 # represents an <ant/> element
 class BaseAnt(Builder):
     """ An Ant command (within a project)"""
@@ -366,61 +360,72 @@ class Mvn2Install(Maven2):
         self._add_property(impl, 'groupId', project.getArtifactGroup())
         self._add_property(impl, Mvn2Install.PACKAGING, self.packaging)
         self._add_property(impl, Mvn2Install.FILE, self.file)
+        if self.version:
+            self._add_property(impl, Mvn2Install.VERSION, self.version)
+        elif not self.packaging == Mvn2Install.POM:
+            project.addError("version attribute is mandatory if the file is"
+                             + " not a POM.")
 
-    def complete(self, project, workspace):
+    def getProperties(self):
         """
-        Complete the model from XML - potentially parse POM for version
+        Get a list of all the property objects - potentially parse POM
+        for version
         """
-        impl = getDOMImplementation()
-        if self.version:
-            self._add_property(impl, Mvn2Install.VERSION, self.version)
-        elif self.packaging == Mvn2Install.POM:
+        props = PropertyContainer.getProperties(self)[:]
+
+        if not self.version and self.packaging == Mvn2Install.POM:
             try:
-                self.resolve_basedir()
                 pomDoc = self._read_pom()
                 root = pomDoc.documentElement
                 if not root.tagName == 'project':
-                    project.addError('file is not a POM, its root element is '
-                                     + root.tagName)
+                    self.project.addError('file is not a POM, its root element'
+                                          + ' is ' + root.tagName)
                     return
 
                 version = _extract_version_from_pom(root)
 
                 if not version:
-                    project.addError("POM doesn't specify a version, you must"
-                                     + " provide the version attribute")
+                    self.project.addError("POM doesn't specify a version,"
+                                          + " you must provide the version"
+                                          + " attribute.")
                     return
+
                 version_text = getDomTextValue(version)
                 if '${' in version_text:
-                    project.addError("POM uses a property reference as version"
-                                     + " which is not supported by Gump.  You"
-                                     + " must provide an explicit version"
-                                     + " attribute to mvn2install.")
+                    self.project.addError('POM uses a property reference as'
+                                          + ' version which is not supported'
+                                          + ' by Gump.  You must provide an'
+                                          + ' explicit version attribute to'
+                                          + ' mvn2install.')
                 else:
-                    self._add_property(impl, Mvn2Install.VERSION,
-                                       version_text)
+                    impl = getDOMImplementation()
+                    dom = _create_dom_property(impl, Mvn2Install.VERSION,
+                                               version_text)
+                    prop = Property(Mvn2Install.VERSION, dom, self.project)
+                    prop.complete(self.project, self.project.getWorkspace())
+                    props.append(prop)
             except Exception, details:
-                project.addError('failed to parse POM because of '
-                                 + str(details))
-        else:
-            project.addError("version attribute is mandatory if the file is"
-                             + " not a POM.")
-
-        Builder.complete(self, project, workspace)
+                self.project.addError('failed to parse POM because of '
+                                      + str(details))
+        return props
 
     def _add_property(self, impl, name, value):
         """ Adds a named property """
-        doc = impl.createDocument(None, 'property', None)
-        prop = doc.documentElement
-        prop.setAttribute('name', name)
-        prop.setAttribute('value', value)
-        self.importProperty(prop)
+        self.importProperty(_create_dom_property(impl, name, value))
 
     def _read_pom(self):
         """ locates the POM, parses it and returns it as DOM Document """ 
         pom = os.path.join(self.getBaseDirectory(), self.file)
         return xml.dom.minidom.parse(pom)
 
+def _create_dom_property(impl, name, value):
+    """ creates and returns a DOM element for a named property """
+    doc = impl.createDocument(None, 'property', None)
+    prop = doc.documentElement
+    prop.setAttribute('name', name)
+    prop.setAttribute('value', value)
+    return prop
+
 def _extract_version_from_pom(root):
     """ Tries to extract the version DOM element from a POM DOM tree """
     version = None



Mime
View raw message