gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject svn commit: r365283 - in /gump/trunk/python/gump/core: build/builder.py build/mvn.py model/builder.py model/module.py model/project.py run/gumpenv.py
Date Mon, 02 Jan 2006 04:05:46 GMT
Author: billbarker
Date: Sun Jan  1 20:05:38 2006
New Revision: 365283

URL: http://svn.apache.org/viewcvs?rev=365283&view=rev
Log:
Inital attempt to add Maven2 support to Gump.

This requires that you have Maven2 installed on your PATH, and M2_HOME set to the installed
home.  

AFAIK, we're not running trunk anywhere, and even if we were, none of the changes would be
triggered unless a <project /> declared an <mvn /> target.  So this should be
safe for review.

This still needs some work for defining Maven overrides, but it's been my experiance that
code gets more comments ;).


Added:
    gump/trunk/python/gump/core/build/mvn.py
Modified:
    gump/trunk/python/gump/core/build/builder.py
    gump/trunk/python/gump/core/model/builder.py
    gump/trunk/python/gump/core/model/module.py
    gump/trunk/python/gump/core/model/project.py
    gump/trunk/python/gump/core/run/gumpenv.py

Modified: gump/trunk/python/gump/core/build/builder.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/build/builder.py?rev=365283&r1=365282&r2=365283&view=diff
==============================================================================
--- gump/trunk/python/gump/core/build/builder.py (original)
+++ gump/trunk/python/gump/core/build/builder.py Sun Jan  1 20:05:38 2006
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2003-2006 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@
 from gump.core.build.ant import AntBuilder
 from gump.core.build.nant import NAntBuilder
 from gump.core.build.maven import MavenBuilder
+from gump.core.build.mvn import Maven2Builder
 from gump.core.build.configure import ConfigureBuilder
 from gump.core.build.make import MakeBuilder
 
@@ -80,6 +81,7 @@
         self.ant=AntBuilder(run)
         self.nant=NAntBuilder(run)
         self.maven=MavenBuilder(run)
+        self.mvn=Maven2Builder(run)
         self.script=ScriptBuilder(run)
         self.configure = ConfigureBuilder(run)
         self.make = MakeBuilder(run);
@@ -139,6 +141,8 @@
                     self.nant.buildProject(project, languageHelper, stats)
                 elif project.hasMaven():
                     self.maven.buildProject(project, languageHelper, stats)
+                elif project.hasMvn():
+                    self.mvn.buildProject(project, languageHelper, stats)
                 elif project.hasConfigure():
                     self.configure.buildProject(project, languageHelper, stats)
                 elif project.hasMake():
@@ -485,5 +489,7 @@
             self.nant.preview(project,  languageHelper, stats)
         elif project.hasMaven():
             self.maven.preview(project,  languageHelper, stats)
+        elif project.hasMvn():
+            self.mvn.preview(project, languageHelper, stats);
         else:
             print 'No builder for project: ' + project.getName()

Added: gump/trunk/python/gump/core/build/mvn.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/build/mvn.py?rev=365283&view=auto
==============================================================================
--- gump/trunk/python/gump/core/build/mvn.py (added)
+++ gump/trunk/python/gump/core/build/mvn.py Sun Jan  1 20:05:38 2006
@@ -0,0 +1,300 @@
+#!/usr/bin/python
+
+
+# Copyright 2003-2006 The Apache Software Foundation
+#
+# Licensed 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.
+
+__revision__  = "$Rev: 36667 $"
+__date__      = "$Date: 2004-08-20 08:55:45 -0600 (Fri, 20 Aug 2004) $"
+__copyright__ = "Copyright (c) 1999-2004 Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"
+
+
+"""
+
+"""
+
+import os.path
+import sys
+
+from gump import log
+from gump.core.run.gumprun import *
+from gump.core.config import dir, default, basicConfig
+
+from gump.util import dump, display, getIndent, logResourceUtilization, \
+                            invokeGarbageCollection
+from gump.util.note import Annotatable
+from gump.util.work import *
+
+from gump.util.tools import *
+
+from gump.core.model.workspace import *
+from gump.core.model.module import Module
+from gump.core.model.project import Project
+from gump.core.model.depend import  ProjectDependency
+from gump.core.model.stats import *
+from gump.core.model.state import *
+
+
+###############################################################################
+# Classes
+###############################################################################
+
+class Maven2Builder(gump.core.run.gumprun.RunSpecific):
+    
+    def __init__(self,run):
+        gump.core.run.gumprun.RunSpecific.__init__(self,run)
+
+    def buildProject(self,project,languageHelper,stats):
+        """
+        Build a Maven2 project
+        """
+        
+        workspace=self.run.getWorkspace()
+                
+        log.debug('Run Maven2 on Project: #[' + `project.getPosition()` + '] ' + project.getName())
+        
+        self.performPreBuild(project, languageHelper, stats)
+          
+        if project.okToPerformWork():
+
+            #
+            # Get the appropriate build command...
+            #
+            cmd=self.getMavenCommand(project,languageHelper)
+
+            if cmd:
+                # Execute the command ....
+                cmdResult=execute(cmd,workspace.tmpdir)
+    
+                # Update Context    
+                work=CommandWorkItem(WORK_TYPE_BUILD,cmd,cmdResult)
+                project.performedWork(work)
+                project.setBuilt(True)
+                    
+                # Update Context w/ Results  
+                if not cmdResult.state==CMD_STATE_SUCCESS:
+                    reason=REASON_BUILD_FAILED
+                    if cmdResult.state==CMD_STATE_TIMED_OUT:
+                        reason=REASON_BUILD_TIMEDOUT
+                    project.changeState(STATE_FAILED,reason)                        
+                else:                         
+                    # For now, things are going good...
+                    project.changeState(STATE_SUCCESS)
+                    
+        if project.wasBuilt():
+            pomFile=self.locateMavenProjectFile(project) 
+            if os.path.exists(pomFile):                               
+                project.addDebug('Maven POM in: ' + pomFile) 
+                catFileToFileHolder(project, pomFile, FILE_TYPE_CONFIG) 
+                    
+            projpFile=self.locateMavenProjectPropertiesFile(project) 
+            if os.path.exists(projpFile):                                               

+                project.addDebug('Maven project properties in: ' + projpFile)           
    
+                catFileToFileHolder(project, projpFile, FILE_TYPE_CONFIG)               
           
+  
+    #
+    # Build an Maven command for this project
+    #        
+    def getMavenCommand(self,project,languageHelper):
+        maven=project.mvn
+    
+        # The maven goal (or none == maven default goal)
+        goal=maven.getGoal()
+    
+        # Optional 'verbose' or 'debug'
+        verbose=maven.isVerbose()
+        debug=maven.isDebug()
+    
+        #
+        # Where to run this:
+        #
+        basedir = maven.getBaseDirectory() or project.getBaseDirectory()
+    
+        #
+        # Build a classpath (based upon dependencies)
+        #
+        (classpath,bootclasspath)=languageHelper.getClasspaths(project)
+    
+        # Run Maven...
+        cmd=Cmd('mvn','build_'+project.getModule().getName()+'_'+project.getName(),\
+            basedir,{'CLASSPATH':classpath})
+            
+        # Set this as a system property. Setting it here helps JDK1.4+
+        # AWT implementations cope w/o an X11 server running (e.g. on
+        # Linux)
+        # cmd.addPrefixedParameter('-D','java.awt.headless','true','=')
+    
+        #
+        # Add BOOTCLASSPATH
+        #
+        #if bootclasspath:
+        #    cmd.addPrefixedParameter('-X','bootclasspath/p',bootclasspath,':')
+            
+        #if jvmargs:
+        #    cmd.addParameters(jvmargs)
+            
+        # cmd.addParameter('org.apache.maven.cli.App')  
+    
+        #
+        # Allow maven-level debugging...
+        #
+        if project.getWorkspace().isDebug() or project.isDebug() or debug: 
+            cmd.addParameter('--debug')  
+        if project.getWorkspace().isVerbose()  or project.isVerbose() or verbose: 
+            cmd.addParameter('--exception') 
+        
+        #
+        # Suppress downloads
+        #          
+        cmd.addParameter('--offline')  
+        
+        #
+        #	This sets the *defaults*, a workspace could override them.
+        #
+        #cmd.addPrefixedParameter('-D','build.sysclasspath','only','=')
+    
+        # End with the goal...
+        if goal: 
+            for goalParam in goal.split(','):
+                cmd.addParameter(goalParam)
+    
+        return cmd
+  
+        # Do this even if not ok
+    def performPreBuild(self, project, languageHelper, stats):
+                   
+        # Maven requires a build.properties to be generated...
+        if project.okToPerformWork():
+            try:
+                propertiesFile=self.generateMavenProperties(project,languageHelper)     
                          
+                project.addDebug('(Gump generated) Maven Properties in: ' + propertiesFile)
+                
+                try:
+                    catFileToFileHolder(project,propertiesFile,
+                        FILE_TYPE_CONFIG,
+                        os.path.basename(propertiesFile))
+                except:
+                    log.error('Display Properties [ ' + propertiesFile + '] Failed', exc_info=1)
  
+               
+            except Exception, details:
+                message='Generate Maven Properties Failed:' + str(details)
+                log.error(message, exc_info=1)
+                project.addError(message)    
+                project.changeState(STATE_FAILED,REASON_PREBUILD_FAILED)
+ 
+    # The propertiesFile parameter is primarily for testing.
+    def generateMavenProperties(self,project,languageHelper,propertiesFile=None):
+        """Set properties/overrides for a Maven project"""
+        
+        #:TODO: Does Maven have the idea of system properties?
+        
+        #
+        # Where to put this:
+        #
+        basedir = project.mvn.getBaseDirectory() or project.getBaseDirectory()
+        if not propertiesFile: 
+            propertiesFile=os.path.abspath(os.path.join(basedir,'profile.xml'))
+            
+        # Ensure containing directory exists, or make it.
+        propsdir=os.path.dirname(propertiesFile)
+        if not os.path.exists(propsdir):
+            project.addInfo('Making directory for Maven properties: ['+propsdir+']')
+            os.makedirs(propsdir)
+        
+        if os.path.exists(propertiesFile):
+            project.addWarning('Overriding Maven properties: ['+propertiesFile+']')
+    
+        
+        props=open(propertiesFile,'w')
+        
+        props.write('<?xml version="1.0"?>\n')
+        props.write(("""<!-- ------------------------------------------------------------------------
+# DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT

+#
+# File Automatically Generated by Gump, see http://gump.apache.org/
+#
+# Generated For : %s
+# Generated At  : %s
+#
+#
+# DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT  DO NOT EDIT
+# ------------------------------------------------------------------------
+-->\n""")	%	(project.getName(), time.strftime('%Y-%m-%d %H:%M:%S')) )
+        props.write("<profiles>\n")
+        props.write("  <project>\n")
+        props.write("   <id>Gump</id>\n")
+        props.write("   <activation><activeByDefault/></activation>\n")
+        (classpath,bootclasspath)=languageHelper.getClasspathObjects(project)
+        
+        # :TODO: write...
+        props.write("   <dependencies>\n")
+        for annotatedPath in classpath.getPathParts()+bootclasspath.getPathParts():
+            if isinstance(annotatedPath,gump.core.language.path.AnnotatedPath):
+                props.write("    <dependency>\n")
+                # Sort of punting here
+                props.write("<!-- Contributor: %s -->\n    <groupId>%s</groupId>\n"
% \
+                    ( annotatedPath.getContributor(),
+                      annotatedPath.getContributor()))
+                props.write("     <artifactId>%s</artifactId>\n" % \
+                             (annotatedPath.getId()))
+                props.write("     <scope>SYSTEM</scope>\n")
+                props.write("     <systemPath>%s</systemPath>\n" % \
+                             (annotatedPath.getPath().replace('\\', '/')))
+                props.write("   </dependency>\n")
+
+        props.write("   </dependencies>\n")
+
+        props.write("   <properties>\n")   
+        #
+        # Output basic properties
+        #
+        for property in project.getWorkspace().getProperties()+project.getMvn().getProperties():
+            # build.sysclasspath makes Maven sick.
+            if not 'build.sysclasspath' == property.name:
+                props.write(('<property><name>%s</name><value>%s</value></property>\n')
% (property.name,property.value.replace('\\','/')))            
+        
+        #
+        # Output classpath properties
+        #
+        props.write("""<!--
+# ------------------------------------------------------------------------
+# M A V E N  J A R  O V E R R I D E
+# ------------------------------------------------------------------------
+-->
+<property><name>maven.jar.override</name><value>on</value></property>
+<!--
+# ------------------------------------------------------------------------
+# Jars set explicity by path.
+# ------------------------------------------------------------------------
+-->""")
+        
+        props.write("   </properties>\n")
+        props.write("</profile></profiles>\n")
+        return propertiesFile
+      
+    def locateMavenProjectPropertiesFile(self,project):
+        """Return Maven project properties file location""" 
+        basedir = project.mvn.getBaseDirectory() or project.getBaseDirectory()
+        return os.path.abspath(os.path.join(basedir,'project.properties'))
+        
+    def locateMavenProjectFile(self,project):
+        """Return Maven project file location"""      
+        basedir = project.mvn.getBaseDirectory() or project.getBaseDirectory()
+        return os.path.abspath(os.path.join(basedir,'pom.xml'))  
+        
+    def preview(self,project,languageHelper,stats):        
+        command=self.getMavenCommand(project,languageHelper) 
+        command.dump()
+            

Modified: gump/trunk/python/gump/core/model/builder.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/model/builder.py?rev=365283&r1=365282&r2=365283&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/builder.py (original)
+++ gump/trunk/python/gump/core/model/builder.py Sun Jan  1 20:05:38 2006
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2003-2006 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -263,6 +263,24 @@
     	
         # Import the goal
         self.goal=self.getDomAttributeValue('goal','jar')
+            	    
+    def getGoal(self):
+        return self.goal
+    	
+    def dump(self, indent=0, output=sys.stdout):
+        """ Display the contents of this object """
+        Builder.dump(self,indent,output)
+        i=getIndent(indent+1)
+        output.write(i+'Goal: ' + self.getGoal() + '\n')
+
+# represents an <mvn/> element
+class Maven2(Builder):
+    """ A Maven command (within a project)"""
+    def __init__(self,dom,project):
+    	Builder.__init__(self,dom,project)
+    	
+        # Import the goal
+        self.goal=self.getDomAttributeValue('goal','package')
             	    
     def getGoal(self):
         return self.goal

Modified: gump/trunk/python/gump/core/model/module.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/model/module.py?rev=365283&r1=365282&r2=365283&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/module.py (original)
+++ gump/trunk/python/gump/core/model/module.py Sun Jan  1 20:05:38 2006
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2003-2006 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.

Modified: gump/trunk/python/gump/core/model/project.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/model/project.py?rev=365283&r1=365282&r2=365283&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/project.py (original)
+++ gump/trunk/python/gump/core/model/project.py Sun Jan  1 20:05:38 2006
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2003-2006 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
                             AddressPair
 from gump.core.model.stats import Statable, Statistics
 from gump.core.model.property import Property
-from gump.core.model.builder import Ant,NAnt,Maven,Script,Configure,Make
+from gump.core.model.builder import Ant,NAnt,Maven,Maven2,Script,Configure,Make
 from gump.util import getIndent
 from gump.util.file import *
 from gump.core.model.depend import *
@@ -78,8 +78,9 @@
     	#
     	self.ant=None
         self.nant=None
-    	self.maven=None
-    	self.script=None
+        self.maven=None
+        self.mvn= None
+        self.script=None
         self.configure = None
         self.make = None
         self.builder = []
@@ -158,6 +159,10 @@
         if self.maven: return True
         return False
         
+    def hasMvn(self):
+        if self.mvn: return True
+        return False
+        
     def hasScript(self):
         if self.script: return True
         return False
@@ -179,6 +184,9 @@
     def getMaven(self):
         return self.maven
         
+    def getMvn(self):
+        return self.mvn
+        
     def getScript(self):
         return self.script
     
@@ -398,6 +406,14 @@
             # Copy over any XML errors/warnings
             # :TODO:#1: transferAnnotations(self.xml.maven, self)
             
+        # Import any <mvn part [if not packaged]
+        if self.hasDomChild('mvn') and not packaged:
+            self.mvn = Maven2(self.getDomChild('mvn'),self)
+            self.builder.append(self.mvn)
+            
+            # Copy over any XML errors/warnings
+            # :TODO:#1: transferAnnotations(self.xml.maven, self)
+            
         # Import any <script part [if not packaged]
         if self.hasDomChild('script') and not packaged:
             self.script = Script(self.getDomChild('script'),self)
@@ -615,6 +631,9 @@
 
         if self.maven:
             self.addJVMArgs(self.getDomChild("maven"))
+
+        if self.mvn:
+            self.addJVMArgs(self.getDomChild("mvn"))
 
         #
         # complete properties

Modified: gump/trunk/python/gump/core/run/gumpenv.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/run/gumpenv.py?rev=365283&r1=365282&r2=365283&view=diff
==============================================================================
--- gump/trunk/python/gump/core/run/gumpenv.py (original)
+++ gump/trunk/python/gump/core/run/gumpenv.py Sun Jan  1 20:05:38 2006
@@ -73,6 +73,7 @@
         self.noMono = False
         self.noNAnt = False    
         self.noMaven = False    	
+        self.noMaven2 = False
         self.noSvn = False    	
         self.noCvs = False   
         self.noP4 = False   
@@ -131,6 +132,10 @@
             self.noMaven=True
             self.addWarning('MAVEN_HOME environmental variable not found, no maven builds.')
             
+        if not self.noMaven2 and not self._checkEnvVariable('M2_HOME',False): 
+            self.noMaven=True
+            self.addWarning('M2_HOME environmental variable not found, no mvn builds.')
+            
         # Check for executables
         
         self._checkExecutable('env','',False)
@@ -161,6 +166,11 @@
             not self._checkExecutable('maven','--version',False,False,'check_maven'): 
             self.noMaven=True
             self.addWarning('"maven" command not found, no Maven builds')
+       
+        if not self.noMaven2 and \
+            not self._checkExecutable('mvn','--version',False,False,'check_maven2'): 
+            self.noMaven=True
+            self.addWarning('"mvn" command not found, no Maven2 builds')
        
         if not self.noNAnt and \
             not self._checkExecutable('NAnt','-help',False,False,'check_NAnt'): 



Mime
View raw message