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

Begin migration to Jakarta Annotations #320

Merged
merged 2 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!--
For compatibility only. TODO once plugins have migrated to Jakarta Annotations,
this dependency can be dropped.
-->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.kohsuke.stapler;

import jakarta.annotation.PostConstruct;
import net.sf.json.JSONObject;

import javax.annotation.PostConstruct;
import java.beans.Introspector;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/kohsuke/stapler/MetaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
package org.kohsuke.stapler;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.PostConstruct;
import net.sf.json.JSONArray;
import org.apache.commons.io.IOUtils;
import org.kohsuke.stapler.bind.JavaScriptMethod;
import org.kohsuke.stapler.lang.FieldRef;
import org.kohsuke.stapler.lang.Klass;
import org.kohsuke.stapler.lang.MethodRef;

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -601,7 +601,7 @@ public SingleLinkedList<MethodRef> getPostConstructMethods() {
SingleLinkedList<MethodRef> l = baseClass==null ? SingleLinkedList.empty() : baseClass.getPostConstructMethods();

for (MethodRef mr : klass.getDeclaredMethods()) {
if (mr.hasAnnotation(PostConstruct.class)) {
if (mr.hasAnnotation(PostConstruct.class) || mr.hasAnnotation(javax.annotation.PostConstruct.class)) {
l = l.grow(mr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void flush() throws IOException {

private void flushOutput() throws IOException {
writer.write(out.array(),0,out.position());
out.clear();
// Downcasting to Buffer is needed to avoid NoSuchMethodError errors because Java 11 uses covariance in the ByteBuffer return type.
((Buffer) out).clear();
}

@Override
Expand All @@ -96,7 +97,8 @@ public void close() throws IOException {
flushOutput();
writer.close();

buf.rewind();
// Downcasting to Buffer is needed to avoid NoSuchMethodError errors because Java 11 uses covariance in the ByteBuffer return type.
((Buffer) buf).rewind();
}

/**
Expand All @@ -111,7 +113,8 @@ public void close() throws IOException {
* if true, tell the decoder that all the input bytes are ready.
*/
private void decode(boolean last) throws IOException {
buf.flip();
// Downcasting to Buffer is needed to avoid NoSuchMethodError errors because Java 11 uses covariance in the ByteBuffer return type.
((Buffer) buf).flip();
while(true) {
CoderResult r = decoder.decode(buf, out, last);
if(r==CoderResult.OVERFLOW) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.kohsuke.stapler;

import jakarta.annotation.PostConstruct;
import junit.framework.TestCase;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.annotation.PostConstruct;
import java.lang.reflect.Type;
import java.net.Proxy;
import java.util.ArrayList;
Expand Down