brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [04/11] brooklyn-dist git commit: add some new scripts (which i find useful)
Date Mon, 08 Feb 2016 11:07:44 GMT
add some new scripts (which i find useful)


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/commit/43faec6b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/tree/43faec6b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/diff/43faec6b

Branch: refs/heads/master
Commit: 43faec6b9e5143e3e9e052e0060a61ac87001ef1
Parents: 3fb5160
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Feb 3 10:34:05 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Feb 3 10:37:42 2016 +0000

----------------------------------------------------------------------
 scripts/README.md        |   5 ++
 scripts/git-summary.sh   | 134 ++++++++++++++++++++++++++++++++++++++++++
 scripts/jstack-active.sh |  78 ++++++++++++++++++++++++
 scripts/mvnf.sh          |  80 +++++++++++++++++++++++++
 scripts/rsd.sh           |  35 +++++++++++
 5 files changed, 332 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/43faec6b/scripts/README.md
----------------------------------------------------------------------
diff --git a/scripts/README.md b/scripts/README.md
index 2852b1c..9a404ff 100644
--- a/scripts/README.md
+++ b/scripts/README.md
@@ -5,3 +5,8 @@ This folder contains a number of items that can assist developers of the project
 
 In general see comments at the start of each file and/or `--help` output when running it.
 
+You can install the `*.sh` files as commands (without the `.sh` suffix linked to these) to
your `bin` dir with:
+
+    for x in *.sh ; do sudo ln -s `pwd`/$x /usr/local/bin/${x%.sh}; done
+
+

http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/43faec6b/scripts/git-summary.sh
----------------------------------------------------------------------
diff --git a/scripts/git-summary.sh b/scripts/git-summary.sh
new file mode 100755
index 0000000..79bde93
--- /dev/null
+++ b/scripts/git-summary.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# displays a summary list of commits in your current repo vs upstream branch and upstream
master,
+# and of working tree changes Added, Modified, Deleted, or not in index ("??")
+
+THIS_COMMAND="$0 $@"
+
+while true; do
+  case $1 in
+    -o|--offline)
+      OFFLINE=true
+      ;;
+    -r|--recurse|--recursive)
+      RECURSE=true
+      ;;
+    -m|--master)
+      shift
+      UPSTREAM_MASTER=$1
+      MASTER_UPSTREAM_REPO=`echo $1 | cut -d / -f 1`
+      ;;
+    -h|--help)
+      cat <<EOF
+Usage: git-summary [--help] [-o|--offline] [-r|--recursive] [-m|--master REPO/BRANCH] [<path>]"
+
+This will display a one-line git log for differences between the local branch, the upstream

+repo and branch of the local branch, and the upstream/master or origin/master branch.  
+
+The following prefixes are shown on commits:
+
+  < means in upstream/master but not in your upstream branch (your upstream is behind
master)
+  > means in your upstream branch but not in upstream/master (your upstream is ahead of
master)
+  ^ means in your upstream branch but not locally (consider a pull)
+  * means local but not in the upstream branch (consider a push)
+
+The optional <path> one or more files or paths to look at.
+
+The following options are supported:
+
+  -o  to operate offline, skipping the fetch done by default (aka --offline)
+  -r  to recurse (aka --recurs{e,ive})
+  -m  to specify a master "repo/branch" to compare upstream with, or "" for none (aka --master);
+      defaults to "upstream/master" or "origin/master" (the first existing)
+ 
+
+EOF
+      exit 1
+      ;;
+    *)
+      break
+      ;;
+    esac
+    shift || break
+done
+
+# assume master is upstream/master or origin/master
+[ -n "${MASTER_UPSTREAM_REPO}" ] || \
+  MASTER_UPSTREAM_REPO=upstream && git config remote.${MASTER_UPSTREAM_REPO}.url
> /dev/null || \
+  MASTER_UPSTREAM_REPO=origin && git config remote.${MASTER_UPSTREAM_REPO}.url >
/dev/null || \
+  unset MASTER_UPSTREAM_REPO
+[ -z "${MASTER_UPSTREAM_REPO}" ] || \
+  [ -n "${UPSTREAM_MASTER}" ] || UPSTREAM_MASTER=${MASTER_UPSTREAM_REPO}/master
+[ -z "${MASTER_UPSTREAM_REPO}" ] || [ -n "${OFFLINE}" ] || \
+  git fetch ${MASTER_UPSTREAM_REPO}
+
+THIS_BRANCH_NAME=$(git symbolic-ref --short -q HEAD)
+if [ -z "${THIS_BRANCH_NAME}" ] ; then
+  THIS_BRANCH_NAME="(DETACHED)"
+  unset THIS_UPSTREAM_BRANCH
+else
+  THIS_UPSTREAM_BRANCH=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref
-q HEAD))
+  THIS_UPSTREAM_BRANCH_REPO=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref
-q HEAD) | cut -f 1 -d '/')
+  # fetch the branch's upstream repo if different to the master
+  [ -n "${OFFLINE}" ] || [ -z "${THIS_UPSTREAM_BRANCH_REPO}" ] || [ "${THIS_UPSTREAM_BRANCH_REPO}"
== "${MASTER_UPSTREAM_REPO}" ] || git fetch ${THIS_UPSTREAM_BRANCH_REPO}
+fi
+[ \! -z "${THIS_UPSTREAM_BRANCH}" ] && THIS_UPSTREAM_BRANCH_NAME="${THIS_UPSTREAM_BRANCH}"
|| THIS_UPSTREAM_BRANCH_NAME="(no upstream)"
+
+TMP=/tmp/git-summary-$(uuidgen)
+rm -f ${TMP}-*
+touch ${TMP}-{1-master-ahead,2-master-behind,3-up,4-local}
+
+if [ -z "${UPSTREAM_MASTER}" -a -z "$THIS_UPSTREAM_BRANCH" ] ; then
+  true # nothing to do
+elif [ "${UPSTREAM_MASTER}" == "$THIS_UPSTREAM_BRANCH" -o -z "$THIS_UPSTREAM_BRANCH" ] ;
then
+  [ -z "${UPSTREAM_MASTER}" ] || git log --pretty=" ^ %h %aN, %ar: %s" ..${UPSTREAM_MASTER}
"$@" > ${TMP}-3-up
+  [ -z "${UPSTREAM_MASTER}" ] || git log --pretty=" * %h %aN, %ar: %s" ${UPSTREAM_MASTER}..
"$@" > ${TMP}-4-local
+else
+  [ -z "${UPSTREAM_MASTER}" ] || git log --pretty=" < %h %aN, %ar: %s" $THIS_UPSTREAM_BRANCH..${UPSTREAM_MASTER}
"$@" > ${TMP}-1-master-ahead
+  [ -z "${UPSTREAM_MASTER}" ] || git log --pretty=" > %h %aN, %ar: %s" ${UPSTREAM_MASTER}..$THIS_UPSTREAM_BRANCH
"$@" > ${TMP}-2-master-behind
+  git log --pretty=" ^ %h %aN, %ar: %s" ..$THIS_UPSTREAM_BRANCH "$@" > ${TMP}-3-up
+  git log --pretty=" * %h %aN, %ar: %s" $THIS_UPSTREAM_BRANCH.. "$@" > ${TMP}-4-local
+fi
+git status --porcelain --ignore-submodules "$@" > ${TMP}-5-commits
+cat ${TMP}-* > ${TMP}
+if [ -s ${TMP} ] ; then
+  AHEAD=$(wc ${TMP}-1-* | awk '{print $1}')
+  BEHIND=$(wc ${TMP}-2-* | awk '{print $1}')
+  UP=$(wc ${TMP}-3-* | awk '{print $1}')
+  LOCAL=$(wc ${TMP}-4-* | awk '{print $1}')
+  [ "${AHEAD}" == "0" ] || COUNTS="upstream ${AHEAD} behind master"
+  [ "${BEHIND}" == "0" ] || COUNTS="${COUNTS}${COUNTS:+, }upstream ${BEHIND} ahead of master"
+  [ "${UP}" == "0" ] || COUNTS="${COUNTS}${COUNTS:+, }local ${UP} behind"
+  [ "${LOCAL}" == "0" ] || COUNTS="${COUNTS}${COUNTS:+, }local ${LOCAL} unpushed"
+  echo $(basename $(pwd))": ${THIS_BRANCH_NAME} <- ${THIS_UPSTREAM_BRANCH_NAME} (${COUNTS:-uncommitted
changes only})"
+  cat ${TMP} | sed 's/^/ /'
+else
+  echo $(basename $(pwd))": ${THIS_BRANCH_NAME} <- ${THIS_UPSTREAM_BRANCH_NAME} (up to
date)"
+fi
+rm -f ${TMP} ${TMP}-*
+
+# submodules ignored; if using them, set up
+
+if [ "$RECURSE" ] ; then
+  echo
+  git submodule --quiet foreach --recursive "${THIS_COMMAND}"
+fi
+

http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/43faec6b/scripts/jstack-active.sh
----------------------------------------------------------------------
diff --git a/scripts/jstack-active.sh b/scripts/jstack-active.sh
new file mode 100755
index 0000000..16646b4
--- /dev/null
+++ b/scripts/jstack-active.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# displays a jstack thread dump showing only "really-running" threads
+#
+# takes a PID as argument
+# filters jstack to remove wait/blocked threads and known
+# wait points which report themselves as active (e.g. socket.read)
+#
+# very useful for spot-checking what is *actually* consuming CPU
+
+
+jstack $@ | awk '
+function onTraceBegin() {
+	onTraceEnd()
+	data["lineCount"]=0
+	data["head"]=$0
+}
+
+function onTraceEnd() {
+	if ("head" in data) {
+		if (data["active"] && "topClass" in data) {
+			print data["head"]
+			for (l=1; l<=data["lineCount"]; l++) { print lines[l] }
+			print ""
+		}
+	}
+	delete lines
+	delete data
+}
+
+function startsWith(whole,prefix) {
+	return (substr(whole,1,length(prefix))==prefix);
+}
+
+{
+  if (!match($0,"[^\\s]")) onTraceEnd();
+  else if (substr($0,1,1)=="\"") onTraceBegin();
+  else if ("head" in data) {
+	lc = ++data["lineCount"];
+	lines[lc]=$0
+	if (lc==1) {
+		state=data["state"]=$2;
+		data["active"] = !(state=="WAITING" || state=="BLOCKED" || state=="TIMED_WAITING")
+	}
+	if ($1=="at") {
+		if ("topClass" in data) {
+		} else {
+			data["topClass"] = $0;
+			tc = $2;
+			if (data["active"]) {
+				if (startsWith(tc,"java.net") || startsWith(tc,"sun.nio")) data["active"]=false;
+			}
+		}
+	}
+  }
+}
+END {
+	onTraceEnd();
+}
+'

http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/43faec6b/scripts/mvnf.sh
----------------------------------------------------------------------
diff --git a/scripts/mvnf.sh b/scripts/mvnf.sh
new file mode 100755
index 0000000..bcd95cf
--- /dev/null
+++ b/scripts/mvnf.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# runs mvn fast in several dirs; run with `-h` for more info
+
+
+export DIRS=""
+export ARGS="-o clean install -DskipTests"
+if [[ -z $1 || $1 = "-h" || $1 == "--help" ]] ; then
+  echo
+  echo "MVNF: a simple script for building multiple maven directories"
+  echo
+  echo "usage:  mvnf [ -x \"install -Dxxx\" ] dir1 [ dir2 [ ... ]]"
+  echo
+  echo "This will do a maven build in each directory specified, in order, "
+  echo "giving arguments '-o clean install -DskipTests' to mvn by default "
+  echo "or other arguments if supplied in the word following -x at start. "
+  echo "The script aborts if any build fails, giving the last return code "
+  echo "code, and returning to the directory where it was invoked."
+  echo
+  echo "eg: \`mvnf ../other . && ./target/dist/run.sh\`"
+  echo "    will build other, then build ., then run a just-build script "
+  echo "    if all went well (but if it fails you'll see that too)"
+  echo
+  if [ -z $1 ] ; then exit 1 ; fi
+  exit 0
+fi
+if [ $1 = "-x" ] ; then
+  shift
+  export ARGS=$1
+  shift
+fi
+echo "MVNF: running \`mvn $ARGS\` on: $@"
+for x in $@
+do
+  if [ ! -d $x ] ; then
+    export RETVAL=1
+    echo "MVNF: no such directory $x"
+    break
+  fi
+  if [ ! -f $x/pom.xml ] ; then
+    export RETVAL=1
+    echo "MVNF: no pom available in $x"
+    break
+  fi
+  pushd $x > /dev/null
+  export DIR=`basename \`pwd\``
+  echo "MVNF: building $DIR (${x})"
+  mvn $ARGS
+  export RETVAL=$?
+  export DIRS="${DIRS}${DIR} "
+  echo
+  popd > /dev/null
+  if [ $RETVAL != 0 ] ; then 
+    echo "MVNF: mvn failed in directory $DIR (${x})"
+    break
+  fi
+done
+if [ $RETVAL = 0 ] ; then
+  echo MVNF: successfully built $DIRS
+fi
+test ${RETVAL} = 0

http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/43faec6b/scripts/rsd.sh
----------------------------------------------------------------------
diff --git a/scripts/rsd.sh b/scripts/rsd.sh
new file mode 100755
index 0000000..effb5e4
--- /dev/null
+++ b/scripts/rsd.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# executes the command supplied as an argument in a tmp directory rsynched against the current
directory
+# the tmp is a hash of `pwd` so the target will be the same on multiple runs
+# esp useful when running something like `rsd mvn clean install` 
+# but you don't want your IDE or other changes to interfere
+
+ORIG=`pwd`
+DIR=`basename $(pwd -P)`-`pwd | md5sum | awk '{print $1}'`
+mkdir -p /tmp/$DIR/
+pushd /tmp/$DIR/ > /dev/null
+echo executing \'$@\' in `pwd` as a copy of $ORIG 
+rsync -a --delete $ORIG/ .
+"$@"
+# not necessary as command invoked in subshell
+# popd > /dev/null
+


Mime
View raw message