diff -Naur ./hibernate/.cvsignore ../../maven-plugins/hibernate/.cvsignore
--- ./hibernate/.cvsignore 2004-06-01 11:31:21.000000000 -0400
+++ ../../maven-plugins/hibernate/.cvsignore 1969-12-31 19:00:00.000000000 -0500
@@ -1,5 +0,0 @@
-target
-velocity.log
-maven.log
-.classpath
-.project
diff -Naur ./hibernate/plugin.jelly ../../maven-plugins/hibernate/plugin.jelly
--- ./hibernate/plugin.jelly 2004-03-04 13:13:45.000000000 -0500
+++ ../../maven-plugins/hibernate/plugin.jelly 2004-07-01 14:34:51.000000000 -0400
@@ -24,7 +24,6 @@
xmlns:h="jelly:org.apache.maven.hibernate.jelly.HibernateTagLibrary">>
-
@@ -45,6 +44,18 @@
includes="${maven.hibernate.input.includes}"
excludes="${maven.hibernate.input.excludes}"/>
+
+
+
+ Aggregating multiple hibernate mapping into one single file
+
+
+
+
diff -Naur ./hibernate/plugin.properties ../../maven-plugins/hibernate/plugin.properties
--- ./hibernate/plugin.properties 2004-03-04 13:13:45.000000000 -0500
+++ ../../maven-plugins/hibernate/plugin.properties 2004-07-01 14:34:51.000000000 -0400
@@ -23,4 +23,5 @@
maven.hibernate.output.file=${maven.hibernate.output.dir}/${maven.final.name}-schema.sql
maven.hibernate.input.dir=${maven.build.dest}
maven.hibernate.input.includes=**/*.hbm.xml
-maven.hibernate.input.excludes=
\ No newline at end of file
+maven.hibernate.input.excludes=
+maven.hibernate.aggregate.output.file=${maven.hibernate.output.dir}/aggregated-mappings.hbm.xml
\ No newline at end of file
diff -Naur ./hibernate/src/main/org/apache/maven/hibernate/beans/CommonOperationsBean.java ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/CommonOperationsBean.java
--- ./hibernate/src/main/org/apache/maven/hibernate/beans/CommonOperationsBean.java 1969-12-31 19:00:00.000000000 -0500
+++ ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/CommonOperationsBean.java 2004-07-01 14:54:52.000000000 -0400
@@ -0,0 +1,144 @@
+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 java.io.File;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.tools.ant.DirectoryScanner;
+
+/**
+ *
+ * @author Alex Shneyderman
+ * @since $Id: $
+ */
+public class CommonOperationsBean {
+
+ private String includes = null;
+ private String excludes = null;
+ private String basedir = null;
+
+ public String getBasedir()
+ {
+ return basedir;
+ }
+
+ public void setBasedir(String basedir)
+ {
+ this.basedir = basedir;
+ }
+
+ public String getExcludes()
+ {
+ return excludes;
+ }
+
+ public void setExcludes(String excludes)
+ {
+ this.excludes = excludes;
+ }
+
+ public String getIncludes()
+ {
+ return includes;
+ }
+
+ public void setIncludes(String includes)
+ {
+ this.includes = includes;
+ }
+
+ protected String[] getBaseDirNames()
+ {
+ System.out.println("Bases string: " + getBasedir());
+ StringTokenizer st = new StringTokenizer(getBasedir(), ",");
+ String r[] = new String[st.countTokens()];
+ for(int i = 0; st.hasMoreTokens(); i++)
+ r[i] = st.nextToken();
+
+ return r;
+ }
+
+ protected File[] getBaseDirs()
+ {
+ String bases[] = getBaseDirNames();
+ List l = new ArrayList();
+ for(int i = 0; i < bases.length; i++)
+ {
+ File t = new File(bases[i]);
+ if(t.isDirectory())
+ {
+ l.add(t);
+ System.out.println(" Adding base dir: " + t.getAbsolutePath());
+ }
+ }
+
+ return (File[])l.toArray(new File[0]);
+ }
+
+ protected String[] getFileNames()
+ {
+ List files = new LinkedList();
+ File dirs[] = getBaseDirs();
+ for(int i = 0; i < dirs.length; i++)
+ {
+ DirectoryScanner directoryScanner = new DirectoryScanner();
+ directoryScanner.setBasedir(dirs[i]);
+ System.out.println("Base dir:" + dirs[i].getAbsolutePath());
+ System.out.println("Excludes:" + getExcludes());
+ System.out.println("Includes:" + getIncludes());
+ directoryScanner.setExcludes(StringUtils.split(getExcludes(), ","));
+ directoryScanner.setIncludes(StringUtils.split(getIncludes(), ","));
+ directoryScanner.scan();
+ String includesFiles[] = directoryScanner.getIncludedFiles();
+ for(int j = 0; j < includesFiles.length; j++)
+ {
+ File file = new File(includesFiles[j]);
+ if(!file.isFile())
+ file = new File(directoryScanner.getBasedir(), includesFiles[j]);
+ files.add(file.getAbsolutePath());
+ System.out.println(" will try to aggregate:" + file.getAbsolutePath());
+ }
+
+ }
+
+ return (String[])files.toArray(new String[0]);
+ }
+
+ protected File[] getFileDescriptors()
+ {
+ String names[] = getFileNames();
+ List files = new ArrayList();
+ for(int i = 0; i < names.length; i++)
+ {
+ File t = new File(names[i]);
+ if(t.isFile())
+ files.add(t);
+ }
+
+ return (File[])files.toArray(new File[0]);
+ }
+
+
+
+
+}
diff -Naur ./hibernate/src/main/org/apache/maven/hibernate/beans/MappingsAggregatorBean.java ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/MappingsAggregatorBean.java
--- ./hibernate/src/main/org/apache/maven/hibernate/beans/MappingsAggregatorBean.java 1969-12-31 19:00:00.000000000 -0500
+++ ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/MappingsAggregatorBean.java 2004-07-01 14:56:11.000000000 -0400
@@ -0,0 +1,104 @@
+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 java.io.File;
+import java.io.FileWriter;
+import java.util.Iterator;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+/**
+ *
+ * @author Alex Shneyderman
+ * @since $Id: $
+ */
+public class MappingsAggregatorBean extends CommonOperationsBean
+{
+
+ private String aggregateOutputFile = null;
+
+ public void execute()
+ throws Exception
+ {
+ String version = null;
+ File files[] = getFileDescriptors();
+ if(files == null || files.length <= 0)
+ {
+ System.out.println("nothing to process");
+ return;
+ }
+ System.out.println("Aggregating to " + getAggregateOutputFile());
+ File f = new File(getAggregateOutputFile());
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ XMLWriter writer = new XMLWriter(new FileWriter(f), format);
+ Document finalDoc = DocumentHelper.createDocument();
+ Element rootHM = null;
+ for(int i = 0; i < files.length; i++)
+ {
+ SAXReader reader = new SAXReader();
+ Document current = reader.read(files[i]);
+ String currentVersion = getVersion(current);
+ if(version == null)
+ {
+ version = currentVersion;
+ finalDoc.setProcessingInstructions(current.processingInstructions());
+ finalDoc.setDocType(current.getDocType());
+ rootHM = finalDoc.addElement("hibernate-mapping");
+ } else
+ if(!version.equals(currentVersion))
+ {
+ System.err.println("Mapping in " + files[i].getName() + " is not of the same mapping version as " + files[0].getName() + " mapping, so merge is impossible. Skipping");
+ continue;
+ }
+ for(Iterator iter = current.selectSingleNode("hibernate-mapping").selectNodes("class").iterator(); iter.hasNext(); rootHM.add((Element)((Element)iter.next()).clone()));
+ }
+
+ writer.write(finalDoc);
+ writer.close();
+ }
+
+ public String getAggregateOutputFile()
+ {
+ return aggregateOutputFile;
+ }
+
+ public void setAggregateOutputFile(String aggregateOutputFile)
+ {
+ this.aggregateOutputFile = aggregateOutputFile;
+ }
+
+ private String getVersion(Document current)
+ {
+ String docType = current.getDocType().getText();
+ if(docType == null || "".equals(docType.trim()))
+ return "";
+ if(docType.indexOf("hibernate-mapping-2.0.dtd") > 0)
+ return "2.0";
+ if(docType.indexOf("hibernate-mapping-1.1.dtd") > 0)
+ return "1.1";
+ else
+ return null;
+ }
+
+}
\ No newline at end of file
diff -Naur ./hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java
--- ./hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java 2004-04-24 22:29:43.000000000 -0400
+++ ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java 2004-07-01 14:52:36.000000000 -0400
@@ -22,17 +22,12 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Properties;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
-import org.apache.commons.lang.StringUtils;
-import org.apache.tools.ant.DirectoryScanner;
-
/**
*
* The Bean which serves as Proxy To Hibernate API
@@ -43,15 +38,12 @@
* @author Michal Maczka
* @version $Id: SchemaExportBean.java,v 1.4 2004/04/25 02:29:43 brett Exp $
*/
-public class SchemaExportBean
+public class SchemaExportBean extends CommonOperationsBean
{
- private String includes = null;
- private String excludes = null;
- private String basedir = null;
private String properties = null;
private String config = null;
- private String outputFile = null;
+ private String schemaOutputFile = null;
private String delimiter = null;
private boolean quiet = false;
private boolean text = false;
@@ -60,9 +52,9 @@
/**
* @return
*/
- public String getIncludes()
+ public String getSchemaOutputFile()
{
- return includes;
+ return schemaOutputFile;
}
/**
@@ -70,9 +62,10 @@
*/
public String getOutputFile()
{
- return outputFile;
+ return schemaOutputFile;
}
+
/**
* @return
*/
@@ -92,17 +85,17 @@
/**
* @param string
*/
- public void setIncludes(String string)
+ public void setSchemaOutputFile(String string)
{
- includes = string;
+ schemaOutputFile = string;
}
-
+
/**
* @param string
*/
public void setOutputFile(String string)
{
- outputFile = string;
+ schemaOutputFile = string;
}
/**
@@ -156,36 +149,12 @@
/**
* @return
*/
- public String getBasedir()
- {
- return basedir;
- }
-
- /**
- * @return
- */
public boolean isDrop()
{
return drop;
}
/**
- * @return
- */
- public String getExcludes()
- {
- return excludes;
- }
-
- /**
- * @param string
- */
- public void setBasedir(String string)
- {
- basedir = string;
- }
-
- /**
* @param b
*/
public void setDrop(boolean b)
@@ -194,14 +163,6 @@
}
/**
- * @param string
- */
- public void setExcludes(String string)
- {
- excludes = string;
- }
-
- /**
* @return
*/
public String getDelimiter()
@@ -237,23 +198,27 @@
try
{
- File baseDirFile = new File(getBasedir());
- URL[] urls = { baseDirFile.toURL()};
- System.out.println(urls[0]);
- URLClassLoader newClassLoader =
+ File [] baseDirs = getBaseDirs ();
+ URL [] urls = new URL [baseDirs.length];
+ for (int i = 0; i < urls.length; i++) {
+ urls [i] = baseDirs [i].toURL ();
+ System.out.println(urls [i]);
+ }
+
+ URLClassLoader newClassLoader =
new URLClassLoader(urls, getClass().getClassLoader());
- currentThread.setContextClassLoader(newClassLoader);
- Configuration cfg = getConfiguration();
- SchemaExport schemaExport = getSchemaExport(cfg);
+ currentThread.setContextClassLoader(newClassLoader);
+ Configuration cfg = getConfiguration();
+ SchemaExport schemaExport = getSchemaExport(cfg);
- if (isDrop())
- {
+ if (isDrop())
+ {
schemaExport.drop(!getQuiet(), !getText());
- }
- else
- {
+ }
+ else
+ {
schemaExport.create(!getQuiet(), !getText());
- }
+ }
}
finally
{
@@ -262,40 +227,6 @@
}
/**
- * Builds list of files for which will be included
- * in the schema. Uses ANT file scanner.
- */
- private String[] getFiles()
- {
-
- List files = new LinkedList();
-
- DirectoryScanner directoryScanner = new DirectoryScanner();
- directoryScanner.setBasedir(getBasedir());
-
- System.out.println("Excludes:" + getExcludes());
- System.out.println("Includes:" + getIncludes());
- System.out.println("Base dir:" + getBasedir());
-
- directoryScanner.setExcludes(StringUtils.split(getExcludes(), ","));
- directoryScanner.setIncludes(StringUtils.split(getIncludes(), ","));
-
- directoryScanner.scan();
- String[] includesFiles = directoryScanner.getIncludedFiles();
- for (int i = 0; i < includesFiles.length; i++)
- {
- File file = new File(includesFiles[i]);
- if (!file.isFile())
- {
- file = new File(directoryScanner.getBasedir(), includesFiles[i]);
- }
- files.add(file.getAbsolutePath());
- }
- String[] retValue = (String[]) files.toArray(new String[0]);
- return retValue;
- }
-
- /**
*
*/
private Configuration getConfiguration() throws HibernateException
@@ -306,7 +237,7 @@
cfg.configure(getConfig());
}
- String[] files = getFiles();
+ String[] files = getFileNames ();
for (int i = 0; i < files.length; i++)
{
String filename = files[i];
@@ -341,4 +272,5 @@
schemaExport.setDelimiter(getDelimiter());
return schemaExport;
}
+
}
diff -Naur ./hibernate/src/main/org/apache/maven/hibernate/jelly/AggregateMappingsTag.java ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/AggregateMappingsTag.java
--- ./hibernate/src/main/org/apache/maven/hibernate/jelly/AggregateMappingsTag.java 1969-12-31 19:00:00.000000000 -0500
+++ ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/AggregateMappingsTag.java 2004-07-01 14:57:46.000000000 -0400
@@ -0,0 +1,81 @@
+// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 7/1/2004 2:49:47 PM
+// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
+// Decompiler options: packimports(3)
+// Source File Name: AggregateMappingsTag.java
+
+package org.apache.maven.hibernate.jelly;
+
+import org.apache.commons.jelly.*;
+import org.apache.maven.hibernate.beans.MappingsAggregatorBean;
+
+public class AggregateMappingsTag extends TagSupport
+{
+
+ private MappingsAggregatorBean bean = new MappingsAggregatorBean();
+
+ protected void execute()
+ throws JellyTagException
+ {
+ try
+ {
+ bean.execute();
+ }
+ catch(Exception e)
+ {
+ String msg = " Mapping aggreagtion failed: " + e.getMessage();
+ throw new JellyTagException(msg, e);
+ }
+ }
+
+ public void doTag(XMLOutput arg0)
+ throws JellyTagException
+ {
+ execute();
+ }
+
+ public String toString()
+ {
+ return bean.toString();
+ }
+
+ public void setExcludes(String string)
+ {
+ bean.setExcludes(string);
+ }
+
+ public void setIncludes(String string)
+ {
+ bean.setIncludes(string);
+ }
+
+ public String getExcludes()
+ {
+ return bean.getExcludes();
+ }
+
+ public String getIncludes()
+ {
+ return bean.getIncludes();
+ }
+
+ public String getBasedir()
+ {
+ return bean.getBasedir();
+ }
+
+ public void setBasedir(String string)
+ {
+ bean.setBasedir(string);
+ }
+
+ public String getAggregateOutputFile()
+ {
+ return bean.getAggregateOutputFile();
+ }
+
+ public void setAggregateOutputFile(String aggregateOutputFile)
+ {
+ bean.setAggregateOutputFile(aggregateOutputFile);
+ }
+
+}
\ No newline at end of file
diff -Naur ./hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java
--- ./hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java 2004-03-02 10:04:01.000000000 -0500
+++ ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java 2004-07-01 14:34:51.000000000 -0400
@@ -34,6 +34,7 @@
*/
public HibernateTagLibrary()
{
- registerTag( "schema-export", SchemaExportTag.class );
+ registerTag( "schema-export", SchemaExportTag.class );
+ registerTag( "aggregate-mappings", AggregateMappingsTag.class );
}
}
diff -Naur ./hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java
--- ./hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java 2004-03-02 10:04:01.000000000 -0500
+++ ../../maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java 2004-07-01 14:34:51.000000000 -0400
@@ -221,4 +221,15 @@
{
bean.setDelimiter(delimiter);
}
+
+ /**
+ */
+ public String getSchemaOutputFile() {
+ return bean.getSchemaOutputFile();
+ }
+ /**
+ */
+ public void setSchemaOutputFile(String string) {
+ bean.setSchemaOutputFile(string);
+ }
}
diff -Naur ./hibernate/xdocs/goals.xml ../../maven-plugins/hibernate/xdocs/goals.xml
--- ./hibernate/xdocs/goals.xml 2004-06-01 11:31:04.000000000 -0400
+++ ../../maven-plugins/hibernate/xdocs/goals.xml 2004-07-01 14:34:51.000000000 -0400
@@ -35,6 +35,13 @@
Creates SQL DDL file from set of *.hbm.xml files
|
+
+
+
+ | hibernate:aggregate-mappings |
+
+ Aggregates multiple hibernate mappings into one
+ |
diff -Naur ./hibernate/xdocs/properties.xml ../../maven-plugins/hibernate/xdocs/properties.xml
--- ./hibernate/xdocs/properties.xml 2004-06-21 06:36:36.000000000 -0400
+++ ../../maven-plugins/hibernate/xdocs/properties.xml 2004-07-01 14:34:51.000000000 -0400
@@ -133,6 +133,12 @@
Yes |
String used to separate commands in SQL output. |
+
+ | maven.hibernate.aggregate.output.file |
+ Yes |
+ When aggreagate-mappings is run, this file will contain the aggreagated mappings |
+
+