Package org.jboss.forge.addon.shell

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


   public void testEscapes() throws Exception
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      tempDir.deleteOnExit();
      DirectoryResource currentResource = resourceFactory.create(DirectoryResource.class, tempDir);
      Shell shell = test.getShell();
      shell.setCurrentResource(currentResource);
      DirectoryResource child = currentResource.getChildDirectory("Forge 2 Escape");
      child.mkdir();
      child.deleteOnExit();
      Result result = test.execute("cd Forge\\ 2\\ Escape", 10, TimeUnit.SECONDS);
      Assert.assertThat(result.getMessage(), CoreMatchers.nullValue());
      Assert.assertEquals(shell.getCurrentResource(), child);
      currentResource.delete(true);
   }
View Full Code Here


   public void testQuotes() throws Exception
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      tempDir.deleteOnExit();
      DirectoryResource currentResource = resourceFactory.create(DirectoryResource.class, tempDir);
      Shell shell = test.getShell();
      shell.setCurrentResource(currentResource);
      FileResource<?> child = currentResource.getChildDirectory("Forge 2 Escape");
      child.mkdir();
      child.deleteOnExit();
      Result result = test.execute("cd \"Forge 2 Escape\"", 10, TimeUnit.SECONDS);
      Assert.assertThat(result.getMessage(), nullValue());
      Assert.assertEquals(shell.getCurrentResource(), child);
      currentResource.delete(true);
   }
View Full Code Here

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      Shell shell = (Shell) uiContext.getProvider();
      TerminalSize terminalSize = shell.getConsole().getShell().getSize();
      List<String> display = new ArrayList<>();

      Iterable<UICommand> commands = commandFactory.getCommands();
      for (UICommand command : commands)
      {
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

   @Test
   public void testKeepShellContext() throws Exception
   {
      DirectoryResource temp = (DirectoryResource) resourceFactory.create(OperatingSystemUtils.createTempDir());
      temp.deleteOnExit();
      Shell shell = shellTest.getShell();
      shell.setCurrentResource(temp);

      FileResource<?> script = (FileResource<?>) temp.getChild("script.fsh");
      script.setContents("mkdir foo\ncd foo");
      Result result = shellTest.execute("run script.fsh", COMMAND_TIMEOUT, TimeUnit.SECONDS);
      Assert.assertFalse(result instanceof Failed);
      Resource<?> child = temp.getChild("foo");
      Assert.assertTrue(child.exists());
      Assert.assertEquals(child, shell.getCurrentResource());
   }
View Full Code Here

   private ProjectFactory projectFactory;
  
   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      PrintStream out = shell.getOutput().out();

      Project project = Projects.getSelectedProject(projectFactory, context.getUIContext());
      Configuration projectConfig = null;
     
      if (project != null)
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(
               resourceFactory, currentResource, it.next()).resolve().get(0).reify(FileResource.class)
               : currentResource;
      if (!newResource.exists())
      {
         result = Results.fail(newResource.getName() + ": No such file or directory");
      }
      else
      {
         Shell provider = context.getProvider();
         UIOutput output = provider.getOutput();
         output.out().println(listMany(newResource.listResources(), context));
         result = Results.success();
      }
      return result;
   }
View Full Code Here

   }

   @Override
   public Result execute(ShellContext shellContext) throws Exception
   {
      Shell provider = shellContext.getProvider();
      UIOutput output = provider.getOutput();
      FileResource<?> currentResource = provider.getCurrentResource();
      output.out().println(currentResource.getFullyQualifiedName());
      return Results.success();
   }
View Full Code Here

   }

   @Override
   public Result execute(ShellContext context) throws Exception
   {
      Shell shell = context.getProvider();
      FileResource<?> currentResource = shell.getCurrentResource();
      Iterable<String> value = arguments.getValue();
      Iterator<String> it = value == null ? Collections.<String> emptyList().iterator() : value.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(ShellContext context) throws Exception
   {
      Shell shell = context.getProvider();
      FileResource<?> currentResource = shell.getCurrentResource();
      for (String file : arguments.getValue())
      {
         List<Resource<?>> resources = new PathspecParser(resourceFactory, currentResource, file).resolve();
         for (Resource<?> resource : resources)
         {
            if (!resource.exists())
            {
               return Results.fail(file + ": No such file or directory");
            }
         }
      }
      boolean forceOption = force.getValue();
      boolean recurse = recursive.getValue();
      for (String file : arguments.getValue())
      {
         List<Resource<?>> resources = new PathspecParser(resourceFactory, currentResource, file).resolve();
         for (Resource<?> resource : resources)
         {
            // TODO: Prompt for removal
            if (forceOption)
            {
               if (!resource.delete(recurse))
               {
                  return Results.fail("rm: cannot remove ‘" + resource.getFullyQualifiedName()
                           + "’: No such file or directory");
               }
            }
         }
      }
      while (!currentResource.exists())
      {
         currentResource = currentResource.getParent();
      }
      shell.setCurrentResource(currentResource);

      return Results.success();
   }
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.