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 org.avaje.classpath.scanner.internal.scanner.classpath.jboss; 017 018import org.avaje.classpath.scanner.internal.UrlUtils; 019import org.avaje.classpath.scanner.internal.scanner.classpath.ClassPathLocationScanner; 020import org.jboss.vfs.VFS; 021import org.jboss.vfs.VirtualFile; 022import org.jboss.vfs.VirtualFileFilter; 023import org.slf4j.Logger; 024import org.slf4j.LoggerFactory; 025 026import java.io.IOException; 027import java.net.URL; 028import java.util.List; 029import java.util.Set; 030import java.util.TreeSet; 031 032/** 033 * ClassPathLocationScanner for JBoss VFS v3. 034 */ 035public class JBossVFSv3ClassPathLocationScanner implements ClassPathLocationScanner { 036 private static final Logger LOG = LoggerFactory.getLogger(JBossVFSv3ClassPathLocationScanner.class); 037 038 public Set<String> findResourceNames(String location, URL locationUrl) throws IOException { 039 String filePath = UrlUtils.toFilePath(locationUrl); 040 String classPathRootOnDisk = filePath.substring(0, filePath.length() - location.length()); 041 if (!classPathRootOnDisk.endsWith("/")) { 042 classPathRootOnDisk = classPathRootOnDisk + "/"; 043 } 044 LOG.debug("Scanning starting at classpath root on JBoss VFS: " + classPathRootOnDisk); 045 046 Set<String> resourceNames = new TreeSet<String>(); 047 048 List<VirtualFile> files = VFS.getChild(filePath).getChildrenRecursively(new VirtualFileFilter() { 049 public boolean accepts(VirtualFile file) { 050 return file.isFile(); 051 } 052 }); 053 for (VirtualFile file : files) { 054 resourceNames.add(file.getPathName().substring(classPathRootOnDisk.length())); 055 } 056 057 return resourceNames; 058 } 059 060}