You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2019/09/16 00:39:17 UTC

[lucene-solr] branch jira/SOLR-13452_gradle_7 updated: SOLR-13452: Add defaultUserConfig task to allow setting reccomended starting config in ~/.gradle/gradle.properties.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch jira/SOLR-13452_gradle_7
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/jira/SOLR-13452_gradle_7 by this push:
     new 4583b86  SOLR-13452: Add defaultUserConfig task to allow setting reccomended starting config in ~/.gradle/gradle.properties.
4583b86 is described below

commit 4583b8693b014afde0f382413ff44addc8b254de
Author: markrmiller <ma...@apache.org>
AuthorDate: Sun Sep 15 19:39:11 2019 -0500

    SOLR-13452: Add defaultUserConfig task to allow setting reccomended starting config in ~/.gradle/gradle.properties.
---
 build.gradle                                       |  6 ++
 buildSrc/build.gradle                              |  2 +
 .../lucene/gradle/SetDefaultUserConfig.groovy      | 79 ++++++++++++++++++++++
 versions.lock                                      |  6 +-
 4 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/build.gradle b/build.gradle
index 7b74db0..223ac82 100644
--- a/build.gradle
+++ b/build.gradle
@@ -25,6 +25,7 @@ import org.apache.lucene.gradle.deps.ListDeps
 import org.apache.lucene.gradle.deps.JdepsReport
 import org.apache.lucene.gradle.TopHints
 import org.apache.lucene.gradle.PristineClean
+import org.apache.lucene.gradle.SetDefaultUserConfig
 import org.gradle.api.Project
 import org.apache.commons.io.FilenameUtils
 import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
@@ -221,6 +222,11 @@ configure(rootProject) {
   
   task pristineClean(type: PristineClean) {}
   
+  task defaultUserConfig(type: SetDefaultUserConfig) {
+    group = 'Build'
+    description = "Sets recommended starting build property values in ~/.gradle/gradle.properties. Use --agressive for better build performance"
+  }
+  
   ext.testsResults = [] // test result summaries
   
   gradle.buildFinished {
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index c74f263..2e2902f 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -34,6 +34,8 @@ dependencies {
   implementation 'com.ibm.icu:icu4j:62.1'
   implementation 'org.apache.rat:apache-rat:0.11'
   implementation 'junit:junit:4.12'
+  implementation 'org.apache.commons:commons-configuration2:2.5'
+  implementation 'commons-beanutils:commons-beanutils:1.9.3'
 }
 
 configurations {
diff --git a/buildSrc/src/main/groovy/org/apache/lucene/gradle/SetDefaultUserConfig.groovy b/buildSrc/src/main/groovy/org/apache/lucene/gradle/SetDefaultUserConfig.groovy
new file mode 100644
index 0000000..ad980fc
--- /dev/null
+++ b/buildSrc/src/main/groovy/org/apache/lucene/gradle/SetDefaultUserConfig.groovy
@@ -0,0 +1,79 @@
+package org.apache.lucene.gradle
+/*
+ * 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.
+ * The ASF licenses this file to You 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.
+ */
+
+/** Task script that is called by Ant's build.xml file:
+ * Checks GIT working copy for unversioned or modified files.
+ */
+
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.options.Option;
+import org.gradle.api.tasks.TaskAction
+import org.apache.commons.configuration2.Configuration
+import org.apache.commons.configuration2.FileBasedConfiguration
+import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder
+import org.apache.commons.configuration2.builder.fluent.Parameters
+import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler
+import org.apache.commons.configuration2.PropertiesConfiguration
+
+class SetDefaultUserConfig extends DefaultTask {
+
+  private String style
+
+  @TaskAction
+  void config() {
+
+    int cores = Runtime.getRuntime().availableProcessors()
+
+    File propFile = project.file(System.getProperty("user.home") + "/.gradle/gradle.properties")
+    
+    char delim = ','
+    
+    Parameters params = new Parameters();
+    FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
+    builder.configure(params.properties()
+    .setFile(propFile)
+    .setListDelimiterHandler(new DefaultListDelimiterHandler(delim)))
+    
+    Configuration config = builder.getConfiguration()
+    
+    if (style != null && style.equals("aggressive")) {
+      config.setProperty("org.gradle.workers.max", (round(cores/2)).toString())
+      config.setProperty("tests_jvms", (round(cores/2)).toString())
+      config.setProperty("org.gradle.caching", "true")
+    } else {
+      config.setProperty("org.gradle.workers.max", (round(cores/3)).toString())
+      config.setProperty("tests_jvms", (round(cores/3)).toString())
+      config.setProperty("org.gradle.caching", "true")
+    }
+    
+    builder.save();
+  }
+  
+  @Option(option = "style", description = "Whether defaults should be aggressive")
+  public void setStyle(String style) {
+    this.style = style
+  }
+  
+  private int round(BigDecimal d) {
+    return Math.max(1, Math.round(d))
+  }
+}
+
+
+
diff --git a/versions.lock b/versions.lock
index f4d3320..3da6c4b 100644
--- a/versions.lock
+++ b/versions.lock
@@ -90,12 +90,12 @@ org.apache.calcite:calcite-linq4j:1.18.0 (1 constraints: 3c05413b)
 org.apache.calcite.avatica:avatica-core:1.13.0 (1 constraints: 3705323b)
 org.apache.commons:commons-collections4:4.2 (1 constraints: aa04252c)
 org.apache.commons:commons-compress:1.18 (5 constraints: 9637cf5d)
-org.apache.commons:commons-configuration2:2.1.1 (2 constraints: 8d12092e)
+org.apache.commons:commons-configuration2:2.5 (2 constraints: 6614d0a3)
 org.apache.commons:commons-digester3:3.2 (2 constraints: 25274d81)
 org.apache.commons:commons-exec:1.3 (1 constraints: a8041d2c)
-org.apache.commons:commons-lang3:3.8.1 (8 constraints: c47450ef)
+org.apache.commons:commons-lang3:3.9 (8 constraints: 6a744064)
 org.apache.commons:commons-math3:3.6.1 (2 constraints: 9412122f)
-org.apache.commons:commons-text:1.6 (2 constraints: d511b6f1)
+org.apache.commons:commons-text:1.6 (3 constraints: 24235027)
 org.apache.curator:curator-client:2.13.0 (5 constraints: a4496710)
 org.apache.curator:curator-framework:2.13.0 (4 constraints: cd317cc0)
 org.apache.curator:curator-recipes:2.13.0 (3 constraints: 7f233592)