public List<TCKArtifact> createArtifacts(String packageName) { Set<Class<?>> classes = new HashSet<Class<?>>(); classes.addAll( new ArtifactScanner( packageName, null ).getClasses() ); List<TCKArtifact> artifacts = new ArrayList<TCKArtifact>(); for ( Class<?> clazz : classes ) { artifacts.add( createArtifact( clazz ) ); } return artifacts; }
private void handle(Set<String> paths) throws IOException { for ( String urlPath: paths ) { log.trace("scanning: " + urlPath); handle(new File(urlPath), packageName.substring(0, packageName.lastIndexOf("."))); } }
public Set<Class<?>> getClasses() { scan(); return classes; }
private void handle(File file, String packageName) throws IOException { if ( file.isDirectory() ) { packageName = packageName + "." + file.getName(); for ( File child: file.listFiles() ) { handle(child, packageName); } } else if (file.getName().endsWith(".class") && ! file.getName().contains("$")) { addClass(packageName + "." + file.getName().replace(".class", "")); } else if (file.getName().endsWith(".jar")) { handleArchiveByFile(file); } }
private void handleArchiveByFile(File file) throws IOException { try { log.trace("archive: " + file); ZipFile zip = new ZipFile(file); Enumeration<? extends ZipEntry> entries = zip.entries(); while ( entries.hasMoreElements() ) { ZipEntry entry = entries.nextElement(); String name = entry.getName(); if (name.startsWith(packageNameAsPath) && name.endsWith(".class")) { addClass(name.replace(".class", "").replace("/", ".")); } } } catch (ZipException e) { throw new RuntimeException("Error handling file " + file, e); } }
private void scan() { try { Set<String> paths = new HashSet<String>(); for (URL url : loadResources(packageNameAsPath)) { String urlPath = url.getFile(); urlPath = URLDecoder.decode(urlPath, "UTF-8"); if ( urlPath.startsWith("file:") ) { urlPath = urlPath.substring(5); } if ( urlPath.indexOf('!')>0 ) { urlPath = urlPath.substring(0, urlPath.indexOf('!')); } paths.add(urlPath); } handle(paths); } catch (IOException ioe) { log.warn("could not read: " + this.packageName, ioe); } }