Skip to content

Commit a52b1d1

Browse files
committed
Reduce documentation complexity.
1 parent 0a8b2a6 commit a52b1d1

File tree

4 files changed

+17
-78
lines changed

4 files changed

+17
-78
lines changed

byte-buddy-agent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<dependency>
7070
<groupId>net.bytebuddy</groupId>
7171
<artifactId>byte-buddy</artifactId>
72-
<version>1.10.15</version>
72+
<version>1.10.16</version>
7373
<scope>test</scope>
7474
</dependency>
7575
</dependencies>

byte-buddy-dep/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<plugin>
102102
<groupId>net.bytebuddy</groupId>
103103
<artifactId>byte-buddy-maven-plugin</artifactId>
104-
<version>1.10.15</version>
104+
<version>1.10.16</version>
105105
<executions>
106106
<execution>
107107
<phase>compile</phase>
@@ -116,13 +116,13 @@
116116
<transformation>
117117
<groupId>net.bytebuddy</groupId>
118118
<artifactId>byte-buddy</artifactId>
119-
<version>1.10.15</version>
119+
<version>1.10.16</version>
120120
<plugin>net.bytebuddy.build.HashCodeAndEqualsPlugin$WithNonNullableFields</plugin>
121121
</transformation>
122122
<transformation>
123123
<groupId>net.bytebuddy</groupId>
124124
<artifactId>byte-buddy</artifactId>
125-
<version>1.10.15</version>
125+
<version>1.10.16</version>
126126
<plugin>net.bytebuddy.build.CachedReturnPlugin</plugin>
127127
</transformation>
128128
</transformations>

byte-buddy-gradle-plugin/README.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The **Byte Buddy Gradle Plugin** enables you to apply bytecode enhancements during the build process. If the *java* plugin
44
is registered, the plugin registers an intermediate task for every source set for which at least one transformation is defined.
5-
For the *main* source set, the task is named *byteBuddy*. For each other source set, the source set name is prefixed as in *[source set]ByteBuddy*.
5+
For the *main* source set, the task is named *byteBuddy*. For each other source set, the source set name is prefixed as in *[source set]ByteBuddy*. If the *java* plugin is not used in a Gradle build or subproject, the Byte Buddy plugin remains passive.
66

77
To apply a transformation, consider the following Gradle build file:
88

@@ -13,43 +13,15 @@ plugins {
1313
id 'net.bytebuddy.byte-buddy-gradle-plugin' version byteBuddyVersion
1414
}
1515
16-
import static net.bytebuddy.dynamic.ElementMatchers.*;
17-
import net.bytebuddy.build.Plugin;
18-
import net.bytebuddy.dynamic.DynamicType;
19-
import net.bytebuddy.description.type.TypeDescription;
20-
import net.bytebuddy.dynamic.ClassFileLocator;
21-
// Skipped dependency declaration of JUnit.
22-
23-
class HookInstallingPlugin implements Plugin {
24-
25-
@Override
26-
boolean matches(TypeDescription target) {
27-
return target.getName().endsWith("Test");
28-
}
29-
30-
@Override
31-
DynamicType.Builder<?> apply(DynamicType.Builder<?> builder,
32-
TypeDescription typeDescription,
33-
ClassFileLocator classFileLocator) {
34-
return builder.method(isAnnotatedWith(anyOf(Test.class, Before.class, After.class))
35-
.or(isStatic().and(isAnnotatedWith(anyOf(BeforeClass.class, AfterClass.class)))))
36-
.intercept(MethodDelegation.to(SampleInterceptor.class))
37-
.implement(Hooked.class);
38-
}
39-
40-
@Override
41-
void close() { }
42-
}
43-
44-
testByteBuddy {
16+
byteBuddy {
4517
transformation {
46-
plugin = HookInstallingPlugin.class
18+
plugin = net.bytebuddy.build.CachedReturnPlugin.class
4719
}
4820
}
4921
```
5022

51-
This example transformation specifies that Byte Buddy should install a method interceptor (defined by **SampleInterceptor**) on all test classes with a name ending with `Test`. The interceptor is added to all methods with the annotations **`@Test`**, **`@Before`**, **`@After`**, **`@BeforeClass`**, or **`@AfterClass`**. This transformation also adds a marker interface **Hooked** so that we can identify enhanced classes at runtime.
23+
This example transformation uses a standard plugin that is shipped with Byte Buddy, which caches any method return value if annotated by `CachedReturnPlugin.Enhance`. The plugin in the example is applied onto the main source set. Custom plugins must implement Byte Buddy's `Plugin` interface, either inline in the build file, within the `buildSrc` directory or within an external artifact that is added as a dependency within the script's *buildscript* block. Note that Gradle also offers a `Plugin` interface which must not be confused with Byte Buddy's plugin API.
5224

53-
A plugin can declare a constructor that can take arguments of type `File`, `BuildLogger` or a Gradle-specific `Logger` where the class file root directory or an appropriate logger is provided. It is also possible to supply an argument explicitly by specifying an argument in the plugin configuration.
25+
A custom can declare a constructor that can take arguments of type `File`, `BuildLogger` or a Gradle-specific `Logger` where the class file root directory or an appropriate logger is provided. It is also possible to supply an argument explicitly by specifying an argument in the plugin configuration.
5426

55-
The plugin offers the implementation of custom tasks, the `ByteBuddyTask` transforms classes within a folder and writes it to another folder while using Gradle's incremental build feature what requires Gradle 6 or later. The `ByteBuddySimpleTask` does not support incremental build but works from Gradle 2 on up whereas the `ByteBuddyJarTask` allows the transformation of a bundled jar file.
27+
The plugin offers the implementation of custom tasks, the `ByteBuddyTask` transforms classes within a folder and writes it to another folder while using Gradle's incremental build feature what requires Gradle 6 or later. The `ByteBuddySimpleTask` does not support incremental build but works from Gradle 2 on up whereas the `ByteBuddyJarTask` allows the transformation of a bundled jar file. Insight into the Byte Buddy plugins autoconfiguration can be found in the debug log.

byte-buddy-maven-plugin/README.md

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ The **Byte Buddy Maven Plugin** enables you to apply bytecode enhancements durin
1313
<executions>
1414
<execution>
1515
<goals>
16-
<goal>transform-test</goal>
16+
<goal>transform</goal>
1717
</goals>
1818
</execution>
1919
</executions>
2020
<configuration>
2121
<transformations>
2222
<transformation>
23-
<plugin>com.example.junit.HookInstallingPlugin</plugin>
23+
<groupId>net.bytebuddy</groupId>
24+
<artifactId>byte-buddy</artifactId>
25+
<version>LATEST</version>
26+
<plugin>net.bytebuddy.build.CachedReturnPlugin</plugin>
2427
</transformation>
2528
</transformations>
2629
</configuration>
@@ -29,42 +32,6 @@ The **Byte Buddy Maven Plugin** enables you to apply bytecode enhancements durin
2932
</build>
3033
```
3134

32-
This `byte-buddy-maven-plugin` element informs Maven to transform all test classes by the `transform-test` goal using the transformation specified by **HookInstallingPlugin**. Alternatively, the plugin can instrument production classes using the `transform` goal.
35+
This example transformation uses a standard plugin that is shipped with Byte Buddy, which caches any method return value if annotated by `CachedReturnPlugin.Enhance`. The plugin in the example is applied onto the main source set, test classes can be transformed by specifying the *transform-test* goal. Custom plugins must implement Byte Buddy's `Plugin` interface where the plugin's location is specified by Maven artifact coordinates as shown in the example. The coordinates can be dropped if the plugin is contained within the transformed artifact itself.
3336

34-
###### HookInstallingPlugin.java
35-
```java
36-
package com.example.junit;
37-
38-
import static net.bytebuddy.matcher.ElementMatchers.*;
39-
40-
import org.junit.After;
41-
import org.junit.AfterClass;
42-
import org.junit.Before;
43-
import org.junit.BeforeClass;
44-
import org.junit.Test;
45-
46-
import net.bytebuddy.build.Plugin;
47-
import net.bytebuddy.description.type.TypeDescription;
48-
import net.bytebuddy.dynamic.DynamicType.Builder;
49-
import net.bytebuddy.implementation.MethodDelegation;
50-
51-
public class HookInstallingPlugin implements Plugin {
52-
53-
@Override
54-
public boolean matches(TypeDescription target) {
55-
return target.getName().endsWith("Test");
56-
}
57-
58-
@Override
59-
public Builder<?> apply(Builder<?> builder, TypeDescription typeDescription) {
60-
return builder.method(isAnnotatedWith(anyOf(Test.class, Before.class, After.class))
61-
.or(isStatic().and(isAnnotatedWith(anyOf(BeforeClass.class, AfterClass.class)))))
62-
.intercept(MethodDelegation.to(SampleInterceptor.class))
63-
.implement(Hooked.class);
64-
}
65-
}
66-
```
67-
68-
This example transformation specifies that Byte Buddy should install a method interceptor (defined by **SampleInterceptor**) on all test classes with a name ending with `Test`. The interceptor is added to all methods with the annotations **`@Test`**, **`@Before`**, **`@After`**, **`@BeforeClass`**, or **`@AfterClass`**. This transformation also adds a marker interface **Hooked** so that we can identify enhanced classes at runtime.
69-
70-
A plugin can declare a constructor that can take arguments of type `File`, `BuildLogger` or a Maven-specific `Log` where the class file root directory or an appropriate logger is provided. It is also possible to supply an argument explicitly by specifying an argument in the plugin configuration.
37+
A custom can declare a constructor that can take arguments of type `File`, `BuildLogger` or a Gradle-specific `Logger` where the class file root directory or an appropriate logger is provided. It is also possible to supply an argument explicitly by specifying an argument in the plugin configuration.

0 commit comments

Comments
 (0)