Examples of VolatileClassOutputManager


Examples of com.asakusafw.utils.java.jsr199.testing.VolatileClassOutputManager

        assert compiler != null;
        assert jar != null;

        DiagnosticCollector<JavaFileObject> diagnostics =
            new DiagnosticCollector<JavaFileObject>();
        VolatileClassOutputManager fileManager = new VolatileClassOutputManager(
                compiler.getStandardFileManager(
                        diagnostics,
                        Locale.getDefault(),
                        CHARSET));
        try {
            List<String> arguments = Lists.create();
            Collections.addAll(arguments, "-source", "1.6");
            Collections.addAll(arguments, "-target", "1.6");
            Collections.addAll(arguments, "-encoding", CHARSET.name());

            StringWriter errors = new StringWriter();
            PrintWriter pw = new PrintWriter(errors);

            CompilationTask task = compiler.getTask(
                    pw,
                    fileManager,
                    diagnostics,
                    arguments,
                    Collections.<String>emptyList(),
                    emitter.getEmitted());

            Boolean successed = task.call();
            pw.close();
            for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) {
                switch (diagnostic.getKind()) {
                case ERROR:
                case MANDATORY_WARNING:
                    getEnvironment().error(diagnostic.getMessage(null));
                    break;
                case WARNING:
                    LOG.warn(diagnostic.getMessage(null));
                    break;
                default:
                    LOG.info(diagnostic.getMessage(null));
                    break;
                }
            }
            if(Boolean.TRUE.equals(successed) == false) {
                throw new IOException(MessageFormat.format(
                        "{0}のコンパイルに失敗しました: {1}",
                        getEnvironment().getTargetId(),
                        errors.toString()));
            }

            for (VolatileResourceFile file : fileManager.getResources()) {
                addEntry(jar, file);
            }
            for (VolatileClassFile file : fileManager.getCompiled()) {
                addEntry(jar, file);
            }
            for (Map.Entry<String, byte[]> entry : contents.entrySet()) {
                addEntry(jar, entry.getKey(), entry.getValue());
            }
        } finally {
            fileManager.close();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.