Split UpdateScheduler functionality into a new ApplicationStartupListener component; relocate configuration classes to model.config package; refine README.md phrasing and structure.
Build and Push Docker Image / build-and-push (push) Successful in 26s

This commit is contained in:
2026-07-12 11:48:21 +02:00
parent 77db44b1f5
commit 11110771a8
9 changed files with 73 additions and 57 deletions
@@ -1,6 +1,6 @@
package codes.thischwa.jdvs.service;
package codes.thischwa.jdvs.config;
import codes.thischwa.jdvs.config.JdvsConfig;
import codes.thischwa.jdvs.model.config.JdvsConfig;
import codes.thischwa.jdvs.jpa.GitRepositoryRepository;
import codes.thischwa.jdvs.model.GitRepository;
import lombok.RequiredArgsConstructor;
@@ -1,4 +1,4 @@
package codes.thischwa.jdvs.config;
package codes.thischwa.jdvs.model.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -1,4 +1,4 @@
package codes.thischwa.jdvs.config;
package codes.thischwa.jdvs.model.config;
import java.util.List;
import lombok.Data;
@@ -1,4 +1,4 @@
package codes.thischwa.jdvs.config;
package codes.thischwa.jdvs.model.config;
import java.util.List;
import java.util.Objects;
@@ -0,0 +1,58 @@
package codes.thischwa.jdvs.service;
import codes.thischwa.jdvs.config.RepoConfigLoader;
import codes.thischwa.jdvs.jpa.GitRepositoryRepository;
import codes.thischwa.jdvs.model.config.JdvsConfig;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
@Slf4j
public class ApplicationStartupListener {
private final GitRepositoryRepository repository;
private final JdvsConfig jdvsConfig;
private final RepoConfigLoader repoConfigLoader;
private final UpdateScheduler updateScheduler;
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady() {
if (jdvsConfig.isCleanOnStart()) {
log.info("'jdvs.clean-on-start' is enabled cleaning base directory and database.");
cleanBaseDir();
repository.deleteAll();
}
repoConfigLoader.loadConfig();
if (jdvsConfig.isRunOnStart()) {
log.info("'jdvs.run-on-start' is enabled running initial update.");
updateScheduler.updateAll();
}
}
private void cleanBaseDir() {
Path baseDir = Path.of(jdvsConfig.getBaseDir());
if (!Files.exists(baseDir)) {
return;
}
try (var stream = Files.walk(baseDir)) {
stream.sorted(Comparator.reverseOrder()).forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
log.warn("Failed to delete path: {}", path, e);
}
});
log.info("Deleted base directory: {}", baseDir);
} catch (IOException e) {
log.error("Failed to walk base directory: {}", baseDir, e);
}
}
}
@@ -1,7 +1,7 @@
package codes.thischwa.jdvs.service;
import codes.thischwa.jdvs.config.JdvsConfig;
import codes.thischwa.jdvs.config.JdvsConfig.RepoConfig;
import codes.thischwa.jdvs.model.config.JdvsConfig;
import codes.thischwa.jdvs.model.config.JdvsConfig.RepoConfig;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
@@ -1,19 +1,12 @@
package codes.thischwa.jdvs.service;
import codes.thischwa.jdvs.config.JdvsConfig;
import codes.thischwa.jdvs.jpa.GitRepositoryRepository;
import codes.thischwa.jdvs.model.GitRepository;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -21,43 +14,9 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
@Slf4j
public class UpdateScheduler {
private final GitRepositoryRepository repository;
private final MavenJavadocService mavenJavadocService;
private final JdvsConfig jdvsConfig;
private final RepoConfigLoader repoConfigLoader;
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady() {
if (jdvsConfig.isCleanOnStart()) {
log.info("'jdvs.clean-on-start' is enabled cleaning base directory and database.");
cleanBaseDir();
repository.deleteAll();
}
repoConfigLoader.loadConfig();
if (jdvsConfig.isRunOnStart()) {
log.info("'jdvs.run-on-start' is enabled running initial update.");
updateAll();
}
}
private void cleanBaseDir() {
Path baseDir = Path.of(jdvsConfig.getBaseDir());
if (!Files.exists(baseDir)) {
return;
}
try (var stream = Files.walk(baseDir)) {
stream.sorted(Comparator.reverseOrder()).forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
log.warn("Failed to delete path: {}", path, e);
}
});
log.info("Deleted base directory: {}", baseDir);
} catch (IOException e) {
log.error("Failed to walk base directory: {}", baseDir, e);
}
}
@Scheduled(cron = "${jdvs.cron}")
public void updateAll() {
@@ -1,6 +1,6 @@
package codes.thischwa.jdvs.web;
import codes.thischwa.jdvs.config.JdvsConfig;
import codes.thischwa.jdvs.model.config.JdvsConfig;
import java.nio.file.Path;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;