]> git.mxchange.org Git - jprojects-scripts.git/commitdiff
Initial commit
authorRoland Haeder <roland@mxchange.org>
Fri, 19 Feb 2016 16:00:26 +0000 (17:00 +0100)
committerRoland Haeder <roland@mxchange.org>
Fri, 19 Feb 2016 16:00:26 +0000 (17:00 +0100)
Signed-off-by: Roland Haeder <roland@mxchange.org>
13 files changed:
.jprojects.sh [new file with mode: 0644]
README [new file with mode: 0644]
build-dist-all.sh [new file with mode: 0755]
check-untracked.sh [new file with mode: 0755]
checkout-jprojects.sh [new file with mode: 0755]
commit-jprojects.sh [new file with mode: 0755]
cp-dist.sh [new file with mode: 0755]
create-jproject-branch.sh [new file with mode: 0755]
dist.sh [new file with mode: 0755]
fix-project-remotes.sh [new file with mode: 0755]
merge-jprojects.sh [new file with mode: 0755]
pull-stick.sh [new file with mode: 0755]
push-stick.sh [new file with mode: 0755]

diff --git a/.jprojects.sh b/.jprojects.sh
new file mode 100644 (file)
index 0000000..201f168
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+LIST="jcore jcore-logger-lib jcore-logger-ejb jcoreee \
+       jcountry-core jcountry-lib jcountry-ejb \
+       jphone-core \
+       jcontacts-core jcontacts-business-core jcontacts-lib jcontacts-ejb \
+       juser-core juser-lib juser-ejb \
+       jletter-core jletter-lib jletter-ejb \
+       jcore-swing \
+       jshop-core jshop-ee-lib jshop-ejb \
+       jshop-receipt-lib jshop-receipt-ejb"
+LIST="${LIST}
+       pizzaservice-lib pizzaservice pizzaservice-swing pizzaservice-war \
+       jjobs-lib jjobs-ejb jjobs jjobs-war \
+       addressbook-lib addressbook-ejb addressbook addressbook-war addressbook-uml"
+
+# BROKEN:
+LIST="${LIST} addressbook-swing"
+
+# Own home directory
+declare -r JPROJECTS_HOME="${PWD}"
+
+# Test on .git availability"
+for project in ${LIST}; do
+       if [ ! -d "${project}" ]
+       then
+               echo "$0: Project '${project}' not created."
+               exit 1
+       elif [ ! -d "${project}" ]
+       then
+               echo "$0: Project '${project}' is no GIT project."
+               exit 1
+       fi
+done
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..bb2077c
--- /dev/null
+++ b/README
@@ -0,0 +1,3 @@
+These are my (Roland Haeder) helper scripts to build and maintain my Java projects.
+
+They are licensed "AS IS" and "WITHOUT ANY WARRANTY", so public domain.
diff --git a/build-dist-all.sh b/build-dist-all.sh
new file mode 100755 (executable)
index 0000000..1738107
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+for DIST in ${LIST}; do
+       echo "$0: Executing '${DIST}' ..."
+       P=${DIST%/*}
+
+       echo "$0: P='${P}'"
+       cd "${JPROJECTS_HOME}/${P}" || exit 255
+
+       if [ ! -e "build.xml" ]
+       then
+               echo "$0: No build.xml found, skipping project '${P}'."
+               continue
+       fi
+
+       if [ "$1" != "d" ]
+       then
+               # Cleanup project and build JAR
+               ant clean jar
+
+               # Save status
+               STATUS="$?"
+
+               # Has it failed?
+               if [ "${STATUS}" != "0" ]
+               then
+                       # This has failed, so try "dist"
+                       ant clean dist
+                       STATUS="$?"
+
+                       # Still failing? Oh, to bad
+                       if [ "${STATUS}" != "0" ]
+                       then
+                               echo "$0: Failed to build '${DIST}'."
+                               exit 1
+                       fi
+               fi
+       fi
+
+       if [ ! -f "./dist.sh" ]
+       then
+               echo "$0: Project '${DIST}' has no dist.sh"
+       elif [ ! -e "./dist.sh" ]
+       then
+               echo "$0: Error: Project '${DIST}' has non-executable dist.sh!"
+               exit 1
+       else
+               ./dist.sh
+       fi
+done
+
+echo "$0: All done."
+exit 0
diff --git a/check-untracked.sh b/check-untracked.sh
new file mode 100755 (executable)
index 0000000..7216a7e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+. ./.jprojects.sh
+
+for project in ${LIST}; do
+       echo "$0: Checking '${project}' ..."
+       cd "${project}"
+       STATUS=`git status`
+       UNTRACKED=`echo "${STATUS}" | grep "Untracked files:"`
+       if [ -n "${UNTRACKED}" ]
+       then
+               echo "${STATUS}"
+       fi
+       cd -
+done
diff --git a/checkout-jprojects.sh b/checkout-jprojects.sh
new file mode 100755 (executable)
index 0000000..a577daa
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+TARGET_BRANCH="master"
+
+for project in ${LIST}; do
+       echo "$0: Processing '${project}' ..."
+       cd "${JPROJECTS_HOME}/${project}"
+
+       # Checkout all
+       git checkout -- .
+
+       if [ -n "${TARGET_BRANCH}" ]
+       then
+               echo "$0: Switching back to '${TARGET_BRANCH}'"
+               git checkout "${TARGET_BRANCH}"
+       fi
+done
+
+echo "$0: All done."
+exit 0
diff --git a/commit-jprojects.sh b/commit-jprojects.sh
new file mode 100755 (executable)
index 0000000..93783cf
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+for project in ${LIST}; do
+       cd "${project}" || exit 255
+       CHECK_CHANGES=`git commit --dry-run | grep "Changes to be committed:"`
+
+       if [ -n "${CHECK_CHANGES}" ]
+       then
+               echo "$0: Committing '${project}' ..."
+               if [ -n "$1" ]
+               then
+                       git commit -a --signoff -S -m "$1" || exit 255
+               else
+                       git commit -a --signoff -S || exit 255
+               fi
+       else
+               echo "$0: Nothing to commit for project '${project}'."
+       fi
+       cd -
+done
+
+echo "$0: All done."
+exit 0
diff --git a/cp-dist.sh b/cp-dist.sh
new file mode 100755 (executable)
index 0000000..ace7597
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+for project in ${LIST}; do
+       if [ -f "${project}/dist.sh" ]
+       then
+               echo "$0: Copying dist.sh to '${project}' ..."
+               cp -v dist.sh "${project}/" || exit 255
+       fi
+
+       if [ ! -d "${project}/docs" -o "$1" = "f" ]
+       then
+               echo "$0: GNU-ifying project '${project}' ..."
+               cp -rv docs "${project}/" || exit 255
+               cd "${JPROJECTS_HOME}/${project}"
+               echo "$0: git add ..."
+               git add docs || exit 255
+               echo "$0: git rm ..."
+               git rm -f COPYING
+               echo "$0: git mv ..."
+               git mv docs/COPYING . || exit 255
+               cd "${JPROJECTS_HOME}"
+       else
+               echo "$0: Project '${project}' already prepared."
+       fi
+done
+
+echo "$0: All done."
+exit 0
diff --git a/create-jproject-branch.sh b/create-jproject-branch.sh
new file mode 100755 (executable)
index 0000000..16ac726
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+echo "$0: JPROJECTS_HOME='${JPROJECTS_HOME}'"
+
+NEW_BRANCH="rewrites/wildfly"
+
+#COMMIT_MESSAGE="WildFly branch created with initial scripts, but it doesn't load my libs."
+COMMIT_MESSAGE=""
+COMMIT_ADD=""
+AFTER_COMMIT_BRANCH="master"
+
+for project in ${LIST}; do
+       echo "$0: Processing '${project}' ..."
+       cd "${JPROJECTS_HOME}/${project}"
+
+       CHECK_BRANCH=`git branch --all | grep "${NEW_BRANCH}"`
+       echo "$0: CHECK_BRANCH='${CHECK_BRANCH}'"
+
+       if [ -z "${CHECK_BRANCH}" ]
+       then
+               echo "$0: Creating branch '${NEW_BRANCH}' ..."
+               git checkout -b "${NEW_BRANCH}"
+       fi
+
+       if [ -n "${COMMIT_MESSAGE}" ]
+       then
+               if [ -n "${COMMIT_ADD}" ]
+               then
+                       echo "$0: Adding '${COMMIT_ADD}' ..."
+                       git add "${COMMIT_ADD}"
+               fi
+
+               echo "$0: Committing '${NEW_BRANCH}' ..."
+               git commit -m "${COMMIT_MESSAGE}" --signoff -S -a
+       fi
+
+       if [ -n "${AFTER_COMMIT_BRANCH}" ]
+       then
+               echo "$0: Switching in '${project}' to '${AFTER_COMMIT_BRANCH}' ..."
+               git checkout "${AFTER_COMMIT_BRANCH}"
+       fi
+done
+
+echo "$0: All done."
+exit 0
diff --git a/dist.sh b/dist.sh
new file mode 100755 (executable)
index 0000000..246c96a
--- /dev/null
+++ b/dist.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+# Name of this project, detected by it's base path
+NAME="${PWD##*/}"
+
+# Generated JAR file
+DIST="dist/${NAME}.jar"
+
+# WildFly module base path
+WILDFLY_MODULE_BASE_PATH="${HOME}/wildfly_domain/modules/org/mxchange"
+
+# And for this "module" (as WildFly calls it)
+WILDFLY_MODULE_PATH="${WILDFLY_MODULE_BASE_PATH}/${NAME}/main"
+
+# module.xml
+WILDFLY_MODULE_XML_FILE="wildfly/module.xml"
+
+# Glassfish base path (domain)
+GLASSFISH_BASE_PATH="${HOME}/gf_domain/domain/lib"
+
+# Generate list
+LIST=`find ../*/lib/${NAME}.jar`
+LIST="${LIST} `find ../*/*-ejb/lib/${NAME}.jar`"
+LIST="${LIST} ${WILDFLY_MODULE_PATH}"
+
+if [ -d "${GLASSFISH_BASE_PATH}" ]
+then
+       echo "$0: Glassfish personal domain found, adding to LIST ..."
+       LIST="${LIST} ${GLASSFISH_BASE_PATH}"
+fi
+
+if [ ! -f "${DIST}" ]
+then
+       echo "$0: '${DIST}' not found."
+       exit 1
+elif [ ! -d "${WILDFLY_MODULE_BASE_PATH}" ]
+then
+       echo "$0: WildFly base path '${WILDFLY_MODULE_BASE_PATH}' not created."
+       exit 1
+elif [ ! -d "${WILDFLY_MODULE_PATH}" ]
+then
+       mkdir -vp "${WILDFLY_MODULE_PATH}"
+fi
+
+for target in ${LIST};
+do
+       if [ -d "${target}" ]
+       then
+               cp -v "${DIST}" "${target}"
+       elif [ -f "${target}" ]
+       then
+               cp -v "${DIST}" "${target}"
+       else
+               echo "$0: Target '${target}' not found."
+       fi
+done
+
+# Copy module.xml ...
+if [ -f "${WILDFLY_MODULE_XML_FILE}" ]
+then
+       echo "$0: Generating module.xml ..."
+       XML_CONTENT=`cat "${WILDFLY_MODULE_XML_FILE}"`
+       XML_CONTENT="${XML_CONTENT//NAME/$NAME}"
+       echo "${XML_CONTENT}" > "${WILDFLY_MODULE_PATH}/module.xml"
+fi
+
+echo "$0: All done."
+exit 0
diff --git a/fix-project-remotes.sh b/fix-project-remotes.sh
new file mode 100755 (executable)
index 0000000..6fff377
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+UNWANTED_NAME="stick"
+WANTED_NAME1="upstream"
+WANTED_NAME2="daedalus"
+
+GIT_USER="quix0r"
+GIT_SERVER="git.mxchange.org"
+GIT_PATH="/var/cache/git/repos"
+GIT_BRANCH="master"
+GIT_ORIGIN="origin"
+
+MEDIA_NAME="INTENSO"
+MEDIA_PATH="Java Project"
+MEDIA_BASE="/media"
+
+for project in ${LIST}; do
+       GIT_URL1="${GIT_USER}@${GIT_SERVER}:${GIT_PATH}/${project}.git"
+       GIT_URL2="${GIT_PATH}/${project}.git"
+       echo "$0: GIT_URL1='${GIT_URL1}',GIT_URL2='${GIT_URL2}'"
+
+       cd "${project}"
+
+       if [ "$1" = "l" ]
+       then
+               echo "$0: Listing remotes for '${project}' ..."
+               git remote -v
+               cd -
+               continue;
+       fi
+
+       REMOTES=`git remote | wc -l`
+       echo "$0: REMOTES='${REMOTES}'"
+
+       if [ "${REMOTES}" = "1" ]
+       then
+               echo "$0: Only one remote found for '${project}'"
+
+               REMOTE=`git remote`
+               REMOTE_PUSH=`git remote -v | grep "push"`
+               echo "$0: REMOTE='${REMOTE}',REMOTE_PUSH='${REMOTE_PUSH}'"
+
+               MEDIA=`echo "${REMOTE_PUSH}" | grep "${MEDIA_BASE}/"`
+               echo "$0: MEDIA='${MEDIA}'"
+
+               if [ -n "${MEDIA}" ]
+               then
+                       echo "$0: Found ${MEDIA_BASE}/ remote for '${project}'."
+                       if [ "${REMOTE}" = "${GIT_ORIGIN}" ]
+                       then
+                               echo "$0: Project '${project}' has already fixed '${GIT_ORIGIN}'."
+                       else
+                               echo "$0: Renaming '${REMOTE}' to '${GIT_ORIGIN}' ..."
+                               git remote rename "${REMOTE}" "${GIT_ORIGIN}" || exit 255
+                       fi
+               else
+                       echo "$0: Not a media remote."
+                       MXCHANGE_REMOTE=`echo "${REMOTE_PUSH}" | grep "${GIT_URL1}"`
+                       echo "$0: MXCHANGE_REMOTE='${MXCHANGE_REMOTE}'"
+
+                       if [ -n "${MXCHANGE_REMOTE}" ]
+                       then
+                               echo "$0: Found a '${GIT_SERVER}' remote."
+
+                               if [ "${REMOTE}" != "${WANTED_NAME1}" ]
+                               then
+                                       echo "$0: Project '${project}' has one correct '${WANTED_NAME1}'."
+                               else
+                                       echo "$0: Renaming '${REMOTE}' to '${WANTED_NAME1}' ..."
+                                       git remote rename "${REMOTE}" "${WANTED_NAME1}" || exit 255
+                               fi
+
+                               echo "$0: Adding '${GIT_ORIGIN}' to '${project}' ..."
+                               git remote add "${GIT_ORIGIN}" "${MEDIA_BASE}/${USER}/${MEDIA_NAME}/${MEDIA_PATH}/${project}.git" --track "${GIT_BRANCH}" || exit 255
+                       else
+                               echo "$0: Unknown remote '${REMOTE_PUSH}' found. Exiting ..."
+                               exit 1
+                       fi
+               fi
+       fi
+
+       UNWANTED_REMOTE=`git remote | grep "${UNWANTED_NAME}"`
+       echo "$0: UNWANTED_REMOTE='${UNWANTED_REMOTE}'"
+
+       if [ -n "${UNWANTED_REMOTE}" ]
+       then
+               echo "$0: Found remote '${UNWANTED_NAME1}' in '${project}'. Renaming '${GIT_ORIGIN}'->'${WANTED_NAME1}' and '${UNWANTED_NAME1}'->'${GIT_ORIGIN}' ..."
+
+               UPSTREAM_REMOTE=`git remote | grep "${WANTED_NAME1}"`
+               echo "$0: UPSTREAM_REMOTE='${UPSTREAM_REMOTE}'"
+
+               if [ -n "${UPSTREAM_REMOTE}" ]
+               then
+                       echo "$0: Remotes '${UNWANTED_NAME1}' and '${WANTED_NAME1}' exist! Removing '${WANTED_NAME1}' ..."
+                       git remote rm "${WANTED_NAME1}" || exit 255
+               fi
+
+               git remote rename "${GIT_ORIGIN}" "${WANTED_NAME1}" || exit 255
+               git remote rename "${UNWANTED_NAME1}" "${GIT_ORIGIN}" || exit 255
+       else
+               echo "$0: No unwanted '${UNWANTED_NAME1}' remote in '${project}' ..."
+               UPSTREAM_REMOTE1=`git remote | grep "${WANTED_NAME1}"`
+               UPSTREAM_REMOTE2=`git remote | grep "${WANTED_NAME2}"`
+               echo "$0: UPSTREAM_REMOTE1='${UPSTREAM_REMOTE1}',UPSTREAM_REMOTE2='${UPSTREAM_REMOTE2}'"
+
+               if [ -n "${UPSTREAM_REMOTE1}" ]
+               then
+                       echo "$0: Remote '${WANTED_NAME1}' found in '${project}'."
+               else
+                       echo "$0: No wanted '${WANTED_NAME1}' in '${project}'. Adding ..."
+                       git remote add "${WANTED_NAME1}" "${GIT_URL1}" --track "${GIT_BRANCH}" || exit 255
+               fi
+
+               if [ -n "${UPSTREAM_REMOTE2}" ]
+               then
+                       echo "$0: Remote '${WANTED_NAME2}' found in '${project}'."
+               else
+                       echo "$0: No wanted '${WANTED_NAME2}' in '${project}'. Adding ..."
+                       git remote add "${WANTED_NAME2}" "${GIT_URL2}" --track "${GIT_BRANCH}" || exit 255
+               fi
+       fi
+
+       cd -
+done
diff --git a/merge-jprojects.sh b/merge-jprojects.sh
new file mode 100755 (executable)
index 0000000..7257499
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+SOURCE_BRANCH="master"
+TARGET_BRANCH="rewrites/jpa"
+SWITCH_TO_SOURCE="Y"
+
+for project in ${LIST}; do
+       echo "$0: Processing '${project}' ..."
+       cd "${JPROJECTS_HOME}/${project}"
+
+       # Make sure the source branch is there
+       git checkout "${SOURCE_BRANCH}" || exit 255
+
+       # ... and target branch
+       git checkout "${TARGET_BRANCH}" 2>&1
+       STATUS="$?"
+
+       if [ "${STATUS}" = "0" ]
+       then
+               # Then merge
+               echo "$0: Merging '${SOURCE_BRANCH}' in project '${project}' ..."
+               git merge -S "${SOURCE_BRANCH}" || exit 255
+
+               if [ "${SWITCH_TO_SOURCE}" = "Y" ]
+               then
+                       echo "$0: Switching back to '${SOURCE_BRANCH}'"
+                       git checkout "${SOURCE_BRANCH}"
+               fi
+       else
+               echo "$0: Project '${project}' has no branch '${TARGET_BRANCH}'."
+       fi
+done
+
+echo "$0: All done."
+exit 0
diff --git a/pull-stick.sh b/pull-stick.sh
new file mode 100755 (executable)
index 0000000..a187860
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+for ENTRY in ${LIST}; do
+       cd "${ENTRY}" || exit 255
+
+       if [ "$1" = "c" ]
+       then
+               echo "$0: Checkout '${ENTRY}' ..."
+               git checkout -- .
+       fi
+
+       echo "$0: Pulling '${ENTRY}' ..."
+       git pull || exit 255
+       echo "$0: Rebasing '${ENTRY}' ..."
+       git rebase origin/master || exit 255
+       cd -
+done
diff --git a/push-stick.sh b/push-stick.sh
new file mode 100755 (executable)
index 0000000..a797e34
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+. ./.jprojects.sh || exit 255
+
+for ENTRY in ${LIST}; do
+       echo "$0: Pushing '${ENTRY}' ..."
+       cd "${ENTRY}" || exit 255
+       git push --all
+       if [ "$1" = "u" ]
+       then
+               git push --all upstream
+       elif [ "$1" = "d" ]
+       then
+               git push --all daedalus
+       fi
+       cd -
+done