@Override
    public Asset<?> assetAt(String path) {
        List<WebJarLib> candidates = findLibsContaining(path);

        if (candidates.size() == 1) {
            // Perfect ! only one match
            return new DefaultAsset<>(
                    "/libs/" + candidates.get(0).name + "/" + candidates.get(0).version + "/" + path,
                    candidates.get(0).get(path),
                    candidates.get(0).toString(),
                    candidates.get(0).lastModified(),
                    CacheUtils.computeEtag(candidates.get(0).lastModified(), configuration, crypto)
            );
        } else if (candidates.size() > 1) {
            // Several candidates
            logger().warn("{} WebJars provide '{}' - returning the one from {}-{}", candidates.size(), path,
                    candidates.get(0).name, candidates.get(0).version);
            return new DefaultAsset<>(
                    "/libs/" + candidates.get(0).name + "/" + candidates.get(0).version + "/" + path,
                    candidates.get(0).get(path),
                    candidates.get(0).toString(),
                    candidates.get(0).lastModified(),
                    CacheUtils.computeEtag(candidates.get(0).lastModified(), configuration, crypto)
            );
        } else {
            Matcher matcher = PATTERN.matcher(path);
            if (!matcher.matches()) {
                // It should have been handled by the path match.
                return null;
            }

            final String name = matcher.group(1);
            final String version = matcher.group(3);
            if (version != null) {
                String rel = matcher.group(4);
                // We have a name and a version
                // Try to find the matching library
                WebJarLib lib = find(name, version);
                if (lib != null) {
                    return new DefaultAsset<>(
                            rel,
                            lib.get(rel),
                            lib.toString(),
                            lib.lastModified(),
                            CacheUtils.computeEtag(lib.lastModified(), configuration, crypto)
                    );
                }
                // If not found, it may be because the version is not really the version but a segment of the path.
            }
            // If we reach this point it means that the name/version lookup has failed, try without the version
            String rel = matcher.group(4);
            if (version != null) {
                // We have a group 3
                rel = version + "/" + rel;
            }

            List<WebJarLib> libs = find(name);
            if (libs.size() == 1) {
                // Only on library has the given name
                if (libs.get(0).contains(rel)) {
                    WebJarLib lib = libs.get(0);
                    return new DefaultAsset<>(
                            "/libs/" + lib.name + "/" + lib.version + "/" + rel,
                            lib.get(rel),
                            lib.toString(),
                            lib.lastModified(),
                            CacheUtils.computeEtag(lib.lastModified(), configuration, crypto)
                    );
                }
            } else if (libs.size() > 1) {
                // Several candidates
                WebJarLib higher = null;
                ComparableVersion higherVersion = null;
                for (WebJarLib lib: libs) {
                    if (lib.contains(rel)) {
                        if(higher == null) {
                            higher = lib;
                            higherVersion = new ComparableVersion(higher.version);
                        } else {
                            ComparableVersion newVersion = new ComparableVersion(lib.version);
                            if(newVersion.compareTo(higherVersion) > 0) {
                                higher = lib;
                                higherVersion = new ComparableVersion(higher.version);
                            }
                        }
                    }
                }
                if(higher != null) {
                    logger().warn("{} WebJars match the request '{}' - returning the resource from {}-{}",
                            libs.size(), path, higher.name, higher.version);
                    return new DefaultAsset<>(
                            "/libs/" + higher.name + "/" + higher.version + "/" + rel,
                            higher.get(rel),
                            higher.toString(),
                            higher.lastModified(),
                            CacheUtils.computeEtag(higher.lastModified(), configuration, crypto)
                    );
                }

            }

            return null;
        }
    }
@ Override public Asset < ? > assetAt ( String path ) { List < WebJarLib > candidates = findLibsContaining ( path ) ; if ( candidates . size ( ) == 1 ) { return new DefaultAsset < > ( "/libs/" + candidates . get ( 0 ) . name + "/" + candidates . get ( 0 ) . version + "/" + path , candidates . get ( 0 ) . get ( path ) , candidates . get ( 0 ) . toString ( ) , candidates . get ( 0 ) . lastModified ( ) , CacheUtils . computeEtag ( candidates . get ( 0 ) . lastModified ( ) , configuration , crypto ) ) ; } else if ( candidates . size ( ) > 1 ) { logger ( ) . warn ( "{} WebJars provide '{}' - returning the one from {}-{}" , candidates . size ( ) , path , candidates . get ( 0 ) . name , candidates . get ( 0 ) . version ) ; return new DefaultAsset < > ( "/libs/" + candidates . get ( 0 ) . name + "/" + candidates . get ( 0 ) . version + "/" + path , candidates . get ( 0 ) . get ( path ) , candidates . get ( 0 ) . toString ( ) , candidates . get ( 0 ) . lastModified ( ) , CacheUtils . computeEtag ( candidates . get ( 0 ) . lastModified ( ) , configuration , crypto ) ) ; } else { Matcher matcher = PATTERN . matcher ( path ) ; if ( ! matcher . matches ( ) ) { return null ; } final String name = matcher . group ( 1 ) ; final String version = matcher . group ( 3 ) ; if ( version != null ) { String rel = matcher . group ( 4 ) ; WebJarLib lib = find ( name , version ) ; if ( lib != null ) { return new DefaultAsset < > ( rel , lib . get ( rel ) , lib . toString ( ) , lib . lastModified ( ) , CacheUtils . computeEtag ( lib . lastModified ( ) , configuration , crypto ) ) ; } } String rel = matcher . group ( 4 ) ; if ( version != null ) { rel = version + "/" + rel ; } List < WebJarLib > libs = find ( name ) ; if ( libs . size ( ) == 1 ) { if ( libs . get ( 0 ) . contains ( rel ) ) { WebJarLib lib = libs . get ( 0 ) ; return new DefaultAsset < > ( "/libs/" + lib . name + "/" + lib . version + "/" + rel , lib . get ( rel ) , lib . toString ( ) , lib . lastModified ( ) , CacheUtils . computeEtag ( lib . lastModified ( ) , configuration , crypto ) ) ; } } else if ( libs . size ( ) > 1 ) { WebJarLib higher = null ; ComparableVersion higherVersion = null ; for ( WebJarLib lib : libs ) { if ( lib . contains ( rel ) ) { if ( higher == null ) { higher = lib ; higherVersion = new ComparableVersion ( higher . version ) ; } else { ComparableVersion newVersion = new ComparableVersion ( lib . version ) ; if ( newVersion . compareTo ( higherVersion ) > 0 ) { higher = lib ; higherVersion = new ComparableVersion ( higher . version ) ; } } } } if ( higher != null ) { logger ( ) . warn ( "{} WebJars match the request '{}' - returning the resource from {}-{}" , libs . size ( ) , path , higher . name , higher . version ) ; return new DefaultAsset < > ( "/libs/" + higher . name + "/" + higher . version + "/" + rel , higher . get ( rel ) , higher . toString ( ) , higher . lastModified ( ) , CacheUtils . computeEtag ( higher . lastModified ( ) , configuration , crypto ) ) ; } } return null ; } }
Retrieves an asset.

@param path the asset path
@return the Asset object, or {@literal null} if the current provider can't serve this asset.