Skip to content

Add an API for authoring multi-release archives #269

Open

Description

@xjusko

Split out from #119, which was about reading multi-release JARs (fixed in #268). This is @jamezp's proposal from #119 (comment) for building them:

addMultiReleaseClass(String version, Class<?> type, String targetName);

so that

.addMultiReleaseClass("25", Resource25.class, "Resource");

writes META-INF/versions/25/com/example/Resource.class.

There is no way to do this with the class API today. addClasses derives the target path from clazz.getName() through AssetUtil.getFullPathForClassResource, so a versioned class cannot be renamed to match the FQN of the class it overrides, which is what a multi-release JAR requires. The workaround is to drop down to the asset API and build the path by hand:

jar.add(new ClassAsset(Resource25.class), "META-INF/versions/25/com/example/Resource.class");

A few things worth settling before implementing:

  1. Where should it live? ClassContainer also covers WebArchive, EnterpriseArchive and ResourceAdapterArchive, where getClassesPath() is not the archive root and a versions directory would not mean much. JavaArchive only?
  2. Inner classes. addClasses pulls them in with the $ filter (SHRINKWRAP-335), so Resource25$Inner would need the same rename, unless we declare it out of scope.
  3. The proposal leaves Multi-Release: true to the user. Should we set it when the first versioned class is added, or add a separate setMultiRelease()?
  4. String version or int? Runtime.Version.feature() is an int.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions