jars) throws IOException {
return (BootJarOperation) super.launcherJars(jars);
}
/**
* Provides the fully-qualified main class name.
*/
public BootJarOperation mainClass(String className) {
return (BootJarOperation) super.mainClass(className);
}
/**
* Provides an attribute to put in the JAR manifest.
*
* @param name the attribute name to put in the manifest
* @param value the attribute value to put in the manifest
* @return this operation instance
*/
@Override
public BootJarOperation manifestAttribute(String name, String value) {
return (BootJarOperation) super.manifestAttribute(name, value);
}
/**
* Provides a map of attributes to put in the jar manifest.
*
* A copy will be created to allow this map to be independently modifiable.
*
* @param attributes the attributes to put in the manifest
* @return this operation instance
*/
@Override
public BootJarOperation manifestAttributes(Collection attributes) {
return (BootJarOperation) super.manifestAttributes(attributes);
}
/**
* Provides the bld project.
*/
@Override
public BootJarOperation project(Project project) {
return (BootJarOperation) super.project(project);
}
/**
* Provides source directories that will be used for the jar archive creation.
*
* @param directories source directories
* @return this operation instance
*/
@Override
public BootJarOperation sourceDirectories(File... directories) {
return (BootJarOperation) super.sourceDirectories(directories);
}
/**
* Performs the BootJar operation.
*/
@Override
public void execute() throws Exception {
verifyExecute();
var staging_dir = Files.createTempDirectory("bootjar").toFile();
try {
var boot_inf_dir = executeCreateBootInfDirectory(staging_dir);
executeCopyInfClassesFiles(boot_inf_dir);
executeCopyInfLibs(boot_inf_dir);
executeCopyBootLoader(staging_dir);
executeCreateArchive(staging_dir, LOGGER);
if (!silent() && LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(String.format("The executable JAR (%s) was created in: %s%n", destinationArchiveFileName(),
destinationDirectory()));
}
} finally {
FileUtils.deleteDirectory(staging_dir);
}
}
/**
* Part of the {@link #execute} operation, creates the {@code BOOT-INF} staging directory.
*/
protected File executeCreateBootInfDirectory(File stagingDirectory) throws IOException {
var boot_inf = new File(stagingDirectory, "BOOT-INF");
mkDirs(boot_inf);
return boot_inf;
}
/**
* Configures the operation from a {@link Project}.
*/
public BootJarOperation fromProject(Project project) throws IOException {
project(project);
mainClass(project.mainClass());
return destinationDirectory(project.buildDistDirectory())
.destinationArchiveFileName(project.archiveBaseName() + "-" + project.version() + "-boot.jar")
.infLibs(project.compileClasspathJars())
.infLibs(project.runtimeClasspathJars())
.launcherClass("org.springframework.boot.loader.JarLauncher")
.launcherJars(project.standaloneClasspathJars())
.manifestAttributes(
List.of(
new BootManifestAttribute("Manifest-Version", "1.0"),
new BootManifestAttribute("Main-Class", launcherClass()),
new BootManifestAttribute("Start-Class", mainClass()))
)
.sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory());
}
}