db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r491475 - in /db/ddlutils/trunk: ./ lib/ src/java/org/apache/ddlutils/task/
Date Sun, 31 Dec 2006 20:24:09 GMT
Author: tomdz
Date: Sun Dec 31 12:24:08 2006
New Revision: 491475

URL: http://svn.apache.org/viewvc?view=rev&rev=491475
Log:
Changed logging in the Ant tasks so that everything now logs to commons-logging/log4j which
in turn logs to the console
Added verbosity attribute to the two main tasks that control the output verbosity

Added:
    db/ddlutils/trunk/lib/log4j-1.2.8.jar   (with props)
Modified:
    db/ddlutils/trunk/.classpath
    db/ddlutils/trunk/build-sample.xml
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDtdToFileCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java

Modified: db/ddlutils/trunk/.classpath
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/.classpath?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/.classpath (original)
+++ db/ddlutils/trunk/.classpath Sun Dec 31 12:24:08 2006
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src/java"/>
-	<classpathentry output="target/test" kind="src" path="src/test"/>
-	<classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>
+	<classpathentry kind="src" output="target/test" path="src/test"/>
+	<classpathentry kind="var" path="JRE_LIB" sourcepath="JRE_SRC"/>
 	<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.0.4.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/dom4j-1.4.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/commons-collections-3.1.jar"/>
@@ -16,5 +16,6 @@
 	<classpathentry kind="lib" path="lib/build-only/junit-3.8.2.jar"/>
 	<classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/>
 	<classpathentry kind="lib" path="lib/commons-betwixt-0.8-RC1.jar"/>
+	<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: db/ddlutils/trunk/build-sample.xml
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/build-sample.xml?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/build-sample.xml (original)
+++ db/ddlutils/trunk/build-sample.xml Sun Dec 31 12:24:08 2006
@@ -35,6 +35,7 @@
   <property name="platform" value=""/>
   <property name="alterdatabase" value="true"/>
   <property name="delimitedsqlidentifiers" value="false"/>
+  <property name="verbosity" value="debug"/>
   
   <!-- The classpath used for running the tasks -->
   <path id="project-classpath">
@@ -56,7 +57,8 @@
     <ddlToDatabase usedelimitedsqlidentifiers="${delimitedsqlidentifiers}"
                    catalogpattern="${catalogpattern}"
                    schemapattern="${schemapattern}"
-                   databasetype="${platform}" >
+                   databasetype="${platform}"
+                   verbosity="${verbosity}">
       <database driverclassname="${datasource.driverClassName}"
                 url="${datasource.url}"
                 username="${datasource.username}"
@@ -70,7 +72,8 @@
                    usedelimitedsqlidentifiers="${delimitedsqlidentifiers}"
                    catalogpattern="${catalogpattern}"
                    schemapattern="${schemapattern}"
-                   databasetype="${platform}" >
+                   databasetype="${platform}"
+                   verbosity="${verbosity}">
       <database driverclassname="${datasource.driverClassName}"
                 url="${datasource.url}"
                 username="${datasource.username}"
@@ -90,7 +93,8 @@
                    usedelimitedsqlidentifiers="${delimitedsqlidentifiers}"
                    catalogpattern="${catalogpattern}"
                    schemapattern="${schemapattern}"
-                   databasetype="${platform}" >
+                   databasetype="${platform}"
+                   verbosity="${verbosity}">
       <database driverclassname="${datasource.driverClassName}"
                 url="${datasource.url}"
                 username="${datasource.username}"
@@ -111,7 +115,8 @@
                    usedelimitedsqlidentifiers="${delimitedsqlidentifiers}"
                    catalogpattern="${catalogpattern}"
                    schemapattern="${schemapattern}"
-                   databasetype="${platform}" >
+                   databasetype="${platform}"
+                   verbosity="${verbosity}">
       <database driverclassname="${datasource.driverClassName}"
                 url="${datasource.url}"
                 username="${datasource.username}"

Added: db/ddlutils/trunk/lib/log4j-1.2.8.jar
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/lib/log4j-1.2.8.jar?view=auto&rev=491475
==============================================================================
Binary file - no diff available.

Propchange: db/ddlutils/trunk/lib/log4j-1.2.8.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java Sun Dec
31 12:24:08 2006
@@ -23,11 +23,11 @@
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
 import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
 /**
@@ -84,11 +84,13 @@
                                     dataSource.getPassword(),
                                     getFilteredParameters(platform.getName()));
 
-            task.log("Created database", Project.MSG_INFO);
+            _log.info("Created database");
         }
         catch (UnsupportedOperationException ex)
         {
-            task.log("Database platform "+getPlatform().getName()+" does not support database
creation via JDBC or there was an error while creating it: "+ex.getMessage(), Project.MSG_ERR);
+            _log.error("Database platform " + getPlatform().getName() + " does not support
database creation " +
+                       "via JDBC or there was an error while creating it.",
+                       ex);
         }
         catch (Exception ex)
         {
@@ -98,7 +100,7 @@
             }
             else
             {
-                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+                _log.error(ex);
             }
         }
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java Sun Dec 31 12:24:08
2006
@@ -20,6 +20,8 @@
  */
 
 import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ddlutils.Platform;
 import org.apache.tools.ant.BuildException;
 
@@ -31,6 +33,9 @@
  */
 public abstract class DatabaseCommand implements Command
 {
+    /** The log. */
+    protected final Log _log = LogFactory.getLog(getClass());
+
     /** The platform configuration. */
     private PlatformConfiguration _platformConf = new PlatformConfiguration();
     /** Whether to stop execution upon an error. */

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java Sun Dec 31 12:24:08
2006
@@ -21,14 +21,20 @@
 
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.Properties;
 
 import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Database;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.PropertyConfigurator;
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.EnumeratedAttribute;
 
 /**
  * Base class for DdlUtils Ant tasks that operate on a database.
@@ -38,10 +44,78 @@
  */
 public abstract class DatabaseTaskBase extends Task
 {
+    /**
+     * Helper class that defines the possible values for the verbosity attribute.
+     */
+    public static class VerbosityLevel extends EnumeratedAttribute {
+        /** The possible levels. */
+        private static final String[] LEVELS = { Level.FATAL.toString().toUpperCase(),
+                                                 Level.ERROR.toString().toUpperCase(),
+                                                 Level.WARN.toString().toUpperCase(),
+                                                 Level.INFO.toString().toUpperCase(),
+                                                 Level.DEBUG.toString().toUpperCase(),
+                                                 Level.FATAL.toString().toLowerCase(),
+                                                 Level.ERROR.toString().toLowerCase(),
+                                                 Level.WARN.toString().toLowerCase(),
+                                                 Level.INFO.toString().toLowerCase(),
+                                                 Level.DEBUG.toString().toLowerCase() };
+
+        /**
+         * Creates an uninitialized verbosity level object.
+         */
+        public VerbosityLevel()
+        {
+            super();
+        }
+
+        /**
+         * Creates an initialized verbosity level object.
+         * 
+         * @param level The level
+         */
+        public VerbosityLevel(String level)
+        {
+            super();
+            setValue(level);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public String[] getValues() {
+            return LEVELS;
+        }
+
+        /**
+         * Determines whether this is DEBUG verbosity.
+         * 
+         * @return <code>true</code> if this is the DEBUG level
+         */
+        public boolean isDebug()
+        {
+            return Level.DEBUG.toString().equalsIgnoreCase(getValue());
+        }
+    }
+
+    /** The log. */
+    protected Log _log;
+
     /** The platform configuration. */
     private PlatformConfiguration _platformConf = new PlatformConfiguration();
     /** The sub tasks to execute. */
     private ArrayList _commands = new ArrayList();
+    /** The verbosity of the task's debug output. */
+    private VerbosityLevel _verbosity = new VerbosityLevel(Level.INFO.toString());
+
+    /**
+     * Specifies the verbosity of the task's debug output. Default is <code>WARN</code>.
+     * 
+     * @param verbosity The verbosity level
+     */
+    public void setVerbosity(VerbosityLevel level)
+    {
+        _verbosity = level;
+    }
 
     /**
      * Returns the database type.
@@ -258,6 +332,27 @@
     protected abstract Database readModel();
 
     /**
+     * Initializes the logging.
+     */
+    private void initLogging()
+    {
+        // For Ant, we're forcing DdlUtils to do logging via log4j to the console
+        Properties props = new Properties();
+
+        props.setProperty("log4j.rootCategory", _verbosity.getValue().toUpperCase() + ",A");
+        props.setProperty("log4j.appender.A", "org.apache.log4j.ConsoleAppender");
+        props.setProperty("log4j.appender.A.layout", "org.apache.log4j.PatternLayout");
+        props.setProperty("log4j.appender.A.layout.ConversionPattern", "%m%n");
+        // we don't want debug logging from Digester/Betwixt
+        props.setProperty("log4j.logger.org.apache.commons", (_verbosity.isDebug() ? "DEBUG"
: "WARN"));
+
+        LogManager.resetConfiguration();
+        PropertyConfigurator.configure(props);
+
+        _log = LogFactory.getLog(getClass());
+    }
+
+    /**
      * Executes the commands.
      * 
      * @param model The database model
@@ -285,9 +380,11 @@
      */
     public void execute() throws BuildException
     {
+        initLogging();
+
         if (!hasCommands())
         {
-            log("No sub tasks specified, so there is nothing to do.", Project.MSG_INFO);
+            _log.info("No sub tasks specified, so there is nothing to do.");
             return;
         }
 
@@ -297,7 +394,7 @@
         // we're changing the thread classloader so that we can access resources
         // from the classpath used to load this task's class
         Thread.currentThread().setContextClassLoader(newClassLoader);
-        
+
         try
         {
             executeCommands(readModel());

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java Sun Dec 31
12:24:08 2006
@@ -27,7 +27,6 @@
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.FileSet;
 
 /**
@@ -256,18 +255,18 @@
 
         if (!schemaFile.isFile())
         {
-            log("Path "+schemaFile.getAbsolutePath()+" does not denote a schema file", Project.MSG_ERR);
+            _log.error("Path " + schemaFile.getAbsolutePath() + " does not denote a file");
         }
         else if (!schemaFile.canRead())
         {
-            log("Could not read schema file "+schemaFile.getAbsolutePath(), Project.MSG_ERR);
+            _log.error("Could not read schema file " + schemaFile.getAbsolutePath());
         }
         else
         {
             try
             {
                 model = reader.read(schemaFile);
-                log("Read schema file "+schemaFile.getAbsolutePath(), Project.MSG_INFO);
+                _log.info("Read schema file " + schemaFile.getAbsolutePath());
             }
             catch (Exception ex)
             {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java Sun Dec 31
12:24:08 2006
@@ -23,7 +23,6 @@
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
 /**
@@ -66,11 +65,12 @@
                                   dataSource.getUsername(),
                                   dataSource.getPassword());
 
-            task.log("Dropped database", Project.MSG_INFO);
+            _log.info("Dropped database");
         }
         catch (UnsupportedOperationException ex)
         {
-            task.log("Database platform "+getPlatform().getName()+" does not support database
dropping via JDBC", Project.MSG_ERR);
+            _log.info("Database platform " + getPlatform().getName() + " does not support
database dropping via JDBC",
+                      ex);
         }
         catch (Exception ex)
         {
@@ -80,7 +80,7 @@
             }
             else
             {
-                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+                _log.error(ex);
             }
         }
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java Sun
Dec 31 12:24:08 2006
@@ -23,12 +23,10 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 
-import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.ddlutils.io.DataReader;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.FileSet;
 
@@ -51,7 +49,7 @@
 public class WriteDataToDatabaseCommand extends ConvertingDatabaseCommand
 {
     /** A single data file to insert. */
-    private File      _singleDataFile = null;
+    private File _singleDataFile = null;
     /** The input files. */
     private ArrayList _fileSets = new ArrayList();
     /** Whether explicit values for identity columns will be used. */
@@ -207,33 +205,33 @@
     {
         if (!dataFile.exists())
         {
-            task.log("Could not find data file "+dataFile.getAbsolutePath(), Project.MSG_ERR);
+            _log.error("Could not find data file " + dataFile.getAbsolutePath());
         }
         else if (!dataFile.isFile())
         {
-            task.log("Path "+dataFile.getAbsolutePath()+" does not denote a data file", Project.MSG_ERR);
+            _log.error("Path " + dataFile.getAbsolutePath() + " does not denote a data file");
         }
         else if (!dataFile.canRead())
         {
-            task.log("Could not read data file "+dataFile.getAbsolutePath(), Project.MSG_ERR);
+            _log.error("Could not read data file " + dataFile.getAbsolutePath());
         }
         else
         {
             try
             {
                 getDataIO().writeDataToDatabase(reader, dataFile.getAbsolutePath());
-                task.log("Written data file "+dataFile.getAbsolutePath() + " to database",
Project.MSG_INFO);
+                _log.info("Written data from file " + dataFile.getAbsolutePath() + " to database");
             }
             catch (Exception ex)
             {
                 if (isFailOnError())
                 {
-                    throw new BuildException("Could not parse or write data file "+dataFile.getAbsolutePath(),
ex);
+                    throw new BuildException("Could not parse or write data file " + dataFile.getAbsolutePath(),
ex);
                 }
                 else
                 {
-                    task.log("Could not parse or write data file "+dataFile.getAbsolutePath()
+ ":", Project.MSG_ERR);
-                    task.log(ExceptionUtils.getFullStackTrace(ex));
+                    _log.error("Could not parse or write data file " + dataFile.getAbsolutePath(),
+                               ex);
                 }
             }
         }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java Sun Dec
31 12:24:08 2006
@@ -36,7 +36,7 @@
 public class WriteDataToFileCommand extends ConvertingDatabaseCommand
 {
     /** The file to output the data to. */
-    private File   _outputFile;
+    private File _outputFile;
     /** The character encoding to use. */
     private String _encoding;
 
@@ -71,6 +71,7 @@
         {
             getDataIO().writeDataToXML(getPlatform(),
                                        new FileOutputStream(_outputFile), _encoding);
+            _log.info("Written data XML to file" + _outputFile.getAbsolutePath());
         }
         catch (Exception ex)
         {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDtdToFileCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDtdToFileCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDtdToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDtdToFileCommand.java Sun Dec
31 12:24:08 2006
@@ -22,10 +22,11 @@
 import java.io.File;
 import java.io.FileWriter;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ddlutils.io.DataDtdWriter;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
 /**
@@ -38,6 +39,9 @@
  */
 public class WriteDtdToFileCommand implements Command
 {
+    /** The log. */
+    private final Log _log = LogFactory.getLog(getClass());
+
     /** The file to output the DTD to. */
     private File _outputFile;
 
@@ -71,7 +75,7 @@
         }
         if (_outputFile.exists() && !_outputFile.canWrite())
         {
-            throw new BuildException("Cannot overwrite output file "+_outputFile.getAbsolutePath());
+            throw new BuildException("Cannot overwrite output file " + _outputFile.getAbsolutePath());
         }
 
         try
@@ -81,11 +85,11 @@
 
             dtdWriter.writeDtd(model, outputWriter);
             outputWriter.close();
-            task.log("Written DTD to "+_outputFile.getAbsolutePath(), Project.MSG_INFO);
+            _log.info("Written DTD to " + _outputFile.getAbsolutePath());
         }
         catch (Exception ex)
         {
-            throw new BuildException("Failed to write to output file "+_outputFile.getAbsolutePath(),
ex);
+            throw new BuildException("Failed to write to output file " + _outputFile.getAbsolutePath(),
ex);
         }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java Sun
Dec 31 12:24:08 2006
@@ -28,7 +28,6 @@
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.platform.CreationParameters;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
 /**
@@ -143,9 +142,8 @@
                 if (getDataSource() == null)
                 {
                     shouldAlter = false;
-                    task.log("Cannot alter the database because no database connection was
specified." +
-                             " SQL for database creation will be generated instead.",
-                             Project.MSG_WARN);
+                    _log.warn("Cannot alter the database because no database connection was
specified." +
+                              " SQL for database creation will be generated instead.");
                 }
                 else
                 {
@@ -158,10 +156,9 @@
                     catch (SQLException ex)
                     {
                         shouldAlter = false;
-                        task.log("Could not establish a connection to the specified database,
" +
-                                 "so SQL for database creation will be generated instead.
The error was: " +
-                                 ex.getMessage(),
-                                 Project.MSG_WARN);
+                        _log.warn("Could not establish a connection to the specified database,
" +
+                                  "so SQL for database creation will be generated instead.",
+                                  ex);
                     }
                 }
             }
@@ -178,7 +175,7 @@
                 platform.getSqlBuilder().createTables(model, params, _doDrops);
             }
             writer.close();
-            task.log("Written SQL to "+_outputFile.getAbsolutePath(), Project.MSG_INFO);
+            _log.info("Written schema SQL to " + _outputFile.getAbsolutePath());
         }
         catch (Exception ex)
         {
@@ -188,7 +185,7 @@
             }
             else
             {
-                task.log(ex.getMessage() == null ? ex.toString() : ex.getMessage(), Project.MSG_ERR);
+                _log.error(ex);
             }
         }
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
Sun Dec 31 12:24:08 2006
@@ -23,7 +23,6 @@
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.platform.CreationParameters;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
 /**
@@ -129,7 +128,7 @@
                                       true);
             }
 
-            task.log("Written schema to database", Project.MSG_INFO);
+            _log.info("Written schema to database");
         }
         catch (Exception ex)
         {
@@ -139,7 +138,7 @@
             }
             else
             {
-                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+                _log.error(ex);
             }
         }
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java?view=diff&rev=491475&r1=491474&r2=491475
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java Sun
Dec 31 12:24:08 2006
@@ -22,10 +22,11 @@
 import java.io.File;
 import java.io.FileWriter;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ddlutils.io.DatabaseIO;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
 /**
@@ -37,6 +38,9 @@
  */
 public class WriteSchemaToFileCommand implements Command
 {
+    /** The log. */
+    private final Log _log = LogFactory.getLog(getClass());
+
     /** The file to output the schema to. */
     private File _outputFile;
 
@@ -80,11 +84,11 @@
 
             dbIO.write(model, outputWriter);
             outputWriter.close();
-            task.log("Written schema to "+_outputFile.getAbsolutePath(), Project.MSG_INFO);
+            _log.info("Written schema to " + _outputFile.getAbsolutePath());
         }
         catch (Exception ex)
         {
-            throw new BuildException("Failed to write to output file "+_outputFile.getAbsolutePath(),
ex);
+            throw new BuildException("Failed to write to output file " + _outputFile.getAbsolutePath(),
ex);
         }
     }
 }



Mime
View raw message