All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.solon.resolver.resource.ClassPathResourceResolver Maven / Gradle / Ivy

There is a newer version: 3.0.5-M3
Show newest version
package graphql.solon.resolver.resource;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.noear.solon.core.util.ResourceUtil;
import org.noear.solon.core.util.ScanUtil;
import graphql.solon.resource.ClassPathResource;
import graphql.solon.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author fuzi1996
 * @since 2.3
 */
public class ClassPathResourceResolver implements GraphqlResourceResolver {

    private static Logger log = LoggerFactory.getLogger(ClassPathResourceResolver.class);

    private List locations;
    private List fileExtensions;

    public ClassPathResourceResolver(List locations, List fileExtensions) {
        this.locations = locations;
        this.fileExtensions = fileExtensions;
    }

    @Override
    public Set getGraphqlResource() {
        Set resources = this.locations.stream()
                .map(location -> {
                    Set scanResult = ScanUtil
                            .scan(location, (path) -> this.fileExtensions.stream().anyMatch(
                                    path::endsWith));
                    log.debug("[{}]文件夹下共扫描到[{}]个定义文件", location, scanResult.size());
                    return scanResult;
                }).flatMap(Set::stream)
                .map(ResourceUtil::getResource)
                .map(ClassPathResource::new)
                .collect(Collectors.toSet());

        log.debug("共扫描到[{}]个定义文件", resources.size());

        return resources;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy