Author: cbegin
Date: Sat May  1 20:42:04 2010
New Revision: 940104

URL: http://svn.apache.org/viewvc?rev=940104&view=rev
Log:
ibatis-783 added set/get PrintStream methods to BaseCommand and renamed related 
methods in CommandLine

Modified:
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/CommandLine.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/InitializeCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/NewCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/PendingCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/ScriptCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java
    
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/VersionCommand.java

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/CommandLine.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/CommandLine.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/CommandLine.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/CommandLine.java
 Sat May  1 20:42:04 2010
@@ -30,7 +30,7 @@ public class CommandLine {
   private static final Set<String> KNOWN_COMMANDS = 
Collections.unmodifiableSet(
       new HashSet<String>(Arrays.asList(INIT, NEW, UP, VERSION, DOWN, PENDING, 
STATUS, BOOTSTRAP, SCRIPT)));
 
-  private PrintStream out;
+  private PrintStream printStream;
 
   private File repository;
   private String environment;
@@ -44,17 +44,17 @@ public class CommandLine {
   private boolean help;
 
   public CommandLine(String[] args) {
-    this.out = System.out;
+    this.printStream = System.out;
     parse(args);
     validate();
   }
 
-  public void setOutputStream(PrintStream out) {
-    this.out = out;
+  public void setPrintStream(PrintStream out) {
+    this.printStream = out;
   }
 
-  public PrintStream getOutputStream() {
-    return this.out;
+  public PrintStream getPrintStream() {
+    return this.printStream;
   }
 
   public void execute() {
@@ -71,14 +71,14 @@ public class CommandLine {
           runCommand();
         } catch (Exception e) {
           error = true;
-          out.println("\nERROR: " + e.getMessage());
+          printStream.println("\nERROR: " + e.getMessage());
           if (trace) {
             e.printStackTrace();
           }
         }
       }
     } finally {
-      out.flush();
+      printStream.flush();
       if (error) {
         System.exit(1);
       }
@@ -164,34 +164,34 @@ public class CommandLine {
   }
 
   private void printError() {
-    out.println(parseError);
-    out.flush();
+    printStream.println(parseError);
+    printStream.flush();
   }
 
   private void printUsage() {
-    out.println();
-    out.println("Usage: migrate command [parameter] [--path=<directory>] 
[--env=<environment>]");
-    out.println();
-    out.println("--path=<directory>   Path to repository.  Default current 
working directory.");
-    out.println("--env=<environment>  Environment to configure. Default 
environment is 'development'.");
-    out.println("--force              Forces script to continue even if SQL 
errors are encountered.");
-    out.println("--help               Displays this usage message.");
-    out.println("--trace              Shows additional error details (if 
any).");
-    out.println();
-    out.println("Commands:");
-    out.println("  init               Creates (if necessary) and initializes a 
migration path.");
-    out.println("  bootstrap          Runs the bootstrap SQL script (see 
scripts/bootstrap.sql for more).");
-    out.println("  new <description>  Creates a new migration with the 
provided description.");
-    out.println("  up [n]             Run unapplied migrations, ALL by 
default, or 'n' specified.");
-    out.println("  down [n]           Undoes migrations applied to the 
database. ONE by default or 'n' specified.");
-    out.println("  version <version>  Migrates the database up or down to the 
specified version.");
-    out.println("  pending            Force executes pending migrations out of 
order (not recommended).");
-    out.println("  status             Prints the changelog from the database 
if the changelog table exists.");
-    out.println("  script <v1> <v2>   Generates a delta migration script from 
version v1 to v2 (undo if v1 > v2).");
-    out.println("");
-    out.println("  * Shortcuts are accepted by using the first few 
(unambiguous) letters of each command..");
-    out.println();
-    out.flush();
+    printStream.println();
+    printStream.println("Usage: migrate command [parameter] 
[--path=<directory>] [--env=<environment>]");
+    printStream.println();
+    printStream.println("--path=<directory>   Path to repository.  Default 
current working directory.");
+    printStream.println("--env=<environment>  Environment to configure. 
Default environment is 'development'.");
+    printStream.println("--force              Forces script to continue even 
if SQL errors are encountered.");
+    printStream.println("--help               Displays this usage message.");
+    printStream.println("--trace              Shows additional error details 
(if any).");
+    printStream.println();
+    printStream.println("Commands:");
+    printStream.println("  init               Creates (if necessary) and 
initializes a migration path.");
+    printStream.println("  bootstrap          Runs the bootstrap SQL script 
(see scripts/bootstrap.sql for more).");
+    printStream.println("  new <description>  Creates a new migration with the 
provided description.");
+    printStream.println("  up [n]             Run unapplied migrations, ALL by 
default, or 'n' specified.");
+    printStream.println("  down [n]           Undoes migrations applied to the 
database. ONE by default or 'n' specified.");
+    printStream.println("  version <version>  Migrates the database up or down 
to the specified version.");
+    printStream.println("  pending            Force executes pending 
migrations out of order (not recommended).");
+    printStream.println("  status             Prints the changelog from the 
database if the changelog table exists.");
+    printStream.println("  script <v1> <v2>   Generates a delta migration 
script from version v1 to v2 (undo if v1 > v2).");
+    printStream.println("");
+    printStream.println("  * Shortcuts are accepted by using the first few 
(unambiguous) letters of each command..");
+    printStream.println();
+    printStream.flush();
   }
 
 }
\ No newline at end of file

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java
 Sat May  1 20:42:04 2010
@@ -21,7 +21,7 @@ public abstract class BaseCommand implem
 
   private static final String DATE_FORMAT = "yyyyMMddHHmmss";
 
-  protected static final PrintStream out = System.out;
+  protected PrintStream printStream = System.out;
 
   protected File basePath;
   protected File envPath;
@@ -31,10 +31,6 @@ public abstract class BaseCommand implem
   protected boolean force;
   private ClassLoader driverClassLoader;
 
-  public void setDriverClassLoader(ClassLoader driverClassLoader) {
-    this.driverClassLoader = driverClassLoader;
-  }
-
   protected BaseCommand(File repository, String environment, boolean force) {
     this.basePath = repository;
     this.envPath = subdirectory(repository, "environments");
@@ -44,6 +40,22 @@ public abstract class BaseCommand implem
     this.force = force;
   }
 
+  public PrintStream getPrintStream() {
+    return printStream;
+  }
+
+  public void setPrintStream(PrintStream printStream) {
+    this.printStream = printStream;
+  }
+
+  public ClassLoader getDriverClassLoader() {
+    return driverClassLoader;
+  }
+
+  public void setDriverClassLoader(ClassLoader driverClassLoader) {
+    this.driverClassLoader = driverClassLoader;
+  }
+
   protected boolean paramsEmpty(String... params) {
     return params == null || params.length < 1 || params[0] == null || 
params[0].length() < 1;
   }
@@ -141,7 +153,7 @@ public abstract class BaseCommand implem
   }
 
   protected void copyResourceTo(String resource, File toFile, Properties 
variables) {
-    out.println("Creating: " + toFile.getName());
+    printStream.println("Creating: " + toFile.getName());
     try {
       LineNumberReader reader = new 
LineNumberReader(Resources.getResourceAsReader(this.getClass().getClassLoader(),
 resource));
       try {
@@ -191,7 +203,7 @@ public abstract class BaseCommand implem
       String username = props.getProperty("username");
       String password = props.getProperty("password");
       String charSetName = props.getProperty("script_char_set");
-      PrintWriter outWriter = new PrintWriter(out);
+      PrintWriter outWriter = new PrintWriter(printStream);
       UnpooledDataSource dataSource = new 
UnpooledDataSource(driverClassLoader, driver, url, username, password);
       dataSource.setAutoCommit(false);
       ScriptRunner scriptRunner = new ScriptRunner(dataSource.getConnection());

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java
 Sat May  1 20:42:04 2010
@@ -16,20 +16,20 @@ public class BootstrapCommand extends Ba
   public void execute(String... params) {
     try {
       if (changelogExists() && !force) {
-        out.println("For your safety, the bootstrap SQL script will only run 
before migrations are applied (i.e. before the changelog exists).  If you're 
certain, you can run it using the --force option.");
+        printStream.println("For your safety, the bootstrap SQL script will 
only run before migrations are applied (i.e. before the changelog exists).  If 
you're certain, you can run it using the --force option.");
       } else {
         File bootstrap = scriptFile("bootstrap.sql");
         if (bootstrap.exists()) {
-          out.println(horizontalLine("Applying: bootstrap.sql", 80));
+          printStream.println(horizontalLine("Applying: bootstrap.sql", 80));
           ScriptRunner runner = getScriptRunner();
           try {
             runner.runScript(new MigrationReader(new FileReader(bootstrap), 
false, environmentProperties()));
           } finally {
             runner.closeConnection();
           }
-          out.println();
+          printStream.println();
         } else {
-          out.println("Error, could not run bootstrap.sql.  The file does not 
exist.");
+          printStream.println("Error, could not run bootstrap.sql.  The file 
does not exist.");
         }
       }
     } catch (Exception e) {

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java
 Sat May  1 20:42:04 2010
@@ -28,7 +28,7 @@ public class DownCommand extends BaseCom
       int steps = 0;
       for (Change change : migrations) {
         if (change.getId().equals(lastChange.getId())) {
-          out.println(horizontalLine("Undoing: " + change.getFilename(), 80));
+          printStream.println(horizontalLine("Undoing: " + 
change.getFilename(), 80));
           ScriptRunner runner = getScriptRunner();
           try {
             runner.runScript(new MigrationReader(new 
FileReader(scriptFile(change.getFilename())), true, environmentProperties()));
@@ -38,9 +38,9 @@ public class DownCommand extends BaseCom
           if (changelogExists()) {
             deleteChange(change);
           } else {
-            out.println("Changelog doesn't exist. No further migrations will 
be undone (normal for the last migration).");
+            printStream.println("Changelog doesn't exist. No further 
migrations will be undone (normal for the last migration).");
           }
-          out.println();
+          printStream.println();
           steps++;
           final int limit = getStepCountParameter(1, params);
           if (steps == limit) {

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/InitializeCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/InitializeCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/InitializeCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/InitializeCommand.java
 Sat May  1 20:42:04 2010
@@ -12,7 +12,7 @@ public class InitializeCommand extends B
   }
 
   public void execute(String... args) {
-    out.println("Initializing: " + basePath);
+    printStream.println("Initializing: " + basePath);
 
     createDirectoryIfNecessary(basePath);
     ensureDirectoryIsEmpty(basePath);
@@ -31,8 +31,8 @@ public class InitializeCommand extends B
             setProperty("description", "First migration.");
           }
         });
-    out.println("Done!");
-    out.println();
+    printStream.println("Done!");
+    printStream.println();
   }
 
   protected void ensureDirectoryIsEmpty(File path) {
@@ -50,7 +50,7 @@ public class InitializeCommand extends B
     if (!path.exists()) {
       File parent = new File(path.getParent());
       createDirectoryIfNecessary(parent);
-      out.println("Creating: " + path.getName());
+      printStream.println("Creating: " + path.getName());
       if (!path.mkdir()) {
         throw new MigrationException("Could not create directory path for an 
unknown reason. Make sure you have access to the directory.");
       }

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/NewCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/NewCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/NewCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/NewCommand.java
 Sat May  1 20:42:04 2010
@@ -21,8 +21,8 @@ public class NewCommand extends BaseComm
     existingEnvironmentFile();
     String filename = getNextIDAsString() + "_" + description.replace(' ', 
'_') + ".sql";
     copyResourceTo("org/apache/ibatis/migration/template_migration.sql", 
scriptFile(filename), variables);
-    out.println("Done!");
-    out.println();
+    printStream.println("Done!");
+    printStream.println();
   }
 
 }

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/PendingCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/PendingCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/PendingCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/PendingCommand.java
 Sat May  1 20:42:04 2010
@@ -23,9 +23,9 @@ public class PendingCommand extends Base
         throw new MigrationException("Change log doesn't exist, no migrations 
applied.  Try running 'up' instead.");
       }
       List<Change> pending = getPendingChanges();
-      out.println("WARNING: Running pending migrations out of order can create 
unexpected results.");
+      printStream.println("WARNING: Running pending migrations out of order 
can create unexpected results.");
       for (Change change : pending) {
-        out.println(horizontalLine("Applying: " + change.getFilename(), 80));
+        printStream.println(horizontalLine("Applying: " + 
change.getFilename(), 80));
         ScriptRunner runner = getScriptRunner();
         try {
           runner.runScript(new MigrationReader(new 
FileReader(scriptFile(change.getFilename())), false, environmentProperties()));
@@ -33,7 +33,7 @@ public class PendingCommand extends Base
           runner.closeConnection();
         }
         insertChangelog(change);
-        out.println();
+        printStream.println();
       }
     } catch (Exception e) {
       throw new MigrationException("Error executing command.  Cause: " + e, e);

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/ScriptCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/ScriptCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/ScriptCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/ScriptCommand.java
 Sat May  1 20:42:04 2010
@@ -39,20 +39,20 @@ public class ScriptCommand extends BaseC
       }
       for (Change change : migrations) {
         if (shouldRun(change, v1, v2)) {
-          out.println("-- " + change.getFilename());
+          printStream.println("-- " + change.getFilename());
           File file = scriptFile(change.getFilename());
           FileReader fileReader = new FileReader(file);
           MigrationReader migrationReader = new MigrationReader(fileReader, 
undo, variables);
           char[] cbuf = new char[1024];
           int l;
           while ((l = migrationReader.read(cbuf)) == cbuf.length) {
-            out.print(new String(cbuf, 0, l));
+            printStream.print(new String(cbuf, 0, l));
           }
-          out.print(new String(cbuf, 0, l - 1));
-          out.println();
-          out.println();
-          out.println(undo ? generateVersionDelete(change) : 
generateVersionInsert(change));
-          out.println();
+          printStream.print(new String(cbuf, 0, l - 1));
+          printStream.println();
+          printStream.println();
+          printStream.println(undo ? generateVersionDelete(change) : 
generateVersionInsert(change));
+          printStream.println();
         }
       }
     } catch (IOException e) {

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java
 Sat May  1 20:42:04 2010
@@ -14,8 +14,8 @@ public class StatusCommand extends BaseC
   }
 
   public void execute(String... params) {
-    out.println("ID             Applied At          Description");
-    out.println(horizontalLine("", 80));
+    printStream.println("ID             Applied At          Description");
+    printStream.println(horizontalLine("", 80));
     List<Change> merged = new ArrayList<Change>();
     List<Change> migrations = getMigrations();
     if (changelogExists()) {
@@ -33,9 +33,9 @@ public class StatusCommand extends BaseC
       merged.addAll(migrations);
     }
     for (Change change : merged) {
-      out.println(change);
+      printStream.println(change);
     }
-    out.println();
+    printStream.println();
   }
 
 

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java
 Sat May  1 20:42:04 2010
@@ -32,7 +32,7 @@ public class UpCommand extends BaseComma
       int steps = 0;
       for (Change change : migrations) {
         if (lastChange == null || change.getId().compareTo(lastChange.getId()) 
> 0) {
-          out.println(horizontalLine("Applying: " + change.getFilename(), 80));
+          printStream.println(horizontalLine("Applying: " + 
change.getFilename(), 80));
           ScriptRunner runner = getScriptRunner();
           try {
             runner.runScript(new MigrationReader(new 
FileReader(scriptFile(change.getFilename())), false, environmentProperties()));
@@ -40,7 +40,7 @@ public class UpCommand extends BaseComma
             runner.closeConnection();
           }
           insertChangelog(change);
-          out.println();
+          printStream.println();
           steps++;
           final int limit = getStepCountParameter(Integer.MAX_VALUE, params);
           if (steps == limit || runOneStepOnly) {

Modified: 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/VersionCommand.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/VersionCommand.java?rev=940104&r1=940103&r2=940104&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/VersionCommand.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/src/main/java/org/apache/ibatis/migration/commands/VersionCommand.java
 Sat May  1 20:42:04 2010
@@ -22,23 +22,23 @@ public class VersionCommand extends Base
 
     Change change = getLastAppliedChange();
     if (version.compareTo(change.getId()) > 0) {
-      out.println("Upgrading to: " + version);
+      printStream.println("Upgrading to: " + version);
       Command up = new UpCommand(basePath, environment, force, true);
       while (!version.equals(change.getId())) {
         up.execute();
         change = getLastAppliedChange();
       }
     } else if (version.compareTo(change.getId()) < 0) {
-      out.println("Downgrading to: " + version);
+      printStream.println("Downgrading to: " + version);
       Command down = new DownCommand(basePath, environment, force);
       while (!version.equals(change.getId())) {
         down.execute();
         change = getLastAppliedChange();
       }
     } else {
-      out.println("Already at version: " + version);
+      printStream.println("Already at version: " + version);
     }
-    out.println();
+    printStream.println();
   }
 
   private void ensureParamsPassed(String... params) {


Reply via email to