Rename jvs to jdvs in codebase and configurations, clean up unused imports, and refactor RepoConfigLoader for improved loading logic and initialization
Build and Push Docker Image / build-and-push (push) Successful in 58s
Build and Push Docker Image / build-and-push (push) Successful in 58s
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>codes.thischwa</groupId>
|
||||
<artifactId>jvc</artifactId>
|
||||
<artifactId>jdvc</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
|
||||
<name>JavadocViewerService</name>
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "jdvs")
|
||||
@Data
|
||||
public class JvsConfig {
|
||||
private String configPath;
|
||||
public class JdvsConfig {
|
||||
private String baseDir;
|
||||
private boolean cleanOnStart;
|
||||
private boolean runOnStart;
|
||||
private List<RepoConfig> repositories;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codes.thischwa.jdvs.service;
|
||||
|
||||
import codes.thischwa.jdvs.config.JvsConfig;
|
||||
import codes.thischwa.jdvs.config.JdvsConfig;
|
||||
import codes.thischwa.jdvs.model.GitRepository;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -20,10 +20,10 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class GitService {
|
||||
private final JvsConfig jvsConfig;
|
||||
private final JdvsConfig jdvsConfig;
|
||||
|
||||
public Optional<String> updateAndCheckoutLatestTag(GitRepository repoEntity) {
|
||||
Path repoPath = Path.of(jvsConfig.getBaseDir(), "repos", repoEntity.getName());
|
||||
Path repoPath = Path.of(jdvsConfig.getBaseDir(), "repos", repoEntity.getName());
|
||||
try {
|
||||
Git git;
|
||||
if (Files.exists(repoPath)) {
|
||||
@@ -58,6 +58,6 @@ public class GitService {
|
||||
}
|
||||
|
||||
public File getRepoDirectory(String name) {
|
||||
return Path.of(jvsConfig.getBaseDir(), "repos", name).toFile();
|
||||
return Path.of(jdvsConfig.getBaseDir(), "repos", name).toFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codes.thischwa.jdvs.service;
|
||||
|
||||
import codes.thischwa.jdvs.config.JvsConfig;
|
||||
import codes.thischwa.jdvs.config.JdvsConfig;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -17,10 +17,10 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class JavadocService {
|
||||
private final JvsConfig jvsConfig;
|
||||
private final JdvsConfig jdvsConfig;
|
||||
|
||||
public boolean generateJavadoc(String projectName, File repoDir) {
|
||||
File outputDir = Path.of(jvsConfig.getBaseDir(), "javadoc", projectName).toFile();
|
||||
File outputDir = Path.of(jdvsConfig.getBaseDir(), "javadoc", projectName).toFile();
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package codes.thischwa.jdvs.service;
|
||||
|
||||
import codes.thischwa.jdvs.config.JvsConfig;
|
||||
import codes.thischwa.jdvs.config.JdvsConfig;
|
||||
import codes.thischwa.jdvs.model.GitRepository;
|
||||
import codes.thischwa.jdvs.repository.GitRepositoryRepository;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -16,22 +12,12 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class RepoConfigLoader {
|
||||
private final JvsConfig jvsConfig;
|
||||
private final JdvsConfig jdvsConfig;
|
||||
private final GitRepositoryRepository repository;
|
||||
|
||||
@PostConstruct
|
||||
public void loadConfig() {
|
||||
File configFile = new File(jvsConfig.getConfigPath());
|
||||
if (!configFile.exists()) {
|
||||
log.info("Configuration file {} not found.", jvsConfig.getConfigPath());
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
||||
try {
|
||||
JvsConfig yamlConfig = mapper.readValue(configFile, JvsConfig.class);
|
||||
if (yamlConfig.getRepositories() != null) {
|
||||
for (JvsConfig.RepoConfig repoCfg : yamlConfig.getRepositories()) {
|
||||
if (jdvsConfig.getRepositories() != null) {
|
||||
for (JdvsConfig.RepoConfig repoCfg : jdvsConfig.getRepositories()) {
|
||||
if (repository.findByName(repoCfg.getName()).isEmpty()) {
|
||||
GitRepository repo = new GitRepository();
|
||||
repo.setName(repoCfg.getName());
|
||||
@@ -41,8 +27,5 @@ public class RepoConfigLoader {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error reading configuration file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package codes.thischwa.jdvs.service;
|
||||
|
||||
import codes.thischwa.jdvs.config.JvsConfig;
|
||||
import codes.thischwa.jdvs.config.JdvsConfig;
|
||||
import codes.thischwa.jdvs.model.GitRepository;
|
||||
import codes.thischwa.jdvs.repository.GitRepositoryRepository;
|
||||
import java.io.File;
|
||||
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;
|
||||
@@ -21,16 +25,36 @@ public class UpdateScheduler {
|
||||
private final GitRepositoryRepository repository;
|
||||
private final GitService gitService;
|
||||
private final JavadocService javadocService;
|
||||
private final JvsConfig jvsConfig;
|
||||
private final JdvsConfig jdvsConfig;
|
||||
private final RepoConfigLoader repoConfigLoader;
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void onApplicationReady() {
|
||||
if (jvsConfig.isRunOnStart()) {
|
||||
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()).map(Path::toFile).forEach(File::delete);
|
||||
log.info("Deleted base directory: {}", baseDir);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to delete base directory: {}", baseDir, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "${jdvs.cron}")
|
||||
public void updateAll() {
|
||||
log.info("Starting scheduled update of repositories...");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codes.thischwa.jdvs.web;
|
||||
|
||||
import codes.thischwa.jdvs.config.JvsConfig;
|
||||
import codes.thischwa.jdvs.config.JdvsConfig;
|
||||
import java.nio.file.Path;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
@@ -8,15 +8,15 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
private final JvsConfig jvsConfig;
|
||||
private final JdvsConfig jdvsConfig;
|
||||
|
||||
public WebConfig(JvsConfig jvsConfig) {
|
||||
this.jvsConfig = jvsConfig;
|
||||
public WebConfig(JdvsConfig jdvsConfig) {
|
||||
this.jdvsConfig = jdvsConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String javadocPath = Path.of(jvsConfig.getBaseDir(), "javadoc").toAbsolutePath().toUri().toString();
|
||||
String javadocPath = Path.of(jdvsConfig.getBaseDir(), "javadoc").toAbsolutePath().toUri().toString();
|
||||
if (!javadocPath.endsWith("/")) {
|
||||
javadocPath += "/";
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
jdvs:
|
||||
base-dir: ./javadoc-storage
|
||||
cron: 0 0/15 * * * ?
|
||||
clean-on-start: false
|
||||
run-on-start: false
|
||||
|
||||
## import of the individual configuration settings
|
||||
spring:
|
||||
config:
|
||||
import: optional:file:./jdvs.yml
|
||||
|
||||
datasource:
|
||||
url: jdbc:h2:file:./database/jdvsdb
|
||||
driverClassName: org.h2.Driver
|
||||
@@ -8,9 +18,3 @@ spring:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
|
||||
jdvs:
|
||||
config-path: ./jdvs.yml
|
||||
base-dir: ./javadoc-storage
|
||||
cron: 0 0/15 * * * ?
|
||||
run-on-start: false
|
||||
|
||||
Reference in New Issue
Block a user