#!/bin/bash
#
#------------------------------------------------------------------------
#
# Module  Name  : migrate.sh.sh
# Start Date    : 2003/07/26
#
#------------------------------------------------------------------------
# History:
# userid    : date       : Comment
# mcg     : 2003/07/26 : Creation
#
#------------------------------------------------------------------------

# Precondition checks
if [ $# -ne 1 -a $# -ne 2 ]; then
	echo "Usage $1 <diaplytagpath> [-f]"
	exit 1
fi

# Setting var names
ORIG=$1
DEST=displaytag-maven
TEMPLATES=templates

if [ "$2" = -f ]; then
	rm -r $DEST
fi

if [ ! -d $ORIG ]; then
	echo "Sorry $ORIG directory not found. Aborting..."
	exit 1
fi

if [ -a $DEST ]; then
	echo "Sorry $DEST already exists. I won't kill it by my own. Aborting..."
	exit 1
fi



# Safe now? Start running the beast
echo "Ok: Processing displaytag migration from '$ORIG' to '$DEST'"
mkdir $DEST

cp -r $TEMPLATES/* $DEST

echo "Ignoring Lib (delegated to Maven)"
SRC=$ORIG/lib

echo "Processing site"
SRC=$ORIG/site
cp -r $SRC/src/* $DEST/example/src/main/java/
cp -r $SRC/web/* $DEST/example/src/webapp/

echo "Processing src"
SRC=$ORIG/src/*
cp -r $SRC $DEST/display/src/main/java/

echo "Processing tld"
SRC=$ORIG/tld/displaytag.tld 
cp -r $SRC $DEST/display/src/conf/META-INF/taglib.tld

echo "Purging CVS directories."
find $DEST -name CVS -exec rm -r {} \; 2> /dev/null

echo "Updating 'init.jsp' and 'web.xml'"
mv $DEST/example/src/webapp/inc/new_init.jsp $DEST/example/src/webapp/inc/init.jsp
mv $DEST/example/src/webapp/WEB-INF/new_web.xml $DEST/example/src/webapp/WEB-INF/web.xml

echo "Finished!"
cat  <<EOC
Ok the migration is finished.

Now the Display tag library should be Maven-b10 compliant.
As described in the Maven guidelines, the project has been splitted
depending on the artifacts to create: 
  - the example project, which depends on the 
  - display project

The following maven commands could be usefull:
	$ maven -g                            display goals
	$ maven                               default execution
	$ maven ant:generate-build            Create Ant build file
	$ maven jar:jar                       Create  the jar file
	$ maven site:generate                 Create  the jar file
	
	Also checks in the docs:
	$ maven jar:install                   
	$ maven jar:install-snapshot               

On each project, a simple call to "maven" will:
	- for display tag:
		- clean target
		- create the jar,
		- create the site
		- publish snpashot in local repository
	- for display tag example:
		- clean target
		- create the war,
		- create the site
	

What has been done:
	- Splitting  the project into 2 sub projects display and example
	- prepare the maven files
	- Use license.jsp for the LICENSE.txt file
	- displaytag.tld is renamed taglib.tdl and included into the jar's 
	  META-INF 
      see: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags6.html
    - webapp/inc/init.jsp updated accordingly as well as 
	  webapp/WEB-INF/web.xml
	- maven.xml files on both projects ccreated ot ease the build process

Remarks and TODO:
	- The sample.Wrapper seems to have a problem with the getDate method.
	- The example site will have to be updated since some information are 
	  now duplicated on the maven generated sites
	 

EOC



