Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #41

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# What's this?
# Bridge Method Injector

## What's this?

When you are writing a library, there are various restrictions about the kind of changes you can make, in order to maintain binary compatibility.

Expand Down Expand Up @@ -27,7 +29,7 @@ public FooSubType getFoo() {
}
```

... and running the bytecode post processor, your class file will get the additional "bridge methods." In pseudo-code, it'll look like this:
... and running the bytecode post processor, your class file will get the additional "bridge methods." In pseudocode, it'll look like this:

```java
// your original definition
Expand All @@ -47,7 +49,7 @@ Such code isn't allowed in Java source files, but class files allow that. With t

In this way, you can evolve your classes more easily without breaking backward compatibility.

# Widening the return type
## Widening the return type

In some cases, it's convenient to widen the return type of a method. As this is potentially a type-unsafe change
(as the callee can return a type that's not assignable to what the caller expects), so
Expand Down Expand Up @@ -78,7 +80,7 @@ public <T extends Foo> createFoo(Class<T> clazz) {
}
```

Running the bytecode post processor, the resulting class file will look like the following pseudo-code:
Running the bytecode post processor, the resulting class file will look like the following pseudocode:

```java
// your original definition
Expand All @@ -95,45 +97,64 @@ public FooSubType createFoo(Class clazz) {
}
```

# Bridge Methods and Interfaces
## Bridge methods and interfaces

You can use `@WithBridgeMethods` with interfaces, too. However, making this work correctly is tricky,
as you have to ensure that bridge methods are implemented on all the classes that implement the interface,
for example by adding `@WithBridgeMethods` on every implementation of the method in question,
or by introducing a base class that provides a bridge method.

# Integration into Your Build
See the Javadoc for more details:

- [`bridge-method-annotation`](https://javadoc.jenkins.io/component/bridge-method-annotation/)
- [`bridge-method-injector`](https://javadoc.jenkins.io/component/bridge-method-injector/)

## Maven repository

Starting with 1.25, this library is published at:

```xml
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/releases/</url>
</repository>
```

## Java support

Starting with 1.25, this library requires Java 11 or newer.

## Integration into your build

Add the following dependency in your POM. (This dependency is not needed at runtime, but it is necessary
for compilation of source code that transitively depend on this, so it is the simplest to just treat
this like a regular library dependency)

```xml
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
<version>1.24</version>
</dependency>
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
<version>1.25</version>
</dependency>
```

Then put the following fragment in your build to have the byte-code post processor kick in to inject the necessary bridge methods.
Then put the following fragment in your build to have the byte-code post processor kick in to inject the necessary bridge methods.

```xml
<build>
<plugins>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.24</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.25</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```