Skip to content

Look into supporting URLClassLoader internally #132

@ascopes

Description

@ascopes

Some annotation processors rely on the compiler FileManager using URLClassLoader instances internally to work correctly. An example of this is the Manifold framework.

We currently use https://github.com/ascopes/java-compiler-testing/blob/main/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ContainerGroupClassLoaderImpl.java to handle class loading from the compiler paths. Since the path containers use Path objects internally, we should be able to obtain a URI from those via .toUri() and from that obtain a URL object via .toURL().

This depends on whether the in-memory file system library we use (JIMFS) fully supports providing a URL scheme for their filesystem implementation. They seem to provide a URL connection implementation which makes me hopeful.

If URL handling is not supported properly then we might need to look into implementing a protocol handler for JIMFS that does what we need (or contribute it to their GitHub).

PathWrappers should be updated to expose a method that provides a URL of the path (https://github.com/ascopes/java-compiler-testing/blob/main/java-compiler-testing/src/main/java/io/github/ascopes/jct/pathwrappers/PathWrapper.java#L61).

Once this is done, we should be able to swap out the classloader implementation used in the container group classes to use the URL class loader instead, taking the URLs from each container. Subclassing the URL classloader class to provide a constructor to do this might be a good idea. These implementation usages occur at the following locations:

If everything is working, the existing unit tests and acceptance tests should all still pass. The acceptance tests use these classloaders in multiple places to make sure that the expected code is generated by tools like Lombok, Immutables, AutoValue, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementOptimisations and internal improvements in the codebase.good first issuegood first issue for contributors

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions