@ -36,6 +36,8 @@ import java.util.Set;
@@ -36,6 +36,8 @@ import java.util.Set;
import java.util.jar.JarEntry ;
import java.util.jar.JarFile ;
import org.jspecify.annotations.Nullable ;
import org.springframework.asm.AnnotationVisitor ;
import org.springframework.asm.ClassReader ;
import org.springframework.asm.ClassVisitor ;
@ -80,7 +82,7 @@ public abstract class MainClassFinder {
@@ -80,7 +82,7 @@ public abstract class MainClassFinder {
* @return the main class or { @code null }
* @throws IOException if the directory cannot be read
* /
public static String findMainClass ( File rootDirectory ) throws IOException {
public static @Nullable String findMainClass ( File rootDirectory ) throws IOException {
return doWithMainClasses ( rootDirectory , MainClass : : getName ) ;
}
@ -90,7 +92,7 @@ public abstract class MainClassFinder {
@@ -90,7 +92,7 @@ public abstract class MainClassFinder {
* @return the main class or { @code null }
* @throws IOException if the directory cannot be read
* /
public static String findSingleMainClass ( File rootDirectory ) throws IOException {
public static @Nullable String findSingleMainClass ( File rootDirectory ) throws IOException {
return findSingleMainClass ( rootDirectory , null ) ;
}
@ -104,7 +106,8 @@ public abstract class MainClassFinder {
@@ -104,7 +106,8 @@ public abstract class MainClassFinder {
* @return the main class or { @code null }
* @throws IOException if the directory cannot be read
* /
public static String findSingleMainClass ( File rootDirectory , String annotationName ) throws IOException {
public static @Nullable String findSingleMainClass ( File rootDirectory , @Nullable String annotationName )
throws IOException {
SingleMainClassCallback callback = new SingleMainClassCallback ( annotationName ) ;
MainClassFinder . doWithMainClasses ( rootDirectory , callback ) ;
return callback . getMainClassName ( ) ;
@ -119,7 +122,7 @@ public abstract class MainClassFinder {
@@ -119,7 +122,7 @@ public abstract class MainClassFinder {
* @return the first callback result or { @code null }
* @throws IOException in case of I / O errors
* /
static < T > T doWithMainClasses ( File rootDirectory , MainClassCallback < T > callback ) throws IOException {
static < T > @Nullable T doWithMainClasses ( File rootDirectory , MainClassCallback < T > callback ) throws IOException {
if ( ! rootDirectory . exists ( ) ) {
return null ; // nothing to do
}
@ -165,7 +168,7 @@ public abstract class MainClassFinder {
@@ -165,7 +168,7 @@ public abstract class MainClassFinder {
* @return the main class or { @code null }
* @throws IOException if the jar file cannot be read
* /
public static String findMainClass ( JarFile jarFile , String classesLocation ) throws IOException {
public static @Nullable String findMainClass ( JarFile jarFile , String classesLocation ) throws IOException {
return doWithMainClasses ( jarFile , classesLocation , MainClass : : getName ) ;
}
@ -176,7 +179,7 @@ public abstract class MainClassFinder {
@@ -176,7 +179,7 @@ public abstract class MainClassFinder {
* @return the main class or { @code null }
* @throws IOException if the jar file cannot be read
* /
public static String findSingleMainClass ( JarFile jarFile , String classesLocation ) throws IOException {
public static @Nullable String findSingleMainClass ( JarFile jarFile , String classesLocation ) throws IOException {
return findSingleMainClass ( jarFile , classesLocation , null ) ;
}
@ -191,8 +194,8 @@ public abstract class MainClassFinder {
@@ -191,8 +194,8 @@ public abstract class MainClassFinder {
* @return the main class or { @code null }
* @throws IOException if the jar file cannot be read
* /
public static String findSingleMainClass ( JarFile jarFile , String classesLocation , String annotationName )
throws IOException {
public static @Nullable String findSingleMainClass ( JarFile jarFile , String classesLocation ,
@Nullable String annotationName ) throws IOException {
SingleMainClassCallback callback = new SingleMainClassCallback ( annotationName ) ;
MainClassFinder . doWithMainClasses ( jarFile , classesLocation , callback ) ;
return callback . getMainClassName ( ) ;
@ -207,7 +210,7 @@ public abstract class MainClassFinder {
@@ -207,7 +210,7 @@ public abstract class MainClassFinder {
* @return the first callback result or { @code null }
* @throws IOException in case of I / O errors
* /
static < T > T doWithMainClasses ( JarFile jarFile , String classesLocation , MainClassCallback < T > callback )
static < T > @Nullable T doWithMainClasses ( JarFile jarFile , String classesLocation , MainClassCallback < T > callback )
throws IOException {
List < JarEntry > classEntries = getClassEntries ( jarFile , classesLocation ) ;
classEntries . sort ( new ClassEntryComparator ( ) ) ;
@ -226,7 +229,7 @@ public abstract class MainClassFinder {
@@ -226,7 +229,7 @@ public abstract class MainClassFinder {
return null ;
}
private static String convertToClassName ( String name , String prefix ) {
private static String convertToClassName ( String name , @Nullable String prefix ) {
name = name . replace ( '/' , '.' ) ;
name = name . replace ( '\\' , '.' ) ;
name = name . substring ( 0 , name . length ( ) - DOT_CLASS . length ( ) ) ;
@ -236,7 +239,7 @@ public abstract class MainClassFinder {
@@ -236,7 +239,7 @@ public abstract class MainClassFinder {
return name ;
}
private static List < JarEntry > getClassEntries ( JarFile source , String classesLocation ) {
private static List < JarEntry > getClassEntries ( JarFile source , @Nullable String classesLocation ) {
classesLocation = ( classesLocation ! = null ) ? classesLocation : "" ;
Enumeration < JarEntry > sourceEntries = source . entries ( ) ;
List < JarEntry > classEntries = new ArrayList < > ( ) ;
@ -249,7 +252,7 @@ public abstract class MainClassFinder {
@@ -249,7 +252,7 @@ public abstract class MainClassFinder {
return classEntries ;
}
private static ClassDescriptor createClassDescriptor ( InputStream inputStream ) {
private static @Nullable ClassDescriptor createClassDescriptor ( InputStream inputStream ) {
try {
ClassReader classReader = new ClassReader ( inputStream ) ;
ClassDescriptor classDescriptor = new ClassDescriptor ( ) ;
@ -291,13 +294,14 @@ public abstract class MainClassFinder {
@@ -291,13 +294,14 @@ public abstract class MainClassFinder {
}
@Override
public AnnotationVisitor visitAnnotation ( String desc , boolean visible ) {
public @Nullable AnnotationVisitor visitAnnotation ( String desc , boolean visible ) {
this . annotationNames . add ( Type . getType ( desc ) . getClassName ( ) ) ;
return null ;
}
@Override
public MethodVisitor visitMethod ( int access , String name , String desc , String signature , String [ ] exceptions ) {
public @Nullable MethodVisitor visitMethod ( int access , String name , String desc , String signature ,
String [ ] exceptions ) {
if ( isAccess ( access , Opcodes . ACC_PUBLIC , Opcodes . ACC_STATIC ) & & MAIN_METHOD_NAME . equals ( name )
& & MAIN_METHOD_TYPE . getDescriptor ( ) . equals ( desc ) ) {
this . mainMethodFound = true ;
@ -336,7 +340,7 @@ public abstract class MainClassFinder {
@@ -336,7 +340,7 @@ public abstract class MainClassFinder {
* @param mainClass the main class
* @return a non - null value if processing should end or { @code null } to continue
* /
T doWith ( MainClass mainClass ) ;
@Nullable T doWith ( MainClass mainClass ) ;
}
@ -370,7 +374,7 @@ public abstract class MainClassFinder {
@@ -370,7 +374,7 @@ public abstract class MainClassFinder {
}
@Override
public boolean equals ( Object obj ) {
public boolean equals ( @Nullable Object obj ) {
if ( this = = obj ) {
return true ;
}
@ -404,19 +408,19 @@ public abstract class MainClassFinder {
@@ -404,19 +408,19 @@ public abstract class MainClassFinder {
private final Set < MainClass > mainClasses = new LinkedHashSet < > ( ) ;
private final String annotationName ;
private final @Nullable String annotationName ;
private SingleMainClassCallback ( String annotationName ) {
private SingleMainClassCallback ( @Nullable String annotationName ) {
this . annotationName = annotationName ;
}
@Override
public Object doWith ( MainClass mainClass ) {
public @Nullable Object doWith ( MainClass mainClass ) {
this . mainClasses . add ( mainClass ) ;
return null ;
}
private String getMainClassName ( ) {
private @Nullable String getMainClassName ( ) {
Set < MainClass > matchingMainClasses = new LinkedHashSet < > ( ) ;
if ( this . annotationName ! = null ) {
for ( MainClass mainClass : this . mainClasses ) {