FindMainClass Class — spring-boot Architecture
Architecture documentation for the FindMainClass class in FindMainClass.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-antlib/src/main/java/org/springframework/boot/ant/FindMainClass.java lines 37–115
public class FindMainClass extends Task {
private static final String SPRING_BOOT_APPLICATION_CLASS_NAME = "org.springframework.boot.autoconfigure.SpringBootApplication";
private @Nullable String mainClass;
private @Nullable File classesRoot;
private @Nullable String property;
public FindMainClass(Project project) {
setProject(project);
}
@Override
public void execute() throws BuildException {
String mainClass = this.mainClass;
if (!StringUtils.hasText(mainClass)) {
mainClass = findMainClass();
if (!StringUtils.hasText(mainClass)) {
throw new BuildException("Could not determine main class given @classesRoot " + this.classesRoot);
}
}
handle(mainClass);
}
private @Nullable String findMainClass() {
if (this.classesRoot == null) {
throw new BuildException("one of @mainClass or @classesRoot must be specified");
}
if (!this.classesRoot.exists()) {
throw new BuildException("@classesRoot " + this.classesRoot + " does not exist");
}
try {
if (this.classesRoot.isDirectory()) {
return MainClassFinder.findSingleMainClass(this.classesRoot, SPRING_BOOT_APPLICATION_CLASS_NAME);
}
return MainClassFinder.findSingleMainClass(new JarFile(this.classesRoot), "/",
SPRING_BOOT_APPLICATION_CLASS_NAME);
}
catch (IOException ex) {
throw new BuildException(ex);
}
}
private void handle(String mainClass) {
if (StringUtils.hasText(this.property)) {
getProject().setProperty(this.property, mainClass);
}
else {
log("Found main class " + mainClass);
}
}
/**
* Set the main class, which will cause the search to be bypassed.
* @param mainClass the main class name
*/
public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}
/**
* Set the root location of classes to be searched.
* @param classesRoot the root location
*/
public void setClassesRoot(File classesRoot) {
this.classesRoot = classesRoot;
}
/**
* Set the ANT property to set (if left unset, result will be printed to the log).
* @param property the ANT property to set
*/
public void setProperty(String property) {
this.property = property;
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free