Skip to content

Commit 0aa3c25

Browse files
authored
Refresh component (#31)
1 parent b0dda73 commit 0aa3c25

9 files changed

Lines changed: 120 additions & 208 deletions

File tree

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
target
2+
3+
# mvn hpi:run
4+
work
5+
6+
# IntelliJ IDEA project files
27
*.iml
3-
*.ipr
48
*.iws
9+
*.ipr
10+
.idea
11+
12+
# Eclipse project files
13+
.settings
14+
.classpath
15+
.project

.mvn/extensions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
2+
<extension>
3+
<groupId>io.jenkins.tools.incrementals</groupId>
4+
<artifactId>git-changelist-maven-extension</artifactId>
5+
<version>1.4</version>
6+
</extension>
7+
</extensions>

.mvn/maven.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-Pconsume-incrementals
2+
-Pmight-produce-incrementals

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ When you are writing a library, there are various restrictions about the kind of
44

55
One such restriction is an inability to restrict the return type. Say in v1 of your library you had the following code:
66

7-
```
7+
```java
88
public Foo getFoo() {
99
return new Foo();
1010
}
1111
```
1212

1313
In v2, say if you introduce a subtype of `Foo` called `FooSubType`, and you want to change the getFoo method to return `FooSubType`.
1414

15-
```
15+
```java
1616
public FooSubType getFoo() {
1717
return new FooSubType();
1818
}
1919
```
2020

2121
But if you do this, you break the binary compatibility. The clients need to be recompiled to be able to work with the new signature. This is where this bridge method injector can help. By adding an annotation like the following:
2222

23-
```
23+
```java
2424
@WithBridgeMethods(Foo.class)
2525
public FooSubType getFoo() {
2626
return new FooSubType();
@@ -29,7 +29,7 @@ public FooSubType getFoo() {
2929

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

32-
```
32+
```java
3333
// your original definition
3434
@WithBridgeMethods(Foo.class)
3535
public FooSubType getFoo() {
@@ -54,7 +54,7 @@ In some cases, it's convenient to widen the return type of a method. As this is
5454
you as a programmer explicitly need to tell us that you know what you are doing by adding
5555
`castRequired` to the annotation. For example, suppose that v1 had a method:
5656

57-
```
57+
```java
5858
public <T extends FooSubType> createFoo(Class<T> clazz) {
5959
return clazz.newInstance();
6060
}
@@ -63,15 +63,15 @@ public <T extends FooSubType> createFoo(Class<T> clazz) {
6363
and in v2 you wanted to widen this method to. Note that you can prove that this is still type-safe, while
6464
your compile cannot:
6565

66-
```
66+
```java
6767
public <T extends Foo> createFoo(Class<T> clazz) {
6868
return clazz.newInstance();
6969
}
7070
```
7171

7272
The annotation to provide backwards compatibility would be:
7373

74-
```
74+
```java
7575
@WithBridgeMethods(value=FooSubType.class, castRequired=true)
7676
public <T extends Foo> createFoo(Class<T> clazz) {
7777
return clazz.newInstance();
@@ -80,7 +80,7 @@ public <T extends Foo> createFoo(Class<T> clazz) {
8080

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

83-
```
83+
```java
8484
// your original definition
8585
@WithBridgeMethods(value=FooSubType.class, castRequired=true)
8686
public <T extends Foo> createFoo(Class<T> clazz) {
@@ -108,23 +108,23 @@ Add the following dependency in your POM. (This dependency is not needed at runt
108108
for compilation of source code that transitively depend on this, so it is the simplest to just treat
109109
this like a regular library dependency)
110110

111-
```
111+
```xml
112112
<dependency>
113113
<groupId>com.infradna.tool</groupId>
114114
<artifactId>bridge-method-annotation</artifactId>
115-
<version>1.12</version>
115+
<version>1.24</version>
116116
</dependency>
117117
```
118118

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

121-
```
121+
```xml
122122
<build>
123123
<plugins>
124124
<plugin>
125125
<groupId>com.infradna.tool</groupId>
126126
<artifactId>bridge-method-injector</artifactId>
127-
<version>1.4</version>
127+
<version>1.24</version>
128128
<executions>
129129
<execution>
130130
<goals>

annotation/pom.xml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<parent>
45
<groupId>com.infradna.tool</groupId>
56
<artifactId>bridge-method-injector-parent</artifactId>
6-
<version>1.25-SNAPSHOT</version>
7-
<relativePath>../pom.xml</relativePath>
7+
<version>${revision}${changelist}</version>
88
</parent>
99
<artifactId>bridge-method-annotation</artifactId>
1010
<name>Bridge method injection annotations</name>
@@ -13,14 +13,7 @@
1313
<dependency>
1414
<groupId>org.jenkins-ci</groupId>
1515
<artifactId>annotation-indexer</artifactId>
16-
<version>1.15</version>
16+
<version>1.16</version>
1717
</dependency>
1818
</dependencies>
19-
20-
<repositories>
21-
<repository>
22-
<id>Jenkins-CI</id>
23-
<url>http://repo.jenkins-ci.org/releases/</url>
24-
</repository>
25-
</repositories>
2619
</project>

injector/pom.xml

Lines changed: 46 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<parent>
45
<groupId>com.infradna.tool</groupId>
56
<artifactId>bridge-method-injector-parent</artifactId>
6-
<version>1.25-SNAPSHOT</version>
7-
<relativePath>../pom.xml</relativePath>
7+
<version>${revision}${changelist}</version>
88
</parent>
99
<artifactId>bridge-method-injector</artifactId>
1010
<packaging>maven-plugin</packaging>
@@ -14,34 +14,17 @@
1414

1515
<properties>
1616
<asm.version>9.4</asm.version>
17+
<maven-plugin-tools.version>3.7.0</maven-plugin-tools.version>
18+
<!-- TODO fix violations -->
19+
<spotbugs.threshold>High</spotbugs.threshold>
1720
</properties>
1821

1922
<build>
2023
<plugins>
2124
<plugin>
2225
<groupId>org.apache.maven.plugins</groupId>
2326
<artifactId>maven-plugin-plugin</artifactId>
24-
<version>3.6.0</version>
25-
</plugin>
26-
<plugin>
27-
<artifactId>maven-compiler-plugin</artifactId>
28-
<version>3.8.1</version>
29-
<configuration>
30-
<source>1.8</source>
31-
<target>1.8</target>
32-
</configuration>
33-
</plugin>
34-
<plugin>
35-
<groupId>org.apache.maven.plugins</groupId>
36-
<artifactId>maven-release-plugin</artifactId>
37-
<version>2.0</version>
38-
<dependencies>
39-
<dependency>
40-
<groupId>org.apache.maven.scm</groupId>
41-
<artifactId>maven-scm-provider-gitexe</artifactId>
42-
<version>1.2</version>
43-
</dependency>
44-
</dependencies>
27+
<version>${maven-plugin-tools.version}</version>
4528
</plugin>
4629
<plugin>
4730
<artifactId>maven-antrun-plugin</artifactId>
@@ -52,25 +35,26 @@
5235
</goals>
5336
<phase>test</phase>
5437
<configuration>
55-
<tasks>
38+
<target>
5639
<delete dir="target/test-classes" />
5740
<mkdir dir="target/test-classes/v1" />
5841
<mkdir dir="target/test-classes/v2" />
5942
<mkdir dir="target/test-classes/client" />
6043
<mkdir dir="target/test-classes/synthetics" />
6144

6245
<!-- basic sanity. unmodified client and v1 should work as expected -->
63-
<javac source="8" target="8" srcdir="src/test/v1" destdir="target/test-classes/v1" />
64-
<javac source="8" target="8" srcdir="src/test/client" destdir="target/test-classes/client" classpath="target/test-classes/v1" />
65-
<java classname="Main" args="foo" failonerror="true">
46+
<javac release="${maven.compiler.release}" srcdir="src/test/v1" destdir="target/test-classes/v1" includeantruntime="false" />
47+
<javac release="${maven.compiler.release}" srcdir="src/test/client" destdir="target/test-classes/client" classpath="target/test-classes/v1" includeantruntime="false" />
48+
<java classname="Main" failonerror="true">
49+
<arg value="foo" />
6650
<classpath>
6751
<pathelement path="target/test-classes/v1" />
6852
<pathelement path="target/test-classes/client" />
6953
</classpath>
7054
</java>
7155

7256
<!-- compile v2 -->
73-
<javac source="8" target="8" srcdir="src/test/v2" destdir="target/test-classes/v2" classpath="${maven.compile.classpath}">
57+
<javac release="${maven.compiler.release}" srcdir="src/test/v2" destdir="target/test-classes/v2" classpath="${maven.compile.classpath}" includeantruntime="false">
7458
<compilerarg value="-XprintProcessorInfo" />
7559
<classpath>
7660
<pathelement path="target/classes" />
@@ -79,20 +63,22 @@
7963
</javac>
8064

8165
<!-- post process v2 -->
82-
<java classname="com.infradna.tool.bridge_method_injector.MethodInjector" args="${project.basedir}/target/test-classes/v2" failonerror="true">
66+
<java classname="com.infradna.tool.bridge_method_injector.MethodInjector" failonerror="true">
67+
<arg value="${project.basedir}/target/test-classes/v2" />
8368
<classpath refid="maven.compile.classpath" />
8469
</java>
8570

8671
<!-- verify that unmodified client code continue to work with v2 binary -->
87-
<java classname="Main" args="bar" failonerror="true">
72+
<java classname="Main" failonerror="true">
73+
<arg value="bar" />
8874
<classpath>
8975
<pathelement path="target/test-classes/v2" />
9076
<pathelement path="target/test-classes/client" />
9177
</classpath>
9278
</java>
9379

9480
<!-- compile synthetics -->
95-
<javac source="8" target="8" srcdir="src/test/synthetics" destdir="target/test-classes/synthetics" classpath="${maven.compile.classpath}">
81+
<javac release="${maven.compiler.release}" srcdir="src/test/synthetics" destdir="target/test-classes/synthetics" classpath="${maven.compile.classpath}" includeantruntime="false">
9682
<compilerarg value="-XprintProcessorInfo" />
9783
<classpath>
9884
<pathelement path="target/classes" />
@@ -101,75 +87,52 @@
10187
</javac>
10288

10389
<!-- post process synthetics -->
104-
<java classname="com.infradna.tool.bridge_method_injector.MethodInjector" args="${project.basedir}/target/test-classes/synthetics" failonerror="true">
90+
<java classname="com.infradna.tool.bridge_method_injector.MethodInjector" failonerror="true">
91+
<arg value="${project.basedir}/target/test-classes/synthetics" />
10592
<classpath refid="maven.compile.classpath" />
10693
</java>
10794

10895
<!-- was testing source compatibility, but with widening change it won't work anymore -->
10996
<!--
11097
<mkdir dir="target/test-classes/client-on-v2" />
111-
<javac source="8" target="8" srcdir="src/test/client" destdir="target/test-classes/client-on-v2">
98+
<javac release="${maven.compiler.release}" srcdir="src/test/client" destdir="target/test-classes/client-on-v2" includeantruntime="false">
11299
<classpath>
113100
<pathelement path="target/test-classes/v2" />
114101
</classpath>
115102
</javac>
116-
<java classname="Main" args="bar" failonerror="true">
103+
<java classname="Main" failonerror="true">
104+
<arg value="bar" />
117105
<classpath>
118106
<pathelement path="target/test-classes/v2" />
119107
<pathelement path="target/test-classes/client-on-v2" />
120108
</classpath>
121109
</java>
122110
-->
123-
</tasks>
111+
</target>
124112
</configuration>
125113
</execution>
126114
</executions>
127-
<dependencies>
128-
<dependency>
129-
<groupId>com.sun</groupId>
130-
<artifactId>tools</artifactId>
131-
<version>1.8</version>
132-
<scope>system</scope>
133-
<systemPath>${java.home}/../lib/tools.jar</systemPath>
134-
</dependency>
135-
</dependencies>
136115
</plugin>
137116
</plugins>
138-
<extensions>
139-
<extension>
140-
<groupId>org.jvnet.wagon-svn</groupId>
141-
<artifactId>wagon-svn</artifactId>
142-
<version>1.9</version>
143-
</extension>
144-
</extensions>
145117
</build>
146118

147-
<scm>
148-
<connection>scm:git:git@github.com:infradna/bridge-method-injector.git</connection>
149-
<tag>HEAD</tag>
150-
</scm>
151-
152-
<developers>
153-
<developer>
154-
<id>kohsuke</id>
155-
<name>Kohsuke Kawaguchi</name>
156-
</developer>
157-
</developers>
158-
159-
<licenses>
160-
<license>
161-
<name>MIT License</name>
162-
<distribution>repository</distribution>
163-
<url>http://www.opensource.org/licenses/mit-license.php</url>
164-
</license>
165-
</licenses>
166-
167119
<dependencies>
168120
<dependency>
169121
<groupId>${project.groupId}</groupId>
170122
<artifactId>bridge-method-annotation</artifactId>
171123
<version>${project.version}</version>
172124
</dependency>
125+
<dependency>
126+
<groupId>com.github.spotbugs</groupId>
127+
<artifactId>spotbugs-annotations</artifactId>
128+
<optional>true</optional>
129+
<exclusions>
130+
<exclusion>
131+
<groupId>com.google.code.findbugs</groupId>
132+
<artifactId>jsr305</artifactId>
133+
</exclusion>
134+
</exclusions>
135+
</dependency>
173136
<dependency>
174137
<groupId>org.ow2.asm</groupId>
175138
<artifactId>asm</artifactId>
@@ -180,17 +143,23 @@
180143
<artifactId>asm-commons</artifactId>
181144
<version>${asm.version}</version>
182145
</dependency>
146+
<dependency>
147+
<groupId>org.apache.maven</groupId>
148+
<artifactId>maven-plugin-api</artifactId>
149+
<version>3.8.6</version>
150+
<scope>provided</scope>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.apache.maven.plugin-tools</groupId>
154+
<artifactId>maven-plugin-annotations</artifactId>
155+
<version>${maven-plugin-tools.version}</version>
156+
<scope>provided</scope>
157+
</dependency>
183158
<dependency>
184159
<groupId>junit</groupId>
185160
<artifactId>junit</artifactId>
186-
<version>4.13.1</version>
187161
<scope>test</scope>
188162
</dependency>
189-
<dependency>
190-
<groupId>org.apache.maven</groupId>
191-
<artifactId>maven-plugin-api</artifactId>
192-
<version>2.0.1</version>
193-
</dependency>
194163
</dependencies>
195164

196165
</project>

0 commit comments

Comments
 (0)