class DefaultToolchainsBuilder implements ToolchainsBuilder {
    private final org.apache.maven.api.services.ToolchainsBuilder builder;
    private final ToolchainsXmlFactory toolchainsXmlFactory;

    @Inject
    public DefaultToolchainsBuilder(
            org.apache.maven.api.services.ToolchainsBuilder builder, ToolchainsXmlFactory toolchainsXmlFactory) {
        this.builder = builder;
        this.toolchainsXmlFactory = toolchainsXmlFactory;
    }

    @Override
    public ToolchainsBuildingResult build(ToolchainsBuildingRequest request) throws ToolchainsBuildingException {
        try {
            ToolchainsBuilderResult result = builder.build(ToolchainsBuilderRequest.builder()
                    .session((Session) java.lang.reflect.Proxy.newProxyInstance(
                            Session.class.getClassLoader(),
                            new Class[] {Session.class},
                            (Object proxy, Method method, Object[] args) -> {
                                if ("getSystemProperties".equals(method.getName())) {
                                    Map<String, String> properties = new HashMap<>();
                                    Properties env = OperatingSystemUtils.getSystemEnvVars();
                                    env.stringPropertyNames()
                                            .forEach(k -> properties.put("env." + k, env.getProperty(k)));
                                    return properties;
                                } else if ("getUserProperties".equals(method.getName())) {
                                    return Map.of();
                                } else if ("getService".equals(method.getName())) {
                                    if (args[0] == ToolchainsXmlFactory.class) {
                                        return toolchainsXmlFactory;
                                    }
                                }
                                return null;
                            }))
                    .globalToolchainsSource(convert(request.getGlobalToolchainsSource()))
                    .userToolchainsSource(convert(request.getUserToolchainsSource()))
                    .build());

            return new DefaultToolchainsBuildingResult(
                    new PersistedToolchains(result.getEffectiveToolchains()), convert(result.getProblems()));
        } catch (ToolchainsBuilderException e) {
            throw new ToolchainsBuildingException(convert(e.getProblems()));
        }
    }

    private Source convert(org.apache.maven.building.Source source) {<FILL_FUNCTION_BODY>}

    private List<Problem> convert(List<BuilderProblem> problems) {
        ProblemCollector collector = ProblemCollectorFactory.newInstance(null);
        problems.forEach(p -> collector.add(
                Problem.Severity.valueOf(p.getSeverity().name()),
                p.getMessage(),
                p.getLineNumber(),
                p.getColumnNumber(),
                p.getException()));
        return collector.getProblems();
    }
}

        if (source instanceof FileSource fs) {
            return Source.fromPath(fs.getPath());
        } else if (source != null) {
            return new Source() {
                @Override
                public Path getPath() {
                    return null;
                }

                @Override
                public InputStream openStream() throws IOException {
                    return source.getInputStream();
                }

                @Override
                public String getLocation() {
                    return source.getLocation();
                }

                @Override
                public Source resolve(String relative) {
                    return null;
                }
            };
        } else {
            return null;
        }
    
<no_super_class>