Fix the project manager reflection configuration (#1394)

This commit is contained in:
Radosław Waśko 2021-01-14 11:46:01 +01:00 committed by GitHub
parent b751dfb3ec
commit d30a80eedc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 115 additions and 4 deletions

View File

@ -711,6 +711,7 @@ lazy val `project-manager` = (project in file("lib/scala/project-manager"))
"--enable-all-security-services" // Note [HTTPS in the Native Images] "--enable-all-security-services" // Note [HTTPS in the Native Images]
) )
) )
.dependsOn(VerifyReflectionSetup.run)
.dependsOn(assembly) .dependsOn(assembly)
.value, .value,
buildNativeImage := NativeImage buildNativeImage := NativeImage
@ -1170,6 +1171,7 @@ lazy val launcher = project
) )
) )
.dependsOn(assembly) .dependsOn(assembly)
.dependsOn(VerifyReflectionSetup.run)
.value, .value,
buildNativeImage := NativeImage buildNativeImage := NativeImage
.incrementalNativeImageBuild( .incrementalNativeImageBuild(

View File

@ -178,10 +178,11 @@ the test scenarios by starting it with:
java -agentlib:native-image-agent=config-merge-dir=lib/scala/project-manager/src/main/resources/META-INF/native-image/org/enso/projectmanager -jar project-manager.jar java -agentlib:native-image-agent=config-merge-dir=lib/scala/project-manager/src/main/resources/META-INF/native-image/org/enso/projectmanager -jar project-manager.jar
``` ```
For now it seems that it is enough to start the Project Manager and connect an To trace relevant reflection paths, the primary scenario is to start the Project
IDE to it to trace all relevant reflection paths. You can try interacting with Manager and connect an IDE to it. Since the Project Manager is able to install
it a bit more, for example, rename a project or install a new engine version, to engine versions, similar steps should be taken to force it to extract a zip
be sure all scenarios are covered. archive, as described in [Launcher Configuration](#launcher-configuration)
above. If necessary, other scenarios, like project renaming may be covered.
Remember to run the cleanup script as described above, as tracing the Project Remember to run the cleanup script as described above, as tracing the Project
Manager seems to find recursive accesses of some ephemeral-like classes named Manager seems to find recursive accesses of some ephemeral-like classes named

View File

@ -352,6 +352,62 @@
{ "name": "<init>", "parameterTypes": ["sun.security.x509.X500Name"] } { "name": "<init>", "parameterTypes": ["sun.security.x509.X500Name"] }
] ]
}, },
{
"name": "org.apache.commons.compress.archivers.zip.AsiExtraField",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.JarMarker",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.ResourceAlignmentExtraField",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.UnicodeCommentExtraField",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.UnicodePathExtraField",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X000A_NTFS",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X0014_X509Certificates",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X0015_CertificateIdForFile",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X0016_CertificateIdForCentralDirectory",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X0017_StrongEncryptionHeader",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X0019_EncryptionRecipientCertificateList",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.X7875_NewUnix",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{
"name": "org.apache.commons.compress.archivers.zip.Zip64ExtendedInformationExtraField",
"methods": [{ "name": "<init>", "parameterTypes": [] }]
},
{ "name": "scala.Boolean" }, { "name": "scala.Boolean" },
{ "name": "scala.Int" }, { "name": "scala.Int" },
{ "name": "scala.Long" }, { "name": "scala.Long" },

View File

@ -0,0 +1,52 @@
import sbt._
object VerifyReflectionSetup {
private val zipRequiredClass =
"org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp"
private val unwantedPointerInfix = "/0x00"
/** A task that checks if the reflection configuration is set-up properly.
*
* It checks if the configuration contains entries for handling ZIP archives
* and does not contain ephemeral classes.
*/
def run = Def.task {
val root = Keys.baseDirectory.value
val name = Keys.name.value
val log = Keys.streams.value.log
def fail(message: String): Nothing = {
log.error(message)
throw new IllegalStateException(message)
}
val configPath =
root / "src" / "main" / "resources" / "META-INF" / "native-image"
val reflectConfigs = (configPath ** "reflect-config.json").get()
if (reflectConfigs.isEmpty) {
fail(s"Could not locate reflect config for $name.")
}
val content = reflectConfigs.map(IO.read(_)).mkString("\n")
if (!content.contains(zipRequiredClass)) {
fail(
s"Required classes for ZIP archive handling are not present in " +
s"reflection config for $name. This may result in ZIP handling not " +
s"working in native builds. Please add these missing configurations " +
s"as described in `docs/infrastructure/native-image.md` or remove " +
s"this check if ZIP support is no longer needed for this project."
)
}
if (content.contains(unwantedPointerInfix)) {
fail(
s"Reflection configuration for $name seems to contain unnecessary " +
s"ephemeral classes. Please make sure that you have run " +
s"`cd tools/native-image-config-cleanup && npm start` after updating " +
s"the configuration. Please refer to " +
s"`docs/infrastructure/native-image.md` for more details."
)
}
}
}