Package org.jboss.forge.addon.ui.context

Examples of org.jboss.forge.addon.ui.context.UIContext


            project = projectFactory.createProject(targetDir, buildSystem.getValue());
         }

         if (project != null)
         {
            UIContext uiContext = context.getUIContext();
            MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
            metadataFacet.setProjectName(named.getValue());
            metadataFacet.setProjectVersion(version.getValue());
            metadataFacet.setTopLevelPackage(topLevelPackage.getValue());

            if (finalName.hasValue())
            {
               PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);
               packagingFacet.setFinalName(finalName.getValue());
            }

            uiContext.setSelection(project.getRootDirectory());
            uiContext.getAttributeMap().put(Project.class, project);
         }
         else
            result = Results.fail("Could not create project of type: [" + value + "]");
      }
      else
View Full Code Here


   @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(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)
                           .create();

                  try (Shell scriptShell = shellFactory.createShell(currentResource, 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 = readLine(reader);
                              if (skipsLine(line))
                              {
                                 // Skip Comments
                                 continue;
                              }
                              Integer timeoutValue = timeout.getValue();
                              result = execute(scriptShell, writer, line, timeoutValue,
                                       TimeUnit.SECONDS, startTime);

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

public class VerboseExecutionListener extends AbstractCommandExecutionListener
{
   @Override
   public void postCommandFailure(UICommand command, UIExecutionContext context, Throwable failure)
   {
      UIContext uiContext = context.getUIContext();
      if (uiContext instanceof ShellContext)
      {
         ShellContext shellContext = (ShellContext) uiContext;
         if (shellContext.isVerbose() && failure != null)
         {
View Full Code Here

            project = projectFactory.createProject(targetDir, buildSystem.getValue());
         }

         if (project != null)
         {
            UIContext uiContext = context.getUIContext();
            MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
            metadataFacet.setProjectName(named.getValue());
            metadataFacet.setProjectVersion(version.getValue());
            metadataFacet.setTopLevelPackage(topLevelPackage.getValue());

            if (finalName.hasValue())
            {
               PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);
               packagingFacet.setFinalName(finalName.getValue());
            }

            uiContext.setSelection(project.getProjectRoot());
            uiContext.getAttributeMap().put(Project.class, project);
         }
         else
            result = Results.fail("Could not create project of type: [" + value + "]");
      }
      else
View Full Code Here

   private DependencyInstaller dependencyInstaller;

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);

      facetFactory.install(project, FurnaceVersionFacet.class);
      project.getFacet(FurnaceVersionFacet.class).setVersion(furnace.getVersion().toString());
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);
      JavaClassSource javaClass = Roaster.create(JavaClassSource.class).setName(named.getValue())
               .setPackage(packageName.getValue());

      // Add imports
      javaClass.addImport("org.jboss.arquillian.container.test.api.Deployment");
      javaClass.addImport("org.jboss.arquillian.junit.Arquillian");
      javaClass.addImport("org.junit.runner.RunWith");
      javaClass.addImport("org.jboss.forge.arquillian.AddonDependency");
      javaClass.addImport("org.jboss.forge.arquillian.Dependencies");
      javaClass.addImport("org.jboss.forge.arquillian.archive.ForgeArchive");
      javaClass.addImport("org.jboss.forge.furnace.repositories.AddonDependencyEntry");
      javaClass.addImport("org.jboss.shrinkwrap.api.ShrinkWrap");

      // Add Arquillian annotation
      javaClass.addAnnotation("RunWith").setLiteralValue("Arquillian.class");

      // Create getDeployment method
      StringBuilder body = new StringBuilder(
               "ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class).addBeansXML()");
      StringBuilder dependenciesAnnotationBody = new StringBuilder();
      body.append(".addAsAddonDependencies(");
      AddonId furnaceContainerId = furnaceContainer.getValue();
      addAddonDependency(project, body, dependenciesAnnotationBody, furnaceContainerId);
      Iterator<AddonId> it = addonDependencies.getValue().iterator();
      if (it.hasNext())
      {
         body.append(",");
         dependenciesAnnotationBody.append(",");
      }
      while (it.hasNext())
      {
         AddonId addonId = it.next();
         addAddonDependency(project, body, dependenciesAnnotationBody, addonId);
         if (it.hasNext())
         {
            body.append(",");
            dependenciesAnnotationBody.append(",");
         }
      }
      body.append(")");
      body.append(";");
      body.append("return archive;");
      MethodSource<JavaClassSource> getDeployment = javaClass.addMethod().setName("getDeployment").setPublic()
               .setStatic(true)
               .setBody(body.toString()).setReturnType("ForgeArchive");
      getDeployment.addAnnotation("Deployment");
      String annotationBody = dependenciesAnnotationBody.toString();
      if (annotationBody.length() > 0)
      {
         getDeployment.addAnnotation("Dependencies").setLiteralValue("{" + annotationBody + "}");
      }

      JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
      JavaResource javaResource = facet.saveTestJavaSource(javaClass);
      uiContext.setSelection(javaResource);
      return Results.success("Test class " + javaClass.getQualifiedName() + " created");
   }
View Full Code Here

   @SuppressWarnings({ "rawtypes", "unchecked" })
   @Override
   public void initializeUI(UIBuilder builder) throws Exception
   {
      UIContext context = builder.getUIContext();
      Project project = getSelectedProject(context);
      JPAFacet<PersistenceCommonDescriptor> persistenceFacet = project.getFacet(JPAFacet.class);
      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
      targets.setValueChoices(persistenceFacet.getAllEntities());
      targets.setItemLabelConverter(new Converter<JavaClass, String>()
      {
         @Override
         public String convert(JavaClass source)
         {
            return source == null ? null : source.getQualifiedName();
         }
      });
      List<String> persistenceUnits = new ArrayList<String>();
      List<PersistenceUnitCommon> allUnits = persistenceFacet.getConfig().getAllPersistenceUnit();
      for (PersistenceUnitCommon persistenceUnit : allUnits)
      {
         persistenceUnits.add(persistenceUnit.getName());
      }
      if (!persistenceUnits.isEmpty())
      {
         persistenceUnit.setValueChoices(persistenceUnits).setDefaultValue(persistenceUnits.get(0));
      }

      // TODO: May detect where @Path resources are located
      packageName.setDefaultValue(javaSourceFacet.getBasePackage() + ".rest");

      contentType.setValueChoices(Arrays.asList(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
      generator.setDefaultValue(defaultResourceGenerator);
      if (context.getProvider().isGUI())
      {
         generator.setItemLabelConverter(new Converter<RestResourceGenerator, String>()
         {
            @Override
            public String convert(RestResourceGenerator source)
View Full Code Here

   }

   @Override
   public Result execute(final UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      RestGenerationContextImpl generationContext = createContextFor(uiContext);
      Set<JavaClass> endpoints = generateEndpoints(generationContext);
      Project project = generationContext.getProject();
      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
      List<JavaResource> selection = new ArrayList<JavaResource>();

      for (JavaClass javaClass : endpoints)
      {
         selection.add(javaSourceFacet.saveJavaSource(javaClass));
      }
      uiContext.setSelection(selection);
      return Results.success("Endpoint created");
   }
View Full Code Here

   public Result execute(UIExecutionContext context) throws Exception
   {
      String entityName = named.getValue();
      String entityPackage = targetPackage.getValue();
      DirectoryResource targetDir = targetLocation.getValue();
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);
      JavaResource javaResource;
      if (project == null)
      {
         javaResource = facesOperations.newConverter(targetDir, entityName, entityPackage);
      }
      else
      {
         javaResource = facesOperations.newConverter(project, entityName, entityPackage);
      }
      uiContext.setSelection(javaResource);
      return Results.success("Converter " + javaResource + " created");
   }
View Full Code Here

   public Result execute(UIExecutionContext context) throws Exception
   {
      String entityName = named.getValue();
      String entityPackage = targetPackage.getValue();
      DirectoryResource targetDir = targetLocation.getValue();
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);
      JavaResource javaResource;
      if (project == null)
      {
         javaResource = facesOperations.newValidator(targetDir, entityName, entityPackage);
      }
      else
      {
         javaResource = facesOperations.newValidator(project, entityName, entityPackage);
      }
      uiContext.setSelection(javaResource);
      return Results.success("Validator " + javaResource + " created");
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.ui.context.UIContext

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.