newbie version control

U

Ueland

Hi I'm a newbie using winXP and working from console (no IDE). I've
started to experiment with simple classes and objects. As I understand
the name of the class must be same as the name of the file so if I
declare
class Point {...}
then I should save the file as Point.java

Let's say I've done that and now I want to test a new feature without
erasing the old version. So I want to save the new file version as
Point2.java. But this forces me to change all occurances of Point to
Point2, that is the classname, the constructors and so on.
class Point2 {...}

Is there any SIMPLE way to make different versions without having to
change the class name. (I've thought of using different packages but
that also complicates things).

Thanks Bob
 
D

Daniel Dyer

Hi I'm a newbie using winXP and working from console (no IDE). I've
started to experiment with simple classes and objects. As I understand
the name of the class must be same as the name of the file so if I
declare
class Point {...}
then I should save the file as Point.java

Let's say I've done that and now I want to test a new feature without
erasing the old version. So I want to save the new file version as
Point2.java. But this forces me to change all occurances of Point to
Point2, that is the classname, the constructors and so on.
class Point2 {...}

Is there any SIMPLE way to make different versions without having to
change the class name. (I've thought of using different packages but
that also complicates things).

Two really easy ways spring to mind. First you can just take a copy of
your whole source tree and work on that. Secondly, you could just rename
the old file out of the way and make, call it something like
"Point.java_old" so that it doesn't get picked up by the compiler but is
still there and can be reverted to it's old name if you want to use it
again.

This is a reasonable approach as you are getting started, but eventually
you will want to look into something like Subversion or CVS.

Dan.
 
R

Roedy Green

Is there any SIMPLE way to make different versions without having to
change the class name. (I've thought of using different packages but
that also complicates things).

no. Later in your career you will learn to use a version control
system so you can maintain several branches. See
http://mindprod.com/jgloss/cvs.html

the best you can do now is save under a variety of names, and copy one
of the old ones onto Point.java when you want to make it the active
version.
 
R

Roedy Green

the best you can do now is save under a variety of names, and copy one
of the old ones onto Point.java when you want to make it the active
version.

another way to do it is something like this:

xcopy *.* C:\version32
 
Z

zero

Hi I'm a newbie using winXP and working from console (no IDE).

Good! That's the best way to learn to write clean code. Later you may
use an IDE to be able to work faster, but to learn you should work with
a simple editor and compile from the command line.
I've
started to experiment with simple classes and objects. As I understand
the name of the class must be same as the name of the file so if I
declare
class Point {...}
then I should save the file as Point.java

Let's say I've done that and now I want to test a new feature without
erasing the old version. So I want to save the new file version as
Point2.java. But this forces me to change all occurances of Point to
Point2, that is the classname, the constructors and so on.
class Point2 {...}

Is there any SIMPLE way to make different versions without having to
change the class name. (I've thought of using different packages but
that also complicates things).

Sure, you just rename the old version. You can automate this with the
following Java program:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class VersionControl
{
public static void main(String[] args) throws Exception
{
File fFile = new File(args[0]);
int counter = 0;
File fDest = new File(args[0] + "." + counter);
while(fDest.exists())
fDest = new File(args[0] + "." + ++counter);

FileChannel in = null, out = null;
try
{
in = new FileInputStream(fFile).getChannel();
out = new FileOutputStream(fDest).getChannel();

in.transferTo( 0, in.size(), out);
}
finally
{
if (in != null)
in.close();
if (out != null)
out.close();
}
}
}

Just compile this, and run it like this:
java VersionControl Point.java

This will create a copy of Point.java on which you can work, and the old
version will be saved as Point.java.0 On subsequent calls you'll get
Point.java.1, Point.java.2, etc.

As an exercise, try to figure out how VersionControl works. Add a fail-
safe in case you forget to enter the filename as argument. Also add
some code to recover from I/O errors while trying to copy the file.
 
U

Ueland

Thanks, I'll certainly try this! I also came up with this simple
solution.

I create a batch filecalled point.bat

@echo off
xcopy %0%1 %0%2 /I
cd %0%2
cedt *.java

I put this file in C:\jex which is the root for my source code. Suppose
now that the files for my point project is inside the directory point1
(which is inside the root C:\jex). When I write
point 1 2
my batch file automatically creates the directory point2 which contains
a copy of all files in point1 directory. It also automatically makes
point2 my working directory (so that I can compile and run easily). It
also automatically opens all the new .java files in my favourite text
editor (Crimson editor cedt.exe).

(You can use your own favourite text editor but you must update the
Path environment variable so that it contains the path to your text
editor, and change cedt for something else, like TextPad if that is
your text editor).

Next time I want to work on a new version I go to the root (C:\jex) and
write
point 2 3
and so on.

Suppose now that I now start a new project called circle. I put all my
files inside the directory circle1 and make a copy of point.bat and
call it circle.bat. I don't have to change anything inside the bat
file.

This could be improved, so that I could have only one bat file instead
of one for each project, but I'm not a DOS wizard. Any ideas in this
direction would be appreciated.

Thanks Bob
 
Z

zero

Thanks, I'll certainly try this! I also came up with this simple
solution.

I create a batch filecalled point.bat

@echo off
xcopy %0%1 %0%2 /I
cd %0%2
cedt *.java

I put this file in C:\jex which is the root for my source code. Suppose
now that the files for my point project is inside the directory point1
(which is inside the root C:\jex). When I write
my batch file automatically creates the directory point2 which contains
a copy of all files in point1 directory. It also automatically makes
point2 my working directory (so that I can compile and run easily). It
also automatically opens all the new .java files in my favourite text
editor (Crimson editor cedt.exe).

(You can use your own favourite text editor but you must update the
Path environment variable so that it contains the path to your text
editor, and change cedt for something else, like TextPad if that is
your text editor).

Next time I want to work on a new version I go to the root (C:\jex) and
write
and so on.

Suppose now that I now start a new project called circle. I put all my
files inside the directory circle1 and make a copy of point.bat and
call it circle.bat. I don't have to change anything inside the bat
file.

This could be improved, so that I could have only one bat file instead
of one for each project, but I'm not a DOS wizard. Any ideas in this
direction would be appreciated.

Thanks Bob

I'm not a dos wizard either, that's why I used the Java program ;-)
The drawback to your batch file is that you need to know what numbers to use.
But otherwise it's certainly a workable solution, good thinking :)
 
J

jussij

Is there any SIMPLE way to make different versions without
having to change the class name.

I can think of at least two ways to achieve this result.

Option 1) Use version control

Option 2) Use the file system
c:\my projects\version1\Point.java
c:\my projects\version2\Point.java
....
c:\my projects\versionX\Point.java

Jussi Jumppanen
Author: Zeus for Windows Programmer's IDE
http://www.zeusedit.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top