You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by sa...@apache.org on 2005/08/25 23:58:04 UTC

svn commit: r240149 - in /gump/branches/Gump3/pygump/python/gump: config.py engine/loader.py engine/mavenizer.py engine/objectifier.py model/__init__.py plugins/java/builder.py util/executor.py util/mavenToGump.conf

Author: sanders
Date: Thu Aug 25 14:57:47 2005
New Revision: 240149

URL: http://svn.apache.org/viewcvs?rev=240149&view=rev
Log:
Initial contribution of maven-gump plugin from Justin Merz (jrmerz at ucdavis.edu)

Added:
    gump/branches/Gump3/pygump/python/gump/engine/mavenizer.py   (with props)
    gump/branches/Gump3/pygump/python/gump/util/mavenToGump.conf   (with props)
Modified:
    gump/branches/Gump3/pygump/python/gump/config.py
    gump/branches/Gump3/pygump/python/gump/engine/loader.py
    gump/branches/Gump3/pygump/python/gump/engine/objectifier.py
    gump/branches/Gump3/pygump/python/gump/model/__init__.py
    gump/branches/Gump3/pygump/python/gump/plugins/java/builder.py
    gump/branches/Gump3/pygump/python/gump/util/executor.py

Modified: gump/branches/Gump3/pygump/python/gump/config.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/config.py?rev=240149&r1=240148&r2=240149&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Thu Aug 25 14:57:47 2005
@@ -105,6 +105,7 @@
         log.info("Not running updates! (pass --do-updates to enable them)")
         
     if config.do_build:
+        from gump.model import Maven
         from gump.model import Ant
         from gump.model import Script
 
@@ -118,13 +119,17 @@
     
         from gump.plugins.builder import PathPlugin
         plugins.append(PathPlugin(buildlog, Ant))
+        plugins.append(PathPlugin(buildlog, Maven))
         plugins.append(PathPlugin(buildlog, Script))
         from gump.plugins.builder import ScriptBuilderPlugin
         plugins.append(ScriptBuilderPlugin(buildlog))
         from gump.plugins.java.builder import ClasspathPlugin
         plugins.append(ClasspathPlugin(buildlog,Ant))
+        plugins.append(ClasspathPlugin(buildlog,Maven))
         from gump.plugins.java.builder import AntPlugin
         plugins.append(AntPlugin(buildlog))
+        from gump.plugins.java.builder import MavenPlugin
+        plugins.append(MavenPlugin(buildlog))
         #plugins.append(AntPlugin(buildlog, debug=True))
     else:
         log.info("Not running builds! (pass --do-builds to enable them)")

Modified: gump/branches/Gump3/pygump/python/gump/engine/loader.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/loader.py?rev=240149&r1=240148&r2=240149&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/loader.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/loader.py Thu Aug 25 14:57:47 2005
@@ -31,11 +31,12 @@
 from gump.engine.modeller import _find_document_containing_node
 from gump.engine.modeller import _find_module_containing_node
 from gump.engine.modeller import _do_drop
+from gump.engine.mavenizer import _parse_maven_projects
 
 ###
 ### Helper methods
 ###
-def _resolve_hrefs_in_children(element, dropped_nodes, found_hrefs, download_func, error_func):
+def _resolve_hrefs_in_children(element, dropped_nodes, found_hrefs, download_func, error_func, get_vfs):
     """Recursively resolve all hrefs in all the children for a DOM node.
     
     The resolution is done in a resolve-then-recurse manner, so the end
@@ -58,15 +59,15 @@
         if child.tagName == 'url': continue
         if child.hasAttribute('href'):
             # yep, this is one to load...
-            _resolve_href(child, dropped_nodes, found_hrefs, download_func, error_func)
+            _resolve_href(child, dropped_nodes, found_hrefs, download_func, error_func, get_vfs)
 
         # now recurse to resolve any hrefs within this child
         # note that we duplicate the found_hrefs array. This means that the
         # same file can be imported multiple times, as long as it is imported
         # by siblings, rather than as part of some parent<->child relation.
-        _resolve_hrefs_in_children(child, dropped_nodes, found_hrefs[:], download_func, error_func)
+        _resolve_hrefs_in_children(child, dropped_nodes, found_hrefs[:], download_func, error_func, get_vfs)
 
-def _resolve_href(node, dropped_nodes, found_hrefs, download_func, error_func):
+def _resolve_href(node, dropped_nodes, found_hrefs, download_func, error_func, get_vfs):
     """Resolve a href for the provided node.
 
     We merge in the referenced xml document into the provided node.
@@ -74,7 +75,10 @@
     succeeds. If the merge fails the provided node will be removed from
     its parent and appended to the dropped_nodes list.
     """
-    href = node.getAttribute('href')
+    if node.getAttribute('type') == 'maven':
+	href = _parse_maven_projects( node, download_func, get_vfs )
+    else:
+    	href = node.getAttribute('href')
     if href in found_hrefs:
         raise EngineError, \
               """Recursive inclusion because files refer to each other. This href leads to
@@ -183,7 +187,7 @@
         # resolve all hrefs in all elements, for example
         # <project href="blah.xml"/>; replaces that element with the
         # contents of blah.xml
-        _resolve_hrefs_in_children(ws, dropped_nodes, [], self.get_as_stream, self.handle_error)
+        _resolve_hrefs_in_children(ws, dropped_nodes, [], self.get_as_stream, self.handle_error, self.vfs.filesystem_root)
         
         # the combined results
         return (wsdom, dropped_nodes)

Added: gump/branches/Gump3/pygump/python/gump/engine/mavenizer.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/mavenizer.py?rev=240149&view=auto
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/mavenizer.py (added)
+++ gump/branches/Gump3/pygump/python/gump/engine/mavenizer.py Thu Aug 25 14:57:47 2005
@@ -0,0 +1,206 @@
+import os, sys
+from xml import dom
+from xml.dom import minidom
+from gump.engine.modeller import _find_element_text
+from gump.util.io import VFS
+
+def _parse_maven_projects( module_node, download_func, get_vfs):
+        """Looks for <project type="maven"> and converts those."""
+        #create maven DOM
+	try:
+		maven_node = _resolve_maven_import( module_node.getAttribute('href'), download_func )
+		#parse DOM creating new gumped-maven file 
+		#then return file location to be used instead
+		#of original maven file
+		gumped_maven_href = _parse_maven_file(maven_node, download_func, get_vfs, module_node.getAttribute( 'goal' ))
+		return gumped_maven_href
+	except:
+		print 'maven parse error'
+		return '-1'
+        
+    
+def _parse_maven_file( project, download_func, get_vfs, maven_build_goal ):
+        #TODO: implement this!
+	
+	#deal with extended maven projects
+	extend = 0;
+	hasExtend = _find_element_text(project, "extend")
+	if ( hasExtend ):
+		extend = 1;
+		project_ex = _resolve_maven_import( hasExtend, download_func )
+	#get maven id
+        id = _find_element_text(project, "id")
+	if not id and extend:
+        	id = _find_element_text(project_ex, "id")
+        #get maven group id
+	groupid = _find_element_text(project, "groupId")
+	if not groupid and extend:
+        	groupid = _find_element_text(project_ex, "groupId")
+        name = "%s-%s" % (groupid,id)
+	filename = "gumped_%s.xml" % name
+	#TODO get module name
+	modulename = "module_name"
+	#get title
+        title = _find_element_text(project, "title")
+	if not title and extend:
+        	title = _find_element_text(project_ex, "title")
+	#get NAG
+	nag = _find_element_text(project, "nagEmailAddress")
+	if not nag and extend:
+        	nag = _find_element_text(project_ex, "nagEmailAdress")
+        #get url
+	url = _find_element_text(project, "url")
+	if not url and extend:
+        	url = _find_element_text(project_ex, "url")
+	#get repository info	
+	cvsweb = _find_element_text(project.getElementsByTagName("repository").item(0), "url")
+        #get description
+	description = _find_element_text(project, "description")
+	if not description and extend:
+		description = _find_element_text(project_ex, "description")
+        #more repository info
+	repository = _find_element_text(project, "gumpRepositoryId")
+	if not repository and extend:
+		repository = _find_element_text(project_ex, "gumpRepositoryId")
+        if not repository:
+            # create repository and module
+            connection = _find_element_text(project.getElementsByTagName("repository").item(0), "connection")
+            connection = connection[4:] # get rid of "scm:"
+            provider = connection[:connection.index(':')] # "cvs" or "svn" or "starteam"
+            if provider.upper() == "cvs".upper():
+                repository2 = connection[connection.index(':')+1:]
+                parts = repository2.split(':')
+		method = parts[0]	
+		user = parts[1][:parts[1].index('@')]
+		host = parts[1][parts[1].index('@')+1:]
+                path = parts[2]
+                module = parts[3]
+	# get dependencies
+	dependencies = project.getElementsByTagName("dependency");
+	if not dependencies and extend:
+		dependencies = project_ex.getElementsByTagName("dependency");
+	package = _find_element_text(project, "package")
+	if not package and extend:
+		package = _find_element_text(project_ex, "package")
+	#maven build info
+	hasBuild = 0
+	if _find_element_text(project, "build") or _find_element_text(project_ex, "build"):
+		hasBuild = 1
+	buildInfo = "<maven "
+	# TODO work on this call path
+	#sourceDir = _find_element_text(project, "sourceDirectory")
+	#if not sourceDir and extend:
+	#	sourceDir = _find_element_text(project_ex, "sourceDirectory")
+	#if sourceDir:
+	#	buildInfo += 'basedir="%s" ' % sourceDir
+	target = maven_build_goal
+	if target:
+		buildInfo += 'target="%s" ' % target
+	buildInfo += '/>'
+	map = build_map_ID()
+	
+	#find root of metadata/ where data is coming from
+	home_dir = get_vfs
+	mavenfile = open("%s\\%s" % (home_dir, filename), "w")
+	mavenfile.write( '<?xml version="1.0" encoding="UTF-8"?> \n' )
+	mavenfile.write( license() )
+	mavenfile.write( '  <project name="%s">\n\n' % name)
+	if url:
+		mavenfile.write( '    <url href="%s"/>\n' % url );
+	if description:
+		mavenfile.write( '    <description>\n')
+		mavenfile.write( '      %s \n' % description)
+		mavenfile.write( '    </description>\n\n')
+#	if modulename:
+#		mavenfile.write( '    <module name="%s">\n\n' % modulename)
+	if hasBuild:
+		mavenfile.write( '    %s\n\n' % buildInfo )
+	if package:
+		mavenfile.write( '    <package>%s</package>\n' % package )
+	if repository:
+		mavenfile.write( '    <repository name="%s"/>\n\n' % repository)
+	elif repository2:
+		mavenfile.write( '    <repository name="%s" type="%s">\n' % ( module, provider ))
+		mavenfile.write( '      <title>%s</title>\n' % module )
+		if cvsweb:
+			mavenfile.write( '      <cvsweb>%s</cvsweb>\n' % cvsweb )
+		mavenfile.write( '      <redistributable/>\n\n' )
+		if host:
+			mavenfile.write( '      <hostname>%s</hostname>\n' % host )
+		if method:
+			mavenfile.write( '      <method>%s</method>\n' % method )
+		if user:
+			mavenfile.write( '      <user>%s</user>\n' % user )
+			mavenfile.write( '      <password>%s</password>\n' % user)
+		if path:
+			mavenfile.write( '      <path>%s</path>\n' % path )
+		mavenfile.write( '    </repository>\n\n')
+	for dependency in dependencies:
+		depend = _find_element_text( dependency, "artifactId" )
+		if map:
+			depend = map_ID( depend, map )
+		if depend:
+			mavenfile.write( '    <depend project="%s"/>\n' % depend)
+	mavenfile.write( ' \n')
+	if nag:
+		mavenfile.write( '    <nag from="Gump Integration Build &lt;general@gump.apache.org&gt;" to="%s"/>\n\n' % nag); 
+	mavenfile.write( ' \n')
+	mavenfile.write( '  </project>\n')
+	mavenfile.close()
+                            
+	return filename
+    
+def _resolve_maven_import( href, download_func):
+	#opens maven files for reading
+	try:
+		stream = download_func(href)
+		maven_dom = minidom.parse(stream)
+		maven_dom.normalize()
+		return maven_dom
+	except:
+		print "found maven file %s, but could not open!" % href
+
+def build_map_ID():
+	#open config file, set up dictonary
+	try:
+		mycwd = os.getcwd()
+		IDfile = open("%s\python\gump\util\mavenToGump.conf" % mycwd , "r")
+		relation = IDfile.readline()
+		parts = relation.split(',')
+		IDmap = { parts[0]:parts[1][1:parts[1].index(':')] }
+		while( relation ):
+			parts = relation.split(',')
+			IDmap[parts[0]] = parts[1][1:parts[1].index(':')]
+			relation = IDfile.readline()
+		return IDmap
+	except:
+		print 'ERROR building maven to gump ID map'
+		return 0
+
+def map_ID( artifactID, map ):	
+	if map.has_key(artifactID):
+		projectID = map[artifactID]
+		return projectID
+	return artifactID
+
+def license():
+	#for printing apache license
+	license = '<!-- \n'
+	license += '/* \n'
+	license += ' * Copyright 2001-2004 The Apache Software Foundation. \n'
+	license += ' * \n'
+	license += ' * Licensed under the Apache License, Version 2.0 (the "License"); \n'
+	license += ' * you may not use this file except in compliance with the License. \n'
+	license += ' * You may obtain a copy of the License at \n'
+	license += ' * \n'
+	license += ' *      http://www.apache.org/licenses/LICENSE-2.0 \n'
+	license += ' * \n'
+	license += ' * Unless required by applicable law or agreed to in writing, software \n'
+	license += ' * distributed under the License is distributed on an "AS IS" BASIS, \n'
+	license += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n'
+	license += ' * See the License for the specific language governing permissions and \n'
+	license += ' * limitations under the License. \n'
+	license += ' */ \n'
+	license += ' --> \n'
+	return license
+		

Propchange: gump/branches/Gump3/pygump/python/gump/engine/mavenizer.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: gump/branches/Gump3/pygump/python/gump/engine/objectifier.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/objectifier.py?rev=240149&r1=240148&r2=240149&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/objectifier.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/objectifier.py Thu Aug 25 14:57:47 2005
@@ -187,6 +187,7 @@
     _create_specific_script_commands(project, project_definition, "autoconf", Autoconf, log=log)
     _create_specific_script_commands(project, project_definition, "automake", Automake, log=log)
     _create_ant_commands(project, project_definition, log=log)
+    _create_maven_commands(project, project_definition, log=log)
     #TODO more commands
 
 
@@ -415,6 +416,16 @@
 
         project.add_command(command)
 
+def _create_maven_commands(project, project_definition, log=None):
+    mavens = project_definition.getElementsByTagName("maven")
+    for cmd in mavens:
+        buildfile = cmd.getAttribute("buildfile")
+        target = cmd.getAttribute("target")
+        basedir = cmd.getAttribute("basedir")
+        command = Maven(project, target, buildfile=buildfile, basedir=basedir)
+        _create_properties(command, cmd, log=log)
+        _enable_debug(command, cmd)
+	project.add_command(command)
 
 def _create_outputs(project, project_definition):    
     _create_work_outputs(project, project_definition)

Modified: gump/branches/Gump3/pygump/python/gump/model/__init__.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/model/__init__.py?rev=240149&r1=240148&r2=240149&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/model/__init__.py (original)
+++ gump/branches/Gump3/pygump/python/gump/model/__init__.py Thu Aug 25 14:57:47 2005
@@ -658,6 +658,34 @@
     def __str__(self):
         return "<Ant:target=%s,buildfile=%s,basedir=%s>" % (self.target, self.buildfile, self.basedir)
 
+class Maven(Command):
+    """Command to run an Maven build.
+
+    Has the following properties:
+        
+        - all the properties a Command has
+        - target -- the Maven target
+        - buildfile -- the Maven build file
+        - basedir -- directory relative to project home in which to run
+    """
+    def __init__(self, project, target, buildfile="", basedir=None, properties=None):
+        assert isinstance(target, basestring)
+            
+        Command.__init__(self, project, basedir)
+        if properties != None:
+            assert isinstance(properties, dict)
+            for k,v in properties.iteritems():
+                assert isinstance(k, basestring)
+                assert isinstance(v, basestring)
+            self.properties = properties
+        else:
+            self.properties = {}
+
+        self.target = target
+
+    def __str__(self):
+        return "<Maven:target=%s,basedir=%s>" % (self.target, self.basedir)
+
 #TODO: more Commands
 
 class Output(ModelObject):

Modified: gump/branches/Gump3/pygump/python/gump/plugins/java/builder.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/plugins/java/builder.py?rev=240149&r1=240148&r2=240149&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/plugins/java/builder.py (original)
+++ gump/branches/Gump3/pygump/python/gump/plugins/java/builder.py Thu Aug 25 14:57:47 2005
@@ -23,7 +23,7 @@
 import sys
 from os.path import abspath, join, isfile
 
-from gump.model import Script, Error, Project, Ant, Dependency, Classdir, Jar, DEPENDENCY_INHERIT_ALL, DEPENDENCY_INHERIT_HARD, DEPENDENCY_INHERIT_JARS
+from gump.model import Script, Error, Project, Maven, Ant, Dependency, Classdir, Jar, DEPENDENCY_INHERIT_ALL, DEPENDENCY_INHERIT_HARD, DEPENDENCY_INHERIT_JARS
 from gump.model.util import get_project_directory,get_module_directory,get_jar_path,calculate_classpath
 from gump.plugins import AbstractPlugin
 from gump.plugins.builder import BuilderPlugin
@@ -40,6 +40,30 @@
         command.classpath = classpath
         command.boot_classpath = bootclasspath
                 
+class MavenPlugin(BuilderPlugin):
+    """Execute all "Maven" commands for all projects."""
+    def __init__(self, log, debug=False):
+        BuilderPlugin.__init__(self, log, Maven, self._do_maven)
+        self.debug = debug
+
+    def _do_maven(self, project, maven):
+	# pass
+	#environment
+        maven.env['CLASSPATH'] = os.pathsep.join(maven.classpath)
+        self.log.debug("        CLASSPATH is '%s%s%s'" % \
+                       (ansicolor.Blue, maven.env['CLASSPATH'], ansicolor.Black))
+
+        maven.env['PATH'] = maven.path
+        self.log.debug("        PATH is '%s%s%s'" % \
+                       (ansicolor.Blue, maven.env['PATH'], ansicolor.Black))
+	# working directory
+        projectpath = get_project_directory(project)
+        if maven.basedir:
+            projectpath = os.path.join(projectpath, maven.basedir)
+	#command line
+	args = ["maven"]
+	if maven.target: args += [maven.target] 
+        self._do_run_command(maven, args, projectpath, no_cleanup=True)
         
 class AntPlugin(BuilderPlugin):
     """Execute all "ant" commands for all projects."""

Modified: gump/branches/Gump3/pygump/python/gump/util/executor.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/executor.py?rev=240149&r1=240148&r2=240149&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/executor.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/executor.py Thu Aug 25 14:57:47 2005
@@ -38,7 +38,7 @@
 __copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
-import sys
+import sys, os
 from gump.util import ansicolor
 
 # set this to a logging-module-compatible logger to make this module log all
@@ -131,7 +131,7 @@
                     # function
                     pre_exec_function = lambda: (preexec_fn(),savepgid(process_list_filename))
                 
-                
+
                 subprocess.Popen.__init__(self, args, bufsize=bufsize, executable=executable,
                          stdin=stdin, stdout=stdout, stderr=stderr,
                          # note our custom function in there...

Added: gump/branches/Gump3/pygump/python/gump/util/mavenToGump.conf
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/mavenToGump.conf?rev=240149&view=auto
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/mavenToGump.conf (added)
+++ gump/branches/Gump3/pygump/python/gump/util/mavenToGump.conf Thu Aug 25 14:57:47 2005
@@ -0,0 +1,20 @@
+avalon-framework, avalon-framework-api:
+axis, ws-axis:
+bcprov-jdk14, bcprov:
+activation, jaf:
+mail, javamail:
+jaxrpc-api, ws-axis:
+jetty, jetty4:
+jstl, jakarta-taglibs-standard:
+log4j, logging-log4j:
+logkit, avalong-logkit:
+isorelax, iso-relax:
+relaxngDatatype, relaxng:
+ojb, db-ojb:
+oro, jakarta-oro:
+regexp, jakarta-regexp:
+saaj-api, ws-axis:
+servletapi, jakarta-servletapi-5-servelt:
+swt, eclipse:
+velocity, jarkarta-velocity:
+xerces, xml-xerces:

Propchange: gump/branches/Gump3/pygump/python/gump/util/mavenToGump.conf
------------------------------------------------------------------------------
    svn:eol-style = native