FallenRayne Dev One developer's random thoughts are better than nothing.

28Dec/100

Phing – An example build script menu system

Got a little delayed on this post due to trying to find a decent code formatter for WordPress.  So here is my example menu script that I built with Phing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0" encoding="UTF-8"?>

<project name="test" default="main" description="A test build script to see how things work.">    
    <property name="choice" value=""/>

    <target name="main">
        <!-- Main Menu -->
        <echo>Welcome to the Phing Build System</echo>
        <echo>---------------------------------</echo>
        <echo>1) Build Scripts</echo>
        <echo>2) Misc. Scripts</echo>
        <echo>x) Exit</echo>
        <echo>---------------------------------</echo>
       
        <input propertyName="choice" validargs="1,2,x"/>
       
        <if>
            <equals arg1="${choice}" arg2="1" />
            <then>
                <phingcall target="buildscripts"/>
            </then>
           
            <elseif>
                <equals arg1="${choice}" arg2="2" />
                <then>
                    <phingcall target="miscscripts"/>
                </then>
            </elseif>
           
            <elseif>
                <equals arg1="${choice}" arg2="x" />
                <then>
                    <echo>Thanks for using the Phing Build System!</echo>
                    <php expression="exit();"/>
                </then>
            </elseif>
        </if>
    </target>
   
    <target name="buildscripts">
        <!-- Build Script Menu -->
        <echo>Build Scripts</echo>
        <echo>---------------------------------</echo>
        <echo>1) Normal Release</echo>
        <echo>2) Bug Release</echo>
        <echo>x) Back</echo>
        <echo>---------------------------------</echo>
       
        <input propertyName="choice" validargs="1,2,x"/>
       
        <if>
            <equals arg1="${choice}" arg2="1" />
            <then>
                <phing phingfile="normal_release_build_script.xml" inheritRefs="true" target="main" />
                <phingcall target="main"/>
            </then>
           
            <elseif>
                <equals arg1="${choice}" arg2="2" />
                <then>
                    <echo>This should call the bug release build script.</echo>    
                    <echo>That script should house what is needed to execute a build.</echo>
                    <phingcall target="main"/>
                </then>
            </elseif>
           
            <elseif>
                <equals arg1="${choice}" arg2="x" />
                <then>
                    <phingcall target="main"/>
                </then>
            </elseif>
        </if>
    </target>
   
    <target name="miscscripts">
        <!-- Misc Script Menu -->
        <echo>Misc Scripts</echo>
        <echo>---------------------------------</echo>
        <echo>1) Do something</echo>
        <echo>2) Do something else</echo>
        <echo>x) Back</echo>
        <echo>---------------------------------</echo>
       
        <input propertyName="choice" validargs="1,2,x"/>
       
        <if>
            <equals arg1="${choice}" arg2="1" />
            <then>
                <echo>This should do something really cool.</echo>    
                <phingcall target="main"/>
            </then>
           
            <elseif>
                <equals arg1="${choice}" arg2="2" />
                <then>
                    <echo>This should do something cooler than the last thing.</echo>    
                    <phingcall target="main"/>
                </then>
            </elseif>
           
            <elseif>
                <equals arg1="${choice}" arg2="x" />
                <then>
                    <phingcall target="main"/>
                </then>
            </elseif>
        </if>
    </target>
</project>

So, here is a quick explanation of what is going on here. First off, the Project tag sets up the project and defines with the default target will be. A target is basically a function call. I then instantiate a property called "choice". This will hold the menu option that is selected by the user. Target main, the default target, is the main menu. You can see the echo tasks that display the menu. The input task asks the user for a value and that value has to be 1,2, or x. The if statement looks at the selected value and each value leads to either a new menu, a task, or exits. For example, if 1 is chosen then the task phingcall will call for the buildscripts target to execute. This will bring up the menu for buildscripts. If 1 is chosen in buildscripts then first it will call for a different build script file, execute that, and then it will return back to the main target with a phingcall task.

The overall goal of this script is to keep the menu up all day long and just have all of the common tasks built into this. I find this very handy on my Ubuntu box just because I always forget where all of the files I need are located and what commands I need to run for certain tasks. If I use a menu system in Phing then I don't have to remember any of that and I can automate some of my more tedious tasks (like database backups).

If there is a better way to set this up or if you have any questions about this script please drop me a line or leave a comment. I am always looking for ways to improve my processes and products.

Hope this helps someone out! Next week I will probably be just talking about my new phone (I get a brand new EVO 4g on Saturday!) and the apps/customizations that will be done. I especially want to play around with Tasker, that app looks amazing!

Everyone have a happy New Year!

25Dec/100

Merry Christmas!

Hey everyone! Merry Christmas!

I hope everyone has a great Christmas today and gets all the coolest new gadgets and toys. We already bought our new Christmas present and opened it early, but it was hard not too with the Kinect. That is an awesome piece of hardware! I still can't seem to beat my dad at bowling though; he kicks my ass in Wii bowling, Kinect bowling, and real bowling. I should probably take a hint and realize that I suck at bowling.

Everyone be safe, especially if you are having a white Christmas. You know, you would think it is supposed to be all joyous and happy when you have a white Christmas until you are out in the freezing cold shoveling the damn stuff. I can't WAIT until my long term investment in a snow shoveler pays off. My son is turning 3 in January so I figure I got about 2 more years until I get him out there shoveling. Of course, if you look at previous pictures, he doesn't like the snow much. Like this one, where he learned why he needed to wear his gloves.

For some reason he thought it was smart to take off his gloves.

For some reason he thought it was smart to take off his gloves.

Or this one, his first true snow where he could fully appreciate it. Can you see him appreciating it?

Eli pissed off at the snow and the world.

Eli pissed off at the snow and the world.

Well once again, Merry Christmas! Now go get fat eating Turkey and watching football (that is American football, not the rest of the world football). Go GIANTS! Don't lose on the last second again!

Filed under: Personal No Comments
22Dec/100

Phing – A quick intro

Phing is a build system that is entirely built using PHP and is based off of Apache Ant. I have been checking Phing out a bit lately due to needing to automate a bunch of tasks at my job. I kept seeing Phing mentioned on various websites and decided that it could be a pretty good choice after seeing what it was capable of. The tasks we want to automate are:

  • Transferring data from one database to another regularly
  • Doing weekly releases, sending e-mail upon completion to our users and the help desk
  • Running PHPUnit tests on a regular basis
  • Building PHPDoc for every release
  • Bringing on new customers (database changes, file changes, account creation, etc...)
  • Hiring new developers (account creation, directory creation, svn checkouts, etc...)

As you can see, we have a decent little laundry list of things that we could automate and with some research I figured out how to do all of these with Phing. The big selling point for us was the fact that Phing can be extended using Tasks. Tasks are basically PHP scripts that are run in Phing through XML tags. This makes anything that is possible for PHP to do for Phing to automate. Phing can send e-mail, manipulate the file system, access APIs, make database changes, and even build a menu system so that all of your common tasks can be accessed from one script even if the scripts are separated into multiple files.

Next week I am going to show an example build script that I worked on that makes a basic menu system that you can leave up all day to accomplish all of your common command line tasks. I used to have one written in Bash but I seemed to have misplaced it and it only ran on Linux anyways. With Phing I can run the build script on Windows, Linux, or Mac.  Better yet, I can even run it on my Ubuntu machine and have it SSH into my Windows machine to accomplish additional tasks if need be.

19Dec/100

Back to the blogging

Well I am back to blogging again after a good 3-4 year lag. After I lost my last blog and all of its content it took a while to get up the energy to try again.

So here I am again. This time I am going to be signing up for Project 52. This should keep me motivated and adding new content every week.  This new content should come in the form of some decent programming articles and maybe a review or two. If Google is really nice to me and actually ships me a CR-48 then I will get to start blogging about that and my attempt to do most of my personal work from that machine. I only mention the CR-48 because I found out that one is being delivered to my zip code tomorrow! So... maybe it might be to me? There is always a chance.

Past that I should be putting up some stuff on Phing as I do some work with that. I will also be doing some work with ExtJS, Sencha Touch, and JIRA in the next few weeks and should have some decent information about those as well. All in all I believe I finally have some good stuff to write about that will display some solid information. It is good to be working on newer technology and keeping my skill set current.

Filed under: Personal No Comments