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