You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ta...@apache.org on 2016/07/11 06:54:39 UTC

svn commit: r1752125 - /ofbiz/trunk/build.gradle

Author: taher
Date: Mon Jul 11 06:54:39 2016
New Revision: 1752125

URL: http://svn.apache.org/viewvc?rev=1752125&view=rev
Log:
Fix the gradle build script on multiple reported issues - OFBIZ-7534

We were lucky to discover some problems in the build script on the
windows operating system (Thank you Jacques Le Roux). After investigating
the matter we realized that among other problems the process name (executable)
is massive and leads to problems on windows. However, this is not the only
problem with the current build script setup. Sometimes exeucting tasks in a combo
fail due to a dependency-tree problem with the current implementation.

The solution was to create a Jar file that holds the classpath and hides it from
the process name. Hence, instead of a massive classpath shown in the command process
it is all declared inside a single jar file. This lead to multiple improvements in the
build script including:

- The process name is now much shorter and cleaner both on Windows and Unix-like systems
- The task teminateOfbiz now has a much cleaner implementation on Unix systems
- Executing any tasks in combos would still maintain the correct ordering of executing graph

The most tricky part to figure out in the implementation is how to build the Jar Class-Path
for each operating system. Unfortunately, on Windows it was extremely tricky as windows
accepts weird naming conventions on the Class-Path manifest input. For example, \C:\whatever
will work but C:\whatever will not work

So the main difference in this implementation now is that the ofbiz server commands will
retrieve the classpath from a jar, and not directly construct it in the command line

Modified:
    ofbiz/trunk/build.gradle

Modified: ofbiz/trunk/build.gradle
URL: http://svn.apache.org/viewvc/ofbiz/trunk/build.gradle?rev=1752125&r1=1752124&r2=1752125&view=diff
==============================================================================
--- ofbiz/trunk/build.gradle (original)
+++ ofbiz/trunk/build.gradle Mon Jul 11 06:54:39 2016
@@ -234,6 +234,16 @@ sourceSets {
 def jvmArguments = ['-Xms128M', '-Xmx512M']
 ext.ofbizMainClass = 'org.ofbiz.base.start.Start'
 
+jar {
+    manifest {
+        attributes(
+            "Implementation-Title": project.name,
+            "Main-Class": ofbizMainClass,
+            "Class-Path": getJarManifestClasspathForCurrentOs()
+        )
+    }
+}
+
 /* ========================================================
  * Tasks
  * ======================================================== */
@@ -268,7 +278,7 @@ task terminateOfbiz(group: ofbizServer,
             standardOutput = processOutput
         }
         processOutput.toString().split(System.lineSeparator()).each { line ->
-            if(line ==~ /.*java.*/ && line ==~ /.*framework.*/) {
+            if(line ==~ /.*org\.ofbiz\.base\.start\.Start.*/) {
                 exec { commandLine 'kill', '-9', line.tokenize().first() }
             }
         }
@@ -692,11 +702,14 @@ tasks.addRule('Pattern: ofbizBackgroundS
  * ======================================================== */
 
 def createOfbizCommandTask(taskName, arguments, jvmArguments, isDebugMode) {
-    task(type: JavaExec, taskName) {
-        jvmArgs(jvmArguments)
-        classpath = sourceSets.main.runtimeClasspath
-        main = ofbizMainClass 
+
+    def ofbizJarName = buildDir.toString()+'/libs/'+project.name+'.jar'
+
+    task(type: JavaExec, dependsOn: build, taskName) {
+        jvmArgs(jvmArguments) 
         debug = isDebugMode
+        classpath = files(ofbizJarName)
+        main = ofbizMainClass
         arguments.each { argument ->
             args argument
         }
@@ -808,3 +821,15 @@ def generateFileFromTemplate(templateFil
         into targetDirectory
     }
 }
+
+def getJarManifestClasspathForCurrentOs() {
+    def osClassPath = ''
+    if(System.getProperty('os.name').toLowerCase().contains('windows')) {
+        configurations.runtime.files.each { cpEntry ->
+            osClassPath += '\\' + cpEntry.toString() + ' '
+        }
+    } else {
+        osClassPath = configurations.runtime.files.collect { "$it" }.join(' ')
+    }
+    return osClassPath
+}