This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 761ccd222e Utility class modernization
761ccd222e is described below
commit 761ccd222ecfb763554e27bc5daf49d3df374eab
Author: James Bognar <[email protected]>
AuthorDate: Thu Nov 6 12:51:45 2025 -0500
Utility class modernization
---
.../apache/juneau/common/reflect/ClassInfo.java | 20 ++------------------
.../java/org/apache/juneau/rest/RestContext.java | 4 ++--
.../java/org/apache/juneau/rest/RestOpContext.java | 2 +-
.../org/apache/juneau/rest/arg/FormDataArg.java | 4 ++--
.../java/org/apache/juneau/rest/arg/HeaderArg.java | 4 ++--
.../java/org/apache/juneau/rest/arg/PathArg.java | 4 ++--
.../java/org/apache/juneau/rest/arg/QueryArg.java | 4 ++--
.../rest/swagger/BasicSwaggerProviderSession.java | 4 ++--
.../reflect/AnnotationInfo_ValueMethods_Test.java | 3 +--
.../juneau/common/reflect/ClassInfo_Test.java | 22 +++++++++++-----------
scripts/build-and-test.py | 15 ++++++++++-----
11 files changed, 37 insertions(+), 49 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
index 7c6a095803..5d4168e5ad 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
@@ -498,22 +498,6 @@ public class ClassInfo extends ElementInfo implements
Annotatable {
return findAnnotation(annotationProvider, type);
}
- /**
- * Finds the annotation of the specified type defined on this class or
parent class/interface.
- *
- * <p>
- * If the annotation cannot be found on the immediate class, searches
methods with the same
- * signature on the parent classes or interfaces.
- * <br>The search is performed in child-to-parent order.
- *
- * @param <A> The annotation type to look for.
- * @param type The annotation to look for.
- * @return The annotation if found, or <jk>null</jk> if not.
- */
- public <A extends Annotation> A getAnnotation(Class<A> type) {
- return getAnnotation(null, type);
- }
-
/**
* Returns the first matching annotation of the specified type defined
on the specified class or parent classes/interfaces in parent-to-child order.
*
@@ -2508,8 +2492,8 @@ public class ClassInfo extends ElementInfo implements
Annotatable {
.filter(m -> {
var rct = m.getReturnType().getComponentType();
if (rct.hasAnnotation(Repeatable.class)) {
- var r =
rct.getAnnotation(Repeatable.class);
- return r.value().equals(c);
+ var r =
rct.getAnnotationInfos(Repeatable.class).findFirst().map(AnnotationInfo::inner).orElse(null);
+ return r != null && r.value().equals(c);
}
return false;
})
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 7195c37b5a..cc7490f82f 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -4585,7 +4585,7 @@ public class RestContext extends Context {
// Also include methods on @Rest-annotated
interfaces.
if (al.isEmpty()) {
- Predicate<MethodInfo>
isRestAnnotatedInterface = x -> x.getDeclaringClass().isInterface() &&
nn(x.getDeclaringClass().getAnnotation(Rest.class));
+ Predicate<MethodInfo>
isRestAnnotatedInterface = x -> x.getDeclaringClass().isInterface() &&
nn(x.getDeclaringClass().getAnnotationInfos(Rest.class).findFirst().map(AnnotationInfo::inner).orElse(null));
mi.getMatching().filter(isRestAnnotatedInterface).forEach(x ->
al.add(AnnotationInfo.of(x, RestOpAnnotation.DEFAULT)));
}
@@ -5975,7 +5975,7 @@ public class RestContext extends Context {
int code = 500;
var ci = ClassInfo.of(e);
- var r = ci.getAnnotation(StatusCode.class);
+ var r =
ci.getAnnotationInfos(StatusCode.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (nn(r))
if (r.value().length > 0)
code = r.value()[0];
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
index 6af71590b6..3007e2eeb7 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
@@ -2456,7 +2456,7 @@ public class RestOpContext extends Context implements
Comparable<RestOpContext>
var c = o.getClass();
var pm = headerPartMetas.get(c);
if (pm == null) {
- var a = c.getAnnotation(Header.class);
+ var a =
ClassInfo.of(c).getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (nn(a)) {
var schema = HttpPartSchema.create(a);
var serializer =
createPartSerializer(schema.getSerializer(), partSerializer);
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/FormDataArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/FormDataArg.java
index 00d986dc4b..6c0b6d9093 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/FormDataArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/FormDataArg.java
@@ -84,7 +84,7 @@ public class FormDataArg implements RestOpArg {
return null;
// Find @Rest annotation on the class
- Rest restAnnotation = declaringClass.getAnnotation(Rest.class);
+ Rest restAnnotation =
declaringClass.getAnnotationInfos(Rest.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (restAnnotation == null)
return null;
@@ -104,7 +104,7 @@ public class FormDataArg implements RestOpArg {
// Get parameter-level @FormData
FormData paramFormData =
opt(pi.findAnnotationInfo(FormData.class)).map(x -> x.inner()).orElse(null);
if (paramFormData == null)
- paramFormData =
pi.getParameterType().getAnnotation(FormData.class);
+ paramFormData =
pi.getParameterType().getAnnotationInfos(FormData.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (paramFormData == null) {
// No parameter-level @FormData, use class-level as-is
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/HeaderArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/HeaderArg.java
index 2ce27d2729..1b46f5779b 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/HeaderArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/HeaderArg.java
@@ -126,7 +126,7 @@ public class HeaderArg implements RestOpArg {
return null;
// Find @Rest annotation on the class
- Rest restAnnotation = declaringClass.getAnnotation(Rest.class);
+ Rest restAnnotation =
declaringClass.getAnnotationInfos(Rest.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (restAnnotation == null)
return null;
@@ -146,7 +146,7 @@ public class HeaderArg implements RestOpArg {
// Get parameter-level @Header
Header paramHeader = opt(pi.findAnnotationInfo(Header.class)).map(x ->
x.inner()).orElse(null);
if (paramHeader == null)
- paramHeader = pi.getParameterType().getAnnotation(Header.class);
+ paramHeader =
pi.getParameterType().getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (paramHeader == null) {
// No parameter-level @Header, use class-level as-is
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/PathArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/PathArg.java
index 67071ab620..ddea81f623 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/PathArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/PathArg.java
@@ -83,7 +83,7 @@ public class PathArg implements RestOpArg {
return null;
// Find @Rest annotation on the class
- Rest restAnnotation = declaringClass.getAnnotation(Rest.class);
+ Rest restAnnotation =
declaringClass.getAnnotationInfos(Rest.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (restAnnotation == null)
return null;
@@ -103,7 +103,7 @@ public class PathArg implements RestOpArg {
// Get parameter-level @Path
Path paramPath = opt(pi.findAnnotationInfo(Path.class)).map(x ->
x.inner()).orElse(null);
if (paramPath == null)
- paramPath = pi.getParameterType().getAnnotation(Path.class);
+ paramPath =
pi.getParameterType().getAnnotationInfos(Path.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (paramPath == null) {
// No parameter-level @Path, use class-level as-is
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/QueryArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/QueryArg.java
index 38630834e5..1a5ed7ac93 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/QueryArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/QueryArg.java
@@ -84,7 +84,7 @@ public class QueryArg implements RestOpArg {
return null;
// Find @Rest annotation on the class
- Rest restAnnotation = declaringClass.getAnnotation(Rest.class);
+ Rest restAnnotation =
declaringClass.getAnnotationInfos(Rest.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (restAnnotation == null)
return null;
@@ -104,7 +104,7 @@ public class QueryArg implements RestOpArg {
// Get parameter-level @Query
Query paramQuery = opt(pi.findAnnotationInfo(Query.class)).map(x ->
x.inner()).orElse(null);
if (paramQuery == null)
- paramQuery = pi.getParameterType().getAnnotation(Query.class);
+ paramQuery =
pi.getParameterType().getAnnotationInfos(Query.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (paramQuery == null) {
// No parameter-level @Query, use class-level as-is
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 38ef44dbcf..5fec4c1807 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -317,7 +317,7 @@ public class BasicSwaggerProviderSession {
op.appendIf(ne, "deprecated",
firstNonEmpty(
resolve(ms.deprecated()),
- (nn(m.getAnnotation(Deprecated.class))
|| nn(m.getDeclaringClass().getAnnotation(Deprecated.class))) ? "true" : null
+ (nn(m.getAnnotation(Deprecated.class))
||
nn(ClassInfo.of(m.getDeclaringClass()).getAnnotationInfos(Deprecated.class).findFirst().map(AnnotationInfo::inner).orElse(null)))
? "true" : null
)
);
op.appendIf(nec, "tags",
@@ -450,7 +450,7 @@ public class BasicSwaggerProviderSession {
MethodInfo ecmi =
methods.get(i);
Header a =
ecmi.getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (a == null)
- a =
ecmi.getReturnType().unwrap(Value.class,
Optional.class).getAnnotation(Header.class);
+ a =
ecmi.getReturnType().unwrap(Value.class,
Optional.class).getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
if (nn(a) && ! isMulti(a)) {
String ha = a.name();
for (var code : codes) {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/AnnotationInfo_ValueMethods_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/AnnotationInfo_ValueMethods_Test.java
index 0299759dbe..74c7377661 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/AnnotationInfo_ValueMethods_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/AnnotationInfo_ValueMethods_Test.java
@@ -56,8 +56,7 @@ public class AnnotationInfo_ValueMethods_Test {
private AnnotationInfo<TestAnnotation> getTestAnnotationInfo() {
var ci = ClassInfo.of(AnnotatedClass.class);
- var annotation = ci.getAnnotation(TestAnnotation.class);
- return AnnotationInfo.of(ci, annotation);
+ return
ci.getAnnotationInfos(TestAnnotation.class).findFirst().orElse(null);
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
index 49a0ff32c7..91d995f108 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
@@ -543,26 +543,26 @@ public class ClassInfo_Test extends TestBase {
static ClassInfo g3=of(G3.class), g4=of(G4.class), g5=of(G5.class);
@Test void getAnnotation() {
- check("@A(7)", g3.getAnnotation(A.class));
- check(null, g3.getAnnotation(B.class));
- check(null, g3.getAnnotation(null));
+ check("@A(7)",
g3.getAnnotationInfos(A.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check(null,
g3.getAnnotationInfos(B.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check(null, null);
}
@Test void getAnnotation_twice() {
- check("@A(7)", g3.getAnnotation(A.class));
- check("@A(7)", g3.getAnnotation(A.class));
+ check("@A(7)",
g3.getAnnotationInfos(A.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check("@A(7)",
g3.getAnnotationInfos(A.class).findFirst().map(AnnotationInfo::inner).orElse(null));
}
@Test void getAnnotation_onParent() {
- check("@A(7)", g4.getAnnotation(A.class));
- check(null, g4.getAnnotation(B.class));
- check(null, g4.getAnnotation(null));
+ check("@A(7)",
g4.getAnnotationInfos(A.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check(null,
g4.getAnnotationInfos(B.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check(null, null);
}
@Test void getAnnotation_onInterface() {
- check("@A(3)", g5.getAnnotation(A.class));
- check(null, g5.getAnnotation(B.class));
- check(null, g5.getAnnotation(null));
+ check("@A(3)",
g5.getAnnotationInfos(A.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check(null,
g5.getAnnotationInfos(B.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+ check(null, null);
}
@Test void hasAnnotation() {
diff --git a/scripts/build-and-test.py b/scripts/build-and-test.py
index cb431100a8..b5bc39bf81 100755
--- a/scripts/build-and-test.py
+++ b/scripts/build-and-test.py
@@ -39,17 +39,22 @@ def run_command(cmd, verbose=False):
result = subprocess.run(cmd, shell=True,
cwd="/Users/james.bognar/git/juneau")
return result.returncode
else:
- # Show only last lines
+ # Run command and capture all output, then show last lines
result = subprocess.run(
- f"{cmd} 2>&1 | tail -50",
+ cmd,
shell=True,
cwd="/Users/james.bognar/git/juneau",
capture_output=True,
text=True
)
- print(result.stdout)
- if result.stderr:
- print(result.stderr, file=sys.stderr)
+ # Combine stdout and stderr
+ output = result.stdout + result.stderr
+ # Show last 50 lines
+ lines = output.splitlines()
+ if len(lines) > 50:
+ print('\n'.join(lines[-50:]))
+ else:
+ print(output)
return result.returncode
def build(verbose=False):