Package org.jboss.forge.scaffold

Examples of org.jboss.forge.scaffold.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 = "usingTemplate") final Resource<?> template)
    {
        ScaffoldProvider provider = getScaffoldType(scaffoldType);
        targetDir = selectTargetDir(provider, targetDir);
        verifyTemplate(provider, template);
        List<Resource<?>> generatedResources = provider.setup(targetDir, template, 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


                @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 = "usingTemplate") final Resource<?> template)
    {
        ScaffoldProvider provider = getScaffoldType(scaffoldType);
        targetDir = selectTargetDir(provider, targetDir);
        verifyTemplate(provider, template);
        List<Resource<?>> generatedResources = provider.generateIndex(targetDir, template, 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

                @Option(name = "targetDir") String targetDir,
                @Option(name = "scaffoldType", required = false, completer = ScaffoldProviderCompleter.class) final String scaffoldType,

                @Option(flagOnly = true, name = "overwrite") final boolean overwrite)
    {
        ScaffoldProvider provider = getScaffoldType(scaffoldType);
        targetDir = selectTargetDir(provider, targetDir);
        List<Resource<?>> generatedResources = provider.generateTemplates(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

        {
            ShellMessages.error(writer, "Must specify a domain @Entity on which to operate.");
            return;
        }

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

        for (JavaResource jr : javaTargets)
        {
            JavaClass entity = (JavaClass) (jr).getJavaSource();
            List<Resource<?>> generatedResources = provider.generateFromEntity(targetDir, template, entity, 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;

        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 (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/scaffold/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 = "usingTemplate") final Resource<?> template)
   {
      ScaffoldProvider provider = getScaffoldType(scaffoldType);
      targetDir = selectTargetDir(provider, targetDir);
      verifyTemplate(provider, template);
      List<Resource<?>> generatedResources = provider.setup(targetDir, template, 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

            @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 = "usingTemplate") final Resource<?> template)
   {
      ScaffoldProvider provider = getScaffoldType(scaffoldType);
      targetDir = selectTargetDir(provider, targetDir);
      verifyTemplate(provider, template);
      List<Resource<?>> generatedResources = provider.generateIndex(targetDir, template, 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

            @Option(name = "targetDir") String targetDir,
            @Option(name = "scaffoldType", required = false, completer = ScaffoldProviderCompleter.class) final String scaffoldType,

            @Option(flagOnly = true, name = "overwrite") final boolean overwrite)
   {
      ScaffoldProvider provider = getScaffoldType(scaffoldType);
      targetDir = selectTargetDir(provider, targetDir);
      List<Resource<?>> generatedResources = provider.generateTemplates(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

      {
         ShellMessages.error(writer, "Must specify a domain @Entity on which to operate.");
         return;
      }

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

      for (JavaResource jr : javaTargets)
      {
         JavaClass entity = (JavaClass) (jr).getJavaSource();
         List<Resource<?>> generatedResources = provider.generateFromEntity(targetDir, template, entity, 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

      return provider.getClass().getName() + "_targetDir";
   }

   private ScaffoldProvider getScaffoldType(String scaffoldType)
   {
      ScaffoldProvider scaffoldImpl = null;

      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 (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())
                              + "]");
         }
      }

      /*
       * Resolve scaffoldType
       */
      if ((scaffoldImpl == null && scaffoldType == null)
               && prompt.promptBoolean("No scaffold type was selected, use default [JavaServer Faces]?"))
      {
         scaffoldType = "faces";
         for (ScaffoldProvider type : impls)
         {
            if (ConstraintInspector.getName(type.getClass()).equals(scaffoldType))
            {
               scaffoldImpl = type;
            }
         }
      }
      else if (scaffoldImpl == null && scaffoldType != null)
      {
         for (ScaffoldProvider type : impls)
         {
            if (ConstraintInspector.getName(type.getClass()).equals(scaffoldType))
            {
               scaffoldImpl = 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/scaffold/favicon.ico"));
         }
      }

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

TOP

Related Classes of org.jboss.forge.scaffold.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.