December 30, 2006

Using Subversion with IntelliJ

Although IntelliJ comes with built-in support for Subversion (and CVS..), it's not really clear how to start working on a new Version Controlled project.
Searching the web, I couldn't find a tutorial that covers this topic, and the JetBrains site only has this not uninformative article http://www.jetbrains.com/idea/features/version_control.html

If you're unfamiliar with SVN or want to know more about it, there's a great online book available at http://svnbook.red-bean.com/

Prerequisites
1. Have an SVN service installed on your server (possibly via Apache) you can get SVN at http://subversion.tigris.com/
2. Have a repository filled with code.
3. Have IntelliJ 5.5 or 6 installed (http://www.jetbrains.com/idea/

Recommendation
Install the TortoiseSVN application (http://tortoisesvn.tigris.org/).
This application integrates with the windows explorer and enables communication with an SVN service (local or remote), essentially, it contains all the functionality that IntelliJ has, and more.

Now that we got that out of the way, let's start deploying the code and configuring the project.

Step 1: Checkout
Checkout means that we will be copying the latest (HEAD) version of the version controlled project to a local folder (also called a working copy).

  1. Close all the open projects in your IntelliJ Environment.
  2. Choose the checkout a new VCS (Version Controlled Source) – the bottom left link, and then choose the SVN.
    A new window should appear, which should contain a list of links to your SVN repositories. Choose the correct link or rather, If you have none, you can add a link by clicking the golden plus sign.
  3. Create a new local directory for the project and checkout the source files to that local directory.

This step can also be done without IntelliJ, if you've installed TortoiseSVN.
Moreover, if you browse to that directory, you will see it (and each sub-folder) contains a hidden .svn directory. Do not delete these directories!

Step 2: New Project
Using IntelliJ, create a new project and select the directory you've created in the previous step. Follow the New project wizard.
Notice that IntelliJ should detect the source files you've checked out (I tried this with Java files, so I don't know if it detects other types) .

Step 3: Link to the SVN
1. Go to module settings (File / Settings) or press Ctrl+Alt+S
2. Choose Version Control
3. Set the Default Version Control to Subversion (last in the list)

Outcome
There are a few things to notice after performing this step,
  1. Notice that the file names are now colored in black and that if you change the content of a file and save it, the file name will turn blue, indicating that the local version does not match the controlled version in the remote server.
  2. The Version Control Menu Item in the main menu contains more options
  3. If you right-click a file or directory, there's a subversion sub-menu you can expand that contains options such as commit (or check-in on IntelliJ5), update, compare, etc'.

Final Notes
  1. If you're developing a web-app, (possibly under Tomcat), you might want to checkout under the DocumentRoot, or map a location to you code.
  2. Don't commit your .iml, .ipr, .iws (which are Marron Colored)
  3. you might need to link libraries, this can be done by right-clicking a module / Module Settings
  4. I've been using Subversion with 5 other developers, one of which is using NetBeans and all the others are using IntelliJ.
  5. I've also written a post on how to install SVN on Eclipse available at http://levinboim.blogspot.com/2006/09/setting-up-subversion-with-eclipse-on.html

-- Tomer

September 03, 2006

Configuring Subversion on Eclipse

Trying to install SVN (Subversion) on Eclipse for the first time was a bit tricky for me. There seems to be a lack of resources on the subject, or a latent assumption that it's too trivial, so,
here's how I did it:

Prerequisites
1. Apache installed (on your server). If you're using WinXP OS on your server, you must have Apache2.0 installed, as the svn modules are not compatible with Apache2.2.
2. Eclipse installed (on your client)

What to do:
1. Download and install SVN on your server
http://subversion.tigris.org/
This, along with the Apache service will be the Version Control server.

2. Download and install TortoiseSVN on your server (and possibly on other machines)
http://tortoisesvn.tigris.org/
TortoiseSVN integrates with the windows explorer itself (not to be confused with IE..), so, after installation, you will have a few more options when right-clicking a folder or file (namely, you can choose to import them or checkout an existing repository).

3. Open a new Repository
We will now instruct the SVN server to open and import a new repository (a managed storage place for you code\documents).
Right click on a new folder, and have the TortoiseSVN import your data there

4. Download and install Subclipse using the Eclipse IDE
Use the Help->Software Updates->Find and Install menu
Configure a new Update Server for the Subclipse plug-in at:
http://subclipse.tigris.org/update_1.0.x
This tells the Eclipse to download a plug-in, with which it is able to communicate with the Subversion service.

5. Checkout the Repository
Create a new directory on your computer. You can checkout a project from the repository to that directory either by using the Eclipse IDE or via the TortoiseSVN itself (right-click on the directory and select checkout). If Indeed TortoiseSVN is installed on your local computer, the Files and Folders under that directory are now marked with Green Checks, indicating that they are up to date. Notice each folder now contains a hidden directory called .svn. Do not delete these directories.

6. Configure the post-commit hook
If you're working on a web-application like me, you will want a read-only copy of your code (sometimes called a mirror) on a directory accessibly by your HTTP service.
This copy should be updated to reflect the changes made by you or your team members while using the Eclipse IDE.
Subversion provides a hooking mechanism (in the hooks directory, under the repository directory). I use a modification of the post-commit file, taken from
http://www.svnforum.org/2017/viewtopic.php?t=1694.
Essentially, this batch file is called after each commit, and causes the Subversion to update a working copy at D:\WorkingCopyPath.

@ECHO ON
REM POST-COMMIT HOOK
set repo=%1
set rev=%2
set log="D:\SVN\Repository\logs\post-commit_log.txt"
set err="D:\SVN\Repository\logs\post-commit_err-log.txt"
set svn="C:\Progra~1\Subversion\bin\svn.exe"
set svnpath="C:\Progra~1\Subversion\bin"
( echo ========================================================================
echo Start commit %repo% r%rev%
date /t
time /t ) >> %log%
set cmd=%svn% update D:\WorkingCopyPath
(start "start-title" /D%svnpath% /BELOWNORMAL /B %cmd% >> %log%)

That's about it. Hope you find this helpful.

February 11, 2006

Downgrading from PHP5 to PHP4

One of the projects I'm currently involved in is a web based Prediction Market. For those of you who never heard of the field, run a quick search on in Google or in a Wiki and I'm sure you'll get all the information you need.
It's a very intelligant way to aggregate information and obtain insight on the future.
Alas, since we're not here to talk about business or predicting the future (interesting as that might be.... ) let me get to the point.

During an integration with a client, I discovered that they do not use php5, but rather, an earlier version - PHP4 (v4.3.2 I believe). Obviously I requested that they would upgrade, or at least run their HTTP server (Apache) with support to both versions (it is possible...).
They declined.

As they were a very important client (our first..) I had to undergo the rigorous task of making the code PHP4 compatible. following that I decided to publish a short recipe for the process.

Recipe for Converting PHP5 to PHP4 compatible code:
1. Functions - remove the following keywords: 'public', 'private' and 'static'. There are no visibility modifiers, and all functions can be accessed statically or from an instance.
2. Instance variables - replace 'public' and 'private' with 'var'.
3. Static variables - replace with a getter and setter functions. You can use the following pattern for each variables. (Credit to peter joel, a comment at http://il.php.net/keyword.paamayim-nekudotayim):


class A
{
function getVar($val=NULL)
{
static $class_variable = 0;
if ($val != NULL)
$class_variable = $val;
return $class_variable;
}

function setVar($val=0)
{
return A::getVar($val);
}
}

4. object usage - references in PHP4 is a bit different than it is in PHP5
4.1 - prefix all functions that return an object with an amp '&'
4.2 - when invoking a functi0n that returns an object use $obj = &function() (mind the &)
4.3 - when passing an object, we need to pass it by reference, so prefix the parameter with an &, for example: function func_name(&$param_name)

After applying this recipe, your code should be PHP4 compatible.