risdenk commented on code in PR #1320: URL: https://github.com/apache/solr/pull/1320#discussion_r1093601498
########## buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java: ########## @@ -0,0 +1,96 @@ +/* + * 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. + */ +package org.apache.lucene.gradle; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.channels.ReadableByteChannel; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.*; Review Comment: nit: I'm guessing that spotless doesn't run against these files (thats fine) but usually we avoid wildcard imports. ########## gradle/generation/local-settings.gradle: ########## @@ -45,83 +45,4 @@ configure(rootProject) { } } } - Review Comment: @colvinco I think this is still outstanding ########## buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java: ########## @@ -0,0 +1,96 @@ +/* + * 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. + */ +package org.apache.lucene.gradle; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.channels.ReadableByteChannel; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardOpenOption.APPEND; + +/** + * Standalone class that generates a populated gradle.properties from a template. + * <p> + * Has no dependencies outside of standard java libraries + */ +public class GradlePropertiesGenerator { + public static void main(String[] args) { + if (args.length != 2) { + System.err.println("Usage: java GradlePropertiesGenerator.java <source> <destination>"); + System.exit(2); + } + + try { + new GradlePropertiesGenerator().run(Paths.get(args[0]), Paths.get(args[1])); + } catch (Exception e) { + System.err.println("ERROR: " + e.getMessage()); + System.exit(3); + } + } + + public void run(Path source, Path destination) throws IOException { + if (!Files.exists(source)) { + throw new IOException("template file not found: " + source); + } + if (Files.exists(destination)) { + System.out.println(destination + " already exists, skipping generation."); + } + + // Approximate a common-sense default for running gradle/tests with parallel + // workers: half the count of available cpus but not more than 12. + var cpus = Runtime.getRuntime().availableProcessors(); + var maxWorkers = (int) Math.max(1d, Math.min(cpus * 0.5d, 12)); + var testsJvms = (int) Math.max(1d, Math.min(cpus * 0.5d, 12)); + + var replacements = Map.of("org.gradle.workers.max", maxWorkers, "tests.jvms", testsJvms); + + // Java properties doesn't preserve comments, so going line by line instead + // The properties file isn't big, nor is the map of replacements, so not worrying about speed here. + System.out.println("Generating gradle.properties"); + final var lines = Files.readAllLines(source).stream().map(line -> { + if (!line.startsWith("#") && line.contains("=")) { + final String key = line.split("=")[0]; + var value = replacements.get(key); + if (value != null) { + final String newLine = key + '=' + value; + System.out.println("Setting " + newLine); + return newLine; + } Review Comment: nit: indent is off ########## gradle/template.gradle.properties: ########## @@ -0,0 +1,43 @@ +# See gradlew :helpLocalSettings for more information on configuring this file. Review Comment: Yea my comment was about `configuring this file` - agree the concepts are good. I'm not saying we need to change this completely, but it would be good to consolidate to avoid having to go look another place. ########## .gitignore: ########## @@ -38,6 +38,7 @@ __pycache__ # Ignore lucene included build lucene/ Review Comment: so I thought the `lucene/` entry was in case of having local Lucene development? It might be worth changing to `/lucene/` or something similar that matches top level only? I think its a bit surprising that `lucene/` matches any folder in the file structure. -- 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