Example usage for java.lang System setOut

List of usage examples for java.lang System setOut

Introduction

In this page you can find the example usage for java.lang System setOut.

Prototype

public static void setOut(PrintStream out) 

Source Link

Document

Reassigns the "standard" output stream.

Usage

From source file:functionaltests.TagCommandsFunctTest.java

@Test
public void testJobOutputWithUnknownTag() throws Exception {
    typeLine("joboutput(" + jobId.longValue() + ", 'unknownTag')");

    runCli();//from w ww . j a va 2  s.c  om

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testJobOutputWithUnknownTag:");
    System.out.println(out);
    assertTrue(!out.contains("Task 1 : Test STDERR"));
    assertTrue(!out.contains("Task 1 : Test STDOUT"));
    assertTrue(!out.contains("Terminate task number 1"));
}

From source file:functionaltests.NodeSourceCommandsFunctTest.java

private void checkOccurrencesOfNodeSourceInNodeSourceList(String nodeSourceName) {

    System.out.println(LOG_HEADER + " List node sources");

    this.clearAndTypeLine("listns()");
    this.runCli();

    String out = this.capturedOutput.toString();
    System.setOut(this.stdOut);
    System.out.println(out);/*www. java 2  s  .c om*/

    assertThat(out).contains(nodeSourceName);
}

From source file:com.diversityarrays.dal.server.ServerGui.java

public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot,
        DalServerPreferences prefs) {//from   w w w  .j a v  a2 s .c o  m

    this.serverIconImage = serverIconImage;
    this.dalServerFactory = factory;
    this.wwwRoot = wwwRoot;
    this.preferences = prefs;

    JMenuBar menuBar = new JMenuBar();

    JMenu serverMenu = new JMenu("Server");
    menuBar.add(serverMenu);
    serverMenu.add(serverStartAction);
    serverMenu.add(serverStopAction);
    serverMenu.add(exitAction);

    JMenu commandMenu = new JMenu("Command");
    menuBar.add(commandMenu);
    commandMenu.add(doSql);

    JMenu urlMenu = new JMenu("URL");
    menuBar.add(urlMenu);
    urlMenu.add(new JMenuItem(copyDalUrlAction));
    urlMenu.add(new JMenuItem(showDalUrlQRcodeAction));

    setJMenuBar(menuBar);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    messages.setFont(GuiUtil.createMonospacedFont(12));
    messages.setEditable(false);

    setServer(svr);

    quietOption.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean q = quietOption.isSelected();
            if (server != null) {
                server.setQuiet(q);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();

    JButton clear = new JButton(new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            messages.setText("");
        }
    });

    final boolean[] follow = new boolean[] { true };
    final JCheckBox followTail = new JCheckBox("Follow", follow[0]);

    followTail.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            follow[0] = followTail.isSelected();
        }
    });

    final OutputStream os = new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            char ch = (char) b;
            messages.append(new Character(ch).toString());
            if (ch == '\n' && follow[0]) {
                verticalScrollBar.setValue(verticalScrollBar.getMaximum());
            }
        }
    };

    TeePrintStream pso = new TeePrintStream(System.out, os);
    TeePrintStream pse = new TeePrintStream(System.err, os);

    System.setErr(pse);
    System.setOut(pso);

    Box box = Box.createHorizontalBox();
    box.add(clear);
    box.add(followTail);
    box.add(quietOption);
    box.add(Box.createHorizontalGlue());

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(BorderLayout.NORTH, box);
    bottom.add(BorderLayout.SOUTH, statusInfoLine);

    Container cp = getContentPane();
    cp.add(BorderLayout.CENTER, scrollPane);
    cp.add(BorderLayout.SOUTH, bottom);

    pack();
    setSize(640, 480);

    final MemoryUsageMonitor mum = new MemoryUsageMonitor();
    mum.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            statusInfoLine.setMessage(mum.getMemoryUsage());
        }
    });

    if (server == null) {
        // If initial server is null, allow user to specify
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                serverStartAction.actionPerformed(null);
            }
        });
    } else {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                ensureDatabaseInitialisedThenStartServer();
            }
        });
    }
}

From source file:org.apache.maven.cli.NoSyspropChangingMavenCli.java

private void logging(CliRequest cliRequest) {
    cliRequest.debug = cliRequest.commandLine.hasOption(CLIManager.DEBUG);
    cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption(CLIManager.QUIET);
    cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.ERRORS);

    if (cliRequest.debug) {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
    } else if (cliRequest.quiet) {
        // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
        // Ideally, we could use Warn across the board
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        // TODO:Additionally, we can't change the mojo level because the component key includes the version and
        // it isn't known ahead of time. This seems worth changing.
    } else {//  w w  w  .j  a  v a  2  s  .c  om
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO);
    }

    if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE));
        logFile = resolveFile(logFile, cliRequest.workingDirectory);

        try {
            cliRequest.fileStream = new PrintStream(logFile);

            System.setOut(cliRequest.fileStream);
            System.setErr(cliRequest.fileStream);
        } catch (FileNotFoundException e) {
            System.err.println(e);
        }
    }
}

From source file:org.apache.hadoop.fs.CopyFilesBase.java

protected static String execCmd(FsShell shell, String... args) throws Exception {
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baout, true);
    PrintStream old = System.out;
    System.setOut(out);
    shell.run(args);/*from w w w.  j  av  a 2s  .  c o m*/
    out.close();
    System.setOut(old);
    return baout.toString();
}

From source file:ddf.catalog.pubsub.command.ListCommandTest.java

/**
 * Test subscriptions:list command with the LDAP filter arg specified, e.g., subscriptions:list
 * -f "(subscription-id=my*)" Should return matching subscriptions.
 *
 * @throws Exception/*from   w w  w .j  a  va 2 s. c  om*/
 */
@Test
public void testListWithLdapFilterArg() throws Exception {
    // Setup argument captor for LDAP filter that will be passed in to getServiceReferences()
    // call
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);

    ListCommand listCommand = new ListCommand();

    BundleContext bundleContext = mock(BundleContext.class);
    listCommand.setBundleContext(bundleContext);

    ServiceReference mySubscription = mock(ServiceReference.class);
    when(mySubscription.getPropertyKeys()).thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY });
    when(mySubscription.getProperty(SUBSCRIPTION_ID_PROPERTY_KEY)).thenReturn(MY_SUBSCRIPTION_ID);
    when(bundleContext.getServiceReferences(eq(SubscriptionsCommand.SERVICE_PID), anyString()))
            .thenReturn(new ServiceReference[] { mySubscription });

    String ldapFilter = "(" + SUBSCRIPTION_ID_PROPERTY_KEY + "=my*)";

    PrintStream realSystemOut = System.out;

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    System.setOut(new PrintStream(buffer));

    // when
    listCommand.id = ldapFilter;
    listCommand.ldapFilter = true;
    listCommand.doExecute();

    /* cleanup */
    System.setOut(realSystemOut);

    // then
    List<String> linesWithText = getConsoleOutputText(buffer);
    assertThat(linesWithText.size(), is(3));
    assertThat(linesWithText,
            hasItems(
                    "Total subscriptions found: 1", ListCommand.CYAN_CONSOLE_COLOR
                            + ListCommand.SUBSCRIPTION_ID_COLUMN_HEADER + ListCommand.DEFAULT_CONSOLE_COLOR,
                    MY_SUBSCRIPTION_ID));

    buffer.close();

    // Verify the LDAP filter passed in when mock BundleContext.getServiceReferences() was
    // called.
    verify(bundleContext).getServiceReferences(anyString(), argument.capture());
    assertThat(argument.getValue(), containsString(ldapFilter));
}

From source file:com.cisco.dvbu.ps.deploytool.dao.wsapi.ArchiveWSDAOImpl.java

public void takeArchiveAction(String actionName, ArchiveType archive, String serverId, String pathToServersXML,
        String prefix, String propertyFile) throws CompositeException {

    if (logger.isDebugEnabled()) {
        logger.debug(/*from w w w  .j ava  2s. c  o m*/
                "ArchiveWSDAOImpl.takeArchiveAction(actionName, archive, serverId, pathToServersXML, prefix, propertyFile).  actionName="
                        + actionName + "  archive object=" + archive.toString() + "  serverId=" + serverId
                        + "  pathToServersXML=" + pathToServersXML + "  prefix=" + prefix + "  propertyFile="
                        + propertyFile);
    }
    // Set the debug options
    setDebug();

    // Read target server properties from xml and build target server object based on target server name 
    CompositeServer targetServer = WsApiHelperObjects.getServerLogger(serverId, pathToServersXML,
            "ArchiveWSDAOImpl.takeArchiveAction(" + actionName + ")", logger);
    //
    // DA@20120610 Comment unnecessary ping - if server is down the backup/restore command will fail as fast as ping
    // Ping the Server to make sure it is alive and the values are correct.
    //      WsApiHelperObjects.pingServer(targetServer, true);

    // Get the offset location of the java.policy file [offset from PDTool home].
    String javaPolicyOffset = CommonConstants.javaPolicy;
    String javaPolicyLocation = CommonUtils.extractVariable(prefix,
            CommonUtils.getFileOrSystemPropertyValue(propertyFile, "PROJECT_HOME_PHYSICAL"), propertyFile, true)
            + javaPolicyOffset;

    String identifier = "ArchiveWSDAOImpl.takeArchiveAction"; // some unique identifier that characterizes this invocation.
    try {

        if (logger.isDebugEnabled() || debug3) {
            CommonUtils.writeOutput(":: executing action: " + actionName, prefix, "-debug3", logger, debug1,
                    debug2, debug3);
            //logger.debug(identifier+":: executing action: "+actionName);
        }

        List<String> argsList = getCommonArchiveParameters(archive, targetServer);

        if (actionName.equalsIgnoreCase(ArchiveDAO.action.IMPORT.name())) {
            // pkg_import
            boolean archiveISNULL = false;
            if (archive == null)
                archiveISNULL = true;
            if (logger.isDebugEnabled() || debug3) {
                CommonUtils
                        .writeOutput(
                                identifier + ":: " + ArchiveDAO.action.IMPORT.name().toString()
                                        + " archiveISNULL=[" + archiveISNULL + "]",
                                prefix, "-debug3", logger, debug1, debug2, debug3);
            }
            // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation.
            //   If so then force a no operation to happen by performing a -printcontents for pkg_import
            if (!CommonUtils.isExecOperation()
                    || (archive.isPrintcontents() != null && !archive.isPrintcontents()))
                archive.setPrintcontents(true);

            // Construct the variable input for pacakged import
            List<String> parms = getPackageImportParameters(archive);
            argsList.addAll(parms);
            String[] args = argsList.toArray(new String[0]);
            String maskedArgList = CommonUtils.getArgumentListMasked(argsList);
            if (logger.isDebugEnabled() || debug3) {
                CommonUtils
                        .writeOutput(
                                identifier + ":: " + ArchiveDAO.action.IMPORT.name().toString()
                                        + " argument list=[" + maskedArgList + "]",
                                prefix, "-debug3", logger, debug1, debug2, debug3);
                //logger.debug(identifier+":: "+ArchiveDAO.action.IMPORT.name().toString()+" argument list=[" + maskedArgList+"]" );
            }
            /*
             * 2014-02-14 (mtinius): Removed the PDTool Archive capability
             */
            //            ImportCommand.startCommand(".", ".", args);
            /*
             * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because
             *                    it has System.out.println and System.exit commands.  Need to trap both.
             */
            // Get the existing security manager
            SecurityManager sm = System.getSecurityManager();
            PrintStream originalOut = System.out;
            PrintStream originalErr = System.err;
            String command = "ImportCommand.startCommand";
            try {
                // Set the java security policy
                System.getProperties().setProperty("java.security.policy", javaPolicyLocation);

                // Create a new System.out Logger
                Logger importLogger = Logger.getLogger(ImportCommand.class);
                System.setOut(new PrintStream(new LogOutputStream(importLogger, Level.INFO)));
                System.setErr(new PrintStream(new LogOutputStream(importLogger, Level.ERROR)));
                // Create a new security manager
                System.setSecurityManager(new NoExitSecurityManager());

                if (logger.isDebugEnabled()) {
                    logger.debug(identifier + "().  Invoking ImportCommand.startCommand(\".\", \".\", args).");
                }

                // Invoke the Composite native import command.
                ImportCommand.startCommand(".", ".", args);

                if (logger.isDebugEnabled()) {
                    logger.debug(identifier + "().  Successfully imported.");
                }
            } catch (NoExitSecurityExceptionStatusNonZero nesesnz) {
                String error = identifier + ":: Exited with exception from System.exit(): " + command
                        + "(\".\", \".\", " + maskedArgList + ")";
                logger.error(error);
                throw new CompositeException(error);
            } catch (NoExitSecurityExceptionStatusZero nesezero) {
                if (logger.isDebugEnabled() || debug3) {
                    CommonUtils.writeOutput(
                            identifier + ":: Exited successfully from System.exit(): " + command
                                    + "(\".\", \".\", " + maskedArgList + ")",
                            prefix, "-debug3", logger, debug1, debug2, debug3);
                    //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")");
                }
            } finally {
                System.setSecurityManager(sm);
                System.setOut(originalOut);
                System.setErr(originalErr);
            }

        } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.RESTORE.name())) {
            // backup_import         
            // Construct the variable input for backup import
            List<String> parms = getBackupImportParameters(archive);
            argsList.addAll(parms);
            String[] args = argsList.toArray(new String[0]);
            String maskedArgList = CommonUtils.getArgumentListMasked(argsList);
            if (logger.isDebugEnabled() || debug3) {
                CommonUtils
                        .writeOutput(
                                identifier + ":: " + ArchiveDAO.action.RESTORE.name().toString()
                                        + " argument list=[" + maskedArgList + "]",
                                prefix, "-debug3", logger, debug1, debug2, debug3);
                //logger.debug(identifier+":: "+ArchiveDAO.action.RESTORE.name().toString()+" argument list=[" + maskedArgList+"]" );
            }

            /*
             * 2014-02-14 (mtinius): Removed the PDTool Archive capability
             */
            //            RestoreCommand.startCommand(".", ".", args) ;
            /*
             * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because
             *                    it has System.out.println and System.exit commands.  Need to trap both.
             */
            // Get the existing security manager
            SecurityManager sm = System.getSecurityManager();
            PrintStream originalOut = System.out;
            PrintStream originalErr = System.err;
            String command = "RestoreCommand.startCommand";
            try {
                // Set the java security policy
                System.getProperties().setProperty("java.security.policy", javaPolicyLocation);

                // Create a new System.out Logger
                Logger restoreLogger = Logger.getLogger(RestoreCommand.class);
                System.setOut(new PrintStream(new LogOutputStream(restoreLogger, Level.INFO)));
                System.setErr(new PrintStream(new LogOutputStream(restoreLogger, Level.ERROR)));
                // Create a new security manager
                System.setSecurityManager(new NoExitSecurityManager());

                if (logger.isDebugEnabled()) {
                    logger.debug(identifier + "().  Invoking RestoreCommand.startCommand(\".\", \".\", args).");
                }

                // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation.
                if (CommonUtils.isExecOperation()) {
                    // Invoke the Composite native restore command.
                    RestoreCommand.startCommand(".", ".", args);

                    if (logger.isDebugEnabled()) {
                        logger.debug(identifier + "().  Successfully restored.");
                    }
                } else {
                    logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName
                            + "] WAS NOT PERFORMED.\n");
                }
            } catch (NoExitSecurityExceptionStatusNonZero nesesnz) {
                String error = identifier + ":: Exited with exception from System.exit(): " + command
                        + "(\".\", \".\", " + maskedArgList + ")";
                logger.error(error);
                throw new CompositeException(error);
            } catch (NoExitSecurityExceptionStatusZero nesezero) {
                if (logger.isDebugEnabled() || debug3) {
                    CommonUtils.writeOutput(
                            identifier + ":: Exited successfully from System.exit(): " + command
                                    + "(\".\", \".\", " + maskedArgList + ")",
                            prefix, "-debug3", logger, debug1, debug2, debug3);
                    //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")");
                }
            } finally {
                System.setSecurityManager(sm);
                System.setOut(originalOut);
                System.setErr(originalErr);
            }

        } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.EXPORT.name())) {
            // pkg_export
            List<String> parms = getPackageExportParameters(archive);
            argsList.addAll(parms);
            String[] args = argsList.toArray(new String[0]);
            String maskedArgList = CommonUtils.getArgumentListMasked(argsList);
            if (logger.isDebugEnabled() || debug3) {
                CommonUtils
                        .writeOutput(
                                identifier + ":: " + ArchiveDAO.action.EXPORT.name().toString()
                                        + " argument list=[" + maskedArgList + "]",
                                prefix, "-debug3", logger, debug1, debug2, debug3);
                //logger.debug(identifier+":: "+ArchiveDAO.action.EXPORT.name().toString()+" argument list=[" + maskedArgList+"]" );
            }

            /*
             * 2014-02-14 (mtinius): Removed the PDTool Archive capability
             */
            //            ExportCommand.startCommand(".", ".", args);
            /*
             * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because
             *                    it has System.out.println and System.exit commands.  Need to trap both.
             */
            // Get the existing security manager
            SecurityManager sm = System.getSecurityManager();
            PrintStream originalOut = System.out;
            PrintStream originalErr = System.err;
            String command = "ExportCommand.startCommand";
            try {
                // Set the java security policy
                System.getProperties().setProperty("java.security.policy", javaPolicyLocation);

                // Create a new System.out Logger
                Logger exportLogger = Logger.getLogger(ExportCommand.class);
                System.setOut(new PrintStream(new LogOutputStream(exportLogger, Level.INFO)));
                System.setErr(new PrintStream(new LogOutputStream(exportLogger, Level.ERROR)));
                // Create a new security manager
                System.setSecurityManager(new NoExitSecurityManager());

                if (logger.isDebugEnabled()) {
                    logger.debug(identifier + "().  Invoking ExportCommand.startCommand(\".\", \".\", args).");
                }

                // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation.
                if (CommonUtils.isExecOperation()) {
                    // Invoke the Composite native export command.
                    ExportCommand.startCommand(".", ".", args);

                    if (logger.isDebugEnabled()) {
                        logger.debug(identifier + "().  Successfully exported.");
                    }
                } else {
                    logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName
                            + "] WAS NOT PERFORMED.\n");
                }
            } catch (NoExitSecurityExceptionStatusNonZero nesesnz) {
                String error = identifier + ":: Exited with exception from System.exit(): " + command
                        + "(\".\", \".\", " + maskedArgList + ")";
                logger.error(error);
                throw new CompositeException(error);
            } catch (NoExitSecurityExceptionStatusZero nesezero) {
                if (logger.isDebugEnabled() || debug3) {
                    CommonUtils.writeOutput(
                            identifier + ":: Exited successfully from System.exit(): " + command
                                    + "(\".\", \".\", " + maskedArgList + ")",
                            prefix, "-debug3", logger, debug1, debug2, debug3);
                    //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")");
                }
            } finally {
                System.setSecurityManager(sm);
                System.setOut(originalOut);
                System.setErr(originalErr);
            }

        } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.BACKUP.name())) {
            // backup_export
            List<String> parms = getBackupExportParameters(archive);
            argsList.addAll(parms);
            String[] args = argsList.toArray(new String[0]);
            String maskedArgList = CommonUtils.getArgumentListMasked(argsList);
            if (logger.isDebugEnabled() || debug3) {
                CommonUtils
                        .writeOutput(
                                identifier + ":: " + ArchiveDAO.action.BACKUP.name().toString()
                                        + " argument list=[" + maskedArgList + "]",
                                prefix, "-debug3", logger, debug1, debug2, debug3);
                //logger.debug(identifier+":: "+ArchiveDAO.action.BACKUP.name().toString()+" argument list=[" + maskedArgList+"]" );
            }

            /*
             * 2014-02-14 (mtinius): Removed the PDTool Archive capability
             */
            //            BackupCommand.startCommand(".", ".", args);
            /*
             * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because
             *                    it has System.out.println and System.exit commands.  Need to trap both.
             */
            // Get the existing security manager
            SecurityManager sm = System.getSecurityManager();
            PrintStream originalOut = System.out;
            PrintStream originalErr = System.err;
            String command = "BackupCommand.startCommand";
            try {
                // Set the java security policy
                System.getProperties().setProperty("java.security.policy", javaPolicyLocation);

                // Create a new System.out Logger
                Logger backupLogger = Logger.getLogger(BackupCommand.class);
                System.setOut(new PrintStream(new LogOutputStream(backupLogger, Level.INFO)));
                System.setErr(new PrintStream(new LogOutputStream(backupLogger, Level.ERROR)));
                // Create a new security manager
                System.setSecurityManager(new NoExitSecurityManager());

                if (logger.isDebugEnabled()) {
                    logger.debug(identifier + "().  Invoking BackupCommand.startCommand(\".\", \".\", args).");
                }

                // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation.
                if (CommonUtils.isExecOperation()) {
                    // Invoke the Composite native backup command.
                    BackupCommand.startCommand(".", ".", args);

                    if (logger.isDebugEnabled()) {
                        logger.debug(identifier + "().  Successfully backed up.");
                    }
                } else {
                    logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName
                            + "] WAS NOT PERFORMED.\n");
                }
            } catch (NoExitSecurityExceptionStatusNonZero nesesnz) {
                String error = identifier + ":: Exited with exception from System.exit(): " + command
                        + "(\".\", \".\", " + maskedArgList + ")";
                logger.error(error);
                throw new CompositeException(error);
            } catch (NoExitSecurityExceptionStatusZero nesezero) {
                if (logger.isDebugEnabled() || debug3) {
                    CommonUtils.writeOutput(
                            identifier + ":: Exited successfully from System.exit(): " + command
                                    + "(\".\", \".\", " + maskedArgList + ")",
                            prefix, "-debug3", logger, debug1, debug2, debug3);
                    //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")");
                }
            } finally {
                System.setSecurityManager(sm);
                System.setOut(originalOut);
                System.setErr(originalErr);
            }

        }

        if (logger.isDebugEnabled() || debug3) {
            CommonUtils.writeOutput(identifier + ":: completed " + actionName, prefix, "-debug3", logger,
                    debug1, debug2, debug3);
            //logger.debug(identifier+":: completed " + actionName );
        }

    }
    // TO DO: Implement specific catch clauses based on implementation 
    catch (Exception e) {
        // TODO: Be more specific about error messages being returned
        // TODO: null - this is where soap-faults get passed - modify if you return a soap-fault (e.g. e.getFaultInfo())
        if (e.getCause() != null && e.getCause() instanceof WebapiException) {
            //            CompositeLogger.logException(e, DeployUtil.constructMessage(DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer),e.getCause());
            CompositeLogger.logException(e.getCause(), DeployUtil.constructMessage(
                    DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer));
        } else {
            CompositeLogger.logException(e, DeployUtil.constructMessage(DeployUtil.MessageType.ERROR.name(),
                    actionName, "Archive", identifier, targetServer));
        }
        throw new ApplicationException(e.getMessage(), e);
    }

}

From source file:functionaltests.TagCommandsFunctTest.java

@Test
public void testListJobOutputUnknownJob() throws Exception {
    typeLine("joboutput(" + NOT_EXISTENT_JOBID + ", 'unknownTag')");

    runCli();// www. j a v  a 2 s .  c o m

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testListJobOutputUnknownJob:");
    System.out.println(out);
    assertTrue(out.contains("error"));
}

From source file:fr.gouv.culture.vitam.droid.DroidHandler.java

/**
 * Check multiples files specify exactly by the list
 * /*from w w  w . j  a  v  a 2 s  .c  o  m*/
 * @param matchedFiles
 * @param argument
 * @param task
 *            optional
 * @return a List of DroidFileFormat
 * @throws CommandExecutionException
 */
public final List<DroidFileFormat> checkFilesFormat(List<File> matchedFiles, VitamArgument argument,
        RunnerLongTask task) throws CommandExecutionException {
    if (matchedFiles.isEmpty()) {
        throw new CommandExecutionException("Resources not specified");
    }
    File dirToSearch = matchedFiles.get(0);
    String path = dirToSearch.getAbsolutePath();
    String slash = path.contains(FORWARD_SLASH) ? FORWARD_SLASH : BACKWARD_SLASH;
    String slash1 = slash;

    path = "";
    ResultPrinter resultPrinter = new ResultPrinter(vitamBinarySignatureIdentifier,
            containerSignatureDefinitions, path, slash, slash1, argument.archive, argument.checkSubFormat);

    // change System.out
    PrintStream oldOut = System.out;
    DroidFileFormatOutputStream out = new DroidFileFormatOutputStream(
            vitamBinarySignatureIdentifier.getSigFile(), argument);
    PrintStream newOut = new PrintStream(out, true);
    try {
        System.setOut(newOut);
        int currank = 0;
        for (File file : matchedFiles) {
            currank++;
            realCheck(file, resultPrinter);
            if (task != null) {
                float value = ((float) currank) / (float) matchedFiles.size();
                value *= 100;
                task.setProgressExternal((int) value);
            }
        }
    } finally {
        // reset System.out
        System.setOut(oldOut);
        newOut.close();
        newOut = null;
    }
    return out.getResult();
}

From source file:org.graphwalker.machines.ExtendedFiniteStateMachine.java

@Override
public boolean walkEdge(Edge edge) {
    boolean hasWalkedEdge = super.walkEdge(edge);
    if (hasWalkedEdge) {
        if (hasAction(edge)) {
            PrintStream ps = System.out;
            System.setOut(Void);

            if (jsEngine != null) {
                try {
                    jsEngine.eval(getAction(edge));
                } catch (ScriptException e) {
                    logger.error("Problem when running: '" + getAction(edge) + "' in Java Script engine");
                    logger.error("EvalError: " + e);
                    logger.error(e.getCause());
                    throw new RuntimeException("Malformed action sequence\n\t" + edge + "\n\tAction sequence: "
                            + edge.getActionsKey() + "\n\tJava Script error message: '" + e.getMessage()
                            + "'\nDetails: " + e.getCause());
                } finally {
                    System.setOut(ps);
                }//from   www  .ja v a 2 s  .  c o  m
            } else if (beanShellEngine != null) {
                try {
                    beanShellEngine.eval(getAction(edge));
                } catch (EvalError e) {
                    logger.error("Problem when running: '" + getAction(edge) + "' in BeanShell");
                    logger.error("EvalError: " + e);
                    logger.error(e.getCause());
                    throw new RuntimeException("Malformed action sequence\n\t" + edge + "\n\tAction sequence: "
                            + edge.getActionsKey() + "\n\tBeanShell error message: '" + e.getMessage()
                            + "'\nDetails: " + e.getCause());
                } finally {
                    System.setOut(ps);
                }
            }
        }
    }
    return hasWalkedEdge;
}