public SourceFile findSourceFile ( String packageName , String fileName ) throws IOException { // On windows the fileName specification is different between a file in // a directory tree, and a // file in a zip file. In a directory tree the separator used is '\', // while in a zip it's '/' // Therefore for each repository figure out what kind it is and use the // appropriate separator. // In all practicality, this code could just use the hardcoded '/' char, // as windows can open // files with this separator, but to allow for the mythical 'other' // platform that uses an // alternate separator, make a distinction String platformName = getPlatformName ( packageName , fileName ) ; String canonicalName = getCanonicalName ( packageName , fileName ) ; // Is the file in the cache already? Always cache it with the canonical // name SourceFile sourceFile = cache . get ( canonicalName ) ; if ( sourceFile != null ) { return sourceFile ; } // Find this source file, add its data to the cache if ( DEBUG ) { System . out . println ( "Trying " + fileName + " in package " + packageName + "..." ) ; } // Query each element of the source path to find the requested source // file for ( SourceRepository repos : repositoryList ) { if ( repos instanceof BlockingSourceRepository && ! ( ( BlockingSourceRepository ) repos ) . isReady ( ) ) { continue ; } fileName = repos . isPlatformDependent ( ) ? platformName : canonicalName ; if ( DEBUG ) { System . out . println ( "Looking in " + repos + " for " + fileName ) ; } if ( repos . contains ( fileName ) ) { // Found it sourceFile = new SourceFile ( repos . getDataSource ( fileName ) ) ; cache . put ( canonicalName , sourceFile ) ; // always cache with // canonicalName return sourceFile ; } } throw new FileNotFoundException ( "Can't find source file " + fileName ) ; }
Open a source file in given package .