Package com.caucho.java

Examples of com.caucho.java.JavaCompiler


   * Compiles the pending files
   */
  public void compilePendingJava()
    throws IOException, ClassNotFoundException
  {
    JavaCompiler compiler = JavaCompiler.create(getPreloadLoader());

    compiler.setClassLoader(getPreloadLoader());
    compiler.setClassDir(getWorkDir());

    if (_encoding != null)
      compiler.setEncoding(_encoding);

    String []files = new String[_pendingFiles.size()];
    _pendingFiles.toArray(files);
    _pendingFiles.clear();

    compiler.compileBatch(files);
  }
View Full Code Here


      scriptPath = mergePath;
    }
   
    block = null;

    JavaCompiler compiler = JavaCompiler.create(getClassLoader());
    compiler.setClassDir(workPath);

    parseClass = new ParseClass(name, className);
    parseClass.setParser(this);
    if (is.getPath() != null && is.getPath().getLastModified() > 0)
      parseClass.setSourcePath(is.getPath());

    globalFunction = parseClass.newFunction(null, ESId.intern("global"), false);
    globalFunction.setFast(isFast);
    staticFunction = parseClass.newFunction(null, ESId.intern("__es_static"), false);
    parseClass.setGlobal(globalFunction);

    if (isEval) {
      block = Block.create(this, globalFunction);
      block.finish();
      function = parseClass.newFunction(globalFunction, ESId.intern("eval"), false);
      function.setEval();
    }
    else
      function = globalFunction;
   
    block = Block.create(this, function);
    parseBlock(true);
    block.finish();

    if (lexer.peek() != Lexer.EOF)
      throw expect(L.l("end of file"));

    block = Block.create(this, staticFunction);
    block.finish();

    synchronized (LOCK) {
      Path path = workPath.lookup(className.replace('.', '/') + ".java");
      path.getParent().mkdirs();
   
      WriteStream os = path.openWrite();
      os.setEncoding("JAVA");
      parseClass.writeCode(os);
      os.close();

      Script script;
      try {
        compiler.compile(className.replace('.', '/') + ".java", null);
        script = loadScript(className);
      } catch (Exception e) {
        throw new ESParseException(e);
      }
View Full Code Here

  void compileClass(Path javaSource, Path javaClass,
        String sourcePath, boolean isMake)
    throws ClassNotFoundException
  {
    try {
      JavaCompiler compiler = JavaCompiler.create(getClassLoader());
      compiler.setClassDir(_classDir);
      compiler.setSourceDir(_sourceDir);
      if (_encoding != null)
        compiler.setEncoding(_encoding);
      compiler.setArgs(_args);
      compiler.setCompileParent(! isMake);
      compiler.setSourceExtension(_sourceExt);
      if (_compiler != null)
  compiler.setCompiler(_compiler);

      //LineMap lineMap = new LineMap(javaFile.getNativePath());
      // The context path is obvious from the browser url
      //lineMap.add(name.replace('.', '/') + _sourceExt, 1, 1);

      // Force this into a relative path so different compilers will work
      String prefix = _sourceDir.getPath();
      String full = javaSource.getPath();

      String source;
      if (full.startsWith(prefix)) {
        source = full.substring(prefix.length());
        if (source.startsWith("/"))
          source = source.substring(1);
      }
      else
        source = javaSource.getPath();

      /*
      if (javaSource.canRead() && javaClass.exists())
        javaClass.remove();
      */
         
      compiler.compileIfModified(source, null);
    } catch (Exception e) {
      getClassLoader().addDependency(new Depend(javaSource));

      log.log(Level.FINEST, e.toString(), e);

View Full Code Here

   */
  void compileBatch(String []files, boolean isMake)
    throws ClassNotFoundException
  {
    try {
      JavaCompiler compiler = JavaCompiler.create(getClassLoader());
      compiler.setClassDir(_classDir);
      compiler.setSourceDir(_sourceDir);
      if (_encoding != null)
        compiler.setEncoding(_encoding);
      compiler.setArgs(_args);
      compiler.setCompileParent(! isMake);
      compiler.setSourceExtension(_sourceExt);
      if (_compiler != null)
  compiler.setCompiler(_compiler);

      //LineMap lineMap = new LineMap(javaFile.getNativePath());
      // The context path is obvious from the browser url
      //lineMap.add(name.replace('.', '/') + _sourceExt, 1, 1);
         
      compiler.compileBatch(files);
    } catch (Exception e) {
      getClassLoader().addDependency(AlwaysModified.create());

      // Compile errors are wrapped in a special ClassNotFound class
      // so the server can give a nice error message
View Full Code Here

   * Compiles the class.
   */
  public void compileJava(String fullClassName)
    throws IOException, ClassNotFoundException
  {
    JavaCompiler compiler = JavaCompiler.create(getPreloadLoader());

    compiler.setClassLoader(getPreloadLoader());
    compiler.setClassDir(getWorkDir());

    if (_encoding != null)
      compiler.setEncoding(_encoding);

    compiler.compile(fullClassName.replace('.', '/') + ".java", null);
  }
View Full Code Here

   * Compiles the pending files
   */
  public void compilePendingJava()
    throws IOException, ClassNotFoundException
  {
    JavaCompiler compiler = JavaCompiler.create(getPreloadLoader());

    compiler.setClassLoader(getPreloadLoader());
    compiler.setClassDir(getWorkDir());

    if (_encoding != null)
      compiler.setEncoding(_encoding);

    String []files = new String[_pendingFiles.size()];
    _pendingFiles.toArray(files);
    _pendingFiles.clear();

    compiler.compileBatch(files);
  }
View Full Code Here

  void compileClass(Path javaSource, Path javaClass,
                    String sourcePath, boolean isMake)
    throws ClassNotFoundException
  {
    try {
      JavaCompiler compiler = JavaCompiler.create(getClassLoader());
      compiler.setClassDir(_classDir);
      compiler.setSourceDir(_sourceDir);
      if (_encoding != null)
        compiler.setEncoding(_encoding);
      compiler.setArgs(_args);
      compiler.setCompileParent(! isMake);
      compiler.setSourceExtension(_sourceExt);
      if (_compiler != null)
        compiler.setCompiler(_compiler);

      //LineMap lineMap = new LineMap(javaFile.getNativePath());
      // The context path is obvious from the browser url
      //lineMap.add(name.replace('.', '/') + _sourceExt, 1, 1);

      // Force this into a relative path so different compilers will work
      String prefix = _sourceDir.getPath();
      String full = javaSource.getPath();

      String source;
      if (full.startsWith(prefix)) {
        source = full.substring(prefix.length());
        if (source.startsWith("/"))
          source = source.substring(1);
      }
      else
        source = javaSource.getPath();

      /*
      if (javaSource.canRead() && javaClass.exists())
        javaClass.remove();
      */
         
      compiler.compileIfModified(source, null);
    } catch (Exception e) {
      getClassLoader().addDependency(new Depend(javaSource));

      log.log(Level.FINEST, e.toString(), e);

View Full Code Here

   */
  void compileBatch(String []files, boolean isMake)
    throws ClassNotFoundException
  {
    try {
      JavaCompiler compiler = JavaCompiler.create(getClassLoader());
      compiler.setClassDir(_classDir);
      compiler.setSourceDir(_sourceDir);
      if (_encoding != null)
        compiler.setEncoding(_encoding);
      compiler.setArgs(_args);
      compiler.setCompileParent(! isMake);
      compiler.setSourceExtension(_sourceExt);
      if (_compiler != null)
        compiler.setCompiler(_compiler);

      //LineMap lineMap = new LineMap(javaFile.getNativePath());
      // The context path is obvious from the browser url
      //lineMap.add(name.replace('.', '/') + _sourceExt, 1, 1);
         
      compiler.compileBatch(files);
    } catch (Exception e) {
      getClassLoader().addDependency(AlwaysModified.create());

      // Compile errors are wrapped in a special ClassNotFound class
      // so the server can give a nice error message
View Full Code Here

TOP

Related Classes of com.caucho.java.JavaCompiler

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.