alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (remotetest)

This example Scala source code file (remotetest) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

barerepo, command, command, could, it, location, location, logfile, scriptname, usage, user, user, workrepo, workrepo

The Scala remotetest source code



# 
# Remote build&test script.
# Author: Aleksandar Prokopec
# 


SCRIPTNAME="..:: RemoteTest ::.."
DESC="This script pushes the current git repo to a remote bare repo. \
It then checks out the source tree in a workspace repo and starts the\
 build and all the tests. It can also initialize the remote bare repo\
 and the workspace repo. It assumes that the current repo refspec has\
 been set for the remote bare repository - .git/config of the current\
 repo must have a remote called <server> and the corresponding master\
 branch. Git should, naturally, be installed on both systems.\
 "
USAGE="   Usage: remotetest (--help|--init|--all|--incr|--clear) <user>    [logfile]"



function title()
{
  echo
  echo $SCRIPTNAME
  echo
}

function usage()
{
  title
  echo $DESC
  echo 
  echo $USAGE
}


function error()
{
  echo $1
  echo "Failed."
  exit 1
}

function success()
{
  echo "Success!"
  exit 0
}

function instruct()
{
  usage
  error
}

function help()
{
  usage
  echo
  echo "Make sure you have git installed on both your computer and the server, as well as java and ant."
  echo "Add your ssh key to the list of authorized keys on the server (see .ssh dir in your home). This is not required, but makes life easier, as you will have to answer fewer passwords."
  echo "To initialize the remote repositories on a server 'server.url.com', see the following example:"
  echo
  echo "> tools/remotetest --init jack server.url.com ~jack/git-repos-dir/scala ~jack/tmp-build-dir/scala"
  echo
  echo "If you decide you no longer want this remote repository to be tracked (this also tries to delete remote repos on the server):"
  echo
  echo "> tools/remotetest --clear jack server.url.com ~jack/git-repos-dir/scala ~jack/tmp-build-dir/scala"
  echo 
  echo "Once the initialization is successful, simply run: "
  echo
  echo "> tools/remotetest --all jack server.url.com ~jack/git-repos-dir/scala ~jack/tmp-build-dir/scala"
  echo 
  echo "Optionally, build and test results will be saved into the logfile on the server (an additional, last argument). Be aware that problems arise should you push an ammended commit over a previously pushed commit - this has nothing to do with this script per se."
  echo
  echo "  Example workflow:"
  echo 
  echo "          -------------------          "
  echo "         |                   |         "
  echo "         V                   |         "
  echo "   init ---> [ all | incr ] ---> clear "
  echo
  echo "Complete argument list:"
  echo "  --help       prints this help"
  echo "  --init       initializes remote repos"
  echo "  --clear      deletes remote repos and removes the remote repo reference from local git repo"
  echo "  --all        pushes the newest version, checks it out at the server, cleans all, builds and tests"
  echo "  --incr       incremental does the same as --all, but does not clean the directory before testing"
}


if [ $# -lt 1 ]
then
  instruct
fi



if [ $# -lt 5 ]
then
  if [[ $1 = "--help" ]]
  then
    help
    success
  else
    instruct
  fi
fi

COMMAND=$1
USER=$2
LOCATION=$3
BAREREPO=$4
WORKREPO=$5
LOGFILE=$6


if [[ $COMMAND = "--help" ]]
then
  help
  success
fi




# 
# Init
# 


if [[ $COMMAND = "--init" ]]
then
  echo "Initializing."
  
  # init bare repo
  ssh $USER@$LOCATION "mkdir $BAREREPO"
  ssh $USER@$LOCATION "cd $BAREREPO; git init; git config --bool core.bare true"
  if [ $? -ne 0 ]
  then
    error "Could not initialize bare repo."
  fi
  
  # add remote bare repo
  git remote add $LOCATION $USER@$LOCATION:$BAREREPO
  
  # push to bare repo
  git push $LOCATION master
  if [ $? -ne 0 ]
  then
    error "Could not push to bare repo."
  fi
  
  # init and checkout work repo
  ssh $USER@$LOCATION "git clone $BAREREPO $WORKREPO"
  if [ $? -ne 0 ]
  then
    error "Could not init working repo."
  fi
  
  success
fi




# 
# Clear.
# 


if [[ $COMMAND = "--clear" ]]
then
  echo "Clearing remote and deleting remote repos."
  git remote rm $LOCATION
  ssh $USER@$LOCATION "rm -rf $BAREREPO"
  ssh $USER@$LOCATION "cd $WORKREPO; ant all.clean; rm -rf $WORKREPO"
  
  echo "Removed remote repo $LOCATION."
  success
fi




# 
# Test.
# 


if [[ $COMMAND = "--all" || $COMMAND = "--incr" ]]
then
  # proceed
  echo "Starting remote build and testing."
else
  error "Unrecognized command $COMMAND."
fi

# if it's not the init operation, proceed normally
# push to remote bare repo
git push $LOCATION master
if [ $? -ne 0 ]
then
  error "Could not push to bare repo - push from local machine failed."
fi

# remotely checkout the repo
ssh $USER@$LOCATION "cd $WORKREPO; git pull origin master"
if [ $? -ne 0 ]
then
  error "Could not remotely pull from bare repo to work repo."
fi

# clean the build dir if not incremental
if [[ $COMMAND = "--all" ]]
then
  ssh $USER@$LOCATION "cd $WORKREPO; ant all.clean"
fi

# run the build and tests
SET_ANT_OPTS='export ANT_OPTS="-XX:MaxPermSize=192M -Xmx1536m"; echo $ANT_OPTS'
echo "Set ant options command: $SET_ANT_OPTS"
ssh $USER@$LOCATION "cd $WORKREPO; $SET_ANT_OPTS; ant nightly | tee -a $LOGFILE"

success




Other Scala examples (source code examples)

Here is a short list of links related to this Scala remotetest source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.