gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1766679 - in /gump/live/python/gump/core/build: basebuilder.py gradle.py
Date Wed, 26 Oct 2016 12:40:00 GMT
Author: bodewig
Date: Wed Oct 26 12:40:00 2016
New Revision: 1766679

URL: http://svn.apache.org/viewvc?rev=1766679&view=rev
Log:
refactor gradle builder

Modified:
    gump/live/python/gump/core/build/basebuilder.py
    gump/live/python/gump/core/build/gradle.py

Modified: gump/live/python/gump/core/build/basebuilder.py
URL: http://svn.apache.org/viewvc/gump/live/python/gump/core/build/basebuilder.py?rev=1766679&r1=1766678&r2=1766679&view=diff
==============================================================================
--- gump/live/python/gump/core/build/basebuilder.py (original)
+++ gump/live/python/gump/core/build/basebuilder.py Wed Oct 26 12:40:00 2016
@@ -62,6 +62,10 @@ def get_args(builder):
             args.addParameter(arg.value)
     return args
 
+def needs_separate_local_repository(builder):
+    """ Does the given builder signal it needs a separate local repo? """
+    return builder.needsSeparateLocalRepository()
+
 class BaseBuilder(RunSpecific):
     """
     Base class for all builders.

Modified: gump/live/python/gump/core/build/gradle.py
URL: http://svn.apache.org/viewvc/gump/live/python/gump/core/build/gradle.py?rev=1766679&r1=1766678&r2=1766679&view=diff
==============================================================================
--- gump/live/python/gump/core/build/gradle.py (original)
+++ gump/live/python/gump/core/build/gradle.py Wed Oct 26 12:40:00 2016
@@ -16,114 +16,87 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
+"""
+    A gradle builder - rewrites all dependencies to use SNAPSHOT
+    dependencies, not the ones built by Gump, unfortunately.
+"""
+
 from time import strftime
 import os.path
 
 from gump import log
+from gump.core.build.basebuilder import BaseBuilder, get_command_skeleton, \
+    is_debug_enabled, is_verbose_enabled, needs_separate_local_repository
 from gump.actor.mvnrepoproxy.proxycontrol import SNAPSHOT_PROXIES
 from gump.core.build.mvn import local_mvn_repo
-from gump.core.config import setting
-from gump.core.model.workspace import CommandWorkItem, \
-    REASON_BUILD_FAILED, REASON_BUILD_TIMEDOUT, REASON_PREBUILD_FAILED, \
-    STATE_FAILED, STATE_SUCCESS, WORK_TYPE_BUILD
-from gump.core.run.gumprun import RunSpecific
+from gump.core.model.workspace import REASON_PREBUILD_FAILED, STATE_FAILED
 from gump.util.file import FILE_TYPE_CONFIG
-from gump.util.process.command import Cmd, CMD_STATE_SUCCESS, \
-    CMD_STATE_TIMED_OUT, Parameters
-from gump.util.process.launcher import execute
+from gump.util.process.command import Parameters
 from gump.util.tools import catFileToFileHolder
 
-###############################################################################
-# Classes
-###############################################################################
-
 def record_proxy(init_file, name, prefix, uri):
+    """ write repository information about a known SNAPSHOT repo """
     init_file.write("""
                 maven {
                     name "%s"
                     url "%s%s"
                 }""" % (name, uri.replace('\\', ''), prefix))
 
-def locateGradleProjectFile(project):
+def locate_gradle_buildfile(project):
     """Return Gradle project file location"""
     basedir = project.gradle.getBaseDirectory() or project.getBaseDirectory()
     return os.path.abspath(os.path.join(basedir, 'build.gradle'))
 
 def locate_init_script(project):
-    #
-    # Where to put this:
-    #
+    """ returns absolute path of the generated init script """
     basedir = project.gradle.getBaseDirectory() or project.getBaseDirectory()
     return os.path.abspath(os.path.join(basedir, 'gump_init_script.gradle'))
 
-def getGradleProperties(project):
+def get_properties(project):
     """ Get properties for a project """
     properties = Parameters()
-    for property in project.getGradle().getProperties():
-        properties.addPrefixedNamedParameter('-P', property.name, \
-                                                 property.value, '=')
+    for prop in project.getGradle().getProperties():
+        properties.addPrefixedNamedParameter('-P', prop.name, prop.value, '=')
     return properties
 
-def getSysProperties(project):
+def get_sys_properties(project):
     """ Get sysproperties for a project """
     properties = Parameters()
-    for property in project.getWorkspace().getSysProperties() + \
+    for prop in project.getWorkspace().getSysProperties() + \
         project.getGradle().getSysProperties():
-        properties.addPrefixedNamedParameter('-D', property.name, \
-                                                 property.value, '=')
+        properties.addPrefixedNamedParameter('-D', prop.name, prop.value, '=')
     return properties
 
-def needsSeparateLocalRepository(project):
-    return project.gradle.needsSeparateLocalRepository()
-
-def getGradleCommand(project, executable='gradle'):
+def get_gradle_command(project, executable='gradle'):
     """ Build a Gradle command for this project """
     gradle = project.gradle
 
     # The gradle task (or none == gradle default task)
     task = gradle.getTask()
 
-    # Optional 'verbose' or 'debug'
-    verbose = gradle.isVerbose()
-    debug = gradle.isDebug()
-
-    #
-    # Where to run this:
-    #
-    basedir = gradle.getBaseDirectory() or project.getBaseDirectory()
-
-    # Optional 'timeout'
-    if gradle.hasTimeout():
-        timeout = gradle.getTimeout()
-    else:
-        timeout = setting.TIMEOUT
-
     # Run Gradle...
-    cmd = Cmd(executable, 'build_' + project.getModule().getName() + '_' + \
-                project.getName(), basedir, timeout=timeout)
+    cmd = get_command_skeleton(project, executable, gradle)
 
     #
     # Allow gradle-level debugging...
     #
-    if project.getWorkspace().isDebug() or project.isDebug() or debug:
+    if is_debug_enabled(project, gradle):
         cmd.addParameter('--debug')
-    if project.getWorkspace().isVerbose() \
-            or project.isVerbose() or verbose:
+    if is_verbose_enabled(project, gradle):
         cmd.addParameter('--info')
 
-    props = getGradleProperties(project)
-    cmd.addNamedParameters(props)
-    sysprops = getSysProperties(project)
-    cmd.addNamedParameters(sysprops)
+    cmd.addNamedParameters(get_properties(project))
+    cmd.addNamedParameters(get_sys_properties(project))
 
-    if needsSeparateLocalRepository(project):
-        localRepositoryDir = local_mvn_repo(project, gradle)
+    if needs_separate_local_repository(project.gradle):
+        local_repo = local_mvn_repo(project, gradle)
     else:
-        localRepositoryDir = os.path.abspath(\
+        local_repo = os.path.abspath(\
                 os.path.join(project.getWorkspace()
                              .getLocalRepositoryDirectory(),
                              "shared"))
-    cmd.addParameter("-Dmaven.repo.local=" + localRepositoryDir)
+    cmd.addParameter("-Dmaven.repo.local=" + local_repo)
     cmd.addParameter('--refresh-dependencies')
 
     cmd.addParameter('--init-script')
@@ -131,111 +104,28 @@ def getGradleCommand(project, executable
 
     # End with the task...
     if task:
-        for taskParam in task.split(','):
-            cmd.addParameter(taskParam)
+        for single_task in task.split(','):
+            cmd.addParameter(single_task)
 
     return cmd
 
-class GradleBuilder(RunSpecific):
-
-    def __init__(self, run):
-        RunSpecific.__init__(self, run)
-
-    def buildProject(self, project, languageHelper, stats):
-        """
-        Build a Gradle project
-        """
-
-        workspace = self.run.getWorkspace()
-
-        log.debug('Run Gradle on Project: #[' + `project.getPosition()` + '] '\
-                  + project.getName())
-
-        self.performPreBuild(project, languageHelper, stats)
+def generate_init_script(project):
+    """Set repository for a Gradle project"""
 
-        if project.okToPerformWork():
+    init_script = locate_init_script(project)
+    # Ensure containing directory exists, or make it.
+    init_script_dir = os.path.dirname(init_script)
+    if not os.path.exists(init_script_dir):
+        project.addInfo('Making directory for Gradle Init Script: [' \
+                        + init_script_dir + ']')
+        os.makedirs(init_script_dir)
 
-            #
-            # Get the appropriate build command...
-            #
-            cmd = getGradleCommand(project)
-
-            if cmd:
-                # Get/set JVM properties
-                jvmargs = languageHelper.getJVMArgs(project)
-                if jvmargs and len(jvmargs.items()) > 0:
-                    cmd.addEnvironment('GRADLE_OPTS',
-                                       jvmargs.formatCommandLine())
-
-                # 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 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():
-            gradleFile = locateGradleProjectFile(project)
-            if os.path.exists(gradleFile):
-                project.addDebug('Gradle build in: ' + gradleFile)
-                catFileToFileHolder(project, gradleFile, FILE_TYPE_CONFIG)
+    if os.path.exists(init_script):
+        project.addWarning('Overriding Gradle Init Script: [' + init_script + ']')
 
+    init_file = open(init_script, 'w')
 
-    def performPreBuild(self, project, _languageHelper, _stats):
-
-        if project.okToPerformWork():
-            try:
-                init_script = self.generate_init_script(project)
-                project.addDebug('(Apache Gump generated) Gradle Init Script in: ' + \
-                                     init_script)
-
-                try:
-                    catFileToFileHolder(project, init_script,
-                                        FILE_TYPE_CONFIG,
-                                        os.path.basename(init_script))
-                except:
-                    log.error('Display Init Script [ ' + init_script + \
-                                  '] Failed', exc_info=1)
-
-            except Exception, details:
-                message = 'Generate Gradle Init Script Failed:' + str(details)
-                log.error(message, exc_info=1)
-                project.addError(message)
-                project.changeState(STATE_FAILED, REASON_PREBUILD_FAILED)
-
-    def preview(self, project, _languageHelper, _stats):
-        command = getGradleCommand(project)
-        command.dump()
-
-    def generate_init_script(self, project):
-        """Set repository for a Gradle project"""
-
-        init_script = locate_init_script(project)
-        # Ensure containing directory exists, or make it.
-        init_script_dir = os.path.dirname(init_script)
-        if not os.path.exists(init_script_dir):
-            project.addInfo('Making directory for Gradle Init Script: [' \
-                                + init_script_dir + ']')
-            os.makedirs(init_script_dir)
-
-        if os.path.exists(init_script):
-            project.addWarning('Overriding Gradle Init Script: [' + init_script \
-                                   + ']')
-
-        init_file = open(init_script, 'w')
-
-        init_file.write("""/*
+    init_file.write("""/*
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
@@ -272,9 +162,9 @@ class UseLatestSnapshots implements Plug
     void apply(Gradle gradle) {
         gradle.allprojects{ project ->
             project.repositories {""" % (project.getName(), strftime('%Y-%m-%d %H:%M:%S')))
-        for (name, prefix, url) in SNAPSHOT_PROXIES:
-            record_proxy(init_file, name, prefix, url)
-        init_file.write("""
+    for (name, prefix, url) in SNAPSHOT_PROXIES:
+        record_proxy(init_file, name, prefix, url)
+    init_file.write("""
                 mavenLocal()
             }
             project.configurations {
@@ -320,4 +210,58 @@ class GumpExternalModuleDependency exten
 }
 """)
 
-        return init_script
+    return init_script
+
+###############################################################################
+# Classes
+###############################################################################
+
+class GradleBuilder(BaseBuilder):
+
+    """
+    A gradle builder - rewrites all dependencies to use SNAPSHOT
+    dependencies, not the ones built by Gump, unfortunately.
+    """
+
+    def __init__(self, run):
+        BaseBuilder.__init__(self, run, 'Gradle')
+
+    def get_command(self, project, language):
+        cmd = get_gradle_command(project)
+        if cmd:
+            jvmargs = language.getJVMArgs(project)
+            if jvmargs and len(jvmargs.items()) > 0:
+                cmd.addEnvironment('GRADLE_OPTS', jvmargs.formatCommandLine())
+        return cmd
+
+    def pre_build(self, project, _language, _stats):
+        """
+        Create an init script for the build.
+        """
+        try:
+            init_script = generate_init_script(project)
+            project.addDebug('(Apache Gump generated) Gradle Init Script in: ' + \
+                                 init_script)
+
+            try:
+                catFileToFileHolder(project, init_script,
+                                    FILE_TYPE_CONFIG,
+                                    os.path.basename(init_script))
+            except:
+                log.error('Display Init Script [ ' + init_script + \
+                              '] Failed', exc_info=1)
+
+        except Exception, details:
+            message = 'Generate Gradle Init Script Failed:' + str(details)
+            log.error(message, exc_info=1)
+            project.addError(message)
+            project.changeState(STATE_FAILED, REASON_PREBUILD_FAILED)
+
+    def post_build(self, project, _language, _stats):
+        """
+        Attach build file to output.
+        """
+        gradle_file = locate_gradle_buildfile(project)
+        if os.path.exists(gradle_file):
+            project.addDebug('Gradle build in: ' + gradle_file)
+            catFileToFileHolder(project, gradle_file, FILE_TYPE_CONFIG)



Mime
View raw message