2024-06-23 21:37:24 +01:00
|
|
|
package cc.fascinated.bat;
|
|
|
|
|
2024-06-30 04:13:54 +01:00
|
|
|
import cc.fascinated.bat.config.Config;
|
2024-07-01 01:33:52 +01:00
|
|
|
import cc.fascinated.bat.event.EventListener;
|
|
|
|
import cc.fascinated.bat.service.EventService;
|
2024-06-24 17:42:57 +01:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
2024-06-30 00:35:52 +01:00
|
|
|
import io.mongock.runner.springboot.EnableMongock;
|
2024-07-01 01:33:52 +01:00
|
|
|
import jakarta.annotation.PreDestroy;
|
2024-06-23 21:37:24 +01:00
|
|
|
import lombok.NonNull;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
2024-06-26 12:19:11 +01:00
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
2024-06-23 21:37:24 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2024-06-27 13:00:45 +01:00
|
|
|
@EnableScheduling
|
2024-06-30 05:15:37 +01:00
|
|
|
@SpringBootApplication(scanBasePackages = "cc.fascinated.bat")
|
2024-06-30 00:35:52 +01:00
|
|
|
@EnableMongock
|
2024-06-28 03:01:21 +01:00
|
|
|
@Log4j2(topic = "Bat")
|
2024-06-23 21:37:24 +01:00
|
|
|
public class BatApplication {
|
2024-06-28 03:01:21 +01:00
|
|
|
public static Gson GSON = new GsonBuilder().create();
|
2024-06-24 17:42:57 +01:00
|
|
|
|
2024-06-28 03:01:21 +01:00
|
|
|
@SneakyThrows
|
|
|
|
public static void main(@NonNull String[] args) {
|
|
|
|
// Handle loading of our configuration file
|
|
|
|
File config = new File("application.yml");
|
|
|
|
if (!config.exists()) { // Saving the default config if it doesn't exist locally
|
|
|
|
Files.copy(Objects.requireNonNull(BatApplication.class.getResourceAsStream("/application.yml")), config.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
log.info("Saved the default configuration to '{}', please re-launch the application", // Log the default config being saved
|
|
|
|
config.getAbsolutePath()
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log.info("Found configuration at '{}'", config.getAbsolutePath()); // Log the found config
|
2024-06-23 21:37:24 +01:00
|
|
|
|
2024-06-28 03:01:21 +01:00
|
|
|
// Start the app
|
|
|
|
SpringApplication.run(BatApplication.class, args);
|
2024-06-30 04:13:54 +01:00
|
|
|
|
|
|
|
log.info("APP IS RUNNING IN %s MODE!!!!!!!!!".formatted(Config.isProduction() ? "PRODUCTION" : "DEVELOPMENT"));
|
2024-06-28 03:01:21 +01:00
|
|
|
}
|
2024-07-01 01:33:52 +01:00
|
|
|
|
|
|
|
@PreDestroy
|
|
|
|
public void onShutdown() {
|
|
|
|
log.info("Shutting down...");
|
|
|
|
for (EventListener listener : EventService.LISTENERS) {
|
|
|
|
listener.onSpringShutdown();
|
|
|
|
}
|
|
|
|
}
|
2024-06-23 21:37:24 +01:00
|
|
|
}
|