You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2010/11/07 03:22:33 UTC

svn commit: r1032201 - /activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala

Author: chirino
Date: Sun Nov  7 02:22:33 2010
New Revision: 1032201

URL: http://svn.apache.org/viewvc?rev=1032201&view=rev
Log:
making compatible w/ java 1.5

Modified:
    activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala

Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala?rev=1032201&r1=1032200&r2=1032201&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala Sun Nov  7 02:22:33 2010
@@ -22,7 +22,11 @@ import org.fusesource.jansi.Ansi
 import org.fusesource.jansi.Ansi.Color._
 import org.fusesource.jansi.Ansi.Attribute._
 import Helper._
-import java.io.{FileOutputStream, File}
+import java.io._
+
+object Create {
+  val IS_WINDOWS = System.getProperty("os.name").toLowerCase().trim().startsWith("win");
+}
 
 /**
  * The apollo create command
@@ -30,6 +34,8 @@ import java.io.{FileOutputStream, File}
 @command(scope="apollo", name = "create", description = "creates a new broker instance")
 class Create extends Action {
 
+  import Create._
+
   @argument(name = "directory", description = "The instance directory to hold the broker's configuration and data", index=0, required=true)
   var directory:File = _
 
@@ -44,28 +50,33 @@ class Create extends Action {
       val bin = directory / "bin"
       bin.mkdirs
 
-      var target = bin / "apollo-broker"
-      write("bin/apollo-broker", target)
-      target.setExecutable(true)
-
-      target = bin / "apollo-broker.cmd"
-      write("bin/apollo-broker.cmd", target)
-
       val etc = directory / "etc"
       etc.mkdirs
 
-      target = etc / "log4j.properties"
+      var target = etc / "log4j.properties"
       write("etc/log4j.properties", target)
 
       target = etc / "apollo.xml"
       write("etc/apollo.xml", target)
 
+      if( IS_WINDOWS ) {
+        target = bin / "apollo-broker.cmd"
+        write("bin/apollo-broker.cmd", target)
+      } else {
+        target = bin / "apollo-broker"
+        write("bin/apollo-broker", target)
+        setExecutable(target)
+      }
+
       val data = directory / "data"
       data.mkdirs
       
       val log = directory / "log"
       log.mkdirs
 
+      val tmp = directory / "tmp"
+      log.mkdirs
+
     } catch {
       case x:Helper.Failure=>
         println(ansi.a(INTENSITY_BOLD).fg(RED).a("ERROR: ").reset.a(x.getMessage))
@@ -84,4 +95,40 @@ class Create extends Action {
     copy(in, out)
     close(out)
   }
+
+
+  def setExecutable(path:File) = if( !IS_WINDOWS ) {
+    try {
+        system(path.getParentFile(), Array("chmod", "a+x", path.getName))
+    } catch {
+      case x =>
+    }
+  }
+
+  def system(wd:File, command:Array[String]) = {
+    val process = Runtime.getRuntime.exec(command, null, wd);
+    def drain(is:InputStream, os:OutputStream) = {
+      new Thread(command.mkString(" ")) {
+        setDaemon(true)
+        override def run: Unit = {
+          try {
+            val buffer = new Array[Byte](1024 * 4)
+            var c = is.read(buffer)
+            while (c >= 0) {
+              os.write(buffer, 0, c);
+              c = is.read(buffer)
+            }
+          } catch {
+            case x =>
+          }
+        }
+      }.start
+    }
+
+    drain(process.getInputStream, System.out)
+    drain(process.getErrorStream, System.err)
+    process.waitFor
+    process.exitValue
+  }
+
 }
\ No newline at end of file