magibney commented on a change in pull request #304: URL: https://github.com/apache/solr/pull/304#discussion_r720360992
########## File path: gradle/lucene-dev/lucene-dev-repo-composite.gradle ########## @@ -0,0 +1,159 @@ +import java.util.function.BiFunction + +/* + * 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. + */ + +// Local Lucene development repository resolution: +// 1) A "-Plucene.dev.version=[version]" property, resolving Lucene artifacts from a local Maven repository. +// 2) A non-empty property "-Plucene.dev.path=[path]" pointing to a local path. +// 3) An auto-wired 'lucene' subfolder, if present. To skip auto-wiring, pass +// a blank value in step 2: "-Plucene.dev.path=". + + +// This script is applied in settings.gradle and later at build time: these two contexts +// are distinctively different and have separate (and limited) APIs. +def configuringSettings = (rootProject instanceof org.gradle.api.initialization.ProjectDescriptor) + +// Accessor for -P properties from settings or at build time. +BiFunction<String, String, String> resolvePropertyValue = { propertyName, defValue -> + if (configuringSettings) { + return settings.startParameter.projectProperties.getOrDefault(propertyName, defValue) + } else { + return project.properties.getOrDefault(propertyName, defValue) + } +} + +def PROP_FORCE_VERSION="lucene.dev.version" +def PROP_FORCE_PATH="lucene.dev.path" +def READ_ACCESS_PROPERTY="lucene-dev-path.dir" + + +def forcedLuceneVersion = resolvePropertyValue(PROP_FORCE_VERSION, null) +if (forcedLuceneVersion != null) { + if (!configuringSettings) { + logger.lifecycle("Lucene version forced by -P${PROP_FORCE_VERSION}=${forcedLuceneVersion}") + + allprojects { + repositories { + mavenLocal() + } + + tasks.withType(Test) { + def userHome = System.properties.get('user.home') + systemProperty READ_ACCESS_PROPERTY, file("${userHome}/.m2/repository/org/apache/lucene").absolutePath + } + + configurations.all { + resolutionStrategy.eachDependency { + if (requested.group == "org.apache.lucene") { + useVersion(forcedLuceneVersion) + because("Lucene version forced manually by 'lucene.dev.version' property.") + } + } + } + } + } + + // Step 1: end resolution + return +} + +def luceneDevRepo = null +def defaultLuceneDevRepo = file("${rootDir}/lucene") +String propertyValue = resolvePropertyValue(PROP_FORCE_PATH, null) +if (propertyValue != null) { + // Step 2. + if (propertyValue.isBlank()) { + if (defaultLuceneDevRepo.exists() && configuringSettings) { + logger.lifecycle("Local Lucene development repository has been detected but won't be used.") + } + } else { + luceneDevRepo = file("${propertyValue}").absoluteFile + if (!luceneDevRepo.exists()) { + throw new GradleException("Lucene repository does not exist at: -P${PROP_FORCE_PATH}=${luceneDevRepo}.") + } + } +} else if (defaultLuceneDevRepo.exists()) { + // Step 3 + luceneDevRepo = defaultLuceneDevRepo +} + + +if (luceneDevRepo != null) { + // Allow turning off this auto-wiring via -Dlucene.dev.repo=false (can't be a -P property because + // at settings evaluation time we don't have project properties yet). + if (configuringSettings) { + // Include Lucene repository as a composite and substitute module names. + includeBuild(luceneDevRepo) { + dependencySubstitution { + def substitutionMap = [ Review comment: Seems like a shame to have to explicitly enumerate all these here. Is there a way to programmatically generate this list so that it changes dynamically with future module additions/removals? I'm guessing not, but I think you'd be in a better place to judge. In order to simulate what would happen currently if a new module were added to the project and this substitutionMap weren't updated, I commented out one line from the existing config, and verified that (unsurprisingly) that module was indeed not substituted. As long as the versions are reasonably compatible, the build still proceeded ok, just pulling in the dev repo local dependencies and fetching the prerelease5 dependency for the other. If there's not a way to generate the substitutionMap programmatically, perhaps there'd be a way to do a deferred check to cause the build to fail, to reduce the chances of insidious, hard-to-debug issues going forward? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org