1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18allprojects { 19 apply plugin: 'base' 20 21 group "org.apache" 22 23 // Repositories to fetch dependencies from. 24 repositories { 25 mavenCentral() 26 } 27 28 // Artifacts will have names after full gradle project path 29 // so :solr:core will have solr-core.jar, etc. 30 project.archivesBaseName = project.path.replaceAll("^:", "").replace(':', '-') 31 32 ext { 33 // Utility method to support passing overrides via -P or -D. 34 propertyOrDefault = { propName, defValue -> 35 def result 36 if (project.hasProperty(propName)) { 37 result = project.getProperty(propName) 38 } else if (System.properties.containsKey(propName)) { 39 result = System.properties.get(propName) 40 } else if (defValue instanceof Closure) { 41 result = defValue.call() 42 } else { 43 result = defValue 44 } 45 return result 46 } 47 48 // System environment variable or default. 49 envOrDefault = { envName, defValue -> 50 def result = System.getenv(envName) 51 if (result == null) { 52 result = defValue 53 } 54 return result 55 } 56 57 // Either a project, system property, environment variable or default value. 58 propertyOrEnvOrDefault = { propName, envName, defValue -> 59 return propertyOrDefault(propName, envOrDefault(envName, defValue)); 60 } 61 62 // Locate script-relative resource folder. This is context-sensitive so pass 63 // the right buildscript (top-level). 64 scriptResources = { buildscript -> 65 return file(buildscript.sourceFile.absolutePath.replaceAll('.gradle$', "")) 66 } 67 68 // Utility function similar to project.exec but not emitting 69 // any output unless an error code is returned from the executed command. 70 quietExec = { closure -> 71 // Resolve any properties against the provided closure. 72 resolveStrategy = Closure.DELEGATE_ONLY 73 delegate = closure.delegate 74 75 File outputFile = File.createTempFile("exec-output-", ".txt", getTemporaryDir()) 76 ExecResult result 77 boolean saveIgnoreExitValue 78 ExecSpec saveExecSpec 79 80 outputFile.withOutputStream { output -> 81 // we want to capture both stdout and stderr to the same 82 // stream but gradle attempts to close these separately 83 // (it has two independent pumping threads) and it can happen 84 // that one still tries to write something when the other closed 85 // the underlying output stream. 86 def wrapped = new java.io.FilterOutputStream(output) { 87 public void close() { 88 // no-op. we close this stream manually. 89 } 90 } 91 92 result = project.exec { ExecSpec execSpec -> 93 project.configure(execSpec, closure) 94 95 saveIgnoreExitValue = execSpec.ignoreExitValue 96 saveExecSpec = execSpec 97 98 standardOutput = wrapped 99 errorOutput = wrapped 100 ignoreExitValue true 101 } 102 } 103 104 if (result.getExitValue() != 0) { 105 // Pipe the output to console. Intentionally skips any encoding conversion 106 // and pumps raw bytes. 107 logger.error(new String(outputFile.bytes)) 108 109 if (!saveIgnoreExitValue) { 110 result.rethrowFailure() 111 throw new GradleException("The executed process ${saveExecSpec.executable} " + 112 "returned an odd status " + 113 "code: ${result.exitValue}, " + 114 "output at: ${outputFile} (and logged above).") 115 } 116 } 117 118 return result 119 } 120 121 // Convert a list of strings, tasks and task providers into resolved tasks or task providers. 122 resolveTaskRefs = { List<Object> refs -> 123 def resolved = refs.collect { 124 if (it instanceof Task) return it 125 if (it instanceof TaskProvider) return it 126 if (it instanceof String) return project.tasks.named((String) it) 127 throw new GradleException("Can't resolve task: ${it}") 128 } 129 return resolved 130 } 131 132 // Forces sequential ordering of a list of tasks (via mustRunAfter). 133 // This method should not be required in 99% of cases, consider regular dependsOn links. 134 // This method does NOT imply any ordering between dependencies of task on the input 135 // list - the execution of these may still be unordered. 136 mustRunInOrder = { List<Object> taskList -> 137 project.afterEvaluate { 138 def resolved = resolveTaskRefs(taskList) 139 140 // Enforce sequential ordering between tasks (this does NOT apply to their dependencies!) 141 for (int i = 1; i < resolved.size(); i++) { 142 resolved[i].configure { 143 logger.info("Scheduling " + resolved[i].name + " to run after " + resolved[i - 1].name) 144 mustRunAfter resolved[i - 1] 145 } 146 } 147 } 148 return taskList 149 } 150 151 // detect if we run in CI environment by looking at existence of env vars: 152 // "CI": Github (https://docs.github.com/en/actions/learn-github-actions/environment-variables) 153 // anything starting with "JENKINS_" or "HUDSON_": Jenkins/Hudson (https://jenkins.thetaphi.de/env-vars.html/) 154 isCIBuild = System.getenv().keySet().find { it ==~ /(?i)((JENKINS|HUDSON)(_\w+)?|CI)/ } != null 155 } 156} 157