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 |
| 18 | artifactId=$(grep -E "^ <artifactId>.*</artifactId>$" ${pd}/pom.xml | \ |
| 19 | sed 's/.[^>]*>//;s/<.*//') |
| 20 | modulesERE="$modulesERE|$artifactId" |
| 21 | done |
| 22 | modulesERE=${modulesERE#|*} |
| 23 | |
| 24 | # Search through staged app.xml files for any apps that require one or |
| 25 | # more of the modified artifacts. |
| 26 | appProjects=$(find $ONOS_ROOT -type f -path '*/target/oar/app.xml' | \ |
| 27 | xargs grep '<artifact>' | grep -E "/($modulesERE)/" | \ |
| 28 | cut -d: -f1 | sed 's:/target/oar/.*::g' | \ |
| 29 | sort -u | sed "s:$ONOS_ROOT::g" | tr '\n' ',' | \ |
| 30 | sed 's:/,:,:g;s:,/:,:g;s:^/::g;s:,$::g') |
| 31 | |
| 32 | # If we found any, append those app projects to the list of projects to |
| 33 | # be built. |
| 34 | [ -n "$appProjects" ] && projects=$projects,$appProjects |
| 35 | |
| 36 | echo Building projects $projects |
| 37 | cd $ONOS_ROOT && mvn --projects $projects ${@:-clean install} |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 38 | status=$? |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 39 | |
| 40 | [ -n "$appProjects" ] && echo "App staging required for projects $appProjects" |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 41 | exit $status |
| 42 | else |
| 43 | exit 0 |
Thomas Vachuska | 87994d0 | 2015-04-23 11:55:24 -0700 | [diff] [blame] | 44 | fi |