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.ScanLog; 019import io.avaje.classpath.scanner.internal.UrlUtils; 020import io.avaje.classpath.scanner.internal.scanner.classpath.ClassPathLocationScanner; 021import org.jboss.vfs.VFS; 022import org.jboss.vfs.VirtualFile; 023 024import java.io.IOException; 025import java.net.URL; 026import java.util.List; 027import java.util.Set; 028import java.util.TreeSet; 029 030/** 031 * ClassPathLocationScanner for JBoss VFS v3. 032 */ 033public class JBossVFSv3ClassPathLocationScanner implements ClassPathLocationScanner { 034 035 public Set<String> findResourceNames(String location, URL locationUrl) throws IOException { 036 String filePath = UrlUtils.toFilePath(locationUrl); 037 String classPathRootOnDisk = filePath.substring(0, filePath.length() - location.length()); 038 if (!classPathRootOnDisk.endsWith("/")) { 039 classPathRootOnDisk = classPathRootOnDisk + "/"; 040 } 041 ScanLog.log.trace("scan starting on JBossVFS: {}", classPathRootOnDisk); 042 Set<String> resourceNames = new TreeSet<>(); 043 List<VirtualFile> files = VFS.getChild(filePath).getChildrenRecursively(VirtualFile::isFile); 044 for (VirtualFile file : files) { 045 resourceNames.add(file.getPathName().substring(classPathRootOnDisk.length())); 046 } 047 return resourceNames; 048 } 049 050}