langtools/test/tools/javac/T6358166.java
changeset 24897 655b72d7b96e
parent 10193 3e1ef5e9f4fd
child 26264 a09fedde76be
equal deleted inserted replaced
24896:986d876a9121 24897:655b72d7b96e
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    55         test(fm, f, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
    55         test(fm, f, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
    56     }
    56     }
    57 
    57 
    58     static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    58     static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    59         Context context = new Context();
    59         Context context = new Context();
    60         fm.setContext(context);
       
    61 
    60 
    62         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    61         Main compilerMain = initCompilerMain(context, fm, args);
    63         compilerMain.setOptions(Options.instance(context));
       
    64         compilerMain.filenames = new LinkedHashSet<File>();
       
    65         compilerMain.processArgs(args);
       
    66 
    62 
    67         JavaCompiler c = JavaCompiler.instance(context);
    63         JavaCompiler c = JavaCompiler.instance(context);
    68 
    64 
    69         c.compile(List.of(f));
    65         c.compile(List.of(f));
    70 
    66 
    74         long msec = c.elapsed_msec;
    70         long msec = c.elapsed_msec;
    75         if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
    71         if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
    76             throw new AssertionError("elapsed time is suspect: " + msec);
    72             throw new AssertionError("elapsed time is suspect: " + msec);
    77     }
    73     }
    78 
    74 
       
    75     static Main initCompilerMain(Context context, JavacFileManager fm, String... args) {
       
    76         fm.setContext(context);
       
    77         context.put(JavaFileManager.class, fm);
       
    78 
       
    79         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
       
    80         compilerMain.setOptions(Options.instance(context));
       
    81         compilerMain.filenames = new LinkedHashSet<File>();
       
    82         compilerMain.deferredFileManagerOptions = new LinkedHashMap<>();
       
    83         compilerMain.processArgs(args);
       
    84         fm.handleOptions(compilerMain.deferredFileManagerOptions);
       
    85         return compilerMain;
       
    86     }
       
    87 
    79     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    88     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    80         return true;
    89         return true;
    81     }
    90     }
    82 }
    91 }