Package org.jboss.forge.addon.shell

Examples of org.jboss.forge.addon.shell.Shell


   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.hasValue() ? arguments.getValue().iterator() : Collections
               .<String> emptyIterator();

      List<Resource<?>> resourceList;
      if (it.hasNext())
      {
         String value = it.next();
         boolean searching = (value.matches(".*(\\?|\\*)+.*"));
         try
         {
            resourceList = new ResourcePathResolver(resourceFactory, currentResource, value).resolve();
         }
         catch (RuntimeException re)
         {
            if (re.getMessage() == null || !re.getMessage().contains("no such child"))
            {
               throw re;
            }
            else
            {
               return Results.fail(value + ": No such file or directory");
            }
         }
         if (!searching && !resourceList.isEmpty() && resourceList.get(0).exists())
         {
            resourceList = resourceList.get(0).listResources();
         }
      }
      else
      {
         resourceList = currentResource.listResources();
      }
      final Result result;
      if (!resourceList.isEmpty() && !resourceList.get(0).exists())
      {
         result = Results.fail(resourceList.get(0).getName() + ": No such file or directory");
      }
      else
      {
         UIOutput output = shell.getOutput();
         output.out().println(listMany(resourceList, shell));
         result = Results.success();
      }
      return result;
   }
View Full Code Here


                  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));

                  PrintStream stdout = new UncloseablePrintStream(output.out());
                  PrintStream stderr = new UncloseablePrintStream(output.err());
                 
                  Shell currentShell = (Shell) uiContext.getProvider();
                  final TerminalSize terminalSize = currentShell.getConsole().getShell().getSize();
                  ForgeTerminal terminal = new ForgeTerminal(
                           new Terminal()
                           {

                              @Override
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments
               .getValue().iterator();

      Result result = Results.success();
      UIOutput output = shell.getOutput();
      while (it.hasNext())
      {
         final Resource<?> resource = it.hasNext() ?
                  (new ResourcePathResolver(resourceFactory, currentResource, it.next()).resolve().get(0)) : currentResource;
View Full Code Here

               final PipedOutputStream stdin = new PipedOutputStream();
               final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
               final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
               BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));

               Shell scriptShell = shellFactory.createShell(((FileResource<?>) context.getUIContext()
                        .getInitialSelection().get()).getUnderlyingResourceObject(),
                        new SettingsBuilder().inputStream(new PipedInputStream(stdin))
                                 .outputStream(new PrintStream(stdout))
                                 .outputStreamError(new PrintStream(stderr)).create());

               BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getResourceInputStream()));

               try
               {
                  long startTime = System.currentTimeMillis();
                  while (reader.ready())
                  {
                     try
                     {
                        Result result = execute(scriptShell, writer, reader.readLine(), timeout.getValue(),
                                 TimeUnit.SECONDS, startTime);

                        results.add(result);

                        context.getUIContext().getProvider().getOutput().out().write(stdout.toByteArray());
                        context.getUIContext().getProvider().getOutput().err().write(stderr.toByteArray());

                        if (result instanceof Failed)
                           break ALL;
                     }
                     catch (TimeoutException e)
                     {
                        results.add(Results.fail(path + ": timed out.", e));
                        break ALL;
                     }
                  }
               }
               finally
               {
                  reader.close();
                  scriptShell.close();
               }
            }
            else
            {
               results.add(Results.fail(path + ": not found."));
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.hasValue() ? arguments.getValue().iterator() : Collections
               .<String> emptyIterator();

      List<Resource<?>> resourceList;
      if (it.hasNext())
      {
         String value = it.next();
         boolean searching = (value.matches(".*(\\?|\\*)+.*"));
         resourceList = new ResourcePathResolver(resourceFactory, currentResource, value).resolve();
         if (!searching && !resourceList.isEmpty() && resourceList.get(0).exists())
         {
            resourceList = resourceList.get(0).listResources();
         }
      }
      else
      {
         resourceList = currentResource.listResources();
      }
      final Result result;
      if (!resourceList.isEmpty() && !resourceList.get(0).exists())
      {
         result = Results.fail(resourceList.get(0).getName() + ": No such file or directory");
      }
      else
      {
         UIOutput output = shell.getOutput();
         output.out().println(listMany(resourceList, shell));
         result = Results.success();
      }
      return result;
   }
View Full Code Here

                        .inputStream(new PipedInputStream(stdin))
                        .outputStream(stdout)
                        .outputStreamError(stderr)
                        .create();

               Shell scriptShell = shellFactory.createShell(((FileResource<?>) context.getUIContext()
                        .getInitialSelection().get()).getUnderlyingResourceObject(), settings);
              
               scriptShell.getConsole().setPrompt(new Prompt(""));

               try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getResourceInputStream())))
               {
                  long startTime = System.currentTimeMillis();
                  while (reader.ready())
                  {
                     try
                     {
                        String line = reader.readLine();
                        Integer timeoutValue = timeout.getValue();
                        result = execute(scriptShell, writer, line, timeoutValue,
                                 TimeUnit.SECONDS, startTime);

                        if (result != null)
                        {
                           if (result instanceof Failed)
                              break ALL;
                        }
                     }
                     catch (TimeoutException e)
                     {
                        result = Results.fail(path + ": timed out.");
                        break ALL;
                     }
                  }
               }
               finally
               {
                  scriptShell.close();
               }
            }
            else
            {
               result = Results.fail(path + ": not found.");
View Full Code Here

   }

   @Override
   public Result execute(ShellContext context) throws Exception
   {
      Shell shell = context.getProvider();
      FileResource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments
               .getValue()
               .iterator();
      final Result result;
      final FileResource<?> newResource = (it.hasNext()) ? new PathspecParser(
View Full Code Here

   }

   @Override
   public Result execute(ShellContext context) throws Exception
   {
      Shell shell = context.getProvider();
      FileResource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue().iterator();
      final Result result;
      if (it.hasNext())
      {
         String newPath = it.next();
         final List<Resource<?>> newResource = new PathspecParser(resourceFactory, currentResource, newPath).resolve();
         if (newResource.isEmpty() || !newResource.get(0).exists())
         {
            result = Results.fail(newPath + ": No such file or directory");
         }
         else
         {
            FileResource<?> newFileResource = newResource.get(0).reify(FileResource.class);
            if (newFileResource == null)
            {
               result = Results.fail(newPath + ": Invalid path");
            }
            else
            {
               shell.setCurrentResource(newFileResource);
               result = Results.success();
            }
         }
      }
      else
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments
               .getValue().iterator();

      Result result = Results.success();
      UIOutput output = shell.getOutput();
      while (it.hasNext())
      {
         final Resource<?> resource = it.hasNext() ?
                  (new PathspecParser(resourceFactory, currentResource, it.next()).resolve().get(0)) : currentResource;
View Full Code Here

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      final Result result;

      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments
               .getValue().iterator();

      final Resource<?> resource = (it.hasNext()) ?
               (new PathspecParser(resourceFactory, currentResource, it.next()).resolve().get(0)) : currentResource;

      if (!resource.exists())
      {
         result = Results.fail(resource.getName() + ": No such file or directory");
      }
      else
      {
         UIOutput output = shell.getOutput();
         output.out().println(listMany(resource.listResources(), shell));
         result = Results.success();
      }
      return result;
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.shell.Shell

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.