Package org.apache.sling.commons.compiler

Examples of org.apache.sling.commons.compiler.Options


     * @see org.apache.sling.jcr.compiler.JcrJavaCompiler#compile(java.lang.String[], org.apache.sling.commons.compiler.Options)
     */
    public CompilationResult compile(final String[] srcFiles, final Options compilerOptions)
    throws Exception {
        // make sure we have options
        final Options options = (compilerOptions == null ? new Options() : new Options(compilerOptions));
        // open session
        Session session = null;
        try {
            session = this.repository.loginAdministrative(null);

View Full Code Here


     * @see org.apache.sling.commons.compiler.JavaCompiler#compile(org.apache.sling.commons.compiler.CompilationUnit[], org.apache.sling.commons.compiler.Options)
     */
    public CompilationResult compile(final CompilationUnit[] units,
                                     final Options compileOptions) {
        // make sure we have an options object (to avoid null checks all over the place)
        final Options options = (compileOptions != null ? compileOptions : EMPTY_OPTIONS);

        // get classloader and classloader writer
        final ClassLoaderWriter writer = this.getClassLoaderWriter(options);
        if ( writer == null ) {
            return new CompilationResultImpl("Class loader writer for compilation is not available.");
        }
        final ClassLoader loader = this.getClassLoader(options, writer);
        if ( loader == null ) {
            return new CompilationResultImpl("Class loader for compilation is not available.");
        }

        // check sources for compilation
        boolean needsCompilation = isForceCompilation(options);
        if ( !needsCompilation ) {
            for(final CompilationUnit unit : units) {
                if ( this.isOutDated(unit, writer) ) {
                    needsCompilation = true;
                    break;
                }
            }
        }
        if ( !needsCompilation ) {
            logger.debug("All source files are recent - no compilation required.");
            return new CompilationResultImpl(writer);
        }

        // delete old class files
        for(final CompilationUnit unit : units) {
            final String name = '/' + unit.getMainClassName().replace('.', '/') + ".class";
            writer.delete(name);
        }

        // create properties for the settings object
        final Map<String, String> props = new HashMap<String, String>();
        if (options.isGenerateDebugInfo()) {
            props.put(CompilerOptions.OPTION_LocalVariableAttribute, "generate");
            props.put(CompilerOptions.OPTION_LineNumberAttribute, "generate");
            props.put(CompilerOptions.OPTION_SourceFileAttribute, "generate");
        }
        if (options.getSourceVersion() != null) {
            props.put(CompilerOptions.OPTION_Source, options.getSourceVersion());
            props.put(CompilerOptions.OPTION_Compliance, options.getSourceVersion());
        }
        if (options.getTargetVersion() != null) {
            props.put(CompilerOptions.OPTION_TargetPlatform, options.getTargetVersion());
        }
        props.put(CompilerOptions.OPTION_Encoding, "UTF8");

        // create the settings
        final CompilerOptions settings = new CompilerOptions(props);
View Full Code Here

    public void testJava5Support() throws Exception {
        String sourceFile = "Java5Test";

        CompilationUnit unit = createCompileUnit(sourceFile);
        final Options options = new Options();
        options.put(Options.KEY_SOURCE_VERSION, Options.VERSION_1_5);
        options.put(Options.KEY_CLASS_LOADER_WRITER, this);
        options.put(Options.KEY_CLASS_LOADER, this.getClass().getClassLoader());

        final CompilationResult result = new EclipseJavaCompiler().compile(new CompilationUnit[]{unit}, options);
        assertNotNull(result);
        assertNull(result.getErrors());
    }
View Full Code Here

            public String getFileName() {
                return sourceFile;
            }
        };

        final Options options = new Options();
        options.put(Options.KEY_CLASS_LOADER_WRITER, ctxt.getRuntimeContext().getIOProvider().getClassLoaderWriter());
        options.put(Options.KEY_GENERATE_DEBUG_INFO, ctxt.getOptions().getClassDebugInfo());

        // Source JVM
        if (ctxt.getOptions().getCompilerSourceVM() != null) {
            options.put(Options.KEY_SOURCE_VERSION, ctxt.getOptions().getCompilerSourceVM());
        } else {
            // Default to 1.6
            options.put(Options.KEY_SOURCE_VERSION, Options.VERSION_1_6);
        }

        // Target JVM
        if (ctxt.getOptions().getCompilerTargetVM() != null) {
            options.put(Options.KEY_TARGET_VERSION, ctxt.getOptions().getCompilerTargetVM());
        } else {
            // Default to 1.6
            options.put(Options.KEY_TARGET_VERSION, Options.VERSION_1_6);
        }

        final ArrayList<JavacErrorDetail> problemList = new ArrayList<JavacErrorDetail>();
        final CompilationResult result = this.ctxt.getRuntimeContext().getIOProvider().getJavaCompiler().compile(new CompilationUnit[] {unit}, options);
        if ( result.getErrors() != null ) {
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.compiler.Options

Copyright © 2018 www.massapicom. 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.