initializer-generator/src/main/java/com/alibaba/initializer/generation/extension/SampleCodeContributor.java [159:239]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    protected Map<Dependency, String> getRepos(InitializerProjectDescription description) {
        Map<String, Dependency> dependencyMap = description.getRequestedDependencies();
        Architecture arch = description.getArchitecture();

        if (CollectionUtils.isEmpty(dependencyMap)) {
            return Collections.emptyMap();
        }

        return dependencyMap.entrySet().stream()
                .filter(entry -> this.filterByModule(entry, arch))
                .collect(Collectors.toMap(Map.Entry::getValue, entity -> toPath(entity.getKey())));
    }

    private String toPath(String s) {
        String prefix = templates;

        if (!prefix.endsWith("/")) {
            prefix += "/";
        }
        return prefix + s;
    }


    private boolean filterByModule(Map.Entry<String, Dependency> entry, Architecture arch) {

        String id = entry.getKey();
        EnhancedDependency dep = getMetaDependency(id);

        if (dep == null) {
            return true;
        }

        Map<String, DependencyArchConfig> cfgs = dep.getArchCfg();

        DependencyArchConfig cfg = cfgs != null ? cfgs.get(arch.getId()) : null;

        if (cfg != null) {
            if (cfg.getSupported() != null && !cfg.getSupported()) {
                // not supported explicitly
                return false;
            }

            Map<String, ModuleConfig> moduleCfgs = cfg.getModules();
            if (moduleCfgs == null || moduleCfgs.size() == 0) {
                return module.isMain();
            }

            ModuleConfig moduleCfg = moduleCfgs.get(module.getName());

            if (moduleCfg == null) {
                return false;
            }

            return true;
        } else {
            return module.isMain();
        }
    }

    private EnhancedDependency getMetaDependency(String id) {

        for (DependencyGroup group : meta.getDependencies().getContent()) {
            for (io.spring.initializr.metadata.Dependency dependency : group.getContent()) {
                if (StringUtils.equalsIgnoreCase(dependency.getId(), id)) {
                    return (EnhancedDependency) dependency;
                }
            }
        }

        return null;
    }

    protected void writeCode(RepoRenderResult.TemplateRenderResult result, Language language, Path projectRoot, SourceStructure structure) {
        String content = result.getContent();
        Path path = reslovePackagePath(structure.getSourcesDirectory(), content);
        path = path.resolve(result.getFileName());

        try {
            doWirte(path, content, false);
        } catch (IOException e) {
            throw new BizRuntimeException(ErrorCodeEnum.SYSTEM_ERROR, "write code error", e);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



initializer-generator/src/main/java/org/apache/dubbo/initializer/generation/extension/codes/sample/ProtoBufCodeContributor.java [124:204]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    protected Map<Dependency, String> getRepos(InitializerProjectDescription description) {
        Map<String, Dependency> dependencyMap = description.getRequestedDependencies();
        Architecture arch = description.getArchitecture();

        if (CollectionUtils.isEmpty(dependencyMap)) {
            return Collections.emptyMap();
        }

        return dependencyMap.entrySet().stream()
                .filter(entry -> this.filterByModule(entry, arch))
                .collect(Collectors.toMap(Map.Entry::getValue, entity -> toPath(entity.getKey())));
    }

    private String toPath(String s) {
        String prefix = templates;

        if (!prefix.endsWith("/")) {
            prefix += "/";
        }
        return prefix + s;
    }


    private boolean filterByModule(Map.Entry<String, Dependency> entry, Architecture arch) {

        String id = entry.getKey();
        EnhancedDependency dep = getMetaDependency(id);

        if (dep == null) {
            return true;
        }

        Map<String, DependencyArchConfig> cfgs = dep.getArchCfg();

        DependencyArchConfig cfg = cfgs != null ? cfgs.get(arch.getId()) : null;

        if (cfg != null) {
            if (cfg.getSupported() != null && !cfg.getSupported()) {
                // not supported explicitly
                return false;
            }

            Map<String, ModuleConfig> moduleCfgs = cfg.getModules();
            if (moduleCfgs == null || moduleCfgs.size() == 0) {
                return module.isMain();
            }

            ModuleConfig moduleCfg = moduleCfgs.get(module.getName());

            if (moduleCfg == null) {
                return false;
            }

            return true;
        } else {
            return module.isMain();
        }
    }

    private EnhancedDependency getMetaDependency(String id) {

        for (DependencyGroup group : meta.getDependencies().getContent()) {
            for (io.spring.initializr.metadata.Dependency dependency : group.getContent()) {
                if (StringUtils.equalsIgnoreCase(dependency.getId(), id)) {
                    return (EnhancedDependency) dependency;
                }
            }
        }

        return null;
    }

    protected void writeCode(RepoRenderResult.TemplateRenderResult result, Language language, Path projectRoot, SourceStructure structure) {
        String content = result.getContent();
        Path path = reslovePackagePath(structure.getSourcesDirectory(), content);
        path = path.resolve(result.getFileName());

        try {
            doWirte(path, content, false);
        } catch (IOException e) {
            throw new BizRuntimeException(ErrorCodeEnum.SYSTEM_ERROR, "write code error", e);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



