Permalink
Browse files

FORGE-550: created list-scaffold-providers plugin and test case

  • Loading branch information...
1 parent 61d69dd commit 345e417ca1cf55cc1686304c5ef01c001eab3086 @gastaldi gastaldi committed May 4, 2012
@@ -59,6 +59,7 @@
import org.jboss.forge.scaffold.util.ScaffoldUtil;
import org.jboss.forge.shell.ShellPrompt;
import org.jboss.forge.shell.plugins.Alias;
+import org.jboss.forge.shell.plugins.Help;
import org.jboss.forge.shell.plugins.RequiresFacet;
import org.jboss.forge.shell.util.Streams;
import org.jboss.forge.spec.javaee.CDIFacet;
@@ -101,11 +102,12 @@
* writing Metawidget plugins, see <a href="http://metawidget.org/documentation.php">the Metawidget documentation</a>.
* <p>
* This Facet does <em>not</em> require Metawidget to be in the final project.
- *
+ *
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
* @author Richard Kennard
*/
@Alias("faces")
+@Help("JavaServer Faces scaffolding")
@RequiresFacet({ WebResourceFacet.class,
DependencyFacet.class,
PersistenceFacet.class,
@@ -690,8 +692,8 @@ protected Node removeConflictingErrorPages(final ServletFacet servlet)
public boolean accept(Resource<?> resource)
{
FileResource<?> file = (FileResource<?>) resource;
-
- if (!file.isDirectory()
+
+ if (!file.isDirectory()
|| file.getName().equals("resources")
|| file.getName().equals("WEB-INF")
|| file.getName().equals("META-INF"))
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.forge.scaffold.plugins;
+
+import java.io.FileNotFoundException;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.jboss.forge.bus.util.Annotations;
+import org.jboss.forge.scaffold.ScaffoldProvider;
+import org.jboss.forge.shell.ShellColor;
+import org.jboss.forge.shell.plugins.Alias;
+import org.jboss.forge.shell.plugins.DefaultCommand;
+import org.jboss.forge.shell.plugins.Help;
+import org.jboss.forge.shell.plugins.PipeOut;
+import org.jboss.forge.shell.plugins.Plugin;
+import org.jboss.forge.shell.plugins.Topic;
+import org.jboss.forge.shell.util.ConstraintInspector;
+
+/**
+ * Lists all the scaffold providers registered on this forge installation
+ *
+ * @author <a href="mailto:gegastaldi@gmail.com">George Gastaldi</a>
+ *
+ */
+@Alias("list-scaffold-providers")
+@Topic("UI Generation & Scaffolding")
+@Help("Lists all the scaffold providers registered on this forge installation")
+public class ListScaffoldProvidersPlugin implements Plugin
+{
+
+ @Inject
+ @Any
+ private Instance<ScaffoldProvider> providers;
+
+ @DefaultCommand
+ public void listProviders(PipeOut out) throws FileNotFoundException
+ {
+ for (ScaffoldProvider scaffoldProvider : providers)
+ {
+ Class<? extends ScaffoldProvider> scaffoldClass = scaffoldProvider.getClass();
+ String alias = ConstraintInspector.getName(scaffoldClass);
+
+ String description;
+ if (Annotations.isAnnotationPresent(scaffoldClass, Help.class))
+ {
+ description = Annotations.getAnnotation(scaffoldClass, Help.class).value();
+ }
+ else
+ {
+ description = "<no description found>";
+ }
+ out.print(ShellColor.BOLD, "* " + alias + " : ");
+ out.println(description);
+ }
+ }
+}
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.forge.scaffold.plugins;
+
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.forge.test.AbstractShellTest;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+
+public class ListScaffoldProvidersPluginTest extends AbstractShellTest
+{
+ @Deployment
+ public static JavaArchive getDeployment()
+ {
+ return AbstractShellTest.getDeployment().addPackages(true,
+ ListScaffoldProvidersPlugin.class.getPackage());
+ }
+
+ @Test
+ public void testDefaultCommand() throws Exception
+ {
+ getShell().execute("list-scaffold-providers");
+ assertTrue("Wrong output: " + getOutput(), getOutput().contains("* test : Foo"));
+ }
+
+}
@@ -0,0 +1,104 @@
+package org.jboss.forge.scaffold.plugins;
+
+import java.util.List;
+
+import org.jboss.forge.parser.java.JavaClass;
+import org.jboss.forge.project.Project;
+import org.jboss.forge.resources.Resource;
+import org.jboss.forge.scaffold.AccessStrategy;
+import org.jboss.forge.scaffold.ScaffoldProvider;
+import org.jboss.forge.scaffold.TemplateStrategy;
+import org.jboss.forge.shell.plugins.Alias;
+import org.jboss.forge.shell.plugins.Help;
+
+@Alias("test")
+@Help("Foo")
+public class TestScaffoldProvider implements ScaffoldProvider
+{
+
+ @Override
+ public Project getProject()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setProject(Project project)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean install()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isInstalled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean uninstall()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public List<Resource<?>> setup(String targetDir, Resource<?> template, boolean overwrite)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Resource<?>> generateTemplates(String targetDir, boolean overwrite)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Resource<?>> generateIndex(String targetDir, Resource<?> template, boolean overwrite)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Resource<?>> generateFromEntity(String targetDir, Resource<?> template, JavaClass entity,
+ boolean overwrite)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Resource<?>> getGeneratedResources(String targetDir)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AccessStrategy getAccessStrategy()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public TemplateStrategy getTemplateStrategy()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}

0 comments on commit 345e417

Please sign in to comment.