Package org.jostraca.process

Source Code of org.jostraca.process.ExternalGroovyController

/*
* Name:    ExternalGroovyController
* Authors: Richard Rodger
*
* Copyright (c) 2008 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/


// package
package org.jostraca.process;


// import
import org.jostraca.Property;
import org.jostraca.Template;

import org.jostraca.util.Standard;
import org.jostraca.util.StandardException;
import org.jostraca.util.PropertySet;
import org.jostraca.util.BasicWayPoint;
import org.jostraca.util.WayPointRecorder;

import java.util.List;

import java.io.File;


/** Processing class for external jython script execution.
*/
public class ExternalGroovyController extends JythonController {

  public ExternalGroovyController() {
    // do nothing
  }


  protected void processImpl( Template pTemplate ) {
    Template    template   = pTemplate;
    PropertySet tmps       = template.getMergedPropertySet();

    File   codeWriterPath   = template.getCodeWriterPath();
    String codeWriterSource = template.getCodeWriterSource();


    try {
      String externalController        = makeExternalController( tmps );
      String externalControllerOptions = tmps.get( Property.main_ExternalControllerOptions );
      String absoluteCodeWriterPath    = getCodeWriterPath( tmps );
      String codeWriterOptions         = makeCodeWriterOptions( tmps, template );

      String cmd
        = externalController + Standard.SPACE
        + externalControllerOptions + Standard.SPACE
        + absoluteCodeWriterPath + Standard.SPACE
        + codeWriterOptions
        ;
     
      boolean successful = executeGeneratingCmd( cmd, template );
      WayPointRecorder.add( BasicWayPoint.ExecutingCodeWriter.make( template.getCodeWriterPath().getAbsolutePath() ) );
    }
    catch( StandardException se ) {
      throw se;
    }
    catch( Exception e ) {
      // FIX: needs more info
      throw new ProcessException( e );
    }
  }


  protected void completeImpl( List pTemplateList ) {
    // do nothing
  }



  protected String makeExternalController( PropertySet pPropertySet ) {
    String externalController = pPropertySet.get( Property.main_ExternalController );

    // if windows
    /*
    if( -1 != (System.getProperties().getProperty("os.name")).indexOf("Windows") ) {
      if( !externalController.endsWith(".bat") && pPropertySet.isYes("groovy.fixWindowsBatchFileName") ) {
        externalController += ".bat";
      }
    }
  */
   
    return externalController;
  }
   
}




TOP

Related Classes of org.jostraca.process.ExternalGroovyController

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.