epugh 2004/07/02 00:32:53
Modified: hibernate/xdocs changes.xml properties.xml goals.xml
hibernate/src/main/org/apache/maven/hibernate/jelly
HibernateTagLibrary.java SchemaExportTag.java
hibernate plugin.jelly plugin.properties
hibernate/src/plugin-test project.xml project.properties
maven.xml
hibernate/src/main/org/apache/maven/hibernate/beans
SchemaExportBean.java
Added: hibernate/src/main/org/apache/maven/hibernate/jelly
AggregateMappingsTag.java
hibernate/src/plugin-test/src/main/org/apache/maven/hibernate
Component.java
hibernate/src/main/org/apache/maven/hibernate/beans
CommonOperationsBean.java
MappingsAggregatorBean.java
hibernate/src/plugin-test/src/etc Component.hbm.xml
Log:
MPHIBERNATE-6, allow multiple base dirs and new aggregate-mappings goal.
Revision Changes Path
1.16 +3 -1 maven-plugins/hibernate/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/xdocs/changes.xml,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- changes.xml 27 Jun 2004 08:05:07 -0000 1.15
+++ changes.xml 2 Jul 2004 07:32:52 -0000 1.16
@@ -24,7 +24,9 @@
<author email="[EMAIL PROTECTED]">Michal Maczka</author>
</properties>
<body>
- <release version="1.2" date="in CVS">
+ <release version="1.2-SNAPSHOT" date="in CVS">
+ <action dev="epugh" type="add" issue="MPHIBERNATE-6" due-to="Alex
Shnyderman">New aggregate-mappings goal to aggregate multiple .hbm files into one
file.</action>
+ <action dev="epugh" type="add" issue="MPHIBERNATE-6" due-to="Alex
Shnyderman">Added multiple base directories for mapping files</action>
<action dev="epugh" type="update">Update to hibernate-2.1.3.</action>
</release>
<release version="1.1" date="2004-05-15">
1.6 +10 -4 maven-plugins/hibernate/xdocs/properties.xml
Index: properties.xml
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/xdocs/properties.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- properties.xml 21 Jun 2004 10:36:36 -0000 1.5
+++ properties.xml 2 Jul 2004 07:32:52 -0000 1.6
@@ -96,8 +96,8 @@
<td>maven.hibernate.input.dir</td>
<td>Yes</td>
<td>
- Used to generate the <code>url</code> value for Gump
- Indicates base directory where mapping files. It defaults
+ Comma-seperated list of base directories indicating where
+ mapping files are located. It defaults
to <code>${maven.build.dest}</code>.
</td>
</tr>
@@ -105,7 +105,7 @@
<td>maven.hibernate.input.includes</td>
<td>Yes</td>
<td>
- Comma-separated list of patterns of Hiberante mapping files,
+ Comma-separated list of patterns of Hibernate mapping files,
which will be included during generation process.
<br/>
<b>Note</b>: Files are relative to
@@ -119,7 +119,7 @@
<td>maven.hibernate.input.excludes</td>
<td>Yes</td>
<td>
- Comma-separated list of patterns of Hiberante mapping files,
+ Comma-separated list of patterns of Hibernate mapping files,
which will be excluded during generation process.
<br/>
<b>Note</b>: Files are relative to
@@ -133,6 +133,12 @@
<td>Yes</td>
<td>String used to separate commands in SQL output.</td>
</tr>
+ <tr>
+ <td>maven.hibernate.aggregate.output.file</td>
+ <td>Yes</td>
+ <td>When <code>aggregate-mappings</code> is run, this file will contain
the aggregated mappings</td>
+ </tr>
+
</table>
</section>
</body>
1.4 +7 -0 maven-plugins/hibernate/xdocs/goals.xml
Index: goals.xml
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/xdocs/goals.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- goals.xml 1 Jun 2004 15:31:04 -0000 1.3
+++ goals.xml 2 Jul 2004 07:32:52 -0000 1.4
@@ -35,6 +35,13 @@
<td>
Creates SQL DDL file from set of *.hbm.xml files
</td>
+ </tr>
+ <a name="hibernate:aggregate-mappings" />
+ <tr>
+ <td>hibernate:aggregate-mappings</td>
+ <td>
+ Aggregates multiple hibernate mappings into one
+ </td>
</tr>
</table>
</section>
1.3 +3 -2
maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java
Index: HibernateTagLibrary.java
===================================================================
RCS file:
/home/cvs/maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/HibernateTagLibrary.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HibernateTagLibrary.java 2 Mar 2004 15:04:01 -0000 1.2
+++ HibernateTagLibrary.java 2 Jul 2004 07:32:52 -0000 1.3
@@ -34,6 +34,7 @@
*/
public HibernateTagLibrary()
{
- registerTag( "schema-export", SchemaExportTag.class );
+ registerTag( "schema-export", SchemaExportTag.class );
+ registerTag( "aggregate-mappings", AggregateMappingsTag.class );
}
}
1.4 +12 -1
maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java
Index: SchemaExportTag.java
===================================================================
RCS file:
/home/cvs/maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SchemaExportTag.java 2 Mar 2004 15:04:01 -0000 1.3
+++ SchemaExportTag.java 2 Jul 2004 07:32:52 -0000 1.4
@@ -221,4 +221,15 @@
{
bean.setDelimiter(delimiter);
}
+
+ /**
+ */
+ public String getSchemaOutputFile() {
+ return bean.getSchemaOutputFile();
+ }
+ /**
+ */
+ public void setSchemaOutputFile(String string) {
+ bean.setSchemaOutputFile(string);
+ }
}
1.1
maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/AggregateMappingsTag.java
Index: AggregateMappingsTag.java
===================================================================
// 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);
}
}
1.6 +10 -2 maven-plugins/hibernate/plugin.jelly
Index: plugin.jelly
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/plugin.jelly,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- plugin.jelly 2 Jul 2004 06:16:57 -0000 1.5
+++ plugin.jelly 2 Jul 2004 07:32:53 -0000 1.6
@@ -24,15 +24,23 @@
xmlns:h="jelly:org.apache.maven.hibernate.jelly.HibernateTagLibrary">
<goal name="hibernate:init">
-
+ <ant:mkdir dir="${maven.hibernate.output.dir}"/>
</goal>
+ <goal name="hibernate:aggregate-mappings" prereqs="hibernate:init"
description="Aggregate multiple .hbm.xml files into one file">
+
+ <ant:echo>Aggregating multiple hibernate mapping into one single
file</ant:echo>
+ <h:aggregate-mappings
+ aggregateOutputFile="${maven.hibernate.aggregate.output.file}"
+ basedir="${maven.hibernate.input.dir}"
+ includes="${maven.hibernate.input.includes}"
+ excludes="${maven.hibernate.input.excludes}"/>
+ </goal>
<goal name="hibernate:schema-export" prereqs="hibernate:init" description="Export
Hibernate schema">
<ant:echo>Exporting Hibernate Schema file</ant:echo>
- <ant:mkdir dir="${maven.hibernate.output.dir}"/>
<h:schema-export
properties="${maven.hibernate.properties}"
1.4 +2 -1 maven-plugins/hibernate/plugin.properties
Index: plugin.properties
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/plugin.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- plugin.properties 4 Mar 2004 18:13:45 -0000 1.3
+++ plugin.properties 2 Jul 2004 07:32:53 -0000 1.4
@@ -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
1.2 +9 -85 maven-plugins/hibernate/src/plugin-test/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/src/plugin-test/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 2 Jul 2004 06:16:56 -0000 1.1
+++ project.xml 2 Jul 2004 07:32:53 -0000 1.2
@@ -53,97 +53,21 @@
</developers>
<dependencies>
- <dependency>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <version>1.7.1</version>
- <type>jar</type>
- </dependency>
-
- <dependency>
- <groupId>hibernate</groupId>
- <artifactId>hibernate</artifactId>
- <version>2.1.3</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- <version>1.5.3-1</version>
- <type>jar</type>
- </dependency>
+
<dependency>
<groupId>commons-jelly</groupId>
- <artifactId>commons-jelly</artifactId>
- <version>20030902.160215</version>
- <url>http://jakarta.apache.org/commons/jelly/</url>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.0</version>
- <type>jar</type>
+ <artifactId>commons-jelly-tags-xml</artifactId>
+ <version>20030211.142705</version>
+ <url>http://jakarta.apache.org/commons/jelly/libs/xml/</url>
</dependency>
+
<dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.6.1</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
- <version>1.1</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>2.1</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.3</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <version>1.1</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.8</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- <version>1.0.b2</version>
- <url>http://xml.apache.org/xerces2-j/</url>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xerces</artifactId>
- <version>2.4.0</version>
- <url>http://xml.apache.org/xerces2-j/</url>
- </dependency>
- <dependency>
- <groupId>odmg</groupId>
- <artifactId>odmg</artifactId>
- <version>3.0</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>dom4j</groupId>
- <artifactId>dom4j</artifactId>
- <version>1.4</version>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.7.1</version>
<type>jar</type>
</dependency>
+
</dependencies>
<build>
1.2 +2 -1 maven-plugins/hibernate/src/plugin-test/project.properties
Index: project.properties
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/src/plugin-test/project.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.properties 2 Jul 2004 06:16:56 -0000 1.1
+++ project.properties 2 Jul 2004 07:32:53 -0000 1.2
@@ -1,2 +1,3 @@
maven.hibernate.properties=src/main/hibernate.properties
-maven.hibernate.quiet=false
\ No newline at end of file
+maven.hibernate.quiet=false
+maven.hibernate.input.dir=${maven.build.dest},src/etc
\ No newline at end of file
1.2 +20 -4 maven-plugins/hibernate/src/plugin-test/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/maven-plugins/hibernate/src/plugin-test/maven.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven.xml 2 Jul 2004 06:16:56 -0000 1.1
+++ maven.xml 2 Jul 2004 07:32:53 -0000 1.2
@@ -18,10 +18,11 @@
<project xmlns:util="jelly:util"
xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
- xmlns:assert="assert">
+ xmlns:assert="assert"
+ xmlns:x="jelly:xml">
- <goal name="testPlugin" prereqs="test-hibernate-schema-export">
- <attainGoal name="clean"/>
+ <goal name="testPlugin"
prereqs="test-hibernate-schema-export,test-hibernate-aggregate-mappings">
+ <!--attainGoal name="clean"/-->
</goal>
<goal name="test-hibernate-schema-export">
@@ -29,7 +30,22 @@
<attainGoal name="hibernate:schema-export"/>
<assert:assertFileExists file="${maven.hibernate.output.file}"/>
-
+
</goal>
+
+ <goal name="test-hibernate-aggregate-mappings">
+ <attainGoal name="jar"/>
+ <attainGoal name="hibernate:aggregate-mappings"/>
+
+ <assert:assertFileExists file="${maven.hibernate.aggregate.output.file}"/>
+
+ <!-- Verify that that files from both base directories are present -->
+ <util:file var="rawFile" name="${maven.hibernate.aggregate.output.file}"/>
+ <x:parse var="doc" xml="${rawFile}"/>
+
+ <x:set var="count" select="count($doc//hibernate-mapping//class)"/>
+ <assert:assertEquals expected="2" value="${count.intValue().toString()}"/>
+
+ </goal>
</project>
1.1
maven-plugins/hibernate/src/plugin-test/src/main/org/apache/maven/hibernate/Component.java
Index: Component.java
===================================================================
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 <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
*
* @version $Id: Component.java,v 1.1 2004/07/02 07:32:53 epugh Exp $
*/
public class Component {
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;
}
}
1.5 +36 -99
maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java
Index: SchemaExportBean.java
===================================================================
RCS file:
/home/cvs/maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SchemaExportBean.java 25 Apr 2004 02:29:43 -0000 1.4
+++ SchemaExportBean.java 2 Jul 2004 07:32:53 -0000 1.5
@@ -22,17 +22,15 @@
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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
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,26 +41,25 @@
* @author <a href="[EMAIL PROTECTED]">Michal Maczka</a>
* @version $Id$
*/
-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;
private boolean drop = false;
+
+ private static final Log LOG = LogFactory.getLog(MappingsAggregatorBean.class);
/**
* @return
*/
- public String getIncludes()
+ public String getSchemaOutputFile()
{
- return includes;
+ return schemaOutputFile;
}
/**
@@ -70,9 +67,10 @@
*/
public String getOutputFile()
{
- return outputFile;
+ return schemaOutputFile;
}
+
/**
* @return
*/
@@ -92,17 +90,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 +154,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 +168,6 @@
}
/**
- * @param string
- */
- public void setExcludes(String string)
- {
- excludes = string;
- }
-
- /**
* @return
*/
public String getDelimiter()
@@ -237,23 +203,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 +232,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 +242,7 @@
cfg.configure(getConfig());
}
- String[] files = getFiles();
+ String[] files = getFileNames ();
for (int i = 0; i < files.length; i++)
{
String filename = files[i];
@@ -336,9 +272,10 @@
properties.load(new FileInputStream(getProperties()));
schemaExport = new SchemaExport(cfg, properties);
}
- System.out.println("Output file:" + getOutputFile());
+ LOG.debug("Output file:" + getOutputFile());
schemaExport.setOutputFile(getOutputFile());
schemaExport.setDelimiter(getDelimiter());
return schemaExport;
}
+
}
1.1
maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/CommonOperationsBean.java
Index: CommonOperationsBean.java
===================================================================
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.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tools.ant.DirectoryScanner;
/**
*
* @author <a href="[EMAIL PROTECTED]">Alex Shneyderman</a>
* @since $Id: CommonOperationsBean.java,v 1.1 2004/07/02 07:32:53 epugh Exp $
*/
public class CommonOperationsBean {
private String includes = null;
private String excludes = null;
private String basedir = null;
private static final Log LOG = LogFactory.getLog(CommonOperationsBean.class);
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()
{
LOG.debug("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);
LOG.info(" 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]);
LOG.debug("Base dir:" + dirs[i].getAbsolutePath());
LOG.debug("Excludes:" + getExcludes());
LOG.debug("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());
LOG.debug("work with file:" + 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]);
}
}
1.1
maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/MappingsAggregatorBean.java
Index: MappingsAggregatorBean.java
===================================================================
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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 <a href="[EMAIL PROTECTED]">Alex Shneyderman</a>
* @since $Id: MappingsAggregatorBean.java,v 1.1 2004/07/02 07:32:53 epugh Exp $
*/
public class MappingsAggregatorBean extends CommonOperationsBean
{
private String aggregateOutputFile = null;
private static final Log LOG = LogFactory.getLog(MappingsAggregatorBean.class);
public void execute()
throws Exception
{
String version = null;
File files[] = getFileDescriptors();
if(files == null || files.length <= 0)
{
LOG.info("nothing to process");
return;
}
LOG.info("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))
{
LOG.warn("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;
}
}
1.1
maven-plugins/hibernate/src/plugin-test/src/etc/Component.hbm.xml
Index: Component.hbm.xml
===================================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping auto-import="false">
<class name="org.apache.maven.hibernate.Component" table="Component" >
<id name="id" type="int" column="ID" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="NAME" type="string"/>
</class>
</hibernate-mapping>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]