@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2012 - 2020 the original author or authors .
* Copyright 2012 - 2021 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -21,9 +21,11 @@ import java.net.URL;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Iterator ;
import java.util.Iterator ;
import java.util.List ;
import java.util.List ;
import java.util.jar.Attributes ;
import java.util.jar.Manifest ;
import java.util.jar.Manifest ;
import org.springframework.boot.loader.archive.Archive ;
import org.springframework.boot.loader.archive.Archive ;
import org.springframework.boot.loader.archive.ExplodedArchive ;
/ * *
/ * *
* Base class for executable archive { @link Launcher } s .
* Base class for executable archive { @link Launcher } s .
@ -31,6 +33,7 @@ import org.springframework.boot.loader.archive.Archive;
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Madhura Bhave
* @author Madhura Bhave
* @author Scott Frederick
* @since 1 . 0 . 0
* @since 1 . 0 . 0
* /
* /
public abstract class ExecutableArchiveLauncher extends Launcher {
public abstract class ExecutableArchiveLauncher extends Launcher {
@ -39,6 +42,8 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
protected static final String BOOT_CLASSPATH_INDEX_ATTRIBUTE = "Spring-Boot-Classpath-Index" ;
protected static final String BOOT_CLASSPATH_INDEX_ATTRIBUTE = "Spring-Boot-Classpath-Index" ;
protected static final String DEFAULT_CLASSPATH_INDEX_FILE_NAME = "classpath.idx" ;
private final Archive archive ;
private final Archive archive ;
private final ClassPathIndexFile classPathIndex ;
private final ClassPathIndexFile classPathIndex ;
@ -64,9 +69,21 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
}
}
protected ClassPathIndexFile getClassPathIndex ( Archive archive ) throws IOException {
protected ClassPathIndexFile getClassPathIndex ( Archive archive ) throws IOException {
// Only needed for exploded archives, regular ones already have a defined order
if ( archive instanceof ExplodedArchive ) {
String location = getClassPathIndexFileLocation ( archive ) ;
return ClassPathIndexFile . loadIfPossible ( archive . getUrl ( ) , location ) ;
}
return null ;
return null ;
}
}
private String getClassPathIndexFileLocation ( Archive archive ) throws IOException {
Manifest manifest = archive . getManifest ( ) ;
Attributes attributes = ( manifest ! = null ) ? manifest . getMainAttributes ( ) : null ;
String location = ( attributes ! = null ) ? attributes . getValue ( BOOT_CLASSPATH_INDEX_ATTRIBUTE ) : null ;
return ( location ! = null ) ? location : getArchiveEntryPathPrefix ( ) + DEFAULT_CLASSPATH_INDEX_FILE_NAME ;
}
@Override
@Override
protected String getMainClass ( ) throws Exception {
protected String getMainClass ( ) throws Exception {
Manifest manifest = this . archive . getManifest ( ) ;
Manifest manifest = this . archive . getManifest ( ) ;
@ -133,8 +150,11 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
* @since 2 . 3 . 0
* @since 2 . 3 . 0
* /
* /
protected boolean isSearchCandidate ( Archive . Entry entry ) {
protected boolean isSearchCandidate ( Archive . Entry entry ) {
if ( getArchiveEntryPathPrefix ( ) = = null ) {
return true ;
return true ;
}
}
return entry . getName ( ) . startsWith ( getArchiveEntryPathPrefix ( ) ) ;
}
/ * *
/ * *
* Determine if the specified entry is a nested item that should be added to the
* Determine if the specified entry is a nested item that should be added to the
@ -166,6 +186,14 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
protected void postProcessClassPathArchives ( List < Archive > archives ) throws Exception {
protected void postProcessClassPathArchives ( List < Archive > archives ) throws Exception {
}
}
/ * *
* Return the path prefix for entries in the archive .
* @return the path prefix
* /
protected String getArchiveEntryPathPrefix ( ) {
return null ;
}
@Override
@Override
protected boolean isExploded ( ) {
protected boolean isExploded ( ) {
return this . archive . isExploded ( ) ;
return this . archive . isExploded ( ) ;