File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes 	Integrating a simple HelloWorld project with Subversion, CuriseControl. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "	Integrating a simple HelloWorld project with Subversion, CuriseControl." Watch "	Integrating a simple HelloWorld project with Subversion, CuriseControl." New topic
Author

 Integrating a simple HelloWorld project with Subversion, CuriseControl.

Abhishek khare
Greenhorn

Joined: Aug 08, 2007
Posts: 25
Prerequisite of the HelloWorld project.

1. The HelloWorld Project should have two folders—‘src’ (for placing your java sources) and ‘lib’ (for placing all the jar files being used in the project).
2. It should have two xml files— ‘build1.xml’ (will be used to checkout the latest code from the SVN repository) and ‘build2.xml’ (will be used to compile the project, run Junits, generate result and create the project jar file.
3. Unzip the svnant-1.2.1.zip in the C: drive of your machine.
4. Place the junit-4.6.jar in the lib folder of HelloWorld project.
5. Below is the java code used for the project.
**********************************************************************************
HelloWorld.java
package xptoolkit;
import xptoolkit.model.GreetingFactory;
import xptoolkit.model.Greeting;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class HelloWorld{

public static void main(String []args)throws Exception{
Greeting greet = (Greeting)
GreetingFactory.getGreetingFactory().getGreeting();
System.out.println(greet.getGreeting());

}
}
**********************************************************************************
Greeting.java
package xptoolkit.model;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public interface Greeting extends java.io.Serializable{
public String getGreeting();
}
**********************************************************************************
GreetingBean.java
package xptoolkit.model;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class GreetingBean implements Greeting{

public GreetingBean(){}

public String getGreeting(){
return "Hello World!";
}
}
**********************************************************************************
GreetingFactory.java
package xptoolkit.model;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class GreetingFactory {
private GreetingFactory(){}

public Greeting getGreeting()throws Exception {
String clazz = System.getProperty("Greeting.class",
"xptoolkit.model.GreetingBean");
return (Greeting)Class.forName(clazz).newInstance();
}

public static GreetingFactory getGreetingFactory(){
return new GreetingFactory();
}

}
**********************************************************************************
MyMath.java
package math;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class MyMath {
public int multi(int number1, int number2) {
return number1 * number2;
}
}
**********************************************************************************
MyMathTest.java
package xptoolkit.junit.example;

import junit.framework.*;
import math.MyMath;

/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class MyMathTest extends TestCase {
/**
* @return
*/
public static Test suite() {
return new TestSuite(MyMathTest.class);
}
/**
* @param args
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
private static final int VALUE_1 = 5;
private static final int VALUE_2 = 10;
private static final int RESULT = 50;

/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() {
}
/**
* @Test
*/

public void testMulti() {
MyMath math = new MyMath();
assertEquals(RESULT, math.multi(VALUE_1, VALUE_2));
}
/**
*
*/
}
**********************************************************************************
HashMapTest.java
package xptoolkit.junit.example;
import junit.framework.*;
import java.util.Map;
import java.util.HashMap;
import junit.extensions.*;

/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class HashMapTest extends TestCase {
private Map testMap;
private Map testMap2;
/**
* @return
*/
public static Test suite() {
return new TestSuite(HashMapTest.class);
}
/**
* @param args
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
private static final String APPLE_KEY = "AppleCEO";
private static final String APPLE_VALUE = "AppleCEO";

/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() {
testMap = new HashMap();
testMap.put(APPLE_KEY, APPLE_VALUE);
testMap.put("OracleCEO", "Larry Ellison");
testMap2 = new HashMap();
testMap2.put("1", "1");
testMap2.put("2", "2");
}
/**
*
*/
public void testPut() {
String key = "Employee";
String value = "Rick Hightower";
// put the value in
testMap.put(key, value);
// read the value back out
String value2 = (String) testMap.get(key);
assertEquals("The value back from the map ", value, value2);
}
/**
*
*/
public void testSize() {
assertEquals(2, testMap.size());
}
/**
*
*/
public void testGet() {
assertEquals(APPLE_VALUE, testMap.get(APPLE_KEY));
assertNull(testMap.get("JUNK_KEY"));
}
/**
*
*/
public void testPutAll() {
testMap.putAll(testMap2);
assertEquals(4, testMap.size());
assertEquals("1", testMap.get("1"));
testGet();
}
/**
*
*/
public void testContainsKey() {
assertTrue("It should contain the apple key", testMap
.containsKey(APPLE_KEY));

}
/**
*
*/
public void testContainsValue() {
assert (testMap.containsKey(APPLE_VALUE));
}
/**
*
*/
public void testRemove() {
String key = "Employee";
String value = "Rick Hightower";
// put the value in
testMap.put(key, value);
// remove it
testMap.remove(key);
// try to read the value back out
assertNull(testMap.get(key));
}
}
**********************************************************************************
HashMap1Test.java
package xptoolkit.junit.example;

import junit.framework.*;
import java.util.Map;
import java.util.HashMap;
import junit.extensions.*;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class HashMap1Test extends TestCase {
private Map testMap;
private Map testMap2;
/**
* @return
*/
public static Test suite() {
return new TestSuite(HashMap1Test.class);
}
/**
* @param args
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
private static final String APPLE_KEY = "AppleCEO";
private static final String APPLE_VALUE = "AppleCEO";

/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() {
testMap = new HashMap();
testMap.put(APPLE_KEY, APPLE_VALUE);
testMap.put("OracleCEO", "Larry Ellison");
testMap2 = new HashMap();
testMap2.put("1", "1");
testMap2.put("2", "2");
}
/**
*
*/
public void testPut() {
String key = "Employee";
String value = "Rick Hightower";
// put the value in
testMap.put(key, value);
// read the value back out
String value2 = (String) testMap.get(key);
assertEquals("The value back from the map ", value, value2);
}
/**
*
*/
public void testSize() {
assertEquals(2, testMap.size());
}
/**
*
*/
public void testGet() {
assertEquals(APPLE_VALUE, testMap.get(APPLE_KEY));
assertNull(testMap.get("JUNK_KEY"));
}
/**
*
*/
public void testPutAll() {
testMap.putAll(testMap2);
assertEquals(4, testMap.size());
assertEquals("1", testMap.get("1"));
testGet();
}
/**
*
*/
public void testContainsKey() {
assertTrue("It should contain the apple key", testMap
.containsKey(APPLE_KEY));

}
/**
*
*/
public void testContainsValue() {
assert (testMap.containsKey(APPLE_VALUE));
}
/**
*
*/
public void testRemove() {
String key = "Employee";
String value = "Rick Hightower";
// put the value in
testMap.put(key, value);
// remove it
testMap.remove(key);
// try to read the value back out
assertNull(testMap.get(key));
}
}
**********************************************************************************
AllTests.java
package xptoolkit.junit.example;

import junit.framework.Test;
import junit.framework.TestSuite;
/**
*
* @author Abhishek Khare
* @version 1.0
*/
public class AllTests {

public static Test suite() {
TestSuite suite = new TestSuite("Test for xptoolkit.junit.example");
//$JUnit-BEGIN$
suite.addTest(HashMapTest.suite());
suite.addTest(HashMap1Test.suite());
suite.addTest(MyMathTest.suite());
//$JUnit-END$
return suite;
}

}
**********************************************************************************
6. Code for build1.xml.
<project name="svn-test" default="Main">
<import file="build2.xml" />
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="checkout" location="c:\temp\svncheckout\HelloWorld" />
<property name="output.type" value="html" />

<!--tell Ant how to find your SVNAnt task -->
<target name="SetSVNAnt">
<path id="svnant.classpath">
<fileset dir="C:\svnant-1.2.1\lib">
<include name="*.jar" />
</fileset>
</path>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" />
<echo message="SvnAnt Configuration complete" />
</target>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${checkout}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${checkout}" />
</target>
<!-- Checkout the latest source code of svnant itself-->
<target name="SVNAnt">
<svn username="abhi" password="abhi">
<checkout url="http://localhost:81/svn/HelloWorld/" revision="HEAD" destPath="${checkout}" />
</svn>
<echo message="Subversion repository url: ${repository.url}" />
</target>
<target name="Main" depends="clean, makedir, SetSVNAnt,SVNAnt,all">
<description>Main target</description>
</target>
</project>

7. Code for build2.xml.
<project name="model" default="all">
<!-- root of the java code tree -->
<property name="java" value="./"/>
<property name="src" value="${java}\src"/> <!-- the zap source tree -->
<property name="lib" value="${java}\lib"/> <!-- all third party jars -->
<property name="classes" value="${java}\classes"/> <!-- compiler output path -->

<!-- compiler classpath, include all third party libraries -->
<path id="build.classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="init" description="initialize the properties.">
<echo message="****************" />
<echo message="INIT Start" />
<echo message="****************" />
<tstamp />
<property name="outdirJunit" value="${classes}/junitSample" />
<echo message="****************" />
<echo message="INIT End" />
<echo message="****************" />
</target>
<target name="clean" depends="init" description="clean up the output directories and jar.">
<echo message="****************" />
<echo message="CLEAN Start" />
<echo message="****************" />
<delete dir="${classes}" />
<echo message="****************" />
<echo message="CLEAN End" />
<echo message="****************" />
</target>
<target name="prepare" depends="init" description="prepare the output directory.">
<echo message="****************" />
<echo message="PREPARE Start" />
<echo message="****************" />
<mkdir dir="${classes}" />
<mkdir dir="${outdirJunit}" />
<echo message="****************" />
<echo message="PREPARE End" />
<echo message="****************" />
</target>
<target name="compile" depends="prepare" description="compile the Java source.">
<echo message="****************" />
<echo message="COMPILE Start" />
<echo message="****************" />
<javac srcdir="${src}" destdir="${classes}">
<classpath refid="build.classpath"/>
</javac>
<javac srcdir="." destdir="${outdirJunit}">
<classpath refid="build.classpath"/>
</javac>

<echo message="****************" />
<echo message="COMPILE End" />
<echo message="****************" />
</target>
<target name="test" depends="compile">
<echo message="****************" />
<echo message="TEST Start" />
<echo message="****************" />
<mkdir dir="target/test-classes"/>
<javac srcdir="." destdir="target/test-classes">
<classpath refid="build.classpath"/>
<classpath>
<pathelement location="target/classes"/>
</classpath>
</javac>
<mkdir dir="target/test-results"/>
<junit haltonfailure="no" printsummary="on">
<classpath >
<pathelement location="target/classes"/>
<pathelement location="lib/junit-4.6.jar"/>
<pathelement location="target/test-classes"/>
</classpath>
<formatter type="brief" usefile="false"/>
<formatter type="xml" />
<batchtest todir="target/test-results" >
<fileset dir="target/test-classes" includes="**/*Test.class"/>
</batchtest>
</junit>
<echo message="Junit" />
<echo message="****************" />
<echo message="TEST End" />
<echo message="****************" />
</target>
<target name="jar" depends="compile">
<jar jarfile="target/HelloWorld.jar" basedir="./classes"/>
</target>
<target name="all" depends="clean,prepare,compile,test,jar" description="perform all targets.">
<echo message="Running the Build2.xml" />
</target>

</project>

Configure HelloWorld into Subversion repository
1. In the SVN repository (c:\svn) create a folder HelloWorld.
2. As described above create a SVN repository inside HelloWorld folder.
3. Now create a folder ‘Project Repository’ (This is the place where you keep the base code for your project).
4. Copy the HelloWorld code into the Project Repository folder.
5. Select the HelloWorld folder and access the Repo-browser of TortoiseSVN.
6. In the url put http://localhost:81/svn/HelloWorld/ location where we have created the SVN repository.
7. The TortoiseSVN will prompt you to enter the UserId/Password. Enter the UserId/Password you created above.
8. On the next screen choose the Checkout… option.
9. On the checkout dialog box browse to the HelloWorld project inside the Project Repository. Click ok to checkout the project.
10. Use the TortoiseSVN to commit the project you have just added.

Configure HelloWorld into CruiseControl.
1. Open the Directory C:\cc-sandbox\cruisecontrol-bin-2.8\projects. In this directory create a folder ‘HelloWorld’
2. Right-click on the folder and user TortoiseSVN to checkout the HelloWorld project.
3. You have now successfully placed your HelloWorld project in your CruiseControl repository.
4. In order to hook the HelloWorld project with CruiseControl, open the Config.xml (C:\cc-sandbox\cruisecontrol-bin-2.8).
5. Edit the Config.xml to hook the HelloWorld project. The edited Config.xml is attached below:
6. Restart the cruisecontrol.bat.
7. Access the link : http://localhost:8080/cruisecontrol/, to confirm that the project has got properly hooked to CruiseControl.
8. Click on the HelloWorld link to see the details of the build process.
9. Click the Test results tab, to check the test result status.
11. Your SVN project for HelloWorld has been created, you can view the project by accessing the following link: http://localhost:81/svn/HelloWorld/


Integrating a simple HelloWorld project with Subversion, CuriseControl. Example


"Things come to those who wait, but only the things left by those who hustle."
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there,

Again this looks useful, can you please post it to the wiki for permanent sharing, thanks!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
 
subject:  Integrating a simple HelloWorld project with Subversion, CuriseControl.