Leonel FOFOU
2026-07-28 32450e295200b2bc7896518ff74161ff26772e2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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));
    }
}