[jboss-cvs] jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool ...
Gavin King
gavin.king at jboss.com
Sat Oct 28 13:56:04 EDT 2006
User: gavin
Date: 06/10/28 13:56:04
Added: seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool
SeamGenCommandLine.java
BuildPropertiesGenerator.java
BuildPropertiesBean.java FaceletGenerator.java
AbstractSeamGen.java JavaClassGenerator.java
Log:
add seam-gen to CVS
Revision Changes Path
1.1 date: 2006/10/28 17:56:04; author: gavin; state: Exp;jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool/SeamGenCommandLine.java
Index: SeamGenCommandLine.java
===================================================================
package org.jboss.seam.tool;
public class SeamGenCommandLine {
public static void main(String[] args) throws Exception {
if (args[0].equals("set-properties")) {
// check to make sure we have right # of arguments
if (args.length == 9) {
BuildPropertiesBean projectProps = new BuildPropertiesBean(args);
BuildPropertiesGenerator propsGen = new BuildPropertiesGenerator(
projectProps);
propsGen.generate();
} else {
throw new Exception("Wrong number of arguments");
}
} else if (args[0].equals("new-action")) {
if (args.length == 3) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.newAction();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-stateless-action")) {
if (args.length == 3) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.newStatelessAction();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-conversation")) {
if (args.length == 3) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.newConversation();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-testcase")) {
if (args.length == 3) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.newTestcase();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-bpm-action")) {
if (args.length == 3) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.newBpmAction();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-entity")) {
if (args.length == 3) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.newEntity();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-mdb")) {
if (args.length == 5) {
JavaClassGenerator actionGen = new JavaClassGenerator(args);
actionGen.setMdbDestination(args[3]);
actionGen.setMdbDestinationType(args[4]);
actionGen.newMdb();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-page")) {
if (args.length == 3) {
FaceletGenerator faceletGen = new FaceletGenerator(args);
faceletGen.newPage();
} else {
throw new Exception("Wrong number of arguments");
}
}
else if (args[0].equals("new-action-page")) {
if (args.length == 4) {
FaceletGenerator faceletGen = new FaceletGenerator(args);
faceletGen.setActionName(args[3]);
faceletGen.newActionPage();
} else {
throw new Exception("Wrong number of arguments");
}
}
else {
System.out.println("No command executed");
}
}
}
1.1 date: 2006/10/28 17:56:04; author: gavin; state: Exp;jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool/BuildPropertiesGenerator.java
Index: BuildPropertiesGenerator.java
===================================================================
package org.jboss.seam.tool;
import java.io.IOException;
import java.util.HashMap;
import freemarker.template.TemplateException;
public class BuildPropertiesGenerator extends AbstractSeamGen {
BuildPropertiesBean projectProps;
public BuildPropertiesGenerator(BuildPropertiesBean projectProps){
this.projectProps = projectProps;
}
public void generate() throws IOException, TemplateException
{
logger.info("Generating a new build.properties file");
HashMap map = new HashMap();
map.put("projectProps", this.projectProps);
generateFile("build-properties.ftl", "build.properties", map);
}
public void generateWtp() throws IOException, TemplateException
{
logger.info("Generating a new build.properties file");
HashMap map = new HashMap();
map.put("projectProps", this.projectProps);
generateFile("build-properties.ftl", "build.properties", map);
}
}
1.1 date: 2006/10/28 17:56:04; author: gavin; state: Exp;jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool/BuildPropertiesBean.java
Index: BuildPropertiesBean.java
===================================================================
package org.jboss.seam.tool;
public class BuildPropertiesBean {
private String workspaceHome;
private String jbossHome;
private String actionPackage;
private String actionDir;
private String modelPackage;
private String modelDir;
private String testDir;
private String testPackage;
private String bpmDir;
private String bpmPackage;
private String mdbDir;
private String mdbPackage;
private String wtp;
public BuildPropertiesBean(){}
public BuildPropertiesBean(String args[])
{
this.workspaceHome = args[1];
this.jbossHome = args[2];
this.actionPackage = args[3];
this.actionDir = args[3].replace(".", "/");
this.modelPackage = args[4];
this.modelDir = args[4].replace(".", "/");
this.testDir = args[5].replace(".", "/");
this.testPackage = args[5];
this.bpmDir = args[6].replace(".", "/");
this.bpmPackage = args[6];
this.mdbDir = args[7].replace(".", "/");
this.mdbPackage = args[7];
this.wtp = args[8];
}
public String getActionDir() {
return actionDir;
}
public void setActionDir(String actionDir) {
this.actionDir = actionDir;
}
public String getActionPackage() {
return actionPackage;
}
public void setActionPackage(String actionPackage) {
this.actionPackage = actionPackage;
}
public String getBpmDir() {
return bpmDir;
}
public void setBpmDir(String bpmDir) {
this.bpmDir = bpmDir;
}
public String getBpmPackage() {
return bpmPackage;
}
public void setBpmPackage(String bpmPackage) {
this.bpmPackage = bpmPackage;
}
public String getJbossHome() {
return jbossHome;
}
public void setJbossHome(String jbossHome) {
this.jbossHome = jbossHome;
}
public String getMdbDir() {
return mdbDir;
}
public void setMdbDir(String mdbDir) {
this.mdbDir = mdbDir;
}
public String getMdbPackage() {
return mdbPackage;
}
public void setMdbPackage(String mdbPackage) {
this.mdbPackage = mdbPackage;
}
public String getModelDir() {
return modelDir;
}
public void setModelDir(String modelDir) {
this.modelDir = modelDir;
}
public String getModelPackage() {
return modelPackage;
}
public void setModelPackage(String modelPackage) {
this.modelPackage = modelPackage;
}
public String getTestDir() {
return testDir;
}
public void setTestDir(String testDir) {
this.testDir = testDir;
}
public String getTestPackage() {
return testPackage;
}
public void setTestPackage(String testPackage) {
this.testPackage = testPackage;
}
public String getWorkspaceHome() {
return workspaceHome;
}
public void setWorkspaceHome(String workspaceHome) {
this.workspaceHome = workspaceHome;
}
public String getWtp() {
return wtp;
}
public void setWtp(String wtp) {
this.wtp = wtp;
}
}
1.1 date: 2006/10/28 17:56:04; author: gavin; state: Exp;jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool/FaceletGenerator.java
Index: FaceletGenerator.java
===================================================================
package org.jboss.seam.tool;
import java.io.IOException;
import java.util.HashMap;
import freemarker.template.TemplateException;
public class FaceletGenerator extends AbstractSeamGen {
private String pageName;
private String projectName;
private String actionName;
public FaceletGenerator() {};
public FaceletGenerator(String[] args) throws IOException {
this.projectName = args[1];
this.pageName = args[2];
}
private HashMap getModel() throws IOException {
HashMap map = new HashMap();
map.put("projectName", this.projectName);
map.put("pageName", this.pageName);
map.put("actionName", this.actionName);
return map;
}
public void newPage() throws IOException, TemplateException {
logger.info("Generating a new Facelet Page");
String pageTemplate = getFaceletPath( this.projectProps.getWorkspaceHome(),
this.projectName, "template", this.projectProps.getWtp());
String page = getFaceletPath( this.projectProps.getWorkspaceHome(),
this.projectName, this.pageName, this.projectProps.getWtp());
generateFile("template.ftl", pageTemplate, getModel());
generateFile("page.ftl", page, getModel());
}
public void newActionPage() throws IOException, TemplateException {
logger.info("Generating a new action Facelet Page");
String pageTemplate = getFaceletPath( this.projectProps.getWorkspaceHome(),
this.projectName, "template", this.projectProps.getWtp());
String page = getFaceletPath( this.projectProps.getWorkspaceHome(),
this.projectName, this.pageName, this.projectProps.getWtp());
generateFile("template.ftl", pageTemplate, getModel());
generateFile("action-page.ftl", page, getModel());
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getPageName() {
return pageName;
}
public void setPageName(String pageName) {
this.pageName = pageName;
}
public String getActionName() {
return actionName;
}
public void setActionName(String actionName) {
this.actionName = actionName;
}
}
1.1 date: 2006/10/28 17:56:04; author: gavin; state: Exp;jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool/AbstractSeamGen.java
Index: AbstractSeamGen.java
===================================================================
package org.jboss.seam.tool;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public abstract class AbstractSeamGen {
protected static Logger logger = Logger.getLogger("SeamGen");
protected BuildPropertiesBean projectProps = new BuildPropertiesBean();
private static Level logLevel = Level.INFO;
private static Configuration cfg = new Configuration();
public AbstractSeamGen() {
logger.setLevel(logLevel);
try {
init();
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage());
}
}
public void init() throws IOException {
cfg.setDirectoryForTemplateLoading(new File("freemarker-templates"));
cfg.setObjectWrapper(new DefaultObjectWrapper());
setBuildPropertiesBean();
}
public void setBuildPropertiesBean() throws IOException {
Properties buildProps = new Properties();
buildProps.load(new FileInputStream("build.properties"));
this.projectProps.setActionDir(buildProps.getProperty("action.dir"));
this.projectProps.setActionPackage(buildProps
.getProperty("action.package"));
this.projectProps.setBpmDir(buildProps.getProperty("bpm.dir"));
this.projectProps.setBpmPackage(buildProps.getProperty("bpm.package"));
this.projectProps.setJbossHome(buildProps.getProperty("jboss.home"));
this.projectProps.setMdbDir(buildProps.getProperty("mdb.dir"));
this.projectProps.setMdbPackage(buildProps.getProperty("mdb.package"));
this.projectProps.setModelDir(buildProps.getProperty("model.dir"));
this.projectProps.setModelPackage(buildProps
.getProperty("model.package"));
this.projectProps.setTestDir(buildProps.getProperty("test.dir"));
this.projectProps
.setTestPackage(buildProps.getProperty("test.package"));
this.projectProps.setWorkspaceHome(buildProps
.getProperty("workspace.home"));
this.projectProps.setWtp(buildProps.getProperty("eclipse.wtp"));
}
protected String getJavaFilePath(String workspaceHome, String projectName,
String packageDir, String fileName, String wtp) {
// This isn't a testng.xml file
return getJavaFilePath(workspaceHome, projectName, packageDir,
fileName, wtp, false);
}
protected String getJavaFilePath(String workspaceHome, String projectName,
String packageDir, String fileName, String wtp, boolean isTestNgXml) {
StringBuffer buff = new StringBuffer(workspaceHome);
buff.append("/");
buff.append(projectName);
if (wtp.equalsIgnoreCase("Y")) {
buff.append("EJB/ejbModule");
}
else {
buff.append("/src");
}
buff.append("/");
buff.append(packageDir);
buff.append("/");
buff.append(fileName);
if (isTestNgXml)
buff.append(".xml");
else
buff.append(".java");
return buff.toString();
}
protected String getFaceletPath(String workspaceHome, String projectName,
String fileName, String wtp) {
StringBuffer buff = new StringBuffer(workspaceHome);
buff.append("/");
buff.append(projectName);
if (wtp.equalsIgnoreCase("Y")) {
buff.append("Web/WebContent/");
} else {
buff.append("/view/");
}
buff.append(fileName);
buff.append(".xhtml");
return buff.toString();
}
protected static void generateFile(String templateName, String outputFile,
HashMap templateVariables) throws IOException, TemplateException {
Template template;
// Get or create a template
template = cfg.getTemplate(templateName);
// create output file path
File outFile = new File(outputFile);
File basePath = outFile.getParentFile();
//we do want to overwrite build.properties file only in
//all cases for "set-properties" seamgen task
if (!outFile.exists() || outFile.getName() == "build.properties") {
if (basePath != null) {
basePath.mkdirs();
}
// Merge data model with template
Writer out = new FileWriter(outputFile);
template.process(templateVariables, out);
out.flush();
logger
.info("New File Generated by Seam Gen using: "
+ templateName);
logger.info("File path is: " + outFile.getPath());
} else {
logger.info("No file generated because it already exists");
}
}
}
1.1 date: 2006/10/28 17:56:04; author: gavin; state: Exp;jboss-seam/seam-gen/seam-gen-sourcefiles/src/org/jboss/seam/tool/JavaClassGenerator.java
Index: JavaClassGenerator.java
===================================================================
package org.jboss.seam.tool;
import java.io.IOException;
import java.util.HashMap;
import freemarker.template.TemplateException;
public class JavaClassGenerator extends AbstractSeamGen {
private String interfaceName;
private String actionName;
private String projectName;
//for mdb
private String mdbDestination;
private String mdbDestinationType;
public JavaClassGenerator() {};
public JavaClassGenerator(String[] args) throws IOException {
this.projectName = args[1];
this.actionName = args[2];
this.interfaceName = args[2];
}
private HashMap getModel() throws IOException {
HashMap map = new HashMap();
map.put("projectName", this.projectName);
map.put("actionName", this.actionName);
map.put("interfaceName", this.interfaceName);
map.put("packageName", this.projectProps.getActionPackage());
map.put("testPackageName", this.projectProps.getTestPackage());
map.put("bpmPackage", this.projectProps.getBpmPackage());
map.put("mdbPackage", this.projectProps.getMdbPackage());
map.put("entityPackage", this.projectProps.getModelPackage());
return map;
}
public void newAction() throws IOException, TemplateException {
logger.info("Generating a new SFSB and interface");
String sfsbAction = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getActionDir(),
this.actionName+"Action", this.projectProps.getWtp());
String sfsbInterface = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getActionDir(),
this.interfaceName, this.projectProps.getWtp());
generateFile("CreateSFSBAction.ftl", sfsbAction, getModel());
generateFile("CreateSFSBInterface.ftl", sfsbInterface, getModel());
}
public void newStatelessAction() throws IOException, TemplateException {
logger.info("Generating a new SLSB and interface");
String slsbAction = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getActionDir(),
this.actionName+"Action", this.projectProps.getWtp());
String slsbInterface = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getActionDir(),
this.interfaceName, this.projectProps.getWtp());
generateFile("CreateSLSBAction.ftl", slsbAction, getModel());
generateFile("CreateInterface.ftl", slsbInterface, getModel());
}
public void newConversation() throws IOException, TemplateException {
logger.info("Generating a new SFSB Conversation and interface");
String sfsbAction = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getActionDir(),
this.actionName+"Action", this.projectProps.getWtp());
String sfsbInterface = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getActionDir(),
this.interfaceName, this.projectProps.getWtp());
generateFile("CreateSFSBConversation.ftl", sfsbAction, getModel());
generateFile("CreateInterfaceConversation.ftl", sfsbInterface, getModel());
}
public void newTestcase() throws IOException, TemplateException {
logger.info("Generating a new TestNG test case");
String testAction = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getTestDir(),
this.actionName+"Test", this.projectProps.getWtp());
String testNgXml = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getTestDir(),
this.actionName+"Test", this.projectProps.getWtp(), true);
String baseTest = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getTestDir(),
"BaseTest", this.projectProps.getWtp());
generateFile("TestCase.ftl", testAction, getModel());
generateFile("BaseTest.ftl", baseTest, getModel());
generateFile("testng.ftl", testNgXml, getModel());
}
public void newBpmAction() throws IOException, TemplateException {
logger.info("Generating a new jBPM Action Class");
String bpmAction = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getBpmDir(),
this.actionName, this.projectProps.getWtp());
generateFile("BpmAction.ftl", bpmAction, getModel());
}
public void newEntity() throws IOException, TemplateException {
logger.info("Generating a new Entity EJB");
String entity = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getModelDir(),
this.actionName, this.projectProps.getWtp());
generateFile("Entity.ftl", entity, getModel());
}
public void newMdb() throws IOException, TemplateException {
logger.info("Generating a new MDB");
HashMap model = getModel();
String mdb = getJavaFilePath(this.projectProps.getWorkspaceHome(),
this.projectName, this.projectProps.getMdbDir(),
this.actionName, this.projectProps.getWtp());
model.put("destination", this.mdbDestination);
model.put("destinationType", this.mdbDestinationType);
generateFile("Mdb.ftl", mdb, model);
}
public String getActionName() {
return actionName;
}
public void setActionName(String actionName) {
this.actionName = actionName;
}
public String getInterfaceName() {
return interfaceName;
}
public void setInterfaceName(String interfaceName) {
this.interfaceName = interfaceName;
}
public String getMdbDestination() {
return mdbDestination;
}
public void setMdbDestination(String mdbDestination) {
this.mdbDestination = mdbDestination;
}
public String getMdbDestinationType() {
return mdbDestinationType;
}
public void setMdbDestinationType(String mdbDestinationType) {
this.mdbDestinationType = mdbDestinationType;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
}
More information about the jboss-cvs-commits
mailing list