Add utility to toggle project activation 10/70210/3
authorStephen Kitt <skitt@redhat.com>
Fri, 30 Mar 2018 07:28:32 +0000 (00:28 -0700)
committerJamo Luhrsen <jluhrsen@redhat.com>
Sun, 1 Apr 2018 05:20:44 +0000 (05:20 +0000)
This adds a toggle-project script which uses xmlstarlet to toggle
projects’ activation, and {disable,enable}-project scripts to
respectively disable and enable projects.

Change-Id: Ic2bca4ee8596387a3b449dae314aa0a26d4b5602
Signed-off-by: Stephen Kitt <skitt@redhat.com>
disable-project [new file with mode: 0755]
enable-project [new file with mode: 0755]
toggle-project [new file with mode: 0755]

diff --git a/disable-project b/disable-project
new file mode 100755 (executable)
index 0000000..ca4b49a
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -e
+
+if [ $# -lt 1 ]; then
+  echo "$0 <project> [<project> ...]"
+  echo disables the named projects.
+  exit 1
+fi
+
+while [ -n "$1" ]; do
+  echo -n "Processing $1... "
+  for file in $(git grep -l "<id>$1</id>"); do
+    xmlstarlet ed -P -N mvn=http://maven.apache.org/POM/4.0.0 \
+      -u //mvn:profile[mvn:id=\"$1\"]/mvn:activation/mvn:activeByDefault \
+      -v false "${file}" > "${file}.new"
+    mv "${file}"{.new,}
+  done
+  echo done.
+  shift
+done
diff --git a/enable-project b/enable-project
new file mode 100755 (executable)
index 0000000..0c17d6e
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -e
+
+if [ $# -lt 1 ]; then
+  echo "$0 <project> [<project> ...]"
+  echo enables the named projects.
+  exit 1
+fi
+
+while [ -n "$1" ]; do
+  echo -n "Processing $1... "
+  for file in $(git grep -l "<id>$1</id>"); do
+    xmlstarlet ed -P -N mvn=http://maven.apache.org/POM/4.0.0 \
+      -u //mvn:profile[mvn:id=\"$1\"]/mvn:activation/mvn:activeByDefault \
+      -v true "${file}" > "${file}.new"
+    mv "${file}"{.new,}
+  done
+  echo done.
+  shift
+done
diff --git a/toggle-project b/toggle-project
new file mode 100755 (executable)
index 0000000..930bd31
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+set -e
+
+if [ $# -lt 1 ]; then
+  echo "$0 <project> [<project> ...]"
+  echo toggles the activation of the named projects.
+  exit 1
+fi
+
+while [ -n "$1" ]; do
+  echo -n "Processing $1... "
+  for file in $(git grep -l "<id>$1</id>"); do
+    xmlstarlet ed -P -N mvn=http://maven.apache.org/POM/4.0.0 \
+      -u //mvn:profile[mvn:id=\"$1\"]/mvn:activation[mvn:activeByDefault=\"true\"]/mvn:activeByDefault \
+      -v wastrue "${file}" > "${file}.1"
+    xmlstarlet ed -P -N mvn=http://maven.apache.org/POM/4.0.0 \
+      -u //mvn:profile[mvn:id=\"$1\"]/mvn:activation[mvn:activeByDefault=\"false\"]/mvn:activeByDefault \
+      -v true "${file}.1" > "${file}.2"
+    xmlstarlet ed -P -N mvn=http://maven.apache.org/POM/4.0.0 \
+      -u //mvn:profile[mvn:id=\"$1\"]/mvn:activation[mvn:activeByDefault=\"wastrue\"]/mvn:activeByDefault \
+      -v false "${file}.2" > "${file}"
+    rm -f "${file}".{1,2}
+  done
+  echo done.
+  shift
+done