Support provided-scope libraries when extracting an executable war - #51372
Support provided-scope libraries when extracting an executable war#51372skdas20 wants to merge 1 commit into
Conversation
IndexedJarStructure flattened every classpath index entry relative to the single Spring-Boot-Lib location. An executable war also places its provided-scope dependencies under WEB-INF/lib-provided/ and lists them in the index, so the first such entry failed the assertion and aborted the tools jarmode extract command. Accept entries from that location too, mirroring WarLauncher, which already treats WEB-INF/lib/ and WEB-INF/lib-provided/ as library roots. See spring-projectsgh-51367 Signed-off-by: skdas20 <skdas5405@gmail.com>
|
Note on the red build: the failure is MongoDB 5.9.2 has been published since #51339 bumped the BOM to 5.9.1, so the check flags the drift on any build until that's bumped again. This PR only touches Happy to rebase once that lands if you'd like a green run before reviewing. |
|
@philwebb What do you think about adding a new manifest attribite for the |
|
@mhalbritter that reads better to me than the constant, and I'm happy to redo it that way — it would let the jarmode stop knowing war layout at all, which is really the underlying smell here. One fact that may make the decision easier: the tools jarmode is packaged into the archive it operates on — Shape I'd propose unless you'd rather something else:
That's a wider change than this PR, touching |
See gh-51367.
Problem
IndexedJarStructure.toStructureDependencyflattens every classpath index entry relative to the singleSpring-Boot-Liblocation:For an executable war
Spring-Boot-LibisWEB-INF/lib/, but provided-scope dependencies (the embedded container among them) are packaged underWEB-INF/lib-provided/byLayouts.Warand are listed inWEB-INF/classpath.idxalongside the rest. The first such entry trips the assertion, so-Djarmode=tools extractfails withInvalid library location WEB-INF/lib-provided/...on any war built from awebstarter.Only
Spring-Boot-Libis recorded in the manifest, so the second location can't be read from there.WarLauncherhas the same need and hardcodes both:Change
Accept entries from either location when flattening, mirroring
WarLauncher, and keep the failure for anything genuinely outside a library root (now an explicitIllegalStateException, since the two-location check no longer fitsAssert.state).Tests
Added to
IndexedJarStructureTests, using a war-shaped manifest and an index containing both aWEB-INF/lib/and aWEB-INF/lib-provided/entry:shouldResolveLibraryEntryFromWarProvidedLocation— the provided entry resolves as aLIBRARYflattened to its bare jar nameshouldCreateLauncherManifestForWarWithProvidedLibraries— both jars appear in the generatedClass-PathBoth fail on
main:With the change the module's tests and
checkFormatMain/checkFormatTestall pass.One thing worth your call: I hardcoded the location as a constant to match
WarLauncher. If you'd rather it be derived (or carried in the manifest as a new attribute so the tools jarmode doesn't need to know war layout at all), happy to redo it that way.