test_class.declarator: COMMAND_TIMEOUT = 5000
test_class.modifier: private static final
test_class.original_string: private static final int COMMAND_TIMEOUT = 5000;
test_class.type: int
test_class.var_name: COMMAND_TIMEOUT
test_class.declarator: shellTest
test_class.modifier: private
test_class.original_string: private ShellTest shellTest;
test_class.type: ShellTest
test_class.var_name: shellTest
test_class.declarator: resourceFactory
test_class.modifier: private
test_class.original_string: private ResourceFactory resourceFactory;
test_class.type: ResourceFactory
test_class.var_name: resourceFactory
test_class.file: script/src/test/java/org/jboss/forge/addon/script/ui/RunCommandTest.java
test_class.identifier: RunCommandTest
test_case.body: @Test
     public void testRunScriptFailure() throws Exception
     {
        DirectoryResource temp = (DirectoryResource) resourceFactory.create(OperatingSystemUtils.createTempDir());
        temp.deleteOnExit();
        shellTest.getShell().setCurrentResource(temp);
  
        FileResource<?> script = (FileResource<?>) temp.getChild("script.fsh");
        script.setContents("throw-exception");
  
        Result result = shellTest.execute("run script.fsh", COMMAND_TIMEOUT, TimeUnit.SECONDS);
        Assert.assertTrue(result instanceof Failed);
     }
test_case.class_method_signature: RunCommandTest.testRunScriptFailure()
test_case.full_signature: @Test public void testRunScriptFailure()
test_case.identifier: testRunScriptFailure
test_case.invocations: create createTempDir deleteOnExit setCurrentResource getShell getChild setContents execute assertTrue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRunScriptFailure()
focal_class.declarator: scriptEngine
focal_class.modifier: private
focal_class.original_string: private ScriptEngine scriptEngine;
focal_class.type: ScriptEngine
focal_class.var_name: scriptEngine
focal_class.declarator: timeout
focal_class.modifier: private
focal_class.original_string: private UIInput<Integer> timeout;
focal_class.type: UIInput<Integer>
focal_class.var_name: timeout
focal_class.declarator: arguments
focal_class.modifier: private
focal_class.original_string: private UIInputMany<String> arguments;
focal_class.type: UIInputMany<String>
focal_class.var_name: arguments
focal_class.declarator: command
focal_class.modifier: private
focal_class.original_string: private UIInput<String> command;
focal_class.type: UIInput<String>
focal_class.var_name: command
focal_class.file: script/src/main/java/org/jboss/forge/addon/script/ui/RunCommand.java
focal_class.identifier: RunCommand
focal_class.class_method_signature: RunCommand.getMetadata(UIContext context)
focal_class.full_signature: @Override public UICommandMetadata getMetadata(UIContext context)
focal_class.identifier: getMetadata
focal_class.modifiers: @Override public
focal_class.parameters: (UIContext context)
focal_class.return: UICommandMetadata
focal_class.signature: UICommandMetadata getMetadata(UIContext context)
focal_class.class_method_signature: RunCommand.initializeUI(UIBuilder builder)
focal_class.full_signature: @Override public void initializeUI(UIBuilder builder)
focal_class.identifier: initializeUI
focal_class.modifiers: @Override public
focal_class.parameters: (UIBuilder builder)
focal_class.return: void
focal_class.signature: void initializeUI(UIBuilder builder)
focal_class.class_method_signature: RunCommand.validate(UIValidationContext validator)
focal_class.full_signature: @Override public void validate(UIValidationContext validator)
focal_class.identifier: validate
focal_class.modifiers: @Override public
focal_class.parameters: (UIValidationContext validator)
focal_class.return: void
focal_class.signature: void validate(UIValidationContext validator)
focal_class.class_method_signature: RunCommand.execute(UIExecutionContext context)
focal_class.full_signature: @Override public Result execute(UIExecutionContext context)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (UIExecutionContext context)
focal_class.return: Result
focal_class.signature: Result execute(UIExecutionContext context)
focal_class.superclass: extends AbstractShellCommand
focal_method.body: @Override
     public Result execute(UIExecutionContext context) throws Exception
     {
        Result result = Results.fail("Error executing script.");
        UIContext uiContext = context.getUIContext();
        Resource<?> currentResource = (Resource<?>) uiContext.getInitialSelection().get();
        final UIOutput output = uiContext.getProvider().getOutput();
        if (command.hasValue())
        {
           String[] commands = command.getValue().split(" ");
           ProcessBuilder processBuilder = new ProcessBuilder(commands);
           Object currentDir = currentResource.getUnderlyingResourceObject();
           if (currentDir instanceof File)
           {
              processBuilder.directory((File) currentDir);
           }
           final Process process = processBuilder.start();
           ExecutorService executor = Executors.newFixedThreadPool(2);
           // Read std out
           executor.submit(() -> Streams.write(process.getInputStream(), output.out()));
           // Read std err
           executor.submit(() -> Streams.write(process.getErrorStream(), output.err()));
           executor.shutdown();
           try
           {
              int returnCode = process.waitFor();
              if (returnCode == 0)
              {
                 result = Results.success();
              }
              else
              {
                 result = Results.fail("Error while executing native command. See output for more details");
              }
           }
           catch (InterruptedException ie)
           {
              result = Results.success("Command execution interrupted");
           }
           finally
           {
              process.destroy();
           }
        }
        else
        {
           Resource<?> selectedResource = currentResource;
           ALL: for (String path : arguments.getValue())
           {
              List<Resource<?>> resources = currentResource.resolveChildren(path);
              for (Resource<?> resource : resources)
              {
                 if (resource.exists())
                 {
                    ScriptContext scriptContext = ScriptContextBuilder.create().currentResource(currentResource)
                             .stdout(output.out()).stderr(output.err()).timeout(timeout.getValue()).build();
                    result = (Result) scriptEngine.eval(resource.getContents(), scriptContext);
                    selectedResource = (Resource<?>) scriptContext
                             .getAttribute(ScriptContextBuilder.CURRENT_RESOURCE_ATTRIBUTE);
                 }
                 else
                 {
                    result = Results.fail(path + ": not found.");
                    break ALL;
                 }
              }
           }
           if (!(result instanceof Failed))
           {
              uiContext.setSelection(selectedResource);
           }
        }
        return result;
     }
focal_method.class_method_signature: RunCommand.execute(UIExecutionContext context)
focal_method.full_signature: @Override public Result execute(UIExecutionContext context)
focal_method.identifier: execute
focal_method.invocations: fail getUIContext get getInitialSelection getOutput getProvider hasValue split getValue getUnderlyingResourceObject directory start newFixedThreadPool submit write getInputStream out submit write getErrorStream err shutdown waitFor success fail success destroy getValue resolveChildren exists build timeout stderr stdout currentResource create out err getValue eval getContents getAttribute fail setSelection
focal_method.modifiers: @Override public
focal_method.parameters: (UIExecutionContext context)
focal_method.return: Result
focal_method.signature: Result execute(UIExecutionContext context)