001/* 002 Copyright 2010-2016 Boxfuse GmbH 003 <p/> 004 Licensed under the Apache License, Version 2.0 (the "License"); 005 you may not use this file except in compliance with the License. 006 You may obtain a copy of the License at 007 <p/> 008 http://www.apache.org/licenses/LICENSE-2.0 009 <p/> 010 Unless required by applicable law or agreed to in writing, software 011 distributed under the License is distributed on an "AS IS" BASIS, 012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 See the License for the specific language governing permissions and 014 limitations under the License. 015 */ 016package io.avaje.classpath.scanner.internal.scanner.classpath.jboss; 017 018import io.avaje.classpath.scanner.internal.UrlUtils; 019import io.avaje.classpath.scanner.internal.scanner.classpath.ClassPathLocationScanner; 020import org.jboss.vfs.VFS; 021import org.jboss.vfs.VirtualFile; 022import org.slf4j.Logger; 023import org.slf4j.LoggerFactory; 024 025import java.io.IOException; 026import java.net.URL; 027import java.util.List; 028import java.util.Set; 029import java.util.TreeSet; 030 031/** 032 * ClassPathLocationScanner for JBoss VFS v3. 033 */ 034public class JBossVFSv3ClassPathLocationScanner implements ClassPathLocationScanner { 035 private static final Logger LOG = LoggerFactory.getLogger(JBossVFSv3ClassPathLocationScanner.class); 036 037 public Set<String> findResourceNames(String location, URL locationUrl) throws IOException { 038 String filePath = UrlUtils.toFilePath(locationUrl); 039 String classPathRootOnDisk = filePath.substring(0, filePath.length() - location.length()); 040 if (!classPathRootOnDisk.endsWith("/")) { 041 classPathRootOnDisk = classPathRootOnDisk + "/"; 042 } 043 LOG.debug("Scanning starting at classpath root on JBoss VFS: " + classPathRootOnDisk); 044 045 Set<String> resourceNames = new TreeSet<>(); 046 047 List<VirtualFile> files = VFS.getChild(filePath).getChildrenRecursively(VirtualFile::isFile); 048 for (VirtualFile file : files) { 049 resourceNames.add(file.getPathName().substring(classPathRootOnDisk.length())); 050 } 051 052 return resourceNames; 053 } 054 055}