Last active
December 12, 2017 23:00
-
-
Save robstryker/8ab652b7884c4ac074d36123bb63fbc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -xe | |
# see also https://gist.github.com/nickboldt/6afc71826e82518c5e7b7d3c3fdcc4f3 | |
# merge sse repos into a single repo | |
START_TIME=`date +%s` | |
# work in a tempdir. The tmp-dir name is something like /home/user/tmp/this_scripts_name/ | |
tmpdir=~/tmp/${0/.sh/.tmp} | |
tmpdirCache=~/tmp/${0/.sh/.tmp}_cache | |
#rm -fr ${tmpdir} | |
mkdir -p ${tmpdir} | |
cd ${tmpdir} | |
# in case we have another alias for mv, like 'mv -i' | |
alias mv=mv | |
alias rm=rm | |
# set our local pull command depending on git version | |
verlte() { | |
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | |
} | |
verlt() { | |
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | |
} | |
GIT_VERSION=`git version | head -1 | cut -f 3 -d " "` | |
verlte $GIT_VERSION 2.9.0 && ALLOW_PULL_FLAG=false || ALLOW_PULL_FLAG=true | |
if $ALLOW_PULL_FLAG | |
then | |
LOCAL_PULL_CMD="git pull --no-edit --allow-unrelated-histories --no-rebase --rebase=false" | |
else | |
LOCAL_PULL_CMD="git pull --no-edit --no-rebase --rebase=false" | |
fi | |
MVN="mvn clean install -fae -e -Dplatform-repo.url=http://download.eclipse.org/eclipse/updates/4.8-I-builds/" | |
# Make sure different users with different settings will run the script as intended | |
gitBranchSettings () | |
{ | |
git config branch.autosetuprebase never | |
git config branch.autosetupmerge false | |
git config branch.master.rebase false | |
} | |
# handle changes to parent pom | |
if [[ ! -d webtools.releng.aggregator ]]; then git clone http://git.eclipse.org/gitroot/webtools/webtools.releng.aggregator.git; fi | |
pushd webtools.releng.aggregator/wtp-parent | |
gitBranchSettings | |
git reset --hard origin/master | |
${MVN} | |
popd | |
# Now clone the repos | |
for d in webtools.ejb webtools.javaee webtools.javaee.tests; do | |
if [[ ! -d ${d} ]]; then | |
git clone http://git.eclipse.org/gitroot/jeetools/${d}.git | |
fi | |
done | |
for d in webtools.ejb webtools.javaee webtools.javaee.tests; do | |
pushd ${d} | |
gitBranchSettings | |
git reset --hard origin/master | |
popd | |
done | |
# Let's collect all the gitignores into one file to use later | |
for d in webtools.ejb webtools.javaee.tests; do | |
pushd ${d} | |
rm pom.xml | |
rm .project | |
cat .gitignore >> ../git_ignore_accumulator | |
rm .gitignore | |
git commit -a -m "Removing poms and .gitignore files that will be clobbered" --signoff | |
popd | |
done | |
cd webtools.javaee | |
for d in webtools.ejb webtools.javaee.tests; do | |
$LOCAL_PULL_CMD ../${d} | |
done | |
# "Merging all repos together" . | |
cat ../git_ignore_accumulator >> .gitignore | |
cat .gitignore | sort | uniq > .gitignore2 | |
mv -f .gitignore2 .gitignore | |
# WARNING: make sure correct quotes used in next line (stupid google) | |
git commit -s -m "Accumulate all gitignore files. To be cleaned later" .gitignore | |
######## generate poms | |
OVERWRITE_EXISTING_POMS=true # or false | |
NEWLINES="" | |
EXCLUDES=".git|site|sourceTemplate|.settings|src*|config|DevTimeSupport|META-INF" #|schema We have plugins named schema!!! | |
for td in $(find . -maxdepth 1 -type d | egrep -v "${EXCLUDES}" | sort); do | |
TOP_DIR=${td##./} | |
# collect top level dirs to add to root pom later | |
if [[ ${TOP_DIR} != "." ]]; then | |
NEWLINES="${NEWLINES}<module>${TOP_DIR}</module> | |
" | |
fi | |
pushd ${td} >/dev/null | |
count_subs=$(find . -maxdepth 1 -type d | egrep -v "${EXCLUDES}" | egrep -v "^\.$" | wc -l) | |
# don't overwrite existing files and only process this dir if there are children | |
if [[ ${count_subs} -gt 0 ]]; then | |
if [[ -f pom.xml ]] || [[ ${OVERWRITE_EXISTING_POMS} == "true" ]]; then | |
artifactId="<artifactId>javaee.${TOP_DIR}</artifactId>" | |
echo "Generate ${TOP_DIR}/pom.xml :: ${artifactId} ..." | |
cat <<EOT > pom.xml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Copyright (c) 2017 Eclipse Foundation and others. | |
All rights reserved. This program and the accompanying materials | |
are made available under the terms of the Eclipse Distribution License v1.0 | |
which accompanies this distribution, and is available at | |
http://www.eclipse.org/org/documents/edl-v10.php | |
Contributors: | |
Nick Boldt (Red Hat) - initial implementation | |
Rob Stryker (Red Hat) - initial implementation | |
--> | |
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>org.eclipse.webtools.javaee</groupId> | |
<artifactId>org.eclipse.webtools.javaee</artifactId> | |
<version>3.6.0-SNAPSHOT</version> | |
</parent> | |
<groupId>org.eclipse.webtools.javaee</groupId> | |
${artifactId} | |
<version>3.6.0-SNAPSHOT</version> | |
<packaging>pom</packaging> | |
<modules> | |
EOT | |
for ssd in $(find . -maxdepth 1 -type d | egrep -v "${EXCLUDES}" | sort); do | |
SUBSUB_DIR=${ssd##./} | |
if [[ ${SUBSUB_DIR} != "." ]] && [[ $(ls ${SUBSUB_DIR}) ]]; then | |
echo " <module>${SUBSUB_DIR}</module>" >> pom.xml | |
echo " + ${SUBSUB_DIR}" | |
fi | |
done | |
cat <<EOT >> pom.xml | |
</modules> | |
</project> | |
EOT | |
fi | |
fi | |
popd >/dev/null | |
done | |
# don't regen the root pom yet | |
git checkout pom.xml | |
# commit OTHER new */pom.xml and */*/pom.xml | |
git add . | |
git commit -s -m "Commit generated poms" . | |
# note: these line numbers are subject to change | |
{ head -n 50 pom.xml; for d in docs features plugins tests site; do echo $d; done | awk '{ print " <module>" $0 "</module>";}'; tail -n -2 pom.xml; } > pom2.xml | |
mv pom2.xml pom.xml | |
git commit -a -s -m "Update root pom" | |
# Remove patch feature references in the pom.xml for xml specifically | |
for d in features tests; do | |
cd ${d} | |
cat pom.xml | grep -v "patch" > pom2.xml | |
mv pom2.xml pom.xml | |
cd ../ | |
done | |
git commit -a -s -m "Remove feature patches from feature pom files" | |
# add <references> in root pom to resolve upstream (core, server tools) plugins/features | |
wget --no-check-certificate https://raw.githubusercontent.com/jbosstools/jbosstools-build-ci/master/util/insertNode.py -O ../insertNode.py | |
insertRepository () | |
{ | |
# find the end of the file or the end of the <references> section | |
pomfile="$1" | |
repoProperty="$2" | |
repoURL="$3" | |
python -W ignore ../insertNode.py --file ${pomfile} --parent properties --xml "<${repoProperty}>${repoURL}</${repoProperty}>" | |
python -W ignore ../insertNode.py --file ${pomfile} --parent repositories --xml "<repository><id>${repoProperty}</id><layout>p2</layout><url>\${${repoProperty}}</url></repository>" | |
} | |
# TODO this should be a real URL path to the webtools common CI build site, such as this one: | |
# insertRepository $(pwd)/pom.xml webtools_common_site https://hudson.eclipse.org/webtools/job/webtools.common_R3_10/lastSuccessfulBuild/artifact/webtools.common.repositories/repository/target/repository/ | |
# for now use a real site | |
insertRepository $(pwd)/pom.xml webtools_common_site http://download.eclipse.org/webtools/downloads/drops/R3.9.0/I-latest/repository/ | |
git commit -a -s -m "Insert repository to root pom.xml" | |
# At this point, the individual bundles still have incorrect references to parent artifacts | |
# in webtools.sourceediting repo | |
JEEARTID=`cat pom.xml | grep "artifactId" | head -n 2 | tail -n 1 | sed 's/.*artifactId.org/org/' | sed 's/<.*//'` | |
JEEVERSID=`cat pom.xml | grep "version" | head -n 3 | tail -n 1 | sed 's/[^0-9]*//' | sed 's/-SNAPSHOT.*/-SNAPSHOT/'` | |
for td2 in $(find . -maxdepth 1 -type d | grep -v "^\.$" | grep -v "\.git" | grep -v "site$"); do | |
cd $td2 | |
echo "inside " `pwd` | |
BUNDLETYPEARTID=`cat pom.xml | grep "artifactId" | head -n 2 | tail -n 1 | sed 's/[^>]*.//' | sed 's/<.*//'` | |
BUNDLETYPEVERSID=`cat pom.xml | grep "version" | head -n 3 | tail -n 1 | sed 's/[^0-9]*//' | sed 's/-SNAPSHOT.*/-SNAPSHOT/'` | |
for td in $(find . -maxdepth 1 -type d | grep -v "^\.$"); do | |
if [[ -f ${td}/pom.xml ]]; then | |
echo "Fixing $td pom.xml" | |
sed "1,/artifactId.*/s/artifactId.*/artifactId>$BUNDLETYPEARTID<\/artifactId>/" $td/pom.xml > $td/pom2.xml | |
sed "1,/groupId.*/s/groupId.*/groupId>org.eclipse.webtools.javaee<\/groupId>/" $td/pom2.xml > $td/pom3.xml | |
tr '\n' '%' < $td/pom3.xml | sed "s/version>[^>]*/version>$BUNDLETYPEVERSID<\/version/1" | tr '%' '\n' > $td/pom4.xml | |
mv $td/pom4.xml $td/pom.xml | |
rm $td/pom2.xml $td/pom3.xml | |
else | |
echo "[WARNING] ${td}/pom.xml not found, skipping." | |
fi | |
done | |
if [[ -f pom.xml ]]; then | |
echo "Fixing pom.xml" | |
sed "1,/artifactId.*/s/artifactId.*/artifactId>$JEEARTID<\/artifactId>/" pom.xml > pom2.xml | |
tr '\n' '%' < pom2.xml | sed "s/version>[^>]*/version>$JEEVERSID<\/version/1" | tr '%' '\n' > pom3.xml | |
mv pom3.xml pom.xml | |
rm pom2.xml | |
else | |
echo "[WARNING] ${td1}/pom.xml not found, skipping." | |
fi | |
cd ../ | |
done | |
for abc in `grep -R "relativePath>" * | cut -f 1 -d ":" | grep -v "^pom.xml$"`; do | |
if [ -f $abc ]; then | |
cat $abc | grep -v "relativePath>" > $abc.2 | |
mv $abc.2 $abc | |
fi | |
done | |
git commit -a -m "Made sure all poms reference parent-dir's artifact id" | |
END_TIME=`date +%s` | |
EXEC_TIME=$((END_TIME-START_TIME)) | |
echo $EXEC_TIME " seconds execution time without build" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment