private Map computeInsertableFiles()

in freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/Transform.java [1249:1303]


    private Map<String, Path> computeInsertableFiles() throws DocgenException {
        for (String varName : insertableFilesOverrides.keySet()) {
            if (!insertableFilesFromSettingsFile.containsKey(varName)) {
                throw new DocgenException("Attempt to set insertable path with symbolic name "
                        + StringUtil.jQuote(varName)
                        + ", when same was not set in the settings file (" + FILE_SETTINGS + ").");
            }
        }

        Map<String, String> unresolvedInsertableFiles = new HashMap<>();
        unresolvedInsertableFiles.putAll(insertableFilesFromSettingsFile);
        unresolvedInsertableFiles.putAll(insertableFilesOverrides);

        for (Entry<String, String> entry : unresolvedInsertableFiles.entrySet()) {
            if (entry.getValue() == null) {
                throw new DocgenException("The insertable path with symbolic name "
                        + StringUtil.jQuote(entry.getKey()) + " was set to path null, which is not allowed. "
                        + "Probably you are supposed to override its path.");
            }
        }

        Map<String, Path> insertableFiles = new HashMap<>();
        for (Entry<String, String> entry : unresolvedInsertableFiles.entrySet()) {
            String symbolicName = entry.getKey();
            String unresolvedPath = entry.getValue();

            Path path;
            if (unresolvedPath.endsWith("/**") || unresolvedPath.endsWith("\\**")) {
                path = srcDir.toPath().resolve(unresolvedPath.substring(0, unresolvedPath.length() - 3));
                if (!Files.isDirectory(path)) {
                    throw new DocgenException(
                            "Insertable file with symbolic name " + StringUtil.jQuote(symbolicName)
                            + " points to a directory that doesn't exist: " + StringUtil.jQuote(path));
                }
            } else {
                path = srcDir.toPath().resolve(unresolvedPath);
                if (!Files.isRegularFile(path)) {
                    if (Files.isDirectory(path)) {
                        throw new DocgenException(
                                "Insertable file with symbolic name " + StringUtil.jQuote(symbolicName)
                                + " points to a directory, not a file: " + StringUtil.jQuote(path) + "."
                                + " If you want to point to a directory, end the path with \"/**\".");
                    } else {
                        throw new DocgenException(
                                "Insertable file with symbolic name " + StringUtil.jQuote(symbolicName)
                                        + " points to a file that doesn't exist: " + StringUtil.jQuote(path));
                    }
                }
            }

            insertableFiles.put(symbolicName, path);
        }

        return insertableFiles;
    }