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

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


         builder.append(addonId.toCoordinates());

         if (iterator.hasNext())
            builder.append("\n");
      }
      UIOutput output = context.getUIContext().getProvider().getOutput();
      output.out().println("Currently installed addons:");
      output.out().println(builder.toString());
      return Results.success();
   }
View Full Code Here


   {
      // TODO: Option to save sources?
      File tempDir = OperatingSystemUtils.createTempDir();
      DirectoryResource projectRoot = resourceFactory.create(DirectoryResource.class, tempDir);
      UIProgressMonitor progressMonitor = context.getProgressMonitor();
      UIOutput output = context.getUIContext().getProvider().getOutput();
      progressMonitor.beginTask("Installing Addon from Git", 4);

      progressMonitor.subTask("Cloning repository in " + tempDir);

      // Clone repository
      cloneTo(projectRoot);

      progressMonitor.worked(1);
      progressMonitor.subTask("Installing project into local repository");
      // Build project
      Project project = projectFactory.findProject(projectRoot);
      if (project == null)
      {
         return Results.fail("No project found in root " + projectRoot.getFullyQualifiedName());
      }
      Coordinate buildCoordinate = project.getFacet(MetadataFacet.class).getOutputDependency().getCoordinate();
      try
      {
         project.getFacet(PackagingFacet.class).createBuilder().addArguments("clean", "install").runTests(false)
                  .build(output.out(), output.err());
      }
      catch (BuildException e)
      {
         return Results.fail("Unable to execute project build", e);
      }
View Full Code Here

      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
      SOURCETYPE source = buildJavaSource(javaSourceFacet);
      JavaResource javaResource;
      if (source.hasSyntaxErrors())
      {
         UIOutput output = uiContext.getProvider().getOutput();
         PrintStream err = output.err();
         err.println("Syntax Errors:");
         for (SyntaxError error : source.getSyntaxErrors())
         {
            err.println(error);
         }
View Full Code Here

   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(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
      {
         Resource<?> selectedResource = currentResource;
         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

   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(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
      {
         Resource<?> selectedResource = currentResource;
         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 void onCommandNotFound(String line, UIContext context)
   {
      UIOutput output = context.getProvider().getOutput();
      String commandName = line.split(" ")[0];
      // Find similar commands
      Set<String> similarCommands = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
      for (String command : commandRegistry.getAllCommandNames())
      {
         if (getLevenshteinDistance(commandName, command) < LETTERS_NEEDED_TO_BE_REPLACED)
         {
            similarCommands.add(command);
         }
      }

      if (!similarCommands.isEmpty())
      {
         output.out().println();
         if (similarCommands.size() == 1)
         {
            output.out().println("Did you mean this?");
         }
         else
         {
            output.out().println("Did you mean one of these?");
         }
         for (String plugin : similarCommands)
         {
            output.out().println(
                     new TerminalString("\t" + plugin,
                              new TerminalColor(Color.DEFAULT, Color.DEFAULT, Intensity.BRIGHT)));
         }
      }
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 (BuildException e)
      {
         return Results.fail("Build failed.", e);
      }
      finally
      {
         output.out().flush();
         output.err().flush();
      }

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

         if (project != null && project.hasFacet(BuildStatusFacet.class))
         {
            BuildStatusFacet facet = project.getFacet(BuildStatusFacet.class);
            if (!facet.isBuildable())
            {
               UIOutput output = uiContext.getProvider().getOutput();
               PrintStream err = output.err();
               output.error(err, String.format("Project '%s' has errors", project.getRoot()));
               for (LogRecord record : facet.getBuildMessages())
               {
                  if (Level.SEVERE.equals(record.getLevel()))
                  {
                     output.error(err, record.getMessage());
                  }
                  else if (Level.WARNING.equals(record.getLevel()))
                  {
                     output.warn(err, record.getMessage());
                  }
                  else
                  {
                     output.info(err, record.getMessage());
                  }
               }
            }
         }
      }
View Full Code Here

   }

   @Override
   public Result execute(UIContext context) throws Exception
   {
      UIOutput output = context.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 (BuildException e)
      {
         return Results.fail("Build failed.", e);
      }
      finally
      {
         output.out().flush();
         output.err().flush();
      }

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

      {
         PackagingFacet facet = project.getFacet(PackagingFacet.class);
         BuildResult buildResult = facet.getBuildResult();
         if (!buildResult.isSuccess())
         {
            UIOutput output = uiContext.getProvider().getOutput();
            PrintStream err = output.err();
            output.error(err, String.format("Project '%s' has errors", project.getRoot()));
            for (BuildMessage message : buildResult.getMessages())
            {
               switch (message.getSeverity())
               {
               case ERROR:
                  output.error(err, message.getMessage());
                  break;
               case WARN:
                  output.warn(err, message.getMessage());
                  break;
               case INFO:
               default:
                  output.info(err, message.getMessage());
                  break;
               }
            }
         }
      }
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.