Package org.objectweb.speedo.generation.recompiler

Source Code of org.objectweb.speedo.generation.recompiler.Recompiler

/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.generation.recompiler;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.PatternSet.NameEntry;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
import org.objectweb.speedo.generation.mivisitor.MetaInfoVisitorImpl;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.metadata.SpeedoClass;
import org.objectweb.speedo.tools.StringReplace;
import org.objectweb.util.monolog.api.BasicLevel;

import java.io.File;

/**
*
* @author S.Chassande-Barrioz
*/
public class Recompiler extends MetaInfoVisitorImpl {
  /**
   * Ant Task intended to java compilation
   */
  protected Javac compiler;

  public Recompiler(Personality p) {
    super(p);
  }
 
  protected String getLoggerName() {
    return super.getLoggerName() + ".recompiler";
  }

    public String getTitle() {
        return "Recompiling classes ...";
    }


  public void visitCompilerParameter(SpeedoCompilerParameter scp) throws SpeedoException {
    compiler = scp.javac;
    if (compiler == null) {
      compiler = new Javac();
      Project project = new Project();
      project.init();
      compiler.setProject(project);
    }
    compiler.setDestdir(new File(scp.output));
    compiler.setVerbose(debug);
    compiler.setDebug(true);
    compiler.setTaskName("speedo");
    //compiler.setDebugLevel("-g:lines,vars,source");
    compiler.setClasspath(scp.classpath);
    compiler.setClasspath(scp.speedoclasspath);
    Path srcCompiler = new Path(compiler.getProject());
    srcCompiler.createPathElement().setLocation(new File(scp.input));
    compiler.setSrcdir(srcCompiler);
    //Let the visitClass method fill with include
    super.visitCompilerParameter(scp);
    logger.log(BasicLevel.INFO, "Recompilation");
    compiler.execute();
  }

  public void visitClass(SpeedoClass sc) throws SpeedoException {
    super.visitClass(sc);
    if (sc.moPackage.xmlDescriptor.requireEnhancement) {
      String name = sc.getFQName();
      name = StringReplace.replaceChar('.', '/', name);
      name += ".java";
      if (debug) {
        logger.log(BasicLevel.DEBUG, "Class '" + sc.getFQName()
            + "' is going to be recompile (file name= " + name +")");
      }
      NameEntry ne = compiler.createInclude();
      ne.setName(name);
    }
  }
}
TOP

Related Classes of org.objectweb.speedo.generation.recompiler.Recompiler

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.