Examples of ScaffoldProvider


Examples of org.jboss.forge.scaffoldx.ScaffoldProvider

   }

   @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
TOP
Copyright © 2018 www.massapi.com. 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.