<s> package org . eclipse . jdt . internal . core . search . indexing ; import java . io . File ; import java . io . IOException ; import java . net . URI ; import java . util . Enumeration ; import java . util . zip . ZipEntry ; import java . util . zip . ZipFile ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . compiler . InvalidInputException ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchParticipant ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . parser . Scanner ; import org . eclipse . jdt . internal . compiler . parser . TerminalTokens ; import org . eclipse . jdt . internal . compiler . util . SimpleLookupTable ; import org . eclipse . jdt . internal . compiler . util . SuffixConstants ; import org . eclipse . jdt . internal . compiler . util . Util ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . core . index . Index ; import org . eclipse . jdt . internal . core . search . JavaSearchDocument ; import org . eclipse . jdt . internal . core . search . processing . JobManager ; class AddJarFileToIndex extends IndexRequest { private static final char JAR_SEPARATOR = IJavaSearchScope . JAR_FILE_ENTRY_SEPARATOR . charAt ( 0 ) ; IFile resource ; Scanner scanner ; public AddJarFileToIndex ( IFile resource , IndexManager manager ) { super ( resource . getFullPath ( ) , manager ) ; this . resource = resource ; } public AddJarFileToIndex ( IPath jarPath , IndexManager manager ) { super ( jarPath , manager ) ; } public boolean equals ( Object o ) { if ( o instanceof AddJarFileToIndex ) { if ( this . resource != null ) return this . resource . equals ( ( ( AddJarFileToIndex ) o ) . resource ) ; if ( this . containerPath != null ) return this . containerPath . equals ( ( ( AddJarFileToIndex ) o ) . containerPath ) ; } return false ; } public int hashCode ( ) { if ( this . resource != null ) return this . resource . hashCode ( ) ; if ( this . containerPath != null ) return this . containerPath . hashCode ( ) ; return - 1 ; } public boolean execute ( IProgressMonitor progressMonitor ) { if ( this . isCancelled || progressMonitor != null && progressMonitor . isCanceled ( ) ) return true ; try { Index index = this . manager . getIndexForUpdate ( this . containerPath , false , false ) ; if ( index != null ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + this . containerPath ) ; return true ; } index = this . manager . getIndexForUpdate ( this . containerPath , true , true ) ; if ( index == null ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + this . containerPath ) ; return true ; } ReadWriteMonitor monitor = index . monitor ; if ( monitor == null ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + this . containerPath + "" ) ; return true ; } index . separator = JAR_SEPARATOR ; ZipFile zip = null ; try { Path zipFilePath = null ; monitor . enterWrite ( ) ; if ( this . resource != null ) { URI location = this . resource . getLocationURI ( ) ; if ( location == null ) return false ; if ( JavaModelManager . ZIP_ACCESS_VERBOSE ) System . out . println ( "(" + Thread . currentThread ( ) + "" + location . getPath ( ) ) ; File file = null ; try { file = org . eclipse . jdt . internal . core . util . Util . toLocalFile ( location , progressMonitor ) ; } catch ( CoreException e ) { if ( JobManager . VERBOSE ) { org . eclipse . jdt . internal . core . util . Util . verbose ( "" + location . getPath ( ) + "" ) ; e . printStackTrace ( ) ; } } if ( file == null ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + location . getPath ( ) + "" ) ; return false ; } zip = new ZipFile ( file ) ; zipFilePath = ( Path ) this . resource . getFullPath ( ) . makeRelative ( ) ; } else { if ( JavaModelManager . ZIP_ACCESS_VERBOSE ) System . out . println ( "(" + Thread . currentThread ( ) + "" + this . containerPath ) ; zip = new ZipFile ( this . containerPath . toFile ( ) ) ; zipFilePath = ( Path ) this . containerPath ; } if ( this . isCancelled ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + zip . getName ( ) + "" ) ; return false ; } if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "-> indexing " + zip . getName ( ) ) ; long initialTime = System . currentTimeMillis ( ) ; String [ ] paths = index . queryDocumentNames ( "" ) ; if ( paths != null ) { int max = paths . length ; String EXISTS = "OK" ; String DELETED = "DELETED" ; SimpleLookupTable indexedFileNames = new SimpleLookupTable ( max == 0 ? 33 : max + 11 ) ; for ( int i = 0 ; i < max ; i ++ ) indexedFileNames . put ( paths [ i ] , DELETED ) ; for ( Enumeration e = zip . entries ( ) ; e . hasMoreElements ( ) ; ) { ZipEntry ze = ( ZipEntry ) e . nextElement ( ) ; String zipEntryName = ze . getName ( ) ; if ( Util . isClassFileName ( zipEntryName ) && isValidPackageNameForClass ( zipEntryName ) ) indexedFileNames . put ( zipEntryName , EXISTS ) ; } boolean needToReindex = indexedFileNames . elementSize != max ; if ( ! needToReindex ) { Object [ ] valueTable = indexedFileNames . valueTable ; for ( int i = 0 , l = valueTable . length ; i < l ; i ++ ) { if ( valueTable [ i ] == DELETED ) { needToReindex = true ; break ; } } if ( ! needToReindex ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + zip . getName ( ) + " (" + ( System . currentTimeMillis ( ) - initialTime ) + "ms)" ) ; this . manager . saveIndex ( index ) ; return true ; } } } SearchParticipant participant = SearchEngine . getDefaultSearchParticipant ( ) ; if ( ! this . manager . resetIndex ( this . containerPath ) ) { this . manager . removeIndex ( this . containerPath ) ; return false ; } index . separator = JAR_SEPARATOR ; for ( Enumeration e = zip . entries ( ) ; e . hasMoreElements ( ) ; ) { if ( this . isCancelled ) { if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + zip . getName ( ) + "" ) ; return false ; } ZipEntry ze = ( ZipEntry ) e . nextElement ( ) ; String zipEntryName = ze . getName ( ) ; if ( Util . isClassFileName ( zipEntryName ) && isValidPackageNameForClass ( zipEntryName ) ) { final byte [ ] classFileBytes = org . eclipse . jdt . internal . compiler . util . Util . getZipEntryByteContent ( ze , zip ) ; JavaSearchDocument entryDocument = new JavaSearchDocument ( ze , zipFilePath , classFileBytes , participant ) ; this . manager . indexDocument ( entryDocument , participant , index , this . containerPath ) ; } } this . manager . saveIndex ( index ) ; if ( JobManager . VERBOSE ) org . eclipse . jdt . internal . core . util . Util . verbose ( "" + zip . getName ( ) + " (" + ( System . currentTimeMillis ( ) - initialTime ) + "ms)" ) ; } finally { if ( zip != null ) { if ( JavaModelManager . ZIP_ACCESS_VERBOSE ) System . out . println ( "(" + Thread . currentThread ( ) + "" + zip ) ; zip . close ( ) ; } monitor . exitWrite ( ) ; } } catch ( IOException e ) { if ( JobManager . VERBOSE ) { org . eclipse . jdt . internal . core . util . Util . verbose ( "" + this . containerPath + "" ) ; e . printStackTrace ( ) ; } this . manager . removeIndex ( this . containerPath ) ; return false ; } return true ; } public String getJobFamily ( ) { if ( this . resource != null ) return super . getJobFamily ( ) ; return this . containerPath . toOSString ( ) ; } private boolean isValidPackageNameForClass ( String className ) { char [ ] classNameArray = className . toCharArray ( ) ; if ( this . scanner == null ) this . scanner = new Scanner ( false , true , false , ClassFileConstants . JDK1_3 , null , null , true ) ; this . scanner . setSource ( classNameArray ) ; this . scanner . eofPosition = classNameArray . length - SuffixConstants . SUFFIX_CLASS . length ; try { if ( this . scanner . scanIdentifier ( ) == TerminalTokens . TokenNameIdentifier ) { while ( this . scanner . eofPosition > this . scanner . currentPosition ) { if ( this . scanner . getNextChar ( ) != '/' || this . scanner . eofPosition <= this . scanner . currentPosition ) { return false ; } if ( this . scanner . scanIdentifier ( ) != TerminalTokens . TokenNameIdentifier ) { return false ; } } return true ; } } catch ( InvalidInputException e ) { } return false ; } protected Integer updatedIndexState ( ) { return IndexManager . REBUILDING_STATE ; } public String toString ( ) { return "indexing " + this . containerPath . toString ( ) ; } } </s>