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 2014/01/30 21:58:12 UTC

[3/3] git commit: Fixes APLO-332: Apollo not starting with cygwin under windows7

Fixes APLO-332: Apollo not starting with cygwin under windows7

The Apollo unix distro now does the right thing when run in cygwin.

Project: http://git-wip-us.apache.org/repos/asf/activemq-apollo/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-apollo/commit/a325f0fb
Tree: http://git-wip-us.apache.org/repos/asf/activemq-apollo/tree/a325f0fb
Diff: http://git-wip-us.apache.org/repos/asf/activemq-apollo/diff/a325f0fb

Branch: refs/heads/trunk
Commit: a325f0fbe7a4e28bda6f65c89bdb1e3a05b12e11
Parents: feb2a17
Author: Hiram Chirino <hi...@hiramchirino.com>
Authored: Thu Jan 30 15:58:02 2014 -0500
Committer: Hiram Chirino <hi...@hiramchirino.com>
Committed: Thu Jan 30 15:58:02 2014 -0500

----------------------------------------------------------------------
 .../activemq/apollo/broker/BrokerCreate.scala   | 64 +++++++++++++-------
 .../activemq/apollo/commands/Create.scala       |  4 +-
 .../src/main/descriptors/common-bin.xml         | 21 +++++++
 apollo-distro/src/main/descriptors/unix-bin.xml | 14 +----
 .../src/main/descriptors/windows-bin.xml        | 11 ----
 apollo-distro/src/main/release/bin/apollo       |  5 +-
 .../activemq/apollo/web/ApolloApplication.scala |  2 +-
 7 files changed, 71 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
----------------------------------------------------------------------
diff --git a/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala b/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
index 2e57682..a47c621 100644
--- a/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
+++ b/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
@@ -27,8 +27,8 @@ class BrokerCreate {
   var directory:File = _
   var host:String = _
   var force = false
-  var base: String = _
-  var home: String = System.getProperty("apollo.home")
+  var base: File = _
+  var home: File = new File(System.getProperty("apollo.home"))
   var with_ssl = true
   var encoding = "UTF-8"
 
@@ -53,10 +53,12 @@ class BrokerCreate {
 
 
   val IS_WINDOWS = System.getProperty("os.name").toLowerCase().trim().startsWith("win");
+  val IS_CYGWIN = IS_WINDOWS && System.getenv("OSTYPE") == "cygwin";
 
   def run() = {
 
     try {
+
       println("Creating apollo instance at: %s".format(directory))
 
       if( host == null ) {
@@ -92,7 +94,7 @@ class BrokerCreate {
           "-dname", "cn=%s".format(host),
           "-validity", "3650"))==0
         if(!rc) {
-          println("WARNNIG: Could not generate the keystore, make sure the keytool command is in your PATH")
+          println("WARNING: Could not generate the keystore, make sure the keytool command is in your PATH")
         }
         rc
       }
@@ -122,23 +124,25 @@ class BrokerCreate {
           write("bin/apollo-broker.cmd", bin/"apollo-broker.cmd", true)
           write("bin/apollo-broker-service.exe", bin/"apollo-broker-service.exe")
           write("bin/apollo-broker-service.xml", bin/"apollo-broker-service.xml", true)
-        } else {
-          write("bin/apollo-broker", bin/"apollo-broker", true)
+        }
+
+        if( !IS_WINDOWS || IS_CYGWIN ) {
+          write("bin/apollo-broker", bin/"apollo-broker", true, false, true)
           setExecutable(bin/"apollo-broker")
 
-          write("bin/apollo-broker-service", bin/"apollo-broker-service", true)
+          write("bin/apollo-broker-service", bin/"apollo-broker-service", true, false, true)
           setExecutable(bin/"apollo-broker-service")
         }
 
         println("")
         println("You can now start the broker by executing:  ")
         println("")
-        println("   \"%s\" run".format((bin/"apollo-broker").getCanonicalPath))
+        println("   \"%s\" run".format(cp(bin/"apollo-broker", true)))
 
         val service = bin / "apollo-broker-service"
         println("")
 
-        if( !IS_WINDOWS ) {
+        if( !IS_WINDOWS || IS_CYGWIN ) {
 
           // Does it look like we are on a System V init system?
           if( new File("/etc/init.d/").isDirectory ) {
@@ -147,24 +151,26 @@ class BrokerCreate {
             println("")
             println("   sudo ln -s \"%s\" /etc/init.d/".format(service.getCanonicalPath))
             println("   /etc/init.d/apollo-broker-service start")
+            println("")
 
           } else {
 
             println("Or you can run the broker in the background using:")
             println("")
-            println("   \"%s\" start".format(service.getCanonicalPath))
-
+            println("   \"%s\" start".format(cp(service,true)))
+            println("")
           }
 
-        } else {
+        }
+        if ( IS_WINDOWS ) {
 
-          println("Or you can setup the broker as system service and run it in the background:")
+          println("Or you can setup the broker as Windows service and run it in the background:")
+          println("")
+          println("   \"%s\" install".format(cp(service,true)))
+          println("   \"%s\" start".format(cp(service,true)))
           println("")
-          println("   \"%s\" install".format(service.getCanonicalPath))
-          println("   \"%s\" start".format(service.getCanonicalPath))
 
         }
-        println("")
       }
 
 
@@ -176,7 +182,17 @@ class BrokerCreate {
     null
   }
 
-  def write(source:String, target:File, filter:Boolean=false, text:Boolean=false) = {
+  def cp(value:String, unixPaths:Boolean):String = cp(new File(value), unixPaths)
+  def cp(value:File, unixPaths:Boolean):String = {
+    if( unixPaths && IS_CYGWIN ) {
+      import scala.sys.process._
+      Seq("cygpath", value.getCanonicalPath).!!.trim
+    } else {
+      value.getCanonicalPath
+    }
+  }
+
+  def write(source:String, target:File, filter:Boolean=false, text:Boolean=false, unixTarget:Boolean=false) = {
     if( target.exists && !force ) {
       error("The file '%s' already exists.  Use --force to overwrite.".format(target))
     }
@@ -194,20 +210,19 @@ class BrokerCreate {
         def replace(key:String, value:String) = {
           content = content.replaceAll(Pattern.quote(key), Matcher.quoteReplacement(value))
         }
-        def cp(value:String) = new File(value).getCanonicalPath
 
         replace("${user}", System.getProperty("user.name",""))
         replace("${host}", host)
         replace("${version}", Broker.version)
         if( home !=null ) {
-          replace("${home}", cp(home))
+          replace("${home}", cp(home, unixTarget))
         }
-        replace("${base}", directory.getCanonicalPath)
-        replace("${java.home}", cp(System.getProperty("java.home")))
+        replace("${base}", cp(directory, unixTarget))
+        replace("${java.home}", cp(System.getProperty("java.home"), unixTarget))
         replace("${store_config}", store_config)
 
         if( base !=null ) {
-          replace("${apollo.base}", base)
+          replace("${apollo.base}", cp(base, unixTarget))
         }
 
         replace("${broker_security_config}", broker_security_config)
@@ -216,7 +231,12 @@ class BrokerCreate {
 
       // and then writing out in the new target encoding..  Let's also replace \n with the values
       // that is correct for the current platform.
-      val in = new ByteArrayInputStream(content.replaceAll("""\r?\n""",  Matcher.quoteReplacement(System.getProperty("line.separator"))).getBytes(encoding))
+      var separator = if ( unixTarget && IS_CYGWIN ) {
+        "\n"
+      } else {
+        System.getProperty("line.separator")
+      }
+      val in = new ByteArrayInputStream(content.replaceAll("""\r?\n""",  Matcher.quoteReplacement(separator)).getBytes(encoding))
 
       using(new FileOutputStream(target)) { out=>
         copy(in, out)

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
index 02a8d51..64a4e04 100755
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
@@ -38,9 +38,9 @@ class Create extends Action {
   var force = false
 
   @option(name = "--home", description = "Directory where apollo is installed")
-  var home: String = _
+  var home: File = _
 
-  @option(name = "--with-ssl", description = "Generate an SSL enabled configuraiton")
+  @option(name = "--with-ssl", description = "Generate an SSL enabled configuration")
   var with_ssl = true
 
   @option(name = "--encoding", description = "The encoding that text files should use")

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-distro/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apollo-distro/src/main/descriptors/common-bin.xml b/apollo-distro/src/main/descriptors/common-bin.xml
index 4b0008a..0ca203d 100644
--- a/apollo-distro/src/main/descriptors/common-bin.xml
+++ b/apollo-distro/src/main/descriptors/common-bin.xml
@@ -117,6 +117,27 @@
   </dependencySets>
 
   <fileSets>
+    
+    <!-- Copy the unix scripts .. chmod 755 and exclude the windows bits-->
+    <fileSet>
+      <directory>src/main/release/bin</directory>
+      <outputDirectory>/bin</outputDirectory>
+      <lineEnding>unix</lineEnding>
+      <fileMode>0755</fileMode>
+      <excludes>
+        <exclude>*.cmd</exclude>
+      </excludes>
+    </fileSet>
+
+    <!-- Copy the windows scripts .. exclude the unix bits-->
+    <fileSet>
+      <directory>src/main/release/bin</directory>
+      <outputDirectory>/bin</outputDirectory>
+      <lineEnding>dos</lineEnding>
+      <includes>
+        <include>*.cmd</include>
+      </includes>
+    </fileSet>
 
     <!-- copy the website docs -->
     <fileSet>

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-distro/src/main/descriptors/unix-bin.xml
----------------------------------------------------------------------
diff --git a/apollo-distro/src/main/descriptors/unix-bin.xml b/apollo-distro/src/main/descriptors/unix-bin.xml
index 045ed1d..19ec9ba 100755
--- a/apollo-distro/src/main/descriptors/unix-bin.xml
+++ b/apollo-distro/src/main/descriptors/unix-bin.xml
@@ -33,19 +33,7 @@
       </excludes>
       <lineEnding>unix</lineEnding>
     </fileSet>
-    
-    <!-- Copy the unix scripts .. chmod 755 and exclude the windows bits-->
-    <fileSet>
-      <directory>src/main/release/bin</directory>
-      <outputDirectory>/bin</outputDirectory>
-      <lineEnding>unix</lineEnding>
-      <fileMode>0755</fileMode>
-      <excludes>
-        <exclude>*.bat</exclude>
-        <exclude>*.cmd</exclude>
-      </excludes>
-    </fileSet>
-    
+        
     <!-- filtered files --> 
     <fileSet>
       <directory>src/main/release</directory>

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-distro/src/main/descriptors/windows-bin.xml
----------------------------------------------------------------------
diff --git a/apollo-distro/src/main/descriptors/windows-bin.xml b/apollo-distro/src/main/descriptors/windows-bin.xml
index 8679290..9dfc12e 100755
--- a/apollo-distro/src/main/descriptors/windows-bin.xml
+++ b/apollo-distro/src/main/descriptors/windows-bin.xml
@@ -33,17 +33,6 @@
       <lineEnding>dos</lineEnding>
     </fileSet>
     
-    <!-- Copy the windows scripts .. exclude the unix bits-->
-    <fileSet>
-      <directory>src/main/release/bin</directory>
-      <outputDirectory>/bin</outputDirectory>
-      <lineEnding>dos</lineEnding>
-      <includes>
-        <include>*.bat</include>
-        <include>*.cmd</include>
-      </includes>
-    </fileSet>
-
     <!-- filtered files --> 
     <fileSet>
       <directory>src/main/release</directory>

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-distro/src/main/release/bin/apollo
----------------------------------------------------------------------
diff --git a/apollo-distro/src/main/release/bin/apollo b/apollo-distro/src/main/release/bin/apollo
index 75d8005..e502fb5 100755
--- a/apollo-distro/src/main/release/bin/apollo
+++ b/apollo-distro/src/main/release/bin/apollo
@@ -33,7 +33,10 @@ fi
 cygwin=false;
 darwin=false;
 case "`uname`" in
-  CYGWIN*) cygwin=true ;;
+  CYGWIN*) cygwin=true 
+    OSTYPE=cygwin
+    export OSTYPE
+    ;;
   Darwin*) darwin=true
            if [ -z "$JAVA_HOME" ] ; then
              JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/a325f0fb/apollo-web/src/main/scala/org/apache/activemq/apollo/web/ApolloApplication.scala
----------------------------------------------------------------------
diff --git a/apollo-web/src/main/scala/org/apache/activemq/apollo/web/ApolloApplication.scala b/apollo-web/src/main/scala/org/apache/activemq/apollo/web/ApolloApplication.scala
index faecb69..99561f1 100644
--- a/apollo-web/src/main/scala/org/apache/activemq/apollo/web/ApolloApplication.scala
+++ b/apollo-web/src/main/scala/org/apache/activemq/apollo/web/ApolloApplication.scala
@@ -47,7 +47,7 @@ class ApolloApplication extends Filter {
     if( !conf.exists() ) {
       val create = new BrokerCreate
       create.directory = base
-      create.base = base.getCanonicalPath
+      create.base = base
       create.broker_security_config = "<jmx admin_url='"+sc.getContextPath+"'/>"
       create.host_security_config = ""
       create.home = null