forked from apache/lucene
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'branch_9x' into fs/branch_9x
- Loading branch information
Showing
227 changed files
with
8,011 additions
and
3,900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.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.util.Map; | ||
|
||
/** | ||
* 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."); | ||
return; | ||
} | ||
|
||
// 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("@MAX_WORKERS@", maxWorkers, "@TEST_JVMS@", testsJvms); | ||
|
||
System.out.println("Generating gradle.properties"); | ||
String fileContent = Files.readString(source, StandardCharsets.UTF_8); | ||
for (var entry : replacements.entrySet()) { | ||
fileContent = fileContent.replace(entry.getKey(), String.valueOf(entry.getValue())); | ||
} | ||
Files.writeString( | ||
destination, fileContent, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
def resources = scriptResources(buildscript) | ||
|
||
configure(project(":lucene:core")) { | ||
ext { | ||
apijars = file('src/generated/jdk'); | ||
panamaJavaVersions = [ 19, 20 ] | ||
} | ||
|
||
configurations { | ||
apiextractor | ||
} | ||
|
||
dependencies { | ||
apiextractor "org.ow2.asm:asm:${scriptDepVersions['asm']}" | ||
} | ||
|
||
for (jdkVersion : panamaJavaVersions) { | ||
def task = tasks.create(name: "generatePanamaForeignApiJar${jdkVersion}", type: JavaExec) { | ||
description "Regenerate the API-only JAR file with public Panama Foreign API from JDK ${jdkVersion}" | ||
group "generation" | ||
|
||
javaLauncher = javaToolchains.launcherFor { | ||
languageVersion = JavaLanguageVersion.of(jdkVersion) | ||
} | ||
|
||
onlyIf { | ||
try { | ||
javaLauncher.get() | ||
return true | ||
} catch (Exception e) { | ||
logger.warn('Launcher for Java {} is not available; skipping regeneration of Panama Foreign API JAR.', jdkVersion) | ||
logger.warn('Error: {}', e.cause?.message) | ||
logger.warn("Please make sure to point env 'JAVA{}_HOME' to exactly JDK version {} or enable Gradle toolchain auto-download.", jdkVersion, jdkVersion) | ||
return false | ||
} | ||
} | ||
|
||
classpath = configurations.apiextractor | ||
mainClass = file("${resources}/ExtractForeignAPI.java") as String | ||
args = [ | ||
jdkVersion, | ||
new File(apijars, "panama-foreign-jdk${jdkVersion}.apijar"), | ||
] | ||
} | ||
|
||
regenerate.dependsOn task | ||
} | ||
} |
Oops, something went wrong.