Package org.jboss.forge.addon.ui.output

Examples of org.jboss.forge.addon.ui.output.UIOutput


      }

      boolean forceOption = force.getValue();
      boolean recurse = recursive.getValue();
      UIPrompt prompt = context.getPrompt();
      UIOutput output = context.getUIContext().getProvider().getOutput();
      for (String file : arguments.getValue())
      {
         List<Resource<?>> resources = new ResourcePathResolver(resourceFactory, currentResource, file).resolve();
         for (Resource<?> resource : resources)
         {
            if ((resource instanceof DirectoryResource))
            {
               if (!recurse)
               {
                  output.err().println(
                           "rm: cannot remove '" + resource.getName()
                                    + "': Is a directory ");
               }
               else if (!resource.listResources().isEmpty() && !forceOption)
               {
                  output.err().println(
                           "rm: directory '" + resource.getName()
                                    + "' not empty and cannot be deleted without '--force' '-f' option.");
               }
               else if (forceOption || prompt.promptBoolean("Delete '" + resource.getFullyQualifiedName() + "'?"))
               {
                  if (!resource.delete(recurse))
                  {
                     output.err().println("rm: cannot remove ‘" + resource.getFullyQualifiedName()
                              + "’: Error occurred during deletion");
                  }
               }
            }
            else
            {
               if (!resource.delete(recurse))
               {
                  output.err().println("rm: cannot remove ‘" + resource.getFullyQualifiedName()
                           + "’: Error occurred during deletion");
               }
            }

         }
View Full Code Here


   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Result result = Results.fail("Error executing script.");
      Resource<?> currentResource = (Resource<?>) context.getUIContext().getInitialSelection().get();
      final UIOutput output = context.getUIContext().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(new Runnable()
         {
            @Override
            public void run()
            {
               Streams.write(process.getInputStream(), output.out());
            }
         });
         // Read std err
         executor.submit(new Runnable()
         {
            @Override
            public void run()
            {
               Streams.write(process.getErrorStream(), output.err());
            }
         });
         executor.shutdown();
         int returnCode = process.waitFor();
         if (returnCode == 0)
         {
            result = Results.success();
         }
         else
         {
            result = Results.fail("Error while executing native command. See output for more details");
         }
      }
      else
      {
         ALL: for (String path : arguments.getValue())
         {
            List<Resource<?>> resources = new ResourcePathResolver(resourceFactory, currentResource, path).resolve();
            for (Resource<?> resource : resources)
            {
               if (resource.exists())
               {
                  final PipedOutputStream stdin = new PipedOutputStream();
                  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));

                  PrintStream stdout = new UncloseablePrintStream(output.out());
                  PrintStream stderr = new UncloseablePrintStream(output.err());

                  Settings settings = new SettingsBuilder()
                           .inputStream(new PipedInputStream(stdin))
                           .outputStream(stdout)
                           .outputStreamError(stderr)
View Full Code Here

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

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIOutput output = context.getUIContext().getProvider().getOutput();
      Project project = getSelectedProject(context);
      PackagingFacet packaging = project.getFacet(PackagingFacet.class);
      ProjectBuilder builder = packaging.createBuilder();

      if (arguments.getValue() != null && arguments.getValue().iterator().hasNext())
      {
         List<String> args = new ArrayList<String>();
         for (String val : arguments.getValue())
         {
            args.add(val);
         }
         builder.addArguments(args.toArray(new String[args.size()]));
      }
      else
      {
         builder.addArguments("install");
      }

      if (notest.getValue())
      {
         builder.runTests(false);
      }

      if (profile.getValue() != null)
      {
         builder.addArguments("-P" + profile.getValue());
      }

      try
      {
         builder.build(output.out(), output.err());
      }
      catch (Exception e)
      {
         return Results.fail(e.getMessage(), e);
      }
      finally
      {
         output.out().flush();
         output.err().flush();
      }

      return Results.success("Build Success");
   }
View Full Code Here

      String name = named.getValue();
      String fieldName = conversationFieldName.getValue();
      String beginName = beginMethodName.getValue();
      String endName = endMethodName.getValue();
      Boolean overwriteValue = overwrite.getValue();
      UIOutput output = uiContext.getProvider().getOutput();
      if (resource.exists())
      {
         JavaType<?> javaType = resource.getJavaType();
         if (javaType.isClass())
         {
            JavaClassSource javaClass = (JavaClassSource) javaType;

            if (javaClass.hasField(fieldName) && !javaClass.getField(fieldName).getType().isType(Conversation.class))
            {
               if (overwriteValue)
               {
                  javaClass.removeField(javaClass.getField(fieldName));
               }
               else
               {
                  return Results.fail("Field [" + fieldName + "] already exists.");
               }
            }
            if (javaClass.hasMethodSignature(beginName)
                     && (javaClass.getMethod(beginName).getParameters().size() == 0))
            {
               if (overwriteValue)
               {
                  javaClass.removeMethod(javaClass.getMethod(beginName));
               }
               else
               {
                  return Results.fail("Method [" + beginName + "] exists.");
               }
            }
            if (javaClass.hasMethodSignature(endName) && (javaClass.getMethod(endName).getParameters().size() == 0))
            {
               if (overwriteValue)
               {
                  javaClass.removeMethod(javaClass.getMethod(endName));
               }
               else
               {
                  return Results.fail("Method [" + endName + "] exists.");
               }
            }

            javaClass.addField().setPrivate().setName(fieldName).setType(Conversation.class)
                     .addAnnotation(Inject.class);

            MethodSource<JavaClassSource> beginMethod = javaClass.addMethod().setName(beginName).setReturnTypeVoid()
                     .setPublic();
            if (Strings.isNullOrEmpty(name))
            {
               beginMethod.setBody(fieldName + ".begin();");
            }
            else
            {
               beginMethod.setBody(fieldName + ".begin(\"" + name + "\");");
            }

            if (timeout.getValue() != null)
            {
               beginMethod.setBody(beginMethod.getBody() + "\n" + fieldName + ".setTimeout(" + timeout + ");");
            }

            javaClass.addMethod().setName(endName).setReturnTypeVoid().setPublic()
                     .setBody(fieldName + ".end();");

            if (javaClass.hasSyntaxErrors())
            {
               output.err().println("Modified Java class contains syntax errors:");
               for (SyntaxError error : javaClass.getSyntaxErrors())
               {
                  output.err().print(error.getDescription());
               }
            }

            resource.setContents(javaClass);
         }
View Full Code Here

        table.print(getOut());
        return Results.success();
    }

    public PrintStream getOut() {
        UIOutput output = getOutput();
        if (output != null) {
            return output.out();
        } else {
            return System.out;
        }
    }
View Full Code Here

        UIProvider provider = getUiProvider();
        return provider != null ? provider.getOutput() : null;
    }

    protected PrintStream getOut() {
        UIOutput output = getOutput();
        if (output != null) {
            return output.out();
        } else {
            return System.out;
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.ui.output.UIOutput

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.