Package viewer.common

Examples of viewer.common.RuntimeExecCommand


    {
        String              path2jardir;
        String              path2jvm;
        String              opt4jvm;
        String              jar_path;
        RuntimeExecCommand  exec_cmd;
        File                jar_file;
        File                jvm_file;
        Launcher            launcher;
        String              exec_err_msg;
        String              setupfile_msg;

        Launcher.initializeSystemProperties();
        Launcher.initializeLauncherConstants();
        setupfile_msg = Launcher.readLauncherConstants();
        if ( setupfile_msg != null ) {
            if ( Launcher.VERBOSE )
                Dialogs.info( null, setupfile_msg, null );
            Launcher.writeLauncherConstants();
        }

        path2jardir = Launcher.getDefaultPathToJarDir();
        jar_path    = Launcher.getDefaultJarPath( path2jardir );
        jar_file    = new File( jar_path );
        if ( ! jar_file.exists() ) {
            Dialogs.error( null, jar_path + " does not exist!\n"
                               + "Make sure that " + VIEWER_JAR + " is in "
                               + "the same directory as this launcher.\n"
                               + "Then restart this program again." );
            System.exit( 1 );
        }
        if ( ! jar_file.canRead() ) {
            Dialogs.error( null, jar_path + " is NOT readable!\n"
                               + "Reset the read privilege of the file, "
                               + VIEWER_JAR + ".\n"
                               + "Then restart this program again." );
            System.exit( 1 );
        }

        path2jvm = Launcher.getDefaultPathToJVM();
        jvm_file = new File( path2jvm );
        if ( ! jvm_file.exists() ) {
            Dialogs.error( null, path2jvm + " does not exist!\n"
                               + "Make sure that " + path2jvm + " exists.\n"
                               + "Then restart this program again." );
            System.exit( 1 );
        }
        if ( ! jvm_file.canRead() ) {
            Dialogs.error( null, path2jvm + " is NOT readable!\n"
                               + "Reset the read privilege of the file, "
                               + path2jvm + ".\n"
                               + "Then restart this program again." );
            System.exit( 1 );
        }

        opt4jvm  = JVM_OPTIONS;
        exec_cmd = new RuntimeExecCommand();
        exec_cmd.addWholeString( path2jvm );
        exec_cmd.addTokenizedString( opt4jvm );
        exec_cmd.addWholeString( "-jar" );
        exec_cmd.addWholeString( jar_path );

        launcher = new Launcher();
        if (    ( exec_err_msg = launcher.exec( exec_cmd.toStringArray() ) )
             != null ) {
            Dialogs.error( null, "The following process exits with error:\n"
                               + exec_cmd.toString() + "\n" + exec_err_msg );
            System.exit( 1 );
        }

        // Preventive System.exit() to guarantee the launcher exits cleanly
        System.exit( 0 );
View Full Code Here


    {
        String              convertor;
        String              path2jardir;
        String              path2tracelib;
        String              jar_path;
        RuntimeExecCommand  exec_cmd;
        File                jar_file;
        Runtime             runtime;
        Process             proc;
        InputStreamThread   proc_err_task, proc_out_task;

        convertor = (String) cmd_pulldown.getSelectedItem();

        //  Set the path to the jar file
        path2jardir = cmd_path2jardir.getText();
        jar_path  = ConvertorConst.getDefaultJarPath( path2jardir, convertor );
        jar_file  = new File( jar_path );
        if ( ! jar_file.exists() ) {
            Dialogs.error( top_window, jar_path + " does not exist!" );
            return;
        }
        if ( ! jar_file.canRead() ) {
            Dialogs.error( top_window, jar_path + " is NOT readable!\n" );
            return;
        }

        exec_cmd = new RuntimeExecCommand();
        exec_cmd.addWholeString( cmd_path2jvm.getText() );
        exec_cmd.addTokenizedString( cmd_option4jvm.getText() );

        path2tracelib = cmd_path2tracelib.getText();
        if ( path2tracelib != null && path2tracelib.length() > 0 )
            exec_cmd.addWholeString( "-Djava.library.path=" + path2tracelib );

        exec_cmd.addWholeString( "-jar" );
        exec_cmd.addWholeString( jar_path );
        exec_cmd.addWholeString( "-h" );

        cmd_textarea.append( "Executing " + exec_cmd.toString() + "...." );
       
        runtime  = Runtime.getRuntime();
        try {
            proc = runtime.exec( exec_cmd.toStringArray() );
            proc_err_task = new InputStreamThread( proc.getErrorStream(),
                                                   "Error", cmd_textarea );
            proc_out_task = new InputStreamThread( proc.getInputStream(),
                                                   "Output", cmd_textarea );
            proc_err_task.start();
View Full Code Here

        String              path2jardir, path2tracelib;
        String              infile_name, outfile_name, jar_path;
        String              option4jar;
        File                infile, outfile, jar_file;
        InputLog            slog_ins;
        RuntimeExecCommand  exec_cmd;

        SwingProcessWorker  conv_worker;
        ProgressAction      conv_progress;

        // Check the validity of the Input File
        infile_name   = cmd_infile.getText();
        infile        = new File( infile_name );
        if ( ! infile.exists() ) {
            Dialogs.error( top_window,
                           infile_name + " does not exist!\n"
                         + "No conversion will take place." );
            return null;
        }
        if ( infile.isDirectory() ) {
            Dialogs.error( top_window,
                           infile_name + " is a directory!\n"
                         + "No conversion will take place." );
            return null;
        }
        if ( ! infile.canRead() ) {
            Dialogs.error( top_window,
                           "File " + infile_name + " is NOT readable!\n"
                         + "No conversion will take place." );
            return null;
        }
        slog_ins = null;
        try {
            slog_ins = new InputLog( infile_name );
        } catch ( NullPointerException nperr ) {
            slog_ins = null;
        } catch ( Exception err ) {
            slog_ins = null;
        }
        if ( slog_ins != null && slog_ins.isSLOG2() ) {
            Dialogs.error( top_window,
                           infile_name + " is already a SLOG-2 file!\n"
                         + "No conversion will take place." );
            cmd_outfile.setText( infile_name );
            return null;
        }

        // Check the validity of the Output File
        outfile_name  = cmd_outfile.getText();
        outfile       = new File( outfile_name );
        if ( outfile.exists() ) {
            if ( outfile.isDirectory() ) {
                Dialogs.error( top_window,
                               outfile_name + " is a directory!\n"
                             + "No conversion will take place." );
                return null;
            }
            if ( ! outfile.canWrite() ) {
                Dialogs.error( top_window,
                               "File " + outfile_name + " cannot be written!\n"
                             + "No conversion will take place." );
                return null;
            }
            if ( ! Dialogs.confirm( top_window,
                                    outfile_name + " already exists! "
                                  + "Do you want to overwrite it ?" ) ) {
                Dialogs.info( top_window,
                              "Please change the output filename "
                            + "and restart the conversion again.",
                              null );
                return null;
            }
            outfile.delete();
        }

        convertor = (String) cmd_pulldown.getSelectedItem();

        //  Set the path to the jar file
        path2jardir = cmd_path2jardir.getText();
        jar_path  = ConvertorConst.getDefaultJarPath( path2jardir, convertor );
        jar_file  = new File( jar_path );
        if ( ! jar_file.exists() ) {
            Dialogs.error( top_window, jar_path + " does not exist!" );
            return null;
        }

        exec_cmd = new RuntimeExecCommand();
        exec_cmd.addWholeString( cmd_path2jvm.getText() );
        exec_cmd.addTokenizedString( cmd_option4jvm.getText() );

        path2tracelib = cmd_path2tracelib.getText();
        if ( path2tracelib != null && path2tracelib.length() > 0 )
            exec_cmd.addWholeString( "-Djava.library.path=" + path2tracelib );

        exec_cmd.addWholeString( "-jar" );
        exec_cmd.addWholeString( jar_path );

        option4jar  = cmd_option4jar.getText();
        if ( option4jar != null && option4jar.length() > 0 )
            exec_cmd.addTokenizedString( option4jar );

        exec_cmd.addWholeString( "-o" );
        exec_cmd.addWholeString( outfile_name );
        exec_cmd.addWholeString( infile_name );

        /*
           Start a SwingWorker thread to execute the process:
           Prepare a progress action for the JProgressBar for the SwingWorker
        */
        conv_progress = new ProgressAction( cmd_outfile_size, cmd_progress );
        conv_progress.initialize( infile, outfile );
        conv_worker = new SwingProcessWorker( this, cmd_textarea );
        conv_worker.initialize( exec_cmd.toStringArray(), conv_progress );
        conv_worker.start();

        return conv_worker;
    }
View Full Code Here

TOP

Related Classes of viewer.common.RuntimeExecCommand

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.