tom | 1cd74ae | 2014-10-01 14:58:32 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 2 | # ---------------------------------------------------------------------------- |
tom | 1cd74ae | 2014-10-01 14:58:32 -0700 | [diff] [blame] | 3 | # Selectively builds only those projects that contained modified Java files. |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ---------------------------------------------------------------------------- |
tom | 1cd74ae | 2014-10-01 14:58:32 -0700 | [diff] [blame] | 5 | |
Thomas Vachuska | d1f17ac | 2015-04-28 11:43:18 -0700 | [diff] [blame] | 6 | cd $ONOS_ROOT |
| 7 | |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 8 | projects=$(find $ONOS_ROOT -type f -path '*/src/*' \ |
tom | 1cd74ae | 2014-10-01 14:58:32 -0700 | [diff] [blame] | 9 | -exec $ONOS_ROOT/tools/dev/bin/onos-build-selective-hook {} \; | \ |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 10 | grep -v -f $ONOS_ROOT/tools/dev/bin/onos-build-selective.exclude | \ |
| 11 | sort -u | sed "s:$ONOS_ROOT::g" | tr '\n' ',' | \ |
| 12 | sed 's:/,:,:g;s:,/:,:g;s:^/::g;s:,$::g') |
tom | 1cd74ae | 2014-10-01 14:58:32 -0700 | [diff] [blame] | 13 | |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 14 | if [ -n "$projects" ]; then |
| 15 | # Ascertain artifact IDs of the projects to be rebuilt |
| 16 | modulesERE="" |
| 17 | for pd in ${projects//,/ }; do |
Charles Chan | 2ff12e2 | 2015-10-28 17:42:36 -0700 | [diff] [blame] | 18 | if [ -f ${pd}/pom.xml ]; then |
| 19 | artifactId=$(grep -E "^ <artifactId>.*</artifactId>$" ${pd}/pom.xml | \ |
| 20 | sed 's/.[^>]*>//;s/<.*//') |
| 21 | modulesERE="$modulesERE|$artifactId" |
| 22 | fi |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 23 | done |
| 24 | modulesERE=${modulesERE#|*} |
| 25 | |
| 26 | # Search through staged app.xml files for any apps that require one or |
| 27 | # more of the modified artifacts. |
| 28 | appProjects=$(find $ONOS_ROOT -type f -path '*/target/oar/app.xml' | \ |
| 29 | xargs grep '<artifact>' | grep -E "/($modulesERE)/" | \ |
| 30 | cut -d: -f1 | sed 's:/target/oar/.*::g' | \ |
| 31 | sort -u | sed "s:$ONOS_ROOT::g" | tr '\n' ',' | \ |
| 32 | sed 's:/,:,:g;s:,/:,:g;s:^/::g;s:,$::g') |
| 33 | |
| 34 | # If we found any, append those app projects to the list of projects to |
| 35 | # be built. |
| 36 | [ -n "$appProjects" ] && projects=$projects,$appProjects |
| 37 | |
| 38 | echo Building projects $projects |
| 39 | cd $ONOS_ROOT && mvn --projects $projects ${@:-clean install} |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 40 | status=$? |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 41 | |
| 42 | [ -n "$appProjects" ] && echo "App staging required for projects $appProjects" |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 43 | exit $status |
| 44 | else |
| 45 | exit 0 |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 46 | fi |