gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r960303 - /gump/trunk/python/gump/core/model/project.py
Date Sun, 04 Jul 2010 07:53:34 GMT
Author: bodewig
Date: Sun Jul  4 07:53:34 2010
New Revision: 960303

URL: http://svn.apache.org/viewvc?rev=960303&view=rev
Log:
remove now unused methods, extract output handling into separate method, ensure id is unique
for output type

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

Modified: gump/trunk/python/gump/core/model/project.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/model/project.py?rev=960303&r1=960302&r2=960303&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/project.py (original)
+++ gump/trunk/python/gump/core/model/project.py Sun Jul  4 07:53:34 2010
@@ -258,9 +258,6 @@ class Project(NamedModelObject, Statable
             self.outputs[output.getType()] = []
         self.outputs[output.getType()].append(output)
 
-    def getOutputCount(self):
-        return sum(map(len, self.outputs.itervalues()))
-
     def hasLicense(self):
         if self.license:
             return True
@@ -319,9 +316,6 @@ class Project(NamedModelObject, Statable
     def getPackageNames(self):
         return self.packageNames
 
-    def getOutputAt(self, index):
-        return self.getOutputs()[index]
-
     def isRedistributable(self):
         return self.redistributable or \
             (self.module and self.module.isRedistributable())
@@ -560,61 +554,7 @@ class Project(NamedModelObject, Statable
         #
         # Resolve outputs
         #
-        outputTypes = ['jar',
-                       'assembly',
-                       'output',
-                       'pom']
-        rawOutputs = []
-        outputCountByType = {}
-
-        for tag in outputTypes:
-            for tdom in self.getDomChildIterator(tag):
-                name = self.expandVariables(getDomAttributeValue(tdom, 'name'))
-
-                if self.home and name:
-                    output = Output(name, tdom, self)
-                    output.complete()
-                    output.setPath(os.path.abspath(os.path.join(self.home,
-                                                                name)))
-                    if not output.getType() and tag != 'output':
-                        output.setType(tag)
-                    rawOutputs.append(output)
-                    if output.getType() not in outputCountByType:
-                        outputCountByType[output.getType()] = 1
-                    else:
-                        outputCountByType[output.getType()] = \
-                            outputCountByType[output.getType()] + 1
-                else:
-                    self.addError('Missing \'name\' on <' + tag)
-
-
-        # Fix 'ids' on all outputs which don't have them
-        for output in rawOutputs:
-            if not output.hasId():
-                if 1 == outputCountByType[output.getType()]:
-                    self.addDebug('Sole ' + output.getType() + ' output [' + \
-                                      os.path.basename(output.getPath()) + \
-                                      '] identifier set to project name')
-                    output.setId(self.getName())
-                else:
-                    # :TODO: A work in progress, not sure how
-                    # we ought 'construct' ids.
-                    basename = os.path.basename(output.getPath())
-                    newId = basename
-                    # Strip off .jar or .lib (note: both same length)
-                    if newId.endswith('.jar') or newId.endswith('.lib'):
-                        newId = newId[:-4]
-                    # Strip off -@@DATE@@
-                    datePostfix = '-' + str(default.date_s)
-                    if newId.endswith(datePostfix):
-                        reduction = -1 * len(datePostfix)
-                        newId = newId[:reduction]
-                    # Assign...
-                    self.addDebug('Output [' + basename + \
-                                      '] identifier set to output ' + \
-                                      'basename: [' + newId + ']')
-                    output.setId(newId)
-            self.addOutput(output)
+        self.handle_outputs()
 
         # Grab all the work
         for w in self.getDomChildIterator('work'):
@@ -894,6 +834,81 @@ class Project(NamedModelObject, Statable
         b.complete(self, workspace)
         transferAnnotations(b, self)
 
+    def handle_outputs(self):
+        """
+        Parse all child elements that define outputs and resolve their ids
+        """
+        output_tags = ['jar',
+                       'assembly',
+                       'output',
+                       'pom']
+        rawOutputs = []
+        outputCountByType = {}
+
+        for tag in output_tags:
+            for tdom in self.getDomChildIterator(tag):
+                name = self.expandVariables(getDomAttributeValue(tdom, 'name'))
+
+                if self.home and name:
+                    output = Output(name, tdom, self)
+                    output.complete()
+                    output.setPath(os.path.abspath(os.path.join(self.home,
+                                                                name)))
+                    if not output.getType() and tag != 'output':
+                        output.setType(tag)
+                    rawOutputs.append(output)
+                    if output.getType() not in outputCountByType:
+                        outputCountByType[output.getType()] = 1
+                    else:
+                        outputCountByType[output.getType()] = \
+                            outputCountByType[output.getType()] + 1
+                else:
+                    self.addError('Missing \'name\' on <' + tag)
+
+
+        # Fix 'ids' on all outputs which don't have them
+        for output in rawOutputs:
+            if not output.hasId():
+                if 1 == outputCountByType[output.getType()]:
+                    self.addDebug('Sole ' + output.getType() + ' output [' + \
+                                      os.path.basename(output.getPath()) + \
+                                      '] identifier set to project name')
+                    output.setId(self.getName())
+                else:
+                    # :TODO: A work in progress, not sure how
+                    # we ought 'construct' ids.
+                    basename = os.path.basename(output.getPath())
+                    newId = basename
+                    # Strip off .jar or .lib (note: both same length)
+                    if newId.endswith('.jar') or newId.endswith('.lib'):
+                        newId = newId[:-4]
+                    # Strip off -@@DATE@@
+                    datePostfix = '-' + str(default.date_s)
+                    if newId.endswith(datePostfix):
+                        reduction = -1 * len(datePostfix)
+                        newId = newId[:reduction]
+                    # Assign...
+                    self.addDebug('Output [' + basename + \
+                                      '] identifier set to output ' + \
+                                      'basename: [' + newId + ']')
+                    output.setId(newId)
+            self.addOutput(output)
+
+        # ensure id is unique per output type
+        for output_type in self.outputs.keys():
+            d = {}
+            remove = []
+            for o in self.outputs[output_type]:
+                if o.getId() in d:
+                    self.addWarning("Multiple " + output_type + " outputs " \
+                                        + " use id " + o.getId() \
+                                        + " dropping " + o.getPath())
+                    remove.append(o)
+                else:
+                    d[o.getId()] = True
+            for o in remove:
+                self.outputs[output_type].remove(o)
+
 class ProjectStatistics(Statistics):
     """Statistics Holder"""
     def __init__(self, projectName):



Mime
View raw message