Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Forked from robstryker/merge_jee_ejb.sh
Last active December 12, 2017 17:50
Show Gist options
  • Save nickboldt/1319b4a6cd2ae5803d41b5f640e0596e to your computer and use it in GitHub Desktop.
Save nickboldt/1319b4a6cd2ae5803d41b5f640e0596e to your computer and use it in GitHub Desktop.
merge jee and ejb repos (3) into one repo, then apply patches
#!/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 -f pom.xml .project
cat .gitignore >> ../git_ignore_accumulator
rm -f .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"
# 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
# fix relative path refs - remove them and assume parents are in ../
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"
# apply patches!
git remote add nickboldt https://github.com/nickboldt/webtools.javaee
git fetch nickboldt
# move org.eclipse.jst.enterprise_tests.feature to integration profile
# https://github.com/nickboldt/webtools.javaee/commit/f0072567f95c3df8e27c985320ef2414a39f2a83
git cherry-pick --keep-redundant-commits f0072567f95c3df8e27c985320ef2414a39f2a83
# move performance and generation tests to new performance profile so they're not run by default, until we can fix them
# https://github.com/nickboldt/webtools.javaee/commit/8a3b9c53fa5715a39628d22e55c2d66cdc0954e9
git cherry-pick --keep-redundant-commits 8a3b9c53fa5715a39628d22e55c2d66cdc0954e9
# Bug 519793 - remove org.eclipse.wst.web, org.eclipse.wst.web.ui and org.eclipse.wst.web.ui.infopop from webtools.javaee as they've moved upstream to webtools.sourceediting
# https://github.com/nickboldt/webtools.javaee/commit/1e1d784565f05ad9d73994b650b4009b60392d2c
git cherry-pick --keep-redundant-commits 1e1d784565f05ad9d73994b650b4009b60392d2c
# Bug 520040 - add update site generation
# https://github.com/nickboldt/webtools.javaee/commit/2ed0e6c587a9c4a93763d4f095061790a8e6e001
git cherry-pick --keep-redundant-commits 2ed0e6c587a9c4a93763d4f095061790a8e6e001
# add upstream deps to common, servertools, sse, jsdt (v2)
# https://github.com/nickboldt/webtools.javaee/commit/a6ae0220e8dfb719a880d21a76982244aada4530
git cherry-pick --keep-redundant-commits a6ae0220e8dfb719a880d21a76982244aada4530
# remove jem and jem.tests features as they're empty (archived)
# https://github.com/nickboldt/webtools.javaee/commit/c74a503a1b41579712d276185a5fc335bb7e1c5a
git cherry-pick --keep-redundant-commits c74a503a1b41579712d276185a5fc335bb7e1c5a
# comment out 9 features which we have to move down to jsf, webservices, or releng
# https://github.com/nickboldt/webtools.javaee/commit/6f51646b597c3ec9b560f114cfe39983904c1361
git cherry-pick --keep-redundant-commits 6f51646b597c3ec9b560f114cfe39983904c1361
# since features have been commmented out, add the plugins into the update site so downstream can consume them (eg., Dali)
# https://github.com/nickboldt/webtools.javaee/commit/c0cf435c90e75ec3160c8997152d12256ac76f31
git cherry-pick --keep-redundant-commits c0cf435c90e75ec3160c8997152d12256ac76f31
#### these last commits should already have happened on the master branch, and are therefore not needed.
# I'm providing them for completeness since I started this script BEFORE they were merged to master. ~nb
# Bug 527825: Allow for Servlet 3.1 listeners to be added to EE8 projects
# https://github.com/nickboldt/webtools.javaee/commit/7fd7b79cc46f41eb31208ac972e2d747228c49b5
# git cherry-pick --keep-redundant-commits 7fd7b79cc46f41eb31208ac972e2d747228c49b5
# Bug 526303: Fix ConnectorLabelString concatenation issue
# https://github.com/nickboldt/webtools.javaee/commit/01adf7f30c1b8cdc91c82ea4b4d09a29e47ec041
# git cherry-pick --keep-redundant-commits 01adf7f30c1b8cdc91c82ea4b4d09a29e47ec041
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment