Package org.jboss.forge.scaffoldx

Examples of org.jboss.forge.scaffoldx.ScaffoldProvider


            @Option(name = "targetDir") String targetDir,
            @Option(name = "scaffoldType", required = false, completer = ScaffoldProviderCompleter.class) final String scaffoldType,
            @Option(flagOnly = true, name = "overwrite") final boolean overwrite,
            @Option(name = "installTemplates") final boolean installTemplates)
   {
      ScaffoldProvider provider = getScaffoldType(scaffoldType, false);
      targetDir = selectTargetDir(provider, targetDir);
      List<Resource<?>> generatedResources = provider.setup(targetDir, overwrite, installTemplates);

      // TODO give plugins a chance to react to generated resources, use event bus?
      if (!generatedResources.isEmpty())
      {
         generatedEvent.fire(new ScaffoldGeneratedResources(provider, prepareResources(generatedResources)));
View Full Code Here


      if (((resources == null) || (resources.length < 1)))
      {
         resources = new Resource<?>[] { currentResource };
      }

      ScaffoldProvider provider = getScaffoldType(scaffoldType, true);
      targetDir = selectTargetDir(provider, targetDir);

      List<Resource<?>> resourceList = Arrays.asList(resources);
      List<Resource<?>> generatedResources = provider.generateFrom(resourceList, targetDir, overwrite);
      // TODO give plugins a chance to react to generated resources, use event bus?
      if (!generatedResources.isEmpty())
      {
         generatedEvent.fire(new ScaffoldGeneratedResources(provider, prepareResources(generatedResources)));
      }
View Full Code Here

   }

   @SuppressWarnings("unchecked")
   private ScaffoldProvider getScaffoldType(String scaffoldType, boolean invokedViaGeneration)
   {
      ScaffoldProvider scaffoldImpl = null;

      /*
       * Find an installed project facet that matches the scaffold type.
       */
      Collection<Facet> facets = project.getFacets();
      List<ScaffoldProvider> detectedScaffolds = new ArrayList<ScaffoldProvider>();
      for (Facet facet : facets)
      {
         if (facet instanceof ScaffoldProvider)
         {
            detectedScaffolds.add((ScaffoldProvider) facet);
            if (ConstraintInspector.getName(facet.getClass()).equals(scaffoldType))
            {
               scaffoldImpl = (ScaffoldProvider) facet;
            }
         }
      }

      if(invokedViaGeneration)
      {
         /*
          * If no detected (installed) scaffold type matches the requested scaffold type,
          * then use the detected scaffold type if there is only one.
          * If there are more than one scaffold types, then prompt to choose one of them.
          */
         if (scaffoldImpl == null)
         {
            List<String> detectedScaffoldNames = new ArrayList<String>();
            for (ScaffoldProvider sp : detectedScaffolds)
            {
               detectedScaffoldNames.add(ConstraintInspector.getName(sp.getClass()));
            }
  
            if (detectedScaffolds.size() > 1)
            {
               String name = prompt.promptChoiceTyped("Use which previously installed scaffold provider?",
                        detectedScaffoldNames, detectedScaffoldNames.get(detectedScaffoldNames.size() - 1));
  
               for (ScaffoldProvider sp : detectedScaffolds)
               {
                  if (name.equals(ConstraintInspector.getName(sp.getClass())))
                  {
                     scaffoldImpl = sp;
                     break;
                  }
               }
            }
            else if (!detectedScaffolds.isEmpty())
            {
               scaffoldImpl = detectedScaffolds.get(0);
               ShellMessages.info(
                        writer,
                        "Using currently installed scaffold ["
                                 + ConstraintInspector.getName(scaffoldImpl.getClass())
                                 + "]");
            }
         }
      }

      Set<Class<? extends ScaffoldProvider>> providers = new HashSet<Class<? extends ScaffoldProvider>>();
      for (Class<? extends Facet> type : factory.getFacetTypes())
      {
         if (ScaffoldProvider.class.isAssignableFrom(type))
            providers.add((Class<? extends ScaffoldProvider>) type);
      }
      /*
       * Resolve scaffoldType
       */
      if ((scaffoldImpl == null && scaffoldType == null)
               && prompt.promptBoolean("No scaffold type was selected, use default [JavaServer Faces]?"))
      {

         scaffoldType = "faces";
         for (Class<? extends ScaffoldProvider> type : providers)
         {
            if (ConstraintInspector.getName(type).equals(scaffoldType))
            {
               scaffoldImpl = factory.getFacet(type);
            }
         }
      }
      else if (scaffoldImpl == null && scaffoldType != null)
      {
         for (Class<? extends ScaffoldProvider> type : providers)
         {
            if (ConstraintInspector.getName(type).equals(scaffoldType))
            {
               scaffoldImpl = factory.getFacet(type);
            }
         }
      }

      if (scaffoldImpl == null)
      {
         throw new RuntimeException(
                  "No scaffold installed was detected, and no scaffold type was selected; re-run with '--scaffoldType ...' ");
      }

      /*
       * Perform installation
       */
      if (!project.hasFacet(scaffoldImpl.getClass())
               && prompt.promptBoolean("Scaffold provider [" + scaffoldType + "] is not installed. Install it?"))
      {
         /*
          * Fire the InstallFacets event. This would not setup the facet completely, i.e. ScaffoldProvider.setup would
          * not be invoked. But this is necessary, otherwise the ScaffoldProvider would not be registered as
          * project facet!
          */
         project.setAttribute(INSTALLING_SCAFFOLD, Boolean.TRUE);
         installFacets.fire(new InstallFacets(scaffoldImpl.getClass()));
         project.removeAttribute(INSTALLING_SCAFFOLD);
      }
      else if (!project.hasFacet(scaffoldImpl.getClass()))
      {
         throw new RuntimeException("Aborted.");
      }

      if (project.hasFacet(WebResourceFacet.class))
      {
         FileResource<?> favicon = project.getFacet(WebResourceFacet.class).getWebResource("/favicon.ico");
         if (!favicon.exists())
         {
            favicon.setContents(getClass().getResourceAsStream("/org/jboss/forge/scaffoldx/favicon.ico"));
         }
      }

      return project.getFacet(scaffoldImpl.getClass());
   }
View Full Code Here

            @Option(name = "targetDir") String targetDir,
            @Option(name = "scaffoldType", required = false, completer = ScaffoldProviderCompleter.class) final String scaffoldType,
            @Option(flagOnly = true, name = "overwrite") final boolean overwrite,
            @Option(name = "installTemplates") final boolean installTemplates)
   {
      ScaffoldProvider provider = getScaffoldType(scaffoldType);
      targetDir = selectTargetDir(provider, targetDir);
      List<Resource<?>> generatedResources = provider.setup(targetDir, overwrite, installTemplates);

      // TODO give plugins a chance to react to generated resources, use event bus?
      if (!generatedResources.isEmpty())
      {
         generatedEvent.fire(new ScaffoldGeneratedResources(provider, prepareResources(generatedResources)));
View Full Code Here

      if (((resources == null) || (resources.length < 1)))
      {
         resources = new Resource<?>[] { currentResource };
      }

      ScaffoldProvider provider = getScaffoldType(scaffoldType);
      targetDir = selectTargetDir(provider, targetDir);

      List<Resource<?>> resourceList = Arrays.asList(resources);
      List<Resource<?>> generatedResources = provider.generateFrom(resourceList, targetDir, overwrite);
      // TODO give plugins a chance to react to generated resources, use event bus?
      if (!generatedResources.isEmpty())
      {
         generatedEvent.fire(new ScaffoldGeneratedResources(provider, prepareResources(generatedResources)));
      }
View Full Code Here

   }

   @SuppressWarnings("unchecked")
   private ScaffoldProvider getScaffoldType(String scaffoldType)
   {
      ScaffoldProvider scaffoldImpl = null;

      /*
       * Find an installed project facet that matches the scaffold type.
       */
      Collection<Facet> facets = project.getFacets();
      List<ScaffoldProvider> detectedScaffolds = new ArrayList<ScaffoldProvider>();
      for (Facet facet : facets)
      {
         if (facet instanceof ScaffoldProvider)
         {
            detectedScaffolds.add((ScaffoldProvider) facet);
            if (ConstraintInspector.getName(facet.getClass()).equals(scaffoldType))
            {
               scaffoldImpl = (ScaffoldProvider) facet;
            }
         }
      }

      /*
       * If no detected (installed) scaffold type matches the requested scaffold type,
       * then use the detected scaffold type if there is only one.
       * If there are more than one scaffold types, then prompt to choose one of them.
       *
       * FIXME: This should probably not be done.
       * Say, 'faces' is installed, and 'angularjs' is requested, then faces will be used.
       */
      if (scaffoldImpl == null)
      {
         List<String> detectedScaffoldNames = new ArrayList<String>();
         for (ScaffoldProvider sp : detectedScaffolds)
         {
            detectedScaffoldNames.add(ConstraintInspector.getName(sp.getClass()));
         }

         if (detectedScaffolds.size() > 1)
         {
            String name = prompt.promptChoiceTyped("Use which previously installed scaffold provider?",
                     detectedScaffoldNames, detectedScaffoldNames.get(detectedScaffoldNames.size() - 1));

            for (ScaffoldProvider sp : detectedScaffolds)
            {
               if (name.equals(ConstraintInspector.getName(sp.getClass())))
               {
                  scaffoldImpl = sp;
                  break;
               }
            }
         }
         else if (!detectedScaffolds.isEmpty())
         {
            scaffoldImpl = detectedScaffolds.get(0);
            ShellMessages.info(
                     writer,
                     "Using currently installed scaffold ["
                              + ConstraintInspector.getName(scaffoldImpl.getClass())
                              + "]");
         }
      }

      Set<Class<? extends ScaffoldProvider>> providers = new HashSet<Class<? extends ScaffoldProvider>>();
      for (Class<? extends Facet> type : factory.getFacetTypes())
      {
         if (ScaffoldProvider.class.isAssignableFrom(type))
            providers.add((Class<? extends ScaffoldProvider>) type);
      }
      /*
       * Resolve scaffoldType
       */
      if ((scaffoldImpl == null && scaffoldType == null)
               && prompt.promptBoolean("No scaffold type was selected, use default [JavaServer Faces]?"))
      {

         scaffoldType = "faces";
         for (Class<? extends ScaffoldProvider> type : providers)
         {
            if (ConstraintInspector.getName(type).equals(scaffoldType))
            {
               scaffoldImpl = factory.getFacet(type);
            }
         }
      }
      else if (scaffoldImpl == null && scaffoldType != null)
      {
         for (Class<? extends ScaffoldProvider> type : providers)
         {
            if (ConstraintInspector.getName(type).equals(scaffoldType))
            {
               scaffoldImpl = factory.getFacet(type);
            }
         }
      }

      if (scaffoldImpl == null)
      {
         throw new RuntimeException(
                  "No scaffold installed was detected, and no scaffold type was selected; re-run with '--scaffoldType ...' ");
      }

      /*
       * Perform installation
       */
      if (!project.hasFacet(scaffoldImpl.getClass())
               && prompt.promptBoolean("Scaffold provider [" + scaffoldType + "] is not installed. Install it?"))
      {
         installFacets.fire(new InstallFacets(scaffoldImpl.getClass()));
      }
      else if (!project.hasFacet(scaffoldImpl.getClass()))
      {
         throw new RuntimeException("Aborted.");
      }

      if (project.hasFacet(WebResourceFacet.class))
      {
         FileResource<?> favicon = project.getFacet(WebResourceFacet.class).getWebResource("/favicon.ico");
         if (!favicon.exists())
         {
            favicon.setContents(getClass().getResourceAsStream("/org/jboss/forge/scaffoldx/favicon.ico"));
         }
      }

      return project.getFacet(scaffoldImpl.getClass());
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.scaffoldx.ScaffoldProvider

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.