Wednesday, November 08, 2006

How to install CVS as a server repository and connect from Eclipse

I tried to find this on the net the other day and could only find it piece-meal. So, in case you're trying to setup a CVS repository. here it all is in one shot.

I make ONE assumption, which is that you already have a remote server that you are accustomed to connecting to that server using ssh and scp.

SECTION A - LINUX COMMAND LINE COMMANDS
SECTION B - REMOTE SERVER CVS REPOSITORY INSTALL
SECTION C: COMMAND-LINE CVS IMPORT / CHECKOUT / COMMIT / UPDATE
SECTION D: ECLIPSE PROJECT CVS IMPORT
SECTION E: ECLIPSE PROJECT CVS EXPLORATION / GET PROJECTS
SECTION F: ECLIPSE PROJECT FILES CHECKOUT / COMMIT / UPDATE / SYNCHRONIZE

*****

SECTION A - LINUX COMMAND LINE COMMANDS

Let's start with some command-line Linux commands for
creating users and groups, since you'll need these shortly
to set up the CVS repository on the server:

To add a user:
useradd -m -c JohnSmith username
or perl script utility (recommended):
adduser username
To delete a user:
userdel -r username

To change a password:
passwd username
You will be asked for a new password.

To add a group:
groupadd groupname
To delete a group:
groupdel groupname

To add a user to a group:
Go to the /etc directory, and use vi
to edit the text file 'group': locate the group name (likely near the bottom.)
It will have the name plus an identifier, ending in a colon, or an existing user.
If it's a colon, just add the username. If a username is there,
type a comma and add the additional username:
groupname:x:1001:dgadd,cvs

*****

SECTION B - REMOTE SERVER CVS REPOSITORY INSTALL
With those commands in hand, you can proceed with a remote server cvs repository install.

Firstm, use ssh to connect.
Let's suppose the server is named 555.555.555.555
In that case:
ssh myusername@555.555.555.555

Now do the following to set up cvs on the remote server:

1) On Ubuntu use apt-get install cvs to install cvs
2) Create a repository folder:
mkdir /var/lib/cvsroot
3) Use Linux commands to create a user, 'cvs' a group 'cvsusers',
and edit the /etc/group file to add 'cvs' to the end of the 'cvsusers' group.
4) Change the group of the repository folder to cvsusers, make directory read/write/execute, and make cvs the owner.
chgrp cvsusers /var/lib/cvsroot
chmod g+srwx /var/lib/cvsroot
chown -R cvs /var/lib/cvsroot
5) Initialize the repository using the cvs command:
cvs -d /var/lib/cvsroot init

SECTION C: COMMAND-LINE CVS IMPORT / CHECKOUT / COMMIT / UPDATE

1) To import a project on your local server to remote server cvs:
Copy the project to a temp directory, because the copy
you use to import needs to be discarded.
Cd into that temp project directory.
Then, to perform the import, run the following command:
cvs -d cvs@555.555.555.555:/var/lib/cvsroot import example MyProject release_0_1

2) To checkout file1 within the project:
cvs -d cvs@555.555.555.555:/var/lib/cvsroot checkout MyProject/file1

3) To commit (checkin) file1 within the project:
cvs -d cvs@555.555.555.555:/var/lib/cvsroot checkout MyProject/file1

4) To update (synchronize) your local files with the (potentially updated) copies on the server:
Go inside the project directory, and type:
cvs update -d // the -d switch will download new directories

SECTION D: ECLIPSE PROJECT CVS IMPORT

The most important thing to know is that when you right-click on an Eclipse project, there is a Team sub-menu that you may not have noticed before. This Team submenu is the key to all of your CVS interaction!

1) Right-click on your Project folder in Eclipse.
2) Select Team, and then click Share Project...
3) If you have not previously set up your CVS repository, then you will be taken to the Share Project dialog box, which asks you to provide repository information.
4) Enter the following information (assuming your remote server repository ip address is 555.555.555.555, and you have set up the repository as described above):
Host: 555.555.555.555
Repository path: /var/lib/cvsroot
User: cvs
Password: your_password
Connection type: extssh
Use default port: selected
Save password checkbox: checked

5) Click Next->
6) Select the default 'Use project name as module name'.
7) Click Next->
8) Click Finish. (This should launch the Commit Wizard.)
9) A list of default types is shown, all to be saved as binary. Click next.
10) You are now asked to provide a comment before saving. A recommended format would be Date, User, Platform/Machine, Action:
Date: 2006Nov08
User: John Smith
Platform: Linux
Action: Importing project for first time

11) Click Finish. Your project will be imported.

SECTION E: ECLIPSE PROJECT CVS EXPLORATION / GET PROJECTS
Assuming you have completed the previous section and imported your project, you now need to be able to go to Eclipse on other machines, access the CVS repository and get the project(s) that you have imported. Here's how.

1) In Eclipse, from the Window menu, select the Open Perspective submenu and click Other...
2) In the Select Perspective dialog box, click CVS Repository Explorer, and then click OK.
3) Right-click inside the CVS Repositories pallete and select New > Repository Location...
4) In the Add CVS Repository dialog box, enter the following information (assuming your remote server repository ip address is 555.555.555.555, and you have set up the repository as described above):
Host: 555.555.555.555
Repository path: /var/lib/cvsroot
User: cvs
Password: your_password
Connection type: extssh
Use default port: selected
Save password checkbox: checked

5) Expand the new tree that appears in the CVS Repositories pallete.
6) Expand HEAD, and locate the project you imported earlier.
7) Right-click on the project, and click Checkout...
After a few seconds, the project checkout will have completed.
8) Switch back to the default (Java) perspective.
Your newly checked out project will be visible in the Package Explorer.
9) Since library references are imported, but not the libraries themselves, the project will have a red x on it to indicate problems. Click on the Problems palette (typically at the bottom of the Eclipse window) to determine your list of missing libraries.
10) Rclick on the project, select the Build Path submenu, and click Configure Build Path...
11) In the Properties for [Project Name] dialog box, the project referneces will be listed.
12) One-by-one, remove these outdated references and then use the Add External Jar... button to add a reference to a local copy of each jar.

You're done. You can now proceed to checkout, commit, update and synchronize files (below).


SECTION F: ECLIPSE PROJECT FILES CHECKOUT / COMMIT / UPDATE / SYNCHRONIZE

1) To checkout a file:
You don't. Just start editing a file. As soon as you save a change, the file (and it's containing folder / package) will be marked with a greater-than symbol:
>login.jsp

2) To commit a file:
* Right-click on the file, and from the Team submenu, click Commit...
* The Commit Files dialog will appear. Please provide a comment before saving. A recommended format would be Date, User, Platform/Machine, Action:
Date: 2006Nov08
User: John Smith
Platform: Linux
Action: Added blah blah blah to the file.
* Click Finish. The change will be committed.

3) To update a file / project (i.e. get latest).
* If you aren't worried about changes, you can just "get latest" for the entire project.
* Right click on the Project and from the Team submenu, click Update.
* This will update the entire Project to match the latest contents of the repository.

4) To synchronize with the repository
* If you are worried about changes and want the opportunity to diff your files, use this command
* Right click on the project or a specific file, and from the Team submenu, click Synchronize with Repository
* You will be asked to switch to the Team Repository perspective. Allow this.
* In the Synchronize palette, select files that require synchronization. Proceed to diff them, and then commit changes.

1 comment:

Unknown said...

I recognize this when off theme but I’m researching starting my very own blog as well as was thinking what all can be get create? I’m assuming using a blog just like yours would likely cost quite a penny? I’m not to internet experienced so I am not 100% good. Any ideas or advice would be greatly loved. CheersBest advertising Agency in the world | top advertising agencies in pakistan | Marketing Agency | pakistani matrimonial