@Override public void visitArchive(ArchiveContext context) { delegateDescriptor.visitArchive( context ); } }
protected AbstractArchiveDescriptor( ArchiveDescriptorFactory archiveDescriptorFactory, URL archiveUrl, String entryBasePrefix) { this.archiveDescriptorFactory = archiveDescriptorFactory; this.archiveUrl = archiveUrl; this.entryBasePrefix = normalizeEntryBasePrefix( entryBasePrefix ); }
@Override public ArchiveDescriptor buildArchiveDescriptor(URL url) { return buildArchiveDescriptor( url, "" ); }
context.obtainArchiveEntryHandler( entry ).handleEntry( entry, context );
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw new ArchiveException( "Unable to open VirtualFile-based InputStream", e ); } }
private ClassFile toClassFile(ArchiveEntry entry) { final InputStream inputStream = entry.getStreamAccess().accessInputStream(); final DataInputStream dataInputStream = new DataInputStream( inputStream ); try { return new ClassFile( dataInputStream ); } catch (IOException e) { throw new ArchiveException( "Could not build ClassFile", e ); } finally { try { dataInputStream.close(); } catch (Exception ignore) { } try { inputStream.close(); } catch (IOException ignore) { } } }
@Override public void handleEntry(ArchiveEntry entry, ArchiveContext context) { resultCollector.handleMappingFile( new MappingFileDescriptorImpl( entry.getNameWithinArchive(), entry.getStreamAccess() ), context.isRootUrl() ); } }
protected PackageDescriptor toPackageDescriptor(ArchiveEntry entry) { final String packageInfoFilePath = entry.getNameWithinArchive(); final String packageName = packageInfoFilePath.substring( 0, packageInfoFilePath.lastIndexOf( '/' ) ) .replace( '/', '.' ); return new PackageDescriptorImpl( packageName, entry.getStreamAccess() ); } }
@Override public void handleEntry(ArchiveEntry entry, ArchiveContext context) { if ( entry.getNameWithinArchive().equals( "package-info.class" ) ) { // the old code skipped package-info in the root package/dir... return; } resultCollector.handlePackage( toPackageDescriptor( entry ), context.isRootUrl() ); }
private ArchiveDescriptor buildArchiveDescriptor( URL url, ScanEnvironment environment, boolean isRootUrl) { final ArchiveDescriptor descriptor; final ArchiveDescriptorInfo descriptorInfo = archiveDescriptorCache.get( url ); if ( descriptorInfo == null ) { if ( !isRootUrl && archiveDescriptorFactory instanceof JarFileEntryUrlAdjuster ) { url = ( (JarFileEntryUrlAdjuster) archiveDescriptorFactory ).adjustJarFileEntryUrl( url, environment.getRootUrl() ); } descriptor = archiveDescriptorFactory.buildArchiveDescriptor( url ); archiveDescriptorCache.put( url, new ArchiveDescriptorInfo( descriptor, isRootUrl ) ); } else { validateReuse( descriptorInfo, isRootUrl ); descriptor = descriptorInfo.archiveDescriptor; } return descriptor; }
@Override public ArchiveEntryHandler obtainArchiveEntryHandler(ArchiveEntry entry) { final String nameWithinArchive = entry.getNameWithinArchive(); if ( nameWithinArchive.endsWith( "package-info.class" ) ) { return packageEntryHandler; } else if ( nameWithinArchive.endsWith( ".class" ) ) { return classEntryHandler; } else { return fileEntryHandler; } } }
protected String extractName(ZipEntry zipEntry) { return normalizePathName( zipEntry.getName() ); }
protected String extractRelativeName(ZipEntry zipEntry) { final String entryName = extractName( zipEntry ); return entryBasePrefix != null && entryName.contains( entryBasePrefix ) ? entryName.substring( entryBasePrefix.length() ) : entryName; }
private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) { ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;; final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag ); if ( visibleAnnotations != null ) { if ( visibleAnnotations.getAnnotation( Entity.class.getName() ) != null || visibleAnnotations.getAnnotation( MappedSuperclass.class.getName() ) != null || visibleAnnotations.getAnnotation( Embeddable.class.getName() ) != null ) { categorization = ClassDescriptor.Categorization.MODEL; } else if ( visibleAnnotations.getAnnotation( Converter.class.getName() ) != null ) { categorization = ClassDescriptor.Categorization.CONVERTER; } } return new ClassDescriptorImpl( classFile.getName(), categorization, entry.getStreamAccess() ); } }
@Override public void handleEntry(ArchiveEntry entry, ArchiveContext context) { // Ultimately we'd like to leverage Jandex here as long term we want to move to // using Jandex for annotation processing. But even then, Jandex atm does not have // any facility for passing a stream and conditionally indexing it into an Index or // returning existing ClassInfo objects. // // So not sure we can ever not do this unconditional input stream read :( final ClassFile classFile = toClassFile( entry ); final ClassDescriptor classDescriptor = toClassDescriptor( classFile, entry ); if ( classDescriptor.getCategorization() == ClassDescriptor.Categorization.OTHER ) { return; } resultCollector.handleClass( classDescriptor, context.isRootUrl() ); }
context.obtainArchiveEntryHandler( entry ).handleEntry( entry, context );
@Override public InputStream accessInputStream() { try { return new BufferedInputStream( new FileInputStream( file ) ); } catch (FileNotFoundException e) { // should never ever ever happen, but... throw new ArchiveException( "File believed to exist based on File.exists threw error when passed to FileInputStream ctor", e ); } } }
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw new ArchiveException( "Unable to open VirtualFile-based InputStream", e ); } }
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw new ArchiveException( "Unable to open VirtualFile-based InputStream", e ); } }
/** * Extracts the bytes out of an InputStream. This form is the same as {@link #getBytesFromInputStream} * except that any {@link IOException} are wrapped as (runtime) {@link ArchiveException} * * @param inputStream The stream from which to extract bytes. * * @return The bytes * * @throws ArchiveException Indicates a problem accessing the stream */ public static byte[] getBytesFromInputStreamSafely(InputStream inputStream) throws ArchiveException { try { return getBytesFromInputStream( inputStream ); } catch (IOException e) { throw new ArchiveException( "Unable to extract bytes from InputStream", e ); } }