Skip to content

Commit

Permalink
Add filter for multi-release jar files.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 26, 2024
1 parent de561d0 commit d86040b
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 38 deletions.
8 changes: 8 additions & 0 deletions .mvn/checksums.sha256
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ net.bytebuddy:byte-buddy-agent:jar:1.14.8 f7c60fd229df2b0f4e390f50e0582a23ac1d89
net.bytebuddy:byte-buddy-agent:jar:1.14.9 11ed107d4b78e55f8c3d34250494375081a29bc125a1f5c56db582ccdd48835f
net.bytebuddy:byte-buddy-agent:jar:1.15.0 3399a0fdf7ba3f1386ebf831a706037428f1b1af81d653c25cf8a8fde2e4d2ea
net.bytebuddy:byte-buddy-agent:jar:1.15.1 77a39846b42110eb50e49e4ff6137e3f0a92eb3bb6f59ce52dc4095c8b901005
net.bytebuddy:byte-buddy-agent:jar:1.15.2 f8673a2dec2a4c2b0a910d92b4b332bb9622890332138e4c401364cba74eda77
net.bytebuddy:byte-buddy-android:jar:1.12.19 bb73d3b9ace5a60a9a9aa1701761073b3df3baf79ff463aed6cd94b724fd3ba9
net.bytebuddy:byte-buddy-android:jar:1.12.20 f43b8b7eb840f6140135066224f0e6b565b9becb05345fdc572a66bfb92df0aa
net.bytebuddy:byte-buddy-android:jar:1.12.21 bf4ad1405c2fcaa8b179929f9a64c8ee66d04f34b0e3fe8a90b28c738f883fe9
Expand Down Expand Up @@ -675,6 +676,7 @@ net.bytebuddy:byte-buddy-android:jar:1.14.8 9c1ea03f4b06c85a30800b810b196806a480
net.bytebuddy:byte-buddy-android:jar:1.14.9 3cdbdaaf439bce36b94dd27782b86fb1d92bbbedcd527dbf2ee14e0412f6b80e
net.bytebuddy:byte-buddy-android:jar:1.15.0 3874728750cd8917f70190eb0d004ccef4c3e00652b42d89d97e5d890e97c5af
net.bytebuddy:byte-buddy-android:jar:1.15.1 b8724a3372f76dbbe01ea3385baad0c325c583f637a87d32428b612be70b5b32
net.bytebuddy:byte-buddy-android:jar:1.15.2 a19d628dee90c74e96a321e9814e2c5f3fe4e6404b05a7b25ec407e227e25e7e
net.bytebuddy:byte-buddy-dep:jar:1.12.19 a85bb853ec6ec156b10ea0b5b0e38ac0f89c6c2bc89dd0358772a0dff2eb85c9
net.bytebuddy:byte-buddy-dep:jar:1.12.20 d7e15d3ccc0508e78a146f1be420779eb3e2e9a537e3c8add3cd6d802c9a615e
net.bytebuddy:byte-buddy-dep:jar:1.12.21 116b320c1f3f8539978ea67989d94e9bfed3e9422beb5a76749d967439ec8f9d
Expand Down Expand Up @@ -703,6 +705,7 @@ net.bytebuddy:byte-buddy-dep:jar:1.14.8 149957aaeb4c069864cad647c8f8680d8f939350
net.bytebuddy:byte-buddy-dep:jar:1.14.9 e9affd66effe9857856b5948463893c02ad7a91e37cf3d8c07930e73cc8c282f
net.bytebuddy:byte-buddy-dep:jar:1.15.0 5b4840406be9f761d39f314bc1b5d0574b55c163140fcfe7b6f670e82fb0738c
net.bytebuddy:byte-buddy-dep:jar:1.15.1 ade2ebcc897db4ecc13ab61188d8251665314cbf8f3268e558e75f9728380fc6
net.bytebuddy:byte-buddy-dep:jar:1.15.2 50f05dad8a626e588b2f89de7eefc9212515d45d6a03fb87870f946f0bab56f7
net.bytebuddy:byte-buddy-maven-plugin:jar:1.12.19 3419e2afbfac4f21ef709ee3f8f08fc1d71001e07ba2524a0bb2a3c28f3e1087
net.bytebuddy:byte-buddy-maven-plugin:jar:1.12.20 48a36e2e8c2dbe2b3673ef8bf6be22b021cfca35d6205a3d5e722f74db42d52b
net.bytebuddy:byte-buddy-maven-plugin:jar:1.12.21 cb3332f89cc6502e3637dbe509c08c55cb5ad528c675131858dda89eabf7c9fc
Expand All @@ -728,6 +731,7 @@ net.bytebuddy:byte-buddy-maven-plugin:jar:1.14.6 d30844d8955cc7d9bba051bb5509166
net.bytebuddy:byte-buddy-maven-plugin:jar:1.14.9 2bc8809f83aed11a531f093da593c52e3b572b7ee7359c1e3eff3796061db44e
net.bytebuddy:byte-buddy-maven-plugin:jar:1.15.0 e14df4a925a628f3f7b937005eba803b1e9d320ee7a8172f734691dfa58bd432
net.bytebuddy:byte-buddy-maven-plugin:jar:1.15.1 9cb4a37d5bb17cd55ea52e9f660a87b7b9fdae56bfe886f9588b09929207f7e3
net.bytebuddy:byte-buddy-maven-plugin:jar:1.15.2 1cda61087db3b8159f77be5f74e04f816a24ea1d9cd54ba0b537c6573c6d118e
net.bytebuddy:byte-buddy-maven-plugin:pom:1.12.19 c2051f8cbdf328692f36077627be07168334ee9167b72e5bf608eae624163b4f
net.bytebuddy:byte-buddy-maven-plugin:pom:1.12.20 2d112ff342e7db7da484d038807749c1a87c81419b789a86b950a37bdd65b207
net.bytebuddy:byte-buddy-maven-plugin:pom:1.12.21 13576ca6b9c44ab9789ada11ee400dcd3f4bcc22a7cab6f7052aeeb49a8c02e1
Expand All @@ -753,6 +757,7 @@ net.bytebuddy:byte-buddy-maven-plugin:pom:1.14.6 e301c83e77f6b8da2e2090c9eb6288f
net.bytebuddy:byte-buddy-maven-plugin:pom:1.14.9 75c6d50a8cf6d528eb09b198e54035b6bbc10d0653655194ae697b971334fdd2
net.bytebuddy:byte-buddy-maven-plugin:pom:1.15.0 cc233d43805a7e9756c8a94c4751a18cb938ac3ccf83f0691604206157130bd0
net.bytebuddy:byte-buddy-maven-plugin:pom:1.15.1 d8f649ffa066009efc71e967a45cca915c6ffb1c4a4508b0718f4a51d4437197
net.bytebuddy:byte-buddy-maven-plugin:pom:1.15.2 11d71812ac7ea9f397967f984750d4484dd9c027a4a64f5730d840bb3542aa15
net.bytebuddy:byte-buddy-parent:pom:1.12.19 72ab6fef409e812921f4728b3c4b6ef4fa53bc25fabb0488fc2cae367368b54d
net.bytebuddy:byte-buddy-parent:pom:1.12.20 ac59dd7bc0316c51ab29e7c44ae7941ba8c7bf84789edb1dc8fbef2f16535b99
net.bytebuddy:byte-buddy-parent:pom:1.12.21 ff66d886607137e2095f20c90ee093f3c80329164eff091a0688bdce37e3e6b2
Expand All @@ -778,6 +783,7 @@ net.bytebuddy:byte-buddy-parent:pom:1.14.6 f889394b9e576a1e7a3ce13efd47b5cb2e62e
net.bytebuddy:byte-buddy-parent:pom:1.14.9 66b8342251d35f2063e69316f63bafcb056342fe75e921c0f465c2d96593535e
net.bytebuddy:byte-buddy-parent:pom:1.15.0 8ec247e077cdf76e72ad2b9919576cf2a477811935b56c8a27958e7297b4f18b
net.bytebuddy:byte-buddy-parent:pom:1.15.1 7bb21259d04796865f0d83dd3344fcffdd34c94515c00a6525a8996acb1c413f
net.bytebuddy:byte-buddy-parent:pom:1.15.2 3be68060e65990669555e02f4cf7826e10122462c14cb14c1b2db78447795bfd
net.bytebuddy:byte-buddy:jar:1.12.19 030704139e46f32c38d27060edee9e0676b0a0fff8a8be53461515154ba8a7be
net.bytebuddy:byte-buddy:jar:1.12.20 0a9b2795e0e2391117062f0fc7f6ae98fa3c2a7c927847ff1e01bb7cffcd9167
net.bytebuddy:byte-buddy:jar:1.12.21 f6f45c2237a7f132c16745ad2a52c4cdde58028b11ee80b09f0d422f4930d685
Expand All @@ -803,6 +809,7 @@ net.bytebuddy:byte-buddy:jar:1.14.6 6eaf0190ee02731820e9925a544e7cfb48f6dfc3bf29
net.bytebuddy:byte-buddy:jar:1.14.9 377352e253282bf86f731ac90ed88348e8f40a63ce033c00a85982de7e790e6f
net.bytebuddy:byte-buddy:jar:1.15.0 c743cfb4db1e6c67af6297fbe32a3ad94710884cde4c7eecb1bad7d820d4f2ba
net.bytebuddy:byte-buddy:jar:1.15.1 cc5f178f37ef83339b7ec93e8d0bed6b0730871cdb39c663527ddeae4a54a825
net.bytebuddy:byte-buddy:jar:1.15.2 c754a34c3bf9cc7efbe9c229a2ad185504f017b1c255100a4d3023b38e1e14d5
net.bytebuddy:byte-buddy:pom:1.12.19 435fb8664aa9b7e120c8dd6c707d4eafa642fa262dff6d5e3f71dc25c69e89eb
net.bytebuddy:byte-buddy:pom:1.12.20 46353d5c52659c40f0f54d05c757665552e492be36087c19307598d1bf07bbfb
net.bytebuddy:byte-buddy:pom:1.12.21 95eb42c89fd04f62187dd33b9cdf04d2df1b876b375c16ad32c0a5a1cc1a070b
Expand All @@ -828,6 +835,7 @@ net.bytebuddy:byte-buddy:pom:1.14.6 444380f496a38a2b0b7325a4d0f223e3b07f2a2347bc
net.bytebuddy:byte-buddy:pom:1.14.9 2d6772910d16169bd4c9229e8a365cf54e192bc620cbcfa7f84271f5d115e815
net.bytebuddy:byte-buddy:pom:1.15.0 ed4d27216401c5cb6e8f16c09fbfd460679b90c43a033d8d0e7b11e45cfb4e58
net.bytebuddy:byte-buddy:pom:1.15.1 e358152bf7abff7b763a9670c79e798e14aed9a1b07f83476a909e3eaa222f21
net.bytebuddy:byte-buddy:pom:1.15.2 2d72568104ae6c61368aede1864519a2a233ecf0a7aee3c52eed2d046fc4fb2f
net.i2p.crypto:eddsa:jar:0.3.0 4dda1120db856640dbec04140ed23242215a075fe127bdefa0dcfa29fb31267d
net.i2p.crypto:eddsa:pom:0.3.0 b6b13878e4bae8b768d7ea5732cb4d66ab2f5e9fe707c0a1a776cde9de52051b
net.java.dev.jna:jna-platform:jar:5.12.1 8ce969116cac95bd61b07a8d5e07174b352e63301473caac72c395e3c08488d2
Expand Down
2 changes: 1 addition & 1 deletion byte-buddy-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 6 additions & 6 deletions byte-buddy-dep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<executions>
<execution>
<phase>compile</phase>
Expand All @@ -142,7 +142,7 @@
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<plugin>net.bytebuddy.build.HashCodeAndEqualsPlugin$WithNonNullableFields</plugin>
<arguments>
<argument>
Expand All @@ -154,13 +154,13 @@
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<plugin>net.bytebuddy.build.CachedReturnPlugin</plugin>
</transformation>
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<plugin>net.bytebuddy.build.AccessControllerPlugin</plugin>
<arguments>
<argument>
Expand All @@ -172,13 +172,13 @@
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<plugin>net.bytebuddy.build.DispatcherAnnotationPlugin</plugin>
</transformation>
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<plugin>net.bytebuddy.build.RepeatedAnnotationPlugin</plugin>
</transformation>
</transformations>
Expand Down
69 changes: 62 additions & 7 deletions byte-buddy-dep/src/main/java/net/bytebuddy/build/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,11 @@ interface Engine {
/**
* Uses the supplied {@link ClassFileVersion} as a base for resolving multi-release jars, or {@code null}
* if multi-release jars should not be resolved but be treated as regular jar files. This property might
* not be applied if the underlying location mechanism does not supply manual resource resolution.
* not be applied if the underlying location mechanism does not supply manual resource resolution. Note that
* classes that are of newer class file versions than the specified version are not resolved and simply copied.
*
* @param classFileVersion The class file version to use or {@code null}.
* @return A new plugin engine that is equal to this engine but with the supplied class file verion being used.
* @param classFileVersion The class file version to use or {@code null} if multi-release jars should be ignored.
* @return A new plugin engine that is equal to this engine but with the supplied class file version being used.
*/
Engine with(@MaybeNull ClassFileVersion classFileVersion);

Expand Down Expand Up @@ -2421,15 +2422,15 @@ public ClassFileLocator toClassFileLocator(@MaybeNull ClassFileVersion classFile
/**
* {@inheritDoc}
*/
public void close() throws IOException {
delegate.close();
public Iterator<Element> iterator() {
return new FilteringIterator(delegate.iterator(), matcher);
}

/**
* {@inheritDoc}
*/
public Iterator<Element> iterator() {
return new FilteringIterator(delegate.iterator(), matcher);
public void close() throws IOException {
delegate.close();
}

/**
Expand Down Expand Up @@ -3304,12 +3305,66 @@ public Filtering(Source delegate, ElementMatcher<Element> matcher, boolean manif
this.manifest = manifest;
}

/**
* Wraps a source to exclude elements that are above the specified Java version.
*
* @param delegate The delegate source.
* @param classFileVersion The latest multi-release Java version to retain from the source.
* @return A source that applies an appropriate filter.
*/
public static Source dropMultiReleaseClassFilesAbove(Source delegate, ClassFileVersion classFileVersion) {
return new Filtering(delegate, new MultiReleaseVersionMatcher(classFileVersion), true);
}

/**
* {@inheritDoc}
*/
public Origin read() throws IOException {
return new Origin.Filtering(delegate.read(), matcher, manifest);
}

/**
* An element matcher that filters multi-release files above a given version.
*/
@HashCodeAndEqualsPlugin.Enhance
protected static class MultiReleaseVersionMatcher implements ElementMatcher<Element> {

/**
* The latest version to consider.
*/
private final ClassFileVersion classFileVersion;

/**
* Creates a multi-release version matcher.
*
* @param classFileVersion The latest class file version to consider.
*/
protected MultiReleaseVersionMatcher(ClassFileVersion classFileVersion) {
this.classFileVersion = classFileVersion;
}

/**
* {@inheritDoc}
*/
public boolean matches(Element target) {
String name = target.getName();
if (name.startsWith("/")) {
name = name.substring(1);
}
if (name.startsWith(ClassFileLocator.META_INF_VERSIONS)) {
int version;
try {
version = Integer.parseInt(name.substring(
ClassFileLocator.META_INF_VERSIONS.length(),
name.indexOf('/', ClassFileLocator.META_INF_VERSIONS.length())));
} catch (NumberFormatException ignored) {
return true;
}
return version <= classFileVersion.getJavaVersion();
}
return true;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.bytebuddy.build;

import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.matcher.ElementMatcher;
import org.junit.Rule;
Expand Down Expand Up @@ -84,4 +85,22 @@ public void testClassFileLocator() throws Exception {

assertThat(new Plugin.Engine.Source.Filtering(source, matcher).read().toClassFileLocator(null), is(classFileLocator));
}

@Test
public void testMultiReleaseFilter() throws Exception {
when(source.read()).thenReturn(origin);
when(origin.iterator()).thenReturn(Arrays.asList(first, second, third).iterator());

when(first.getName()).thenReturn("foo/Bar.class");
when(second.getName()).thenReturn(ClassFileLocator.META_INF_VERSIONS + "17/foo/Bar.class");
when(third.getName()).thenReturn(ClassFileLocator.META_INF_VERSIONS + "11/foo/Bar.class");

Plugin.Engine.Source.Origin origin = Plugin.Engine.Source.Filtering.dropMultiReleaseClassFilesAbove(this.source, ClassFileVersion.JAVA_V11).read();
Iterator<Plugin.Engine.Source.Element> iterator = origin.iterator();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.next(), is(first));
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.next(), is(third));
assertThat(iterator.hasNext(), is(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public void execute() throws IOException {
Iterable.class,
EntryPoint.class,
ClassFileVersion.class,
ClassFileVersion.class,
Plugin.Factory.UsingReflection.ArgumentResolver.class,
String.class,
int.class,
Expand All @@ -253,6 +254,7 @@ public void execute() throws IOException {
getDiscoverySet().getFiles(),
getEntryPoint().get(),
classFileVersion,
classFileVersion,
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(AndroidDescriptor.class, androidDescriptor),
getSuffix().get(),
getThreads().get(),
Expand Down
Loading

0 comments on commit d86040b

Please sign in to comment.