Permalink
Browse files

Initial source checkin

  • Loading branch information...
Simon
Simon committed Oct 6, 2011
0 parents commit 1ca202d5d8ae7cfcb802926e83705c3ac6960816
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/groovy"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="eclipse-build"/>
</classpath>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>bpipe</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,12 @@
#Tue Oct 04 09:04:24 EST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
187 bin/bpipe
@@ -0,0 +1,187 @@
#!/bin/bash
#
# Bpipe Runner Script
#
# Locate Bpipe's home directory
# Need something more sophisticated to deal with symbolic links?
BPIPE_HOME=`dirname $0`/..
# Default directory for pipes - user can override by setting BPIPE_LIB themselves
: ${BPIPE_LIB:="$HOME/bpipes"}
# Last bpipe commands
if [ ! -e .bpipe ];
then
mkdir -p .bpipe/logs
fi
COMMAND="$1"
TESTMODE=""
# If the only argument is "retry" then actually just run the previous
if [ "$COMMAND" == "retry" ]
then
shift 1
if [ -e .bpipe/lastcmd ];
then
bash < .bpipe/lastcmd
fi
exit
elif [ "$COMMAND" == "history" ];
then
shift 1
if [ -e .bpipe/history ];
then
cat .bpipe/history
else
echo
echo "No history found"
echo
fi
exit
elif [ "$COMMAND" == "log" ];
then
# TODO: will fail if spaces in path
ls -tc .bpipe/logs/*.log | grep -v 'bpipe\.' | head -1 | xargs tail -f
exit
elif [ "$COMMAND" == "jobs" ];
then
if [ -e ~/.bpipedb/jobs/ ];
then
for i in ~/.bpipedb/jobs/* _ ;
do
[ "$i" != _ ] &&
echo `basename $i`" : "`cat $i`
done
fi
exit
elif [ "$COMMAND" == "run" ];
then
shift 1
elif [ "$COMMAND" == "test" ];
then
shift 1
TESTMODE="-t"
COMMAND="run"
fi
################# Default Command => Run ################
echo "$0 $COMMAND $*" > .bpipe/lastcmd
echo "$0 $COMMAND $*" >> .bpipe/history
CP="$BPIPE_HOME"/lib/bpipe.jar:"$BPIPE_HOME"/lib/groovy-all-1.8.2.jar:$BPIPE_HOME/lib/commons-cli-1.2.jar:"$BPIPE_LIB"
# Run in the background with nohup so that jobs do not abort on logout
nohup java -classpath "$CP" -Dbpipe.pid=$$ bpipe.Runner $TESTMODE $* > .bpipe/logs/$$.log 2>&1 &
BPIPE_PID="$!"
# Save the job in the local folder, linked to its PID
mkdir -p .bpipe/jobs
echo "$0 $COMMAND $*" >> .bpipe/jobs/$$
# Save the job in the user's home .bpipe folder - this allows the user to query
# what jobs they have running from anywhere
# Note that it is up to the Java code to remove this when it shuts down
mkdir -p ~/.bpipedb/jobs
ln -s `pwd`/.bpipe/jobs/$$ ~/.bpipedb/jobs/$$
# Kill a whole tree of processes
# for some children it happens automatically, but for some it doesn't
killtree() {
local ppid=$1
# Sadly Mac OS/X does not seem to support --ppid option in default version
# of ps
if uname | grep -q Darwin;
then
pids=`ps -o pid,ppid | grep '^[0-9]' | grep ' '$ppid | cut -f 1 -d ' '`
else
pids=$(ps -o pid --no-headers --ppid ${ppid})
fi
if [ ! -z "$pids" ];
then
for child_pid in ${pids};
do
killtree ${child_pid}
done
fi
kill -TERM ${ppid}
}
# Look for files marked dirty and clean them up
cleanup() {
# Check for any unclean files in .bpipe/unclean
if [ -f .bpipe/unclean ];
then
for f in `cat .bpipe/unclean`;
do
if [ -e "$f" ];
then
target=".bpipe/trash/$f"
echo "Moving unclean file $f to $target"
echo
if [ ! -d .bpipe/trash ];
then
mkdir -p .bpipe/trash
fi
if [ -e "$target" ];
then
echo "WARN: Overwriting target $target"
echo
rm "$target"
fi
mv "$f" ".bpipe/trash/$f"
fi
done
fi
}
# Signal handler that intercepts Ctrl+C
function end() {
if kill -0 $BPIPE_PID ;
then
echo
read -p "Pipeline job running as process $BPIPE_PID. Terminate? (y/n): "
if [ "$REPLY" == "y" ];
then
echo
echo "Terminating process $BPIPE_PID ..."
killtree $BPIPE_PID
# Don't carry on until Bpipe actually finishes
wait $BPIPE_PID > /dev/null 2>&1
echo
cleanup
fi
fi
if kill -0 $TAIL_PID ;
then
kill $TAIL_PID
fi
exit
}
# Set up signal handler to trap Ctrl-C so that we can cleanly abort the job
trap end SIGINT
# Tail the output so that the user sees it
tail -f .bpipe/logs/$$.log &
TAIL_PID="$!"
# Wait for the Java Bpipe process to finish naturally (not Ctrl-C, see above for that)
wait $BPIPE_PID
# Seems like The Java Bpipe process ended by itself: kill the background tail process
# started above
if kill -0 $TAIL_PID ;
then
kill $TAIL_PID
fi
@@ -0,0 +1,35 @@
apply plugin: 'eclipse'
apply plugin: 'groovy'
VERSION=0.1
STAGE="build/stage/bpipe-$VERSION"
repositories {
mavenCentral()
}
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.2'
testCompile group: 'junit', name: 'junit', version: '4.8.2'
}
task stage(dependsOn: jar) << {
ant.mkdir(dir: STAGE)
ant.mkdir(dir: "$STAGE/bin")
ant.mkdir(dir: "$STAGE/lib")
ant.copy(todir: "$STAGE/bin") {
ant.fileset(dir: 'bin', includes: "**")
}
ant.copy(todir: "$STAGE/lib") {
ant.fileset(dir: 'local-lib', includes: "*.jar")
ant.fileset(dir: 'build/libs', includes: "bpipe.jar")
}
}
task dist(dependsOn: stage) << {
ant.tar(destfile: "build/bpipe-${VERSION}.tar") {
ant.fileset(dir: "build/stage", includes: "bpipe-${VERSION}/lib/**", excludes:"**/*.swp")
ant.tarfileset(dir: "build/stage", filemode:"755", includes: "bpipe-${VERSION}/bin/**", excludes:"**/*.swp")
}
ant.gzip(destfile:"build/bpipe-${VERSION}.tar.gz", src: "build/bpipe-${VERSION}.tar")
}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,63 @@
/*
* Copyright (c) Murdoch Childrens Research Institute and Contributers
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package bpipe
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
/**
* The default Java log former uses a format that is too verbose, so
* replace it with something more compact.
*/
public class BpipeLogFormatter extends Formatter {
private static final String lineSep = System.getProperty("line.separator");
/**
* A Custom format implementation that is designed for brevity.
*/
public String format(LogRecord record) {
DateFormat format = new SimpleDateFormat("h:mm:ss");
String loggerName = record.getLoggerName();
if(loggerName == null) {
loggerName = "root";
}
StringBuilder output = new StringBuilder()
.append(loggerName)
.append("\t")
.append(record.getLevel()).append("\t|")
.append(format.format(new Date(record.getMillis())))
.append(record.getMessage()).append(' ')
.append(lineSep);
return output.toString();
}
}
Oops, something went wrong.

0 comments on commit 1ca202d

Please sign in to comment.