gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r960297 - /gump/trunk/python/gump/core/model/project.py
Date Sun, 04 Jul 2010 06:15:23 GMT
Author: bodewig
Date: Sun Jul  4 06:15:22 2010
New Revision: 960297

URL: http://svn.apache.org/viewvc?rev=960297&view=rev
Log:
separate id namespaces for outputs of different types - don't use it until property knows
how to deal with it, though

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=960297&r1=960296&r2=960297&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/project.py (original)
+++ gump/trunk/python/gump/core/model/project.py Sun Jul  4 06:15:22 2010
@@ -107,6 +107,7 @@ class Project(NamedModelObject, Statable
         #############################################################
         # Outputs (like jars, assemblies, poms ...)
         #
+        # kept as {type => [outputs of that type]}
         self.outputs = {}
         self.outputs_expanded = False
 
@@ -253,13 +254,12 @@ class Project(NamedModelObject, Statable
         return self.getModule().getViewUrl()
 
     def addOutput(self, output):
-        self.outputs[output.getName()] = output
+        if output.getType() not in self.outputs:
+            self.outputs[output.getType()] = []
+        self.outputs[output.getType()].append(output)
 
     def getOutputCount(self):
-        return len(self.outputs)
-
-    def hasOutputWithId(self, id):
-        return self.outputs.has_key(id)
+        return sum(map(len, self.outputs.itervalues()))
 
     def hasLicense(self):
         if self.license:
@@ -283,25 +283,27 @@ class Project(NamedModelObject, Statable
 
     def getOutputs(self):
         self.expand_outputs()
-        return self.outputs.values()
+        return reduce(lambda l1, l2: l1 + l2, self.outputs.itervalues(), [])
 
     def expand_outputs(self):
         """ expands glob patterns in output names """
         if (self.built or not self.hasBuilder()) and not self.outputs_expanded:
-            for output in self.outputs.values():
-                path = output.getPath()
-                log.debug("glob expanding " + path)
-                expansions = glob.glob(path)
-                count = len(expansions)
-                if count > 1:
-                    self.changeState(STATE_FAILED, REASON_MISSING_OUTPUTS)
-                    self.addError("%s matched %d files." % (path, count))
-                elif count == 1:
-                    log.debug("replacing " + path + " with " + expansions[0])
-                    output.setPath(expansions[0])
-                else:
-                    log.debug("didn't find any match for " + path)
-            self.outputs_expanded = True
+            for l in self.outputs.itervalues():
+                for output in l:
+                    path = output.getPath()
+                    log.debug("glob expanding " + path)
+                    expansions = glob.glob(path)
+                    count = len(expansions)
+                    if count > 1:
+                        self.changeState(STATE_FAILED, REASON_MISSING_OUTPUTS)
+                        self.addError("%s matched %d files." % (path, count))
+                    elif count == 1:
+                        log.debug("replacing " + path + " with " \
+                                      + expansions[0])
+                        output.setPath(expansions[0])
+                    else:
+                        log.debug("didn't find any match for " + path)
+        self.outputs_expanded = True
 
     def hasAnyOutputs(self):
         """
@@ -562,6 +564,8 @@ class Project(NamedModelObject, Statable
                        'assembly',
                        'output',
                        'pom']
+        rawOutputs = []
+        outputCountByType = {}
 
         for tag in outputTypes:
             for tdom in self.getDomChildIterator(tag):
@@ -574,40 +578,43 @@ class Project(NamedModelObject, Statable
                                                                 name)))
                     if not output.getType() and tag != 'output':
                         output.setType(tag)
-                    self.addOutput(output)
+                    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
-        if self.hasOutputs():
-            if 1 == self.getOutputCount():
-                output = self.getOutputAt(0)
-                if not output.hasId():
-                    self.addDebug('Sole output [' + \
+        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.
-                for output in self.getOutputs():
-                    if not output.hasId():
-                        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)
+                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)
 
         # Grab all the work
         for w in self.getDomChildIterator('work'):



Mime
View raw message