diff --git a/hibernate/plugin.jelly b/hibernate/plugin.jelly index 761798c7..c203e9b7 100644 --- a/hibernate/plugin.jelly +++ b/hibernate/plugin.jelly @@ -68,6 +68,17 @@ includes="${maven.hibernate.input.includes}" excludes="${maven.hibernate.input.excludes}"/> + + + + Generating POJOs from hbm files + + + diff --git a/hibernate/plugin.properties b/hibernate/plugin.properties index 9443e866..d9931bf9 100644 --- a/hibernate/plugin.properties +++ b/hibernate/plugin.properties @@ -24,4 +24,8 @@ maven.hibernate.output.file=${maven.hibernate.output.dir}/${maven.final.name}-sc maven.hibernate.input.dir=${maven.build.dest} maven.hibernate.input.includes=**/*.hbm.xml maven.hibernate.input.excludes= -maven.hibernate.aggregate.output.file=${maven.hibernate.output.dir}/aggregated-mappings.hbm.xml \ No newline at end of file +maven.hibernate.aggregate.output.file=${maven.hibernate.output.dir}/aggregated-mappings.hbm.xml +maven.hibernate.codeGeneration.input.dir=${maven.src.dir}/hibernate +maven.hibernate.codeGeneration.output.dir=${maven.src.dir}/hibernate +maven.hibernate.codeGeneration.input.includes=${maven.hibernate.input.includes} +maven.hibernate.codeGeneration.input.excludes= diff --git a/hibernate/project.xml b/hibernate/project.xml index c4de38d6..533ebd16 100644 --- a/hibernate/project.xml +++ b/hibernate/project.xml @@ -95,6 +95,12 @@ 2.1.3 jar + + hibernate + hibernate-tools + 2.1.3 + jar + ant ant @@ -179,5 +185,12 @@ 1.4 jar + + jdom + jdom + 1.0 + jar + + diff --git a/hibernate/src/main/org/apache/maven/hibernate/beans/CodeGenerationBean.java b/hibernate/src/main/org/apache/maven/hibernate/beans/CodeGenerationBean.java new file mode 100644 index 00000000..f03699b6 --- /dev/null +++ b/hibernate/src/main/org/apache/maven/hibernate/beans/CodeGenerationBean.java @@ -0,0 +1,61 @@ +package org.apache.maven.hibernate.beans; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import net.sf.hibernate.tool.hbm2java.CodeGenerator; + +/** + * @author Paul Kearney + * @version $Id$ + */ +public class CodeGenerationBean extends CommonOperationsBean { + + private static final String OUTPUT_SWITCH = "--output="; + + private String outputdir = null; + + public void execute() { + + // Construct output directory argument + StringBuffer switchArg= new StringBuffer(); + switchArg.append(OUTPUT_SWITCH).append(getOutputdir()); + + // Get list of files that are to be used to generate POJOs + final String[] files = getFileNames(); + + // Require new array to combine command args with hbm files array + String[] args = new String[files.length + 1]; + // Add command arg to new array + args[0] = switchArg.toString(); + // Copy list of hbm files to new array + System.arraycopy(files, 0, args, 1, files.length); + + // Generate POJOs + CodeGenerator generator = new CodeGenerator(); + generator.main(args); + + } + + public String getOutputdir() { + return this.outputdir; + } + + public void setOutputdir(String outputdir) { + this.outputdir = outputdir; + } +} diff --git a/hibernate/src/main/org/apache/maven/hibernate/jelly/CodeGenerationTag.java b/hibernate/src/main/org/apache/maven/hibernate/jelly/CodeGenerationTag.java new file mode 100644 index 00000000..840eb3ce --- /dev/null +++ b/hibernate/src/main/org/apache/maven/hibernate/jelly/CodeGenerationTag.java @@ -0,0 +1,99 @@ +package org.apache.maven.hibernate.jelly; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.apache.commons.jelly.JellyTagException; +import org.apache.commons.jelly.MissingAttributeException; +import org.apache.commons.jelly.TagSupport; +import org.apache.commons.jelly.XMLOutput; +import org.apache.maven.hibernate.beans.CodeGenerationBean; + +/** + * @author Paul Kearney + * @version $Id$ + */ +public class CodeGenerationTag extends TagSupport { + + private CodeGenerationBean bean = new CodeGenerationBean(); + + /** + * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput) + */ + public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { + + execute(); + } + + /** + * + */ + protected void execute() throws JellyTagException + { + try { + bean.execute(); + } catch (Exception e) { + String msg = "Code generation operation failed"; + throw new JellyTagException(msg, e); + } + } + + public String getBasedir() + { + return bean.getBasedir(); + } + + public String getExcludes() + { + return bean.getExcludes(); + } + + public String getIncludes() + { + return bean.getIncludes(); + } + + public String getOutputdir() + { + return bean.getOutputdir(); + } + + public void setBasedir(String string) + { + bean.setBasedir(string); + } + + public void setExcludes(String string) + { + bean.setExcludes(string); + } + + public void setIncludes(String string) + { + bean.setIncludes(string); + } + + public void setOutputdir(String dir) + { + bean.setOutputdir(dir); + } + + public String toString() + { + return bean.toString(); + } +} diff --git a/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java b/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java index 6760eb8b..cca66117 100644 --- a/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java +++ b/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java @@ -24,7 +24,7 @@ import org.apache.commons.jelly.tags.core.CoreTagLibrary; * Hibernate tag library. * * @author Michal Maczka - * @version $Id: HibernateTagLibrary.java,v 1.4 2004/11/06 21:52:23 felipeal Exp $ + * @version $Id$ */ public class HibernateTagLibrary extends CoreTagLibrary { @@ -37,5 +37,6 @@ public class HibernateTagLibrary extends CoreTagLibrary registerTag( "schema-export", SchemaExportTag.class ); registerTag( "schema-update", SchemaUpdateTag.class ); registerTag( "aggregate-mappings", AggregateMappingsTag.class ); + registerTag( "code-generation", CodeGenerationTag.class ); } } diff --git a/hibernate/src/plugin-test/codeGenerationTest/maven.xml b/hibernate/src/plugin-test/codeGenerationTest/maven.xml new file mode 100644 index 00000000..9793e560 --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/maven.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate/src/plugin-test/codeGenerationTest/project.properties b/hibernate/src/plugin-test/codeGenerationTest/project.properties new file mode 100644 index 00000000..947eece0 --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/project.properties @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------- +# Copyright 2004 The Apache Software Foundation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ------------------------------------------------------------------- +maven.hibernate.quiet=false +maven.hibernate.codeGeneration.input.dir=${maven.src.dir}/main +maven.hibernate.codeGeneration.output.dir=${maven.hibernate.codeGeneration.input.dir} + + diff --git a/hibernate/src/plugin-test/codeGenerationTest/project.xml b/hibernate/src/plugin-test/codeGenerationTest/project.xml new file mode 100644 index 00000000..c00a061a --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/project.xml @@ -0,0 +1,110 @@ + + + + + + 3 + test-maven-hibernate-plugin-codeGenerationTest + Test Cases for Maven Hibernate Plugin's CodeGeneration Tag + maven + 1.0-SNAPSHOT + + Apache Software Foundation + http://www.apache.org/ + http://maven.apache.org/images/jakarta-logo-blue.gif + + 2005 + org.apache.maven + http://maven.apache.org/images/maven.jpg + Test for Maven Hibernate plugin + Test for Maven Hibernate plugin + http://maven.apache.org/reference/plugins/hibernate/ + /www/maven.apache.org/reference/plugins/hibernate/ + + scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/hibernate/src/plugin-test + http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/hibernate/src/plugin-test + + + + Felipe Leme + felipeal + maven@felipeal.net + Falcon Informatica + + Java Developer + + -3 + + + + + + + commons-jelly + commons-jelly-tags-xml + 20030211.142705 + http://jakarta.apache.org/commons/jelly/libs/xml/ + + + + + hsqldb + hsqldb + 1.7.1 + jar + + + + hibernate + hibernate + 2.1.3 + jar + + + cglib + cglib + 2.0.2 + jar + + + dom4j + dom4j + 1.4 + jar + + + commons-lang + commons-lang + 2.0 + jar + + + + + src/main + + + src/main + + **/*.xml + + + + + diff --git a/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/ExcludeItem.hbm.xml b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/ExcludeItem.hbm.xml new file mode 100644 index 00000000..9f502f7d --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/ExcludeItem.hbm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + diff --git a/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Item.hbm.xml b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Item.hbm.xml new file mode 100644 index 00000000..16054811 --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Item.hbm.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Item.java b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Item.java new file mode 100644 index 00000000..02ae97aa --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Item.java @@ -0,0 +1,56 @@ +package org.apache.maven.hibernate; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * Class to use with testing the plugin. + * + * @author Eric Pugh + * + * @version $Id: Item.java 125453 2005-01-18 01:03:25Z felipeal $ + */ + +public class Item { + private int id; + private String name; + + /** + * @return Returns the id. + */ + public int getId() { + return id; + } + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } +} diff --git a/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Message.hbm.xml b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Message.hbm.xml new file mode 100644 index 00000000..2a718467 --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/Message.hbm.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/UserType.java b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/UserType.java new file mode 100644 index 00000000..b5ee40f7 --- /dev/null +++ b/hibernate/src/plugin-test/codeGenerationTest/src/main/org/apache/maven/hibernate/UserType.java @@ -0,0 +1,41 @@ +package org.apache.maven.hibernate; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * Class to use with testing the plugin. + * + * @author Paul Kearney + * + * @version $Id$ + */ +public class UserType { + + private Long field; + + private Message message; + + + + public Long getField() { + return field; + } + public void setField(Long field) { + this.field = field; + } +} diff --git a/hibernate/xdocs/changes.xml b/hibernate/xdocs/changes.xml index 082926ab..0d2a69c6 100644 --- a/hibernate/xdocs/changes.xml +++ b/hibernate/xdocs/changes.xml @@ -25,8 +25,9 @@ - Added new goal hibernate:schema-update - plugin:test fails without a network connection + Added new goal hibernate:code-generation. + Added new goal hibernate:schema-update. + plugin:test fails without a network connection. maven-hibernate ignores the "config" attribute diff --git a/hibernate/xdocs/goals.xml b/hibernate/xdocs/goals.xml index 1a2196d6..4fd0a01e 100644 --- a/hibernate/xdocs/goals.xml +++ b/hibernate/xdocs/goals.xml @@ -49,7 +49,14 @@ Aggregates multiple hibernate mappings into one - + + + + hibernate:code-generation + + Generates Java classes from set of *.hbm.xml files + + diff --git a/hibernate/xdocs/properties.xml b/hibernate/xdocs/properties.xml index 6022b34a..098a2097 100644 --- a/hibernate/xdocs/properties.xml +++ b/hibernate/xdocs/properties.xml @@ -133,6 +133,45 @@ Yes When aggregate-mappings is run, this file will contain the aggregated mappings + + maven.hibernate.codeGeneration.input.dir + Yes + Comma-separated list of directories that contains Hibernate mapping files which will be used to generated Java classes when the goal code-generation is used. + + It defaults to ${maven.src.dir}/hibernate. + + + + maven.hibernate.codeGeneration.input.includes + Yes + + Comma-separated list of patterns of Hibernate mapping files, + which will be included during the code generation process (goal code-generation). +
+ Note: Files are relative to ${maven.hibernate.codeGeneration.input.dir}. +
+ Default value is ${maven.hibernate.input.includes}. + + + + maven.hibernate.codeGeneration.input.excludes + Yes + + Comma-separated list of patterns of Hibernate mapping files, + which will be excluded during the code generation process (goal code-generation). +
+ Note: Files are relative to + ${maven.hibernate.codeGeneration.input.dir}. +
+ By default no files are excluded. + + + + maven.hibernate.codeGeneration.output.dir + Yes + When code-generation is run, the generated Java files will be placed in + this directory. It defaults to ${maven.src.dir}/hibernate. +