Skip to content

Commit aaa7193

Browse files
committed
Add API to store multi-version JARs.
1 parent 6f0b5ed commit aaa7193

File tree

1 file changed

+34
-5
lines changed
  • byte-buddy-dep/src/main/java/net/bytebuddy/build

1 file changed

+34
-5
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/build/Plugin.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,6 +3740,11 @@ void materialize(Target.Sink sink,
37403740
*/
37413741
class ForTransformedElement implements Materializable {
37423742

3743+
/**
3744+
* The multi-release Java version number or {@code 0}.
3745+
*/
3746+
private final int version;
3747+
37433748
/**
37443749
* The type that has been transformed.
37453750
*/
@@ -3748,9 +3753,11 @@ class ForTransformedElement implements Materializable {
37483753
/**
37493754
* Creates a new materializable for a successfully transformed type.
37503755
*
3756+
* @param version The multi-release Java version number or {@code 0}.
37513757
* @param dynamicType The type that has been transformed.
37523758
*/
3753-
protected ForTransformedElement(DynamicType dynamicType) {
3759+
protected ForTransformedElement(int version, DynamicType dynamicType) {
3760+
this.version = version;
37543761
this.dynamicType = dynamicType;
37553762
}
37563763

@@ -3762,7 +3769,11 @@ public void materialize(Target.Sink sink,
37623769
Map<TypeDescription,
37633770
List<Throwable>> failed,
37643771
List<String> unresolved) throws IOException {
3765-
sink.store(dynamicType.getAllTypes());
3772+
if (version == 0) {
3773+
sink.store(dynamicType.getAllTypes());
3774+
} else {
3775+
sink.store(version, dynamicType.getAllTypes());
3776+
}
37663777
transformed.add(dynamicType.getTypeDescription());
37673778
}
37683779
}
@@ -4760,6 +4771,9 @@ public Summary apply(Source source, Target target, List<? extends Plugin.Factory
47604771
name.substring(name.startsWith(META_INF_VERSIONS)
47614772
? name.indexOf('/', META_INF_VERSIONS.length()) + 1
47624773
: 0, name.length() - CLASS_FILE_EXTENSION.length()).replace('/', '.'),
4774+
name.startsWith(META_INF_VERSIONS)
4775+
? Integer.parseInt(name.substring(META_INF_VERSIONS.length(), name.indexOf('/', META_INF_VERSIONS.length())))
4776+
: 0,
47634777
classFileLocator,
47644778
typePool,
47654779
listener,
@@ -4824,6 +4838,11 @@ private class Preprocessor implements Callable<Callable<? extends Dispatcher.Mat
48244838
*/
48254839
private final String typeName;
48264840

4841+
/**
4842+
* The multi-release Java version number or {@code 0}.
4843+
*/
4844+
private final int version;
4845+
48274846
/**
48284847
* The class file locator to use.
48294848
*/
@@ -4854,6 +4873,7 @@ private class Preprocessor implements Callable<Callable<? extends Dispatcher.Mat
48544873
*
48554874
* @param element The processed element.
48564875
* @param typeName The name of the processed type.
4876+
* @param version The multi-release Java version number or {@code 0}.
48574877
* @param classFileLocator The class file locator to use.
48584878
* @param typePool The type pool to use.
48594879
* @param listener The listener to notify.
@@ -4862,13 +4882,15 @@ private class Preprocessor implements Callable<Callable<? extends Dispatcher.Mat
48624882
*/
48634883
private Preprocessor(Source.Element element,
48644884
String typeName,
4885+
int version,
48654886
ClassFileLocator classFileLocator,
48664887
TypePool typePool,
48674888
Listener listener,
48684889
List<Plugin> plugins,
48694890
List<WithPreprocessor> preprocessors) {
48704891
this.element = element;
48714892
this.typeName = typeName;
4893+
this.version = version;
48724894
this.classFileLocator = classFileLocator;
48734895
this.typePool = typePool;
48744896
this.listener = listener;
@@ -4889,7 +4911,7 @@ public Callable<Dispatcher.Materializable> call() throws Exception {
48894911
for (WithPreprocessor preprocessor : preprocessors) {
48904912
preprocessor.onPreprocess(typeDescription, classFileLocator);
48914913
}
4892-
return new Resolved(typeDescription);
4914+
return new Resolved(version, typeDescription);
48934915
} else {
48944916
return new Ignored(typeDescription);
48954917
}
@@ -4913,6 +4935,11 @@ public Callable<Dispatcher.Materializable> call() throws Exception {
49134935
*/
49144936
private class Resolved implements Callable<Dispatcher.Materializable> {
49154937

4938+
/**
4939+
* The multi-release Java version number or {@code 0}.
4940+
*/
4941+
private final int version;
4942+
49164943
/**
49174944
* A description of the resolved type.
49184945
*/
@@ -4921,9 +4948,11 @@ private class Resolved implements Callable<Dispatcher.Materializable> {
49214948
/**
49224949
* Creates a new resolved materializable.
49234950
*
4951+
* @param version The multi-release Java version number or {@code 0}.
49244952
* @param typeDescription A description of the resolved type.
49254953
*/
4926-
private Resolved(TypeDescription typeDescription) {
4954+
private Resolved(int version, TypeDescription typeDescription) {
4955+
this.version = version;
49274956
this.typeDescription = typeDescription;
49284957
}
49294958

@@ -4962,7 +4991,7 @@ public Dispatcher.Materializable call() {
49624991
listener.onLiveInitializer(typeDescription, entry.getKey());
49634992
}
49644993
}
4965-
return new Dispatcher.Materializable.ForTransformedElement(dynamicType);
4994+
return new Dispatcher.Materializable.ForTransformedElement(version, dynamicType);
49664995
} catch (Throwable throwable) {
49674996
errored.add(throwable);
49684997
listener.onError(typeDescription, errored);

0 commit comments

Comments
 (0)