boolean processRelease ( String release , Collection < String > classes ) throws IOException { options . addAll ( List . of ( "--release" , release ) ) ; if ( release . equals ( "9" ) ) { List < String > rootMods = List . of ( "java.se" , "java.se.ee" ) ; TraverseProc proc = new TraverseProc ( rootMods ) ; JavaCompiler . CompilationTask task = compiler . getTask ( null , fm , this , // options List . of ( "--add-modules" , String . join ( "," , rootMods ) ) , // classes List . of ( "java.lang.Object" ) , null ) ; task . setProcessors ( List . of ( proc ) ) ; if ( ! task . call ( ) ) { return false ; } Map < PackageElement , List < TypeElement > > types = proc . getPublicTypes ( ) ; options . add ( "--add-modules" ) ; options . add ( String . join ( "," , rootMods ) ) ; return doClassNames ( types . values ( ) . stream ( ) . flatMap ( List :: stream ) . map ( TypeElement :: toString ) . collect ( toList ( ) ) ) ; } else { // TODO: kind of a hack... // Create a throwaway compilation task with options "--release N" // which has the side effect of setting the file manager's // PLATFORM_CLASS_PATH to the right value. JavaCompiler compiler = ToolProvider . getSystemJavaCompiler ( ) ; StandardJavaFileManager fm = compiler . getStandardFileManager ( this , null , StandardCharsets . UTF_8 ) ; JavaCompiler . CompilationTask task = compiler . getTask ( null , fm , this , List . of ( "--release" , release ) , null , null ) ; List < Path > paths = new ArrayList <> ( ) ; for ( Path p : fm . getLocationAsPaths ( StandardLocation . PLATFORM_CLASS_PATH ) ) { try ( Stream < Path > str = Files . walk ( p ) ) { str . forEachOrdered ( paths :: add ) ; } } options . add ( "-Xlint:-options" ) ; return doClassNames ( paths . stream ( ) . filter ( path -> path . toString ( ) . endsWith ( ".sig" ) ) . map ( path -> path . subpath ( 1 , path . getNameCount ( ) ) ) . map ( Path :: toString ) . map ( s -> s . replaceAll ( "\\.sig$" , "" ) ) . map ( s -> s . replace ( ' ' , ' ' ) ) . collect ( toList ( ) ) ) ; } }
Process classes from a particular JDK release using only information in this JDK .