com.sun.tools.javac.file.JavacFileManager Java Examples

The following examples show how to use com.sun.tools.javac.file.JavacFileManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StarImportTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Setup env by creating pseudo-random collection of names, packages and classes.
 */
void setup() {
    log ("setup");
    context = new Context();
    JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
    make = TreeMaker.instance(context);
    names = Names.instance(context);       // Name.Table impls tied to an instance of Names
    symtab = Symtab.instance(context);
    types = Types.instance(context);
    int setupCount = rgen.nextInt(MAX_SETUP_COUNT);
    for (int i = 0; i < setupCount; i++) {
        switch (random(SetupKind.values())) {
            case NAMES:
                setupNames();
                break;
            case PACKAGE:
                setupPackage();
                break;
            case CLASS:
                setupClass();
                break;
        }
    }
}
 
Example #2
Source File: T6725036.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class");

    File testJar = createJar("test.jar", "java.lang.*");

    try (JarFile j = new JarFile(testJar)) {
        JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath());
        long jarEntryTime = je.getTime();

        Context context = new Context();
        JavacFileManager fm = new JavacFileManager(context, false, null);
        fm.setLocation(StandardLocation.CLASS_PATH, Collections.singletonList(testJar));
        FileObject fo =
            fm.getFileForInput(StandardLocation.CLASS_PATH, "", TEST_ENTRY_NAME.getPath());
        long jfoTime = fo.getLastModified();

        check(je, jarEntryTime, fo, jfoTime);

        if (errors > 0)
            throw new Exception(errors + " occurred");
    }
}
 
Example #3
Source File: T6358166.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example #4
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an empty processor iterator if no processors are on the
 * relevant path, otherwise if processors are present, logs an
 * error.  Called when a service loader is unavailable for some
 * reason, either because a service loader class cannot be found
 * or because a security policy prevents class loaders from being
 * created.
 *
 * @param key The resource key to use to log an error message
 * @param e   If non-null, pass this exception to Abort
 */
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
    JavaFileManager fileManager = context.get(JavaFileManager.class);

    if (fileManager instanceof JavacFileManager) {
        StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
        Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
            ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
            : standardFileManager.getLocation(CLASS_PATH);

        if (needClassLoader(options.get(PROCESSOR), workingPath) )
            handleException(key, e);

    } else {
        handleException(key, e);
    }

    java.util.List<Processor> pl = Collections.emptyList();
    return pl.iterator();
}
 
Example #5
Source File: InferenceRegressionTest02.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Trees trees = JavacTrees.instance(context);
    StringWriter strOut = new StringWriter();
    PrintWriter pw = new PrintWriter(strOut);
    DPrinter dprinter = new DPrinter(pw, trees);
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource()));
    Iterable<? extends CompilationUnitTree> elements = ct.parse();
    ct.analyze();
    Assert.check(elements.iterator().hasNext());
    dprinter.treeTypes(true).printTree("", (JCTree)elements.iterator().next());
    String output = strOut.toString();
    Assert.check(!output.contains("java.lang.Object"), "there shouldn't be any type instantiated to Object");
}
 
Example #6
Source File: T6358168.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #7
Source File: T6358166.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Throwable {
    String self = T6358166.class.getName();

    String testSrc = System.getProperty("test.src");

    JavacFileManager fm = new JavacFileManager(new Context(), false, null);
    JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java");

    List<String> addExports = Arrays.asList(
            "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
            "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
            "--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
            "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");

    test(fm, f, addExports, "-verbose", "-d", ".");

    test(fm, f, addExports, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
}
 
Example #8
Source File: T6358168.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #9
Source File: T6358168.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Throwable {

        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
        JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");

        try {
            // first, test case with no annotation processing
            testNoAnnotationProcessing(fm, f);

            // now, test case with annotation processing
            testAnnotationProcessing(fm, f);
        }
        catch (Throwable t) {
            AssertionError e = new AssertionError();
            e.initCause(t);
            throw e;
        }
    }
 
Example #10
Source File: T6358168.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #11
Source File: JavadocTaskImplTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDirectAccess2() throws Exception {
    JavaFileObject srcFile = null; // error, provokes NPE
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    StandardJavaFileManager fm = new JavacFileManager(c, true, null);
    File outDir = getOutDir();
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    try {
        DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
        error("getTask succeeded, no exception thrown");
    } catch (NullPointerException e) {
        System.err.println("exception caught as expected: " + e);
    }
}
 
Example #12
Source File: JavadocTaskImplTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDirectAccess1() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    StandardJavaFileManager fm = new JavacFileManager(c, true, null);
    File outDir = getOutDir();
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
    if (t.call()) {
        System.err.println("task succeeded");
    } else {
        throw new Exception("task failed");
    }
}
 
Example #13
Source File: MakeLiteralTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #14
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an empty processor iterator if no processors are on the
 * relevant path, otherwise if processors are present, logs an
 * error.  Called when a service loader is unavailable for some
 * reason, either because a service loader class cannot be found
 * or because a security policy prevents class loaders from being
 * created.
 *
 * @param key The resource key to use to log an error message
 * @param e   If non-null, pass this exception to Abort
 */
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
    JavaFileManager fileManager = context.get(JavaFileManager.class);

    if (fileManager instanceof JavacFileManager) {
        StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
        Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
            ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
            : standardFileManager.getLocation(CLASS_PATH);

        if (needClassLoader(options.get(PROCESSOR), workingPath) )
            handleException(key, e);

    } else {
        handleException(key, e);
    }

    java.util.List<Processor> pl = Collections.emptyList();
    return pl.iterator();
}
 
Example #15
Source File: JavacTool.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override @DefinedBy(Api.COMPILER)
public JavacFileManager getStandardFileManager(
    DiagnosticListener<? super JavaFileObject> diagnosticListener,
    Locale locale,
    Charset charset) {
    Context context = new Context();
    context.put(Locale.class, locale);
    if (diagnosticListener != null)
        context.put(DiagnosticListener.class, diagnosticListener);
    PrintWriter pw = (charset == null)
            ? new PrintWriter(System.err, true)
            : new PrintWriter(new OutputStreamWriter(System.err, charset), true);
    context.put(Log.errKey, pw);
    CacheFSInfo.preRegister(context);
    return new JavacFileManager(context, true, charset);
}
 
Example #16
Source File: T6358168.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Throwable {

        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
        JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");

        try {
            // first, test case with no annotation processing
            testNoAnnotationProcessing(fm, f);

            // now, test case with annotation processing
            testAnnotationProcessing(fm, f);
        }
        catch (Throwable t) {
            AssertionError e = new AssertionError();
            e.initCause(t);
            throw e;
        }
    }
 
Example #17
Source File: T6358168.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #18
Source File: JavadocTaskImplTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDirectAccess1() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    StandardJavaFileManager fm = new JavacFileManager(c, true, null);
    File outDir = getOutDir();
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
    if (t.call()) {
        System.err.println("task succeeded");
    } else {
        throw new Exception("task failed");
    }
}
 
Example #19
Source File: StarImportTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Setup env by creating pseudo-random collection of names, packages and classes.
 */
void setup() {
    log ("setup");
    context = new Context();
    JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
    names = Names.instance(context);       // Name.Table impls tied to an instance of Names
    symtab = Symtab.instance(context);
    int setupCount = rgen.nextInt(MAX_SETUP_COUNT);
    for (int i = 0; i < setupCount; i++) {
        switch (random(SetupKind.values())) {
            case NAMES:
                setupNames();
                break;
            case PACKAGE:
                setupPackage();
                break;
            case CLASS:
                setupClass();
                break;
        }
    }
}
 
Example #20
Source File: TestJavacParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void test4() {
    Context context = new Context();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    context.put(DiagnosticListener.class, diagnostics);
    Options.instance(context).put("allowStringFolding", "false");
    JCTree.JCCompilationUnit unit;
    JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
    try {
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.<File>of());
    } catch (IOException e) {
        // impossible
        throw new IOError(e);
    }
    SimpleJavaFileObject source =
            new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
                @Override
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    return src;
                }
            };
    Log.instance(context).useSource(source);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Parser parser =
            parserFactory.newParser(
                    src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
}
 
Example #21
Source File: T6625520.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
    Context c = new Context();
    DiagnosticCollector<JavaFileObject> dc =
        new DiagnosticCollector<JavaFileObject>();
    c.put(DiagnosticListener.class, dc);
    StandardJavaFileManager fm = new JavacFileManager(c, false, null);
    fm.setLocation(StandardLocation.CLASS_PATH,
                   Arrays.asList(new File("DOES_NOT_EXIST.jar")));
    FileObject fo = fm.getFileForInput(StandardLocation.CLASS_PATH,
                                       "p", "C.java");
    System.err.println(fo + "\n" + dc.getDiagnostics());
    if (dc.getDiagnostics().size() > 0)
        throw new Exception("unexpected diagnostics found");
}
 
Example #22
Source File: JavaCompiler.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Try to open input stream with given name.
 * Report an error if this fails.
 *
 * @param filename The file name of the input stream to be opened.
 */
public CharSequence readSource(JavaFileObject filename) {
    try {
        inputFiles.add(filename);
        return filename.getCharContent(false);
    } catch (IOException e) {
        log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
        return null;
    }
}
 
Example #23
Source File: DiagnosticSource.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected char[] initBuf(JavaFileObject fileObject) throws IOException {
    char[] buf;
    CharSequence cs = fileObject.getCharContent(true);
    if (cs instanceof CharBuffer) {
        CharBuffer cb = (CharBuffer) cs;
        buf = JavacFileManager.toArray(cb);
        bufLen = cb.limit();
    } else {
        buf = cs.toString().toCharArray();
        bufLen = buf.length;
    }
    refBuf = new SoftReference<char[]>(buf);
    return buf;
}
 
Example #24
Source File: TestJavacParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void test1() {
    Context context = new Context();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    context.put(DiagnosticListener.class, diagnostics);
    Options.instance(context).put("allowStringFolding", "false");
    JCTree.JCCompilationUnit unit;
    JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
    try {
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.<File>of());
    } catch (IOException e) {
        // impossible
        throw new IOError(e);
    }
    SimpleJavaFileObject source =
            new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
                @Override
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    return src;
                }
            };
    Log.instance(context).useSource(source);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Parser parser =
            parserFactory.newParser(
                    src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
}
 
Example #25
Source File: Main.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Programmatic interface for main function.
 *
 * @param args The command line parameters.
 */
public int compile(String[] args) {
    Context context = new Context();
    JavacFileManager.preRegister(context); // can't create it until Log has been set up
    int result = compile(args, context);
    if (fileManager instanceof JavacFileManager) {
        // A fresh context was created above, so jfm must be a JavacFileManager
        ((JavacFileManager) fileManager).close();
    }
    return result;
}
 
Example #26
Source File: CompoundScopeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Setup compiler context
 */
void setup() {
    log ("setup");
    context = new Context();
    JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
    names = Names.instance(context);       // Name.Table impls tied to an instance of Names
    symtab = Symtab.instance(context);
}
 
Example #27
Source File: ImplementationCacheTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    List<? extends JavaFileObject> files = Arrays.asList(new SourceFile());
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files);
    Context ctx = new Context();
    JavacFileManager.preRegister(ctx);
    checkImplementationCache(ct.analyze(), Types.instance(ctx));
}
 
Example #28
Source File: GetDeps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}
 
Example #29
Source File: T6625520.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
    Context c = new Context();
    DiagnosticCollector<JavaFileObject> dc =
        new DiagnosticCollector<JavaFileObject>();
    c.put(DiagnosticListener.class, dc);
    StandardJavaFileManager fm = new JavacFileManager(c, false, null);
    fm.setLocation(StandardLocation.CLASS_PATH,
                   Arrays.asList(new File("DOES_NOT_EXIST.jar")));
    FileObject fo = fm.getFileForInput(StandardLocation.CLASS_PATH,
                                       "p", "C.java");
    System.err.println(fo + "\n" + dc.getDiagnostics());
    if (dc.getDiagnostics().size() > 0)
        throw new Exception("unexpected diagnostics found");
}
 
Example #30
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) {
    Context c = new Context();
    Options options = Options.instance(c);

    options.put("useOptimizedZip", Boolean.toString(useOptimizedZip));

    if (!useSymbolFile) {
        options.put("ignore.symbol.file", "true");
    }
    return new JavacFileManager(c, false, null);
}