package com.megatim.manuel.core.generate;
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import java.io.IOException;
|
import java.nio.charset.StandardCharsets;
|
import java.nio.file.Files;
|
import java.nio.file.Path;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* Manifeste des documents sources du manuel ({@code sources.json}) : liste ordonnée
|
* des fichiers importés (copiés dans {@code <manuel>/sources}) et métadonnées de
|
* génération. Permet à l'écran d'administration de recharger l'état entre deux
|
* sessions et de régénérer le bundle même si les documents originaux ont disparu.
|
*/
|
public class SourcesManifest {
|
|
public static final String SOURCES_JSON = "sources.json";
|
|
/** Noms des fichiers sources (relatifs au dossier {@code <manuel>/sources}), dans l'ordre du manuel. */
|
public List<String> fichiers = new ArrayList<>();
|
public String titreProjet;
|
public String version;
|
public String titreAide;
|
/** Date de la dernière génération (ISO-8601), à titre informatif. */
|
public String dateGeneration;
|
|
public SourcesManifest() {
|
}
|
|
/** Lit le manifeste depuis {@code dir/sources.json}, ou retourne {@code null} s'il n'existe pas. */
|
public static SourcesManifest load(Path dir) throws IOException {
|
Path file = dir.resolve(SOURCES_JSON);
|
if (!Files.exists(file)) {
|
return null;
|
}
|
String json = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
|
ObjectMapper mapper = new ObjectMapper()
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
return mapper.readValue(json, SourcesManifest.class);
|
}
|
|
/** Écrit le manifeste dans {@code dir/sources.json}. */
|
public void save(Path dir) throws IOException {
|
ObjectMapper mapper = new ObjectMapper();
|
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this);
|
Files.write(dir.resolve(SOURCES_JSON), json.getBytes(StandardCharsets.UTF_8));
|
}
|
}
|