[jboss-svn-commits] JBL Code SVN: r10552 - in labs/jbossrules/trunk/lib: utility-scripts and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Mar 27 02:32:01 EDT 2007


Author: michael.neale at jboss.com
Date: 2007-03-27 02:32:01 -0400 (Tue, 27 Mar 2007)
New Revision: 10552

Added:
   labs/jbossrules/trunk/lib/utility-scripts/
   labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/
   labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copy_wrong.rb
   labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copyright.txt
   labs/jbossrules/trunk/lib/utility-scripts/gwt/
   labs/jbossrules/trunk/lib/utility-scripts/gwt/interfacegen.rb
   labs/jbossrules/trunk/lib/utility-scripts/irc-builder/
   labs/jbossrules/trunk/lib/utility-scripts/irc-builder/build.sh
   labs/jbossrules/trunk/lib/utility-scripts/irc-builder/builder.rb
Log:
utility scripts

Added: labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copy_wrong.rb
===================================================================
--- labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copy_wrong.rb	                        (rev 0)
+++ labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copy_wrong.rb	2007-03-27 06:32:01 UTC (rev 10552)
@@ -0,0 +1,65 @@
+#This utility aims to replace the copyright notices in source files with a given one.
+#it will add one if it doesn't already exist.
+
+#directory recursive walker...
+def do_dir(start, copyright) 
+    Dir.foreach(start) { |d| 
+      if d != "." && d != ".." then
+        sub = start + "/" + d        
+        if not File.directory? sub and sub.include? ".java" then
+          do_java(sub, copyright)
+        else 
+          if File.directory? sub and not sub.include? ".svn" 
+	  then do_dir(sub, copyright) end
+        end        
+      end
+    }
+end
+
+
+#replace the guts of a file
+def do_java(f, copyright)
+
+  contents = IO.read(f)
+  exp = Regexp.escape("/*") + ".*Copyright.*?" + Regexp.escape("*/") 
+  existing = Regexp.new(exp, Regexp::MULTILINE)
+  if not contents.include? copyright then
+    if existing.match(contents) != nil 
+      then 
+        #clear out the old one
+        puts "replacing in : " + f
+        contents = contents.sub(existing, "")      
+      else 
+        puts "adding to : " + f
+    end
+    
+    write_to f, put_in(contents, copyright)
+    
+  else 
+    puts "ignoring as it is OK : " + f
+  end    
+  
+end
+
+def put_in(contents, copyright) 
+  new_contents = ""
+  line_num = 0
+  contents.split(/\n/).each { |line| 
+    if line_num == 0 then
+      new_contents = line + "\n" + copyright 
+    else 
+      new_contents = new_contents + "\n" + line
+    end
+    line_num = line_num + 1
+  }
+  return new_contents
+end
+
+def write_to(target, guts) 
+      target = File.new(target, "w")
+      target.write guts
+      target.close
+end
+
+do_dir("c:/temp/tryagain", IO.read ("c:/temp/copyright.txt")) 
+


Property changes on: labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copy_wrong.rb
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copyright.txt
===================================================================
--- labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copyright.txt	                        (rev 0)
+++ labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copyright.txt	2007-03-27 06:32:01 UTC (rev 10552)
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * 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.
+ */
+


Property changes on: labs/jbossrules/trunk/lib/utility-scripts/copyright-headers/copyright.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/lib/utility-scripts/gwt/interfacegen.rb
===================================================================
--- labs/jbossrules/trunk/lib/utility-scripts/gwt/interfacegen.rb	                        (rev 0)
+++ labs/jbossrules/trunk/lib/utility-scripts/gwt/interfacegen.rb	2007-03-27 06:32:01 UTC (rev 10552)
@@ -0,0 +1,38 @@
+#
+# This is a utility script for generating the Async component of a GWT RPC service.
+# You define the normal service, and then point this at it,
+# and it will generate the Async service (keeping everything nice and in sync).
+#
+# (c) Michael Neale
+#
+
+
+OUTPUT = "RepositoryServiceAsync.java"
+INPUT = "RepositoryService.java"
+
+
+interface = IO.read(INPUT)
+output = ""
+interface.each_line { |line|
+ groups = line.scan /\s+public\s+(.*?)\s+(.*?)\)\;\s*/
+ if groups.size > 0 then 
+	 if groups[0][0] == 'interface' then
+		output = output + "\n" + line
+ 	else 
+        	output = output + "\n" + "        public void " + groups[0][1] + ', AsyncCallback callback);'
+ 	end
+ else 
+	output = output + "\n" + line
+
+ end
+
+
+}
+
+if File.exists? OUTPUT then File.delete(OUTPUT) end
+
+f = File.new(OUTPUT, "w")
+f.write output
+f.close
+
+


Property changes on: labs/jbossrules/trunk/lib/utility-scripts/gwt/interfacegen.rb
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/lib/utility-scripts/irc-builder/build.sh
===================================================================
--- labs/jbossrules/trunk/lib/utility-scripts/irc-builder/build.sh	                        (rev 0)
+++ labs/jbossrules/trunk/lib/utility-scripts/irc-builder/build.sh	2007-03-27 06:32:01 UTC (rev 10552)
@@ -0,0 +1,3 @@
+#!bin/sh
+svn up
+mvn clean test


Property changes on: labs/jbossrules/trunk/lib/utility-scripts/irc-builder/build.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/lib/utility-scripts/irc-builder/builder.rb
===================================================================
--- labs/jbossrules/trunk/lib/utility-scripts/irc-builder/builder.rb	                        (rev 0)
+++ labs/jbossrules/trunk/lib/utility-scripts/irc-builder/builder.rb	2007-03-27 06:32:01 UTC (rev 10552)
@@ -0,0 +1,113 @@
+#
+# Bob the builder - as brought to you by Michael Neale
+# http://users.on.net/michaelneale
+#
+require "socket"
+require "net/http"
+require "cgi"
+
+
+# The irc class, which talks to the server and holds the main event loop
+class IRC
+    def initialize(server, port, nick, channel)
+        @server = server
+        @port = port
+        @nick = nick
+        @channel = channel
+    end
+    def send(s)
+        # Send a message to the irc server and print it to the screen
+        puts "--> #{s}"
+        @irc.send "#{s}\n", 0 
+    end
+    def connect()
+        # Connect to the IRC server
+        @irc = TCPSocket.open(@server, @port)
+        send "USER blah blah blah :blah blah"
+        send "NICK #{@nick}"
+        send "JOIN #{@channel}"
+    end
+
+    def handle_server_input(s)
+        # This isn't at all efficient, but it shows what we can do with Ruby
+        # (Dave Thomas calls this construct "a multiway if on steroids")
+	puts "The command is: " + s.strip
+        case s.strip
+            when /^PING :(.+)$/i
+                puts "[ Server ping ]"
+                send "PONG :#{$1}"
+            when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]PING (.+)[\001]$/i
+                puts "[ CTCP PING from #{$1}!#{$2}@#{$3} ]"
+                send "NOTICE #{$1} :\001PING #{$4}\001"
+            when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]VERSION[\001]$/i
+                puts "[ CTCP VERSION from #{$1}!#{$2}@#{$3} ]"
+                send "NOTICE #{$1} :\001VERSION Ruby-irc v0.042\001"
+	    when /.*lisa:\s*build\s*.*/ 		
+			reply "updating and building..."			
+			result = `/bin/sh ./build.sh`
+			if result =~ /.*BUILD SUCCESSFUL.*/ then
+ 				reply "BUILD SUCCESS. Thanks for asking !"
+				@clean = true
+		        else 
+				reply "BUILD FAILURE. Time to do a checkout and try for youself !"
+				@clean = false
+			end
+	    when /.*lisa:\s*hi.*/                
+		reply "Hi. I am Mic's build mistress. Type 'lisa: build' to kick off a build. The last build status: " + @clean.to_s
+                
+        end
+	puts s
+    end
+
+    def reply message 
+	send "PRIVMSG #{@channel} : " + message
+    end
+
+    def no_paste message
+	h = Net::HTTP.new("rafb.net", 80)
+	resp, body = h.post("/paste/paste.php",
+                    "lang=" + CGI.escape("Java") +
+                    "&nick=" + CGI.escape("JBossRules") + 
+		    "&desc=" + CGI.escape(message) + 
+		    "&cvt_tabs=No"
+                    )
+
+	resp.each { |key, val| puts key + "==" +  val }
+	return body
+	
+    end
+
+    def main_loop()
+        # Just keep on truckin' until we disconnect
+        while true
+            ready = select([@irc, $stdin], nil, nil, nil)
+            next if !ready
+            for s in ready[0]
+                if s == $stdin then
+                    return if $stdin.eof
+                    s = $stdin.gets
+                    send s
+                elsif s == @irc then
+                    return if @irc.eof
+                    s = @irc.gets
+                    handle_server_input(s)
+                end
+            end
+        end
+    end
+end
+
+# The main program
+# If we get an exception, then print it out and keep going (we do NOT want
+# to disconnect unexpectedly!)
+irc = IRC.new('irc.codehaus.org', 6667, 'lisa', '#drools')
+#irc = IRC.new('irc.freenode.net',6667, 'pilondial', '#jbms')
+irc.connect()
+begin
+    irc.main_loop()
+rescue Interrupt
+rescue Exception => detail
+    puts detail.message()
+    print detail.backtrace.join("\n")
+    retry
+end


Property changes on: labs/jbossrules/trunk/lib/utility-scripts/irc-builder/builder.rb
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list