-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add native-image.properties files to jars (#4208)
This allows adding or removing entries from the set of classes that are initialized at native image build time without requiring changes to graalvm/native-build-tools. The new precompiled script plugin introduced in this commit defines two Gradle tasks: `nativeImageProperties` and `validateNativeImageProperties`. The former is used for writing the `native-image.properties` file to the correct resource folder based (by convention) on the `src/nativeImage/initialize-at-build-time` file in each affected subproject. The latter validates that all listed classes exist and acts as a safeguard when classes are renamed or deleted. Resolves #4207.
- Loading branch information
1 parent
aa922c7
commit 7593ded
Showing
24 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
gradle/plugins/common/src/main/kotlin/junitbuild.native-image-properties.gradle.kts
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,55 @@ | ||
import junitbuild.graalvm.NativeImagePropertiesExtension | ||
import java.util.zip.ZipFile | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
val extension = extensions.create<NativeImagePropertiesExtension>("nativeImageProperties").apply { | ||
val resourceFile: RegularFile = layout.projectDirectory.file("src/nativeImage/initialize-at-build-time") | ||
if (resourceFile.asFile.exists()) { | ||
initializeAtBuildTime.convention(providers.fileContents(resourceFile).asText.map { it.trim().lines() }) | ||
} else { | ||
initializeAtBuildTime.empty() | ||
} | ||
initializeAtBuildTime.finalizeValueOnRead() | ||
} | ||
|
||
val outputDir = layout.buildDirectory.dir("resources/nativeImage") | ||
|
||
val propertyFileTask = tasks.register<WriteProperties>("nativeImageProperties") { | ||
destinationFile = outputDir.map { it.file("META-INF/native-image/${project.group}/${project.name}/native-image.properties") } | ||
// see https://www.graalvm.org/latest/reference-manual/native-image/overview/BuildConfiguration/#configuration-file-format | ||
property("Args", extension.initializeAtBuildTime.map { | ||
if (it.isEmpty()) { | ||
"" | ||
} else { | ||
"--initialize-at-build-time=${it.joinToString(",")}" | ||
} | ||
}) | ||
} | ||
|
||
val validationTask = tasks.register("validateNativeImageProperties") { | ||
dependsOn(tasks.jar) | ||
doLast { | ||
val zipEntries = ZipFile(tasks.jar.get().archiveFile.get().asFile).use { zipFile -> | ||
zipFile.entries().asSequence().map { it.name }.filter { it.endsWith(".class") }.toSet() | ||
} | ||
val missingClasses = extension.initializeAtBuildTime.get().filter { className -> | ||
!zipEntries.contains("${className.replace('.', '/')}.class") | ||
} | ||
if (missingClasses.isNotEmpty()) { | ||
throw GradleException("The following classes were specified as initialize-at-build-time but do not exist (you should probably remove them from nativeImageProperties.initializeAtBuildTime):\n${missingClasses.joinToString("\n- ", "- ")}") | ||
} | ||
} | ||
} | ||
|
||
tasks.check { | ||
dependsOn(validationTask) | ||
} | ||
|
||
sourceSets { | ||
main { | ||
output.dir(propertyFileTask.map { outputDir }) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
gradle/plugins/common/src/main/kotlin/junitbuild/graalvm/NativeImagePropertiesExtension.kt
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,7 @@ | ||
package junitbuild.graalvm | ||
|
||
import org.gradle.api.provider.SetProperty | ||
|
||
abstract class NativeImagePropertiesExtension { | ||
abstract val initializeAtBuildTime: SetProperty<String> | ||
} |
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,4 @@ | ||
org.junit.jupiter.api.DisplayNameGenerator$Standard | ||
org.junit.jupiter.api.TestInstance$Lifecycle | ||
org.junit.jupiter.api.condition.OS | ||
org.junit.jupiter.api.extension.ConditionEvaluationResult |
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
22 changes: 22 additions & 0 deletions
22
junit-jupiter-engine/src/nativeImage/initialize-at-build-time
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,22 @@ | ||
org.junit.jupiter.engine.JupiterTestEngine | ||
org.junit.jupiter.engine.config.CachingJupiterConfiguration | ||
org.junit.jupiter.engine.config.DefaultJupiterConfiguration | ||
org.junit.jupiter.engine.config.EnumConfigurationParameterConverter | ||
org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter | ||
org.junit.jupiter.engine.descriptor.ClassTestDescriptor | ||
org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor | ||
org.junit.jupiter.engine.descriptor.DynamicDescendantFilter | ||
org.junit.jupiter.engine.descriptor.ExclusiveResourceCollector$1 | ||
org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor | ||
org.junit.jupiter.engine.descriptor.JupiterTestDescriptor | ||
org.junit.jupiter.engine.descriptor.JupiterTestDescriptor$1 | ||
org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor | ||
org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor | ||
org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor | ||
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor | ||
org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor | ||
org.junit.jupiter.engine.execution.ConditionEvaluator | ||
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker | ||
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall | ||
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall$VoidMethodInterceptorCall | ||
org.junit.jupiter.engine.execution.InvocationInterceptorChain |
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
2 changes: 2 additions & 0 deletions
2
junit-jupiter-params/src/nativeImage/initialize-at-build-time
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,2 @@ | ||
org.junit.jupiter.params.provider.EnumSource$Mode | ||
org.junit.jupiter.params.provider.EnumSource$Mode$Validator |
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
5 changes: 5 additions & 0 deletions
5
junit-platform-commons/src/nativeImage/initialize-at-build-time
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,5 @@ | ||
org.junit.platform.commons.util.StringUtils | ||
org.junit.platform.commons.logging.LoggerFactory$DelegatingLogger | ||
org.junit.platform.commons.logging.LoggerFactory | ||
org.junit.platform.commons.util.ReflectionUtils | ||
org.junit.platform.commons.util.LruCache |
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
7 changes: 7 additions & 0 deletions
7
junit-platform-engine/src/nativeImage/initialize-at-build-time
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,7 @@ | ||
org.junit.platform.engine.TestDescriptor$Type | ||
org.junit.platform.engine.UniqueId | ||
org.junit.platform.engine.UniqueId$Segment | ||
org.junit.platform.engine.UniqueIdFormat | ||
org.junit.platform.engine.support.descriptor.ClassSource | ||
org.junit.platform.engine.support.descriptor.MethodSource | ||
org.junit.platform.engine.support.hierarchical.Node$ExecutionMode |
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
19 changes: 19 additions & 0 deletions
19
junit-platform-launcher/src/nativeImage/initialize-at-build-time
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,19 @@ | ||
org.junit.platform.launcher.LauncherSessionListener$1 | ||
org.junit.platform.launcher.TestIdentifier | ||
org.junit.platform.launcher.core.DefaultLauncher | ||
org.junit.platform.launcher.core.DefaultLauncherConfig | ||
org.junit.platform.launcher.core.EngineDiscoveryOrchestrator | ||
org.junit.platform.launcher.core.EngineExecutionOrchestrator | ||
org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider | ||
org.junit.platform.launcher.core.InternalTestPlan | ||
org.junit.platform.launcher.core.LauncherConfig | ||
org.junit.platform.launcher.core.LauncherConfigurationParameters | ||
org.junit.platform.launcher.core.LauncherConfigurationParameters$ParameterProvider$1 | ||
org.junit.platform.launcher.core.LauncherConfigurationParameters$ParameterProvider$2 | ||
org.junit.platform.launcher.core.LauncherConfigurationParameters$ParameterProvider$3 | ||
org.junit.platform.launcher.core.LauncherConfigurationParameters$ParameterProvider$4 | ||
org.junit.platform.launcher.core.LauncherDiscoveryResult | ||
org.junit.platform.launcher.core.LauncherListenerRegistry | ||
org.junit.platform.launcher.core.ListenerRegistry | ||
org.junit.platform.launcher.core.SessionPerRequestLauncher | ||
org.junit.platform.launcher.listeners.UniqueIdTrackingListener |
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
2 changes: 2 additions & 0 deletions
2
junit-platform-reporting/src/nativeImage/initialize-at-build-time
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,2 @@ | ||
org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener | ||
org.junit.platform.reporting.shadow.org.opentest4j.reporting.events.api.DocumentWriter$1 |
1 change: 1 addition & 0 deletions
1
junit-platform-suite-engine/junit-platform-suite-engine.gradle.kts
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
4 changes: 4 additions & 0 deletions
4
junit-platform-suite-engine/src/nativeImage/initialize-at-build-time
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,4 @@ | ||
org.junit.platform.suite.engine.SuiteEngineDescriptor | ||
org.junit.platform.suite.engine.SuiteLauncher | ||
org.junit.platform.suite.engine.SuiteTestDescriptor | ||
org.junit.platform.suite.engine.SuiteTestEngine |
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
5 changes: 5 additions & 0 deletions
5
junit-vintage-engine/src/nativeImage/initialize-at-build-time
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,5 @@ | ||
org.junit.vintage.engine.VintageTestEngine | ||
org.junit.vintage.engine.descriptor.RunnerTestDescriptor | ||
org.junit.vintage.engine.descriptor.VintageEngineDescriptor | ||
org.junit.vintage.engine.support.UniqueIdReader | ||
org.junit.vintage.engine.support.UniqueIdStringifier |
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
18 changes: 18 additions & 0 deletions
18
...upport-tests/projects/graalvm-starter/src/test/java/com/example/project/GraalvmSuite.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,18 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package com.example.project; | ||
|
||
import org.junit.platform.suite.api.*; | ||
|
||
@Suite | ||
@SelectPackages("com.example.project") | ||
public class GraalvmSuite { | ||
} |
19 changes: 19 additions & 0 deletions
19
...upport-tests/projects/graalvm-starter/src/test/java/com/example/project/VintageTests.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,19 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package com.example.project; | ||
|
||
import org.junit.Test; | ||
|
||
public class VintageTests { | ||
@Test | ||
public void test() { | ||
} | ||
} |
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