Class InternalResource.Env

java.lang.Object
com.oracle.truffle.api.InternalResource.Env
Enclosing interface:
InternalResource

public static final class InternalResource.Env extends Object
Access to common utilities for unpacking resource files.
Since:
23.1
  • Method Details

    • inContextPreinitialization

      public boolean inContextPreinitialization()
      Returns true if the engine causing the resource unpacking is being pre-initialized.
      Since:
      23.1
    • inNativeImageBuild

      public boolean inNativeImageBuild()
      Returns true if resource unpacking happens during the native image build.
      Since:
      23.1
    • getCPUArchitecture

      public InternalResource.CPUArchitecture getCPUArchitecture()
      Returns the current processor architecture. The value can be used to resolve an architecture specific files during resource unpacking.
      Since:
      23.1
    • getOS

      public InternalResource.OS getOS()
      Returns the current operating system. The value can be used to resolve an OS specific files during resource unpacking.
      Since:
      23.1
    • readResourceLines

      public List<String> readResourceLines(Path location) throws IOException
      Reads a resource from the module, which owns the InternalResource implementation class. If the resource is encapsulated in the module, see Module.getResourceAsStream(String), the module needs to open the location enclosing package to the org.graalvm.truffle module. It is recommended to use non-encapsulated resource paths.
      Parameters:
      location - relative path that identifies the resource in the module. The relative path gets resolved into an absolute path using the archive root.
      Returns:
      the lines from the resource as a List
      Throws:
      IOException - in case of IO error
      Since:
      23.1
    • unpackResourceFiles

      public void unpackResourceFiles(Path source, Path target, Path relativizeTo) throws IOException
      Extracts files from the module, which owns the InternalResource implementation class, listed in the source file list and places them into the target folder. If resources are encapsulated within the module, see Module.getResourceAsStream(String), the module needs to open the enclosing package of the resources to the org.graalvm.truffle module. It is recommended to use non-encapsulated resource paths.

      The file list is a Java properties file where resource files serve as keys, and the corresponding values consist of serialized attributes separated by ','. Currently, only the POSIX file permissions attribute is supported. The format of this attribute follows the same convention used by the PosixFilePermissions.fromString(String).

      Example of a file list content:

       META-INF/resources/darwin/amd64/bin/libtrufflenfi.dylib = rwxr-xr-x
       META-INF/resources/common/include/trufflenfi.h = rw-r--r--
       
      Parameters:
      source - the relative path that identifies the file list resource in the module. The relative path gets resolved into an absolute path using the archive root.
      target - the folder to extract resources to
      relativizeTo - the path used to relativize the file list entries in the target folder. In other words, the file list entries are resolved using the target directory after removing the relativizeTo path.
      Throws:
      IllegalArgumentException - if relativizeTo is an absolute path or file list contains an absolute path
      IOException - in case of IO error
      Since:
      23.1