Package org.jostraca.util

Examples of org.jostraca.util.ExecutableCommand


          + Standard.SPACE
          + compilerOpts
          ;
      }

      ExecutableCommand cmd = new ExecutableCommand( compiler, compilerOpts, sourceFiles );
      String fullcmd = cmd.getFullCmd();

      cmd.setUserMessageHandler( iUserMessageHandler );
      cmd.setActivityDescription( UserText.get( UserText.TXT_compiling ) );

      boolean successful = cmd.execute
        ( new ExecutableCommand.AlternativeExecutableCommands
          (
           // try jikes if javac not found and vice versa
           new ExecutableCommand( JavaUtil.COMPILER_javac.equals( compiler ) ? JavaUtil.COMPILER_jikes : JavaUtil.COMPILER_javac,
                                  compilerOpts, sourceFiles )

           // try to use JAVA_HOME
           ,new ExecutableCommand( "JAVA_HOME/"+JavaUtil.COMPILER_javac, compilerOpts, sourceFiles ) {
               public boolean execute( ExecutableCommand pParent ) {
                 ExecutableCommand jhc = new ExecutableCommand( "cmd", "/c echo %JAVA_HOME%" );
                 if( jhc.execute( new ExecutableCommand.AlternativeExecutableCommands
                   ( new ExecutableCommand( "sh", "-c \"echo $JAVA_HOME\"" ) ) ) ) {
                   String javaHome = jhc.getOutResult().trim();
                   if( !Standard.EMPTY.equals( javaHome ) ) {
                     iCmdPrefix = javaHome + File.separator + "bin" + File.separator + JavaUtil.COMPILER_javac;
                     return execute();
                   }
                   else {
View Full Code Here


    if( compile ) {
      String sourceFiles  = sourceFilesB.toString();
      String compiler     = tmps.get( Property.main_ExternalCompiler );
      String compilerOpts = tmps.get( Property.main_ExternalCompilerOptions );

      ExecutableCommand cmd = new ExecutableCommand( compiler, compilerOpts, sourceFiles );
      String fullcmd = cmd.getFullCmd();

      cmd.setUserMessageHandler( iUserMessageHandler );
      cmd.setActivityDescription( UserText.get( UserText.TXT_compiling ) );

      successful = cmd.execute();

      if( !successful ) {
        if( cmd.hasErrResult() ) {
          throw ProcessException.CODE_compile_errors( cmd.getExecutedCmd() + Standard.NEWLINE
                                                       + cmd.getOutResult() + Standard.NEWLINE
                                                       + cmd.getErrResult() + Standard.NEWLINE
                                                       );
        }
        else if( cmd.wasNotFound() ) {
          throw ProcessException.CODE_compiler_not_found( compiler );
        }
        else {
          throw ProcessException.CODE_compile_failed( cmd.getExecutedCmd() + Standard.NEWLINE
                                                       + cmd.getOutResult() + Standard.NEWLINE
                                                       + cmd.getErrResult() + Standard.NEWLINE
                                                       );
        }
      }
    }
  }
View Full Code Here

  // REVIEW: need to use RecordingUserMessageHandler to verify test

  public void testExecute() throws Exception {

    String args = "/c echo %JAVA_HOME%";
    ExecutableCommand ec = new ExecutableCommand( "badcmd", args );
    final RecordingUserMessageHandler rumh = new RecordingUserMessageHandler();

    ec.setUserMessageHandler( rumh );
    ec.setActivityDescription("Activity:");
    boolean outcome = ec.execute( new ExecutableCommand.AlternativeExecutableCommands
      (
       new ExecutableCommand( "badcmd2", args ),
       new ExecutableCommand( "", args ) {
           public boolean execute( ExecutableCommand pParent ) {
             iCmdPrefix = "badcmd3";
             return super.execute();
           }
         },
       new ExecutableCommand() {
           public boolean execute( ExecutableCommand pParent ) {
             ExecutableCommand sec = new ExecutableCommand( "subcmd1", "r", "s", this );
             sec.setUserMessageHandler( rumh );
             return sec.execute( new ExecutableCommand.AlternativeExecutableCommands
               (
                new ExecutableCommand( "subcmd2", sec.getCmdRoot(), sec.getCmdSuffix() ),
                new ExecutableCommand( "subcmd3", sec.getCmdRoot(), sec.getCmdSuffix() ),
                new ExecutableCommand( "cmd",     pParent.getCmdRoot() )
                ) );
           }
         }

       ) );
View Full Code Here

          + Standard.SPACE
          + compilerOpts
          ;
      }

      ExecutableCommand cmd = new ExecutableCommand( compiler, compilerOpts, sourceFiles );
      String fullcmd = cmd.getFullCmd();

      cmd.setUserMessageHandler( mUserMessageHandler );
      cmd.setActivityDescription( UserText.get( UserText.TXT_compiling ) );

      boolean successful = cmd.execute();
      /*
        ( new ExecutableCommand.AlternativeExecutableCommands
          (
           // try jikes if javac not found and vice versa
           new ExecutableCommand( JavaUtil.COMPILER_javac.equals( compiler ) ? JavaUtil.COMPILER_jikes : JavaUtil.COMPILER_javac,
                                  compilerOpts, sourceFiles )

           // try to use JAVA_HOME
           ,new ExecutableCommand( "JAVA_HOME/"+JavaUtil.COMPILER_javac, compilerOpts, sourceFiles ) {
               public boolean execute( ExecutableCommand pParent ) {
                 ExecutableCommand jhc = new ExecutableCommand( "cmd", "/c echo %JAVA_HOME%" );
                 if( jhc.execute( new ExecutableCommand.AlternativeExecutableCommands
                   ( new ExecutableCommand( "sh", "-c \"echo $JAVA_HOME\"" ) ) ) ) {
                   String javaHome = jhc.getOutResult().trim();
                   if( !Standard.EMPTY.equals( javaHome ) ) {
                     iCmdPrefix = javaHome + File.separator + "bin" + File.separator + JavaUtil.COMPILER_javac;
                     return execute();
                   }
                   else {
                     return false;
                   }
                 }
                 else {
                   return false;
                 }
               }
             }
           ) );
       */
      if( !successful ) {
        boolean containsErrorMsgs = -1 < cmd.getOutResult().indexOf("error");
        System.out.println("cem:"+containsErrorMsgs);
        if( cmd.hasErrResult() || containsErrorMsgs ) {
          throw ProcessException.CODE_compile_errors( cmd.getExecutedCmd() + Standard.NEWLINE
                                                       + cmd.getOutResult() + Standard.NEWLINE
                                                       + cmd.getErrResult() + Standard.NEWLINE
                                                       );
        }
        else if( cmd.wasNotFound() ) {
          throw ProcessException.CODE_compiler_not_found( compiler );
        }
        else {
          throw ProcessException.CODE_compile_failed( cmd.getExecutedCmd() + Standard.NEWLINE
                                                       + cmd.getOutResult() + Standard.NEWLINE
                                                       + cmd.getErrResult() + Standard.NEWLINE
                                                       );
        }
      }
    }
  }
View Full Code Here

    if( compile ) {
      String sourceFiles  = sourceFilesB.toString();
      String compiler     = tmps.get( Property.main_ExternalCompiler );
      String compilerOpts = tmps.get( Property.main_ExternalCompilerOptions );

      ExecutableCommand cmd = new ExecutableCommand( compiler, compilerOpts, sourceFiles );
      String fullcmd = cmd.getFullCmd();

      cmd.setUserMessageHandler( mUserMessageHandler );
      cmd.setActivityDescription( UserText.get( UserText.TXT_compiling ) );

      successful = cmd.execute();

      if( !successful ) {
        if( cmd.hasErrResult() ) {
          throw ProcessException.CODE_compile_errors( cmd.getExecutedCmd() + Standard.NEWLINE
                                                       + cmd.getOutResult() + Standard.NEWLINE
                                                       + cmd.getErrResult() + Standard.NEWLINE
                                                       );
        }
        else if( cmd.wasNotFound() ) {
          throw ProcessException.CODE_compiler_not_found( compiler );
        }
        else {
          throw ProcessException.CODE_compile_failed( cmd.getExecutedCmd() + Standard.NEWLINE
                                                       + cmd.getOutResult() + Standard.NEWLINE
                                                       + cmd.getErrResult() + Standard.NEWLINE
                                                       );
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.jostraca.util.ExecutableCommand

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.