blob: c3ea6fae863c5be156bd4a2edfc9fb475bd3826b [file] [log] [blame]
tom1cd74ae2014-10-01 14:58:32 -07001#!/bin/bash
Pavlin Radoslavov91413792014-10-15 11:00:32 -07002# ----------------------------------------------------------------------------
tom1cd74ae2014-10-01 14:58:32 -07003# Selectively builds only those projects that contained modified Java files.
Pavlin Radoslavov91413792014-10-15 11:00:32 -07004# ----------------------------------------------------------------------------
tom1cd74ae2014-10-01 14:58:32 -07005
Thomas Vachuskad1f17ac2015-04-28 11:43:18 -07006cd $ONOS_ROOT
7
Thomas Vachuska87994d02015-04-23 11:55:24 -07008projects=$(find $ONOS_ROOT -type f -path '*/src/*' \
tom1cd74ae2014-10-01 14:58:32 -07009 -exec $ONOS_ROOT/tools/dev/bin/onos-build-selective-hook {} \; | \
Ayaka Koshibe98c31652016-05-26 11:48:47 -070010 egrep -v -f $ONOS_ROOT/tools/dev/bin/onos-build-selective.exclude | \
Thomas Vachuska87994d02015-04-23 11:55:24 -070011 sort -u | sed "s:$ONOS_ROOT::g" | tr '\n' ',' | \
12 sed 's:/,:,:g;s:,/:,:g;s:^/::g;s:,$::g')
tom1cd74ae2014-10-01 14:58:32 -070013
Thomas Vachuska87994d02015-04-23 11:55:24 -070014if [ -n "$projects" ]; then
15 # Ascertain artifact IDs of the projects to be rebuilt
16 modulesERE=""
17 for pd in ${projects//,/ }; do
Charles Chan2ff12e22015-10-28 17:42:36 -070018 if [ -f ${pd}/pom.xml ]; then
Ayaka Koshibe98c31652016-05-26 11:48:47 -070019 artifactId=$(egrep -E "^ <artifactId>.*</artifactId>$" ${pd}/pom.xml | \
Charles Chan2ff12e22015-10-28 17:42:36 -070020 sed 's/.[^>]*>//;s/<.*//')
21 modulesERE="$modulesERE|$artifactId"
22 fi
Thomas Vachuska87994d02015-04-23 11:55:24 -070023 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' | \
Ayaka Koshibe98c31652016-05-26 11:48:47 -070029 xargs egrep '<artifact>' | egrep -E "/($modulesERE)/" | \
Thomas Vachuska87994d02015-04-23 11:55:24 -070030 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 Vachuskafcd61142015-04-23 13:59:08 -070040 status=$?
Thomas Vachuska87994d02015-04-23 11:55:24 -070041
42 [ -n "$appProjects" ] && echo "App staging required for projects $appProjects"
Thomas Vachuskafcd61142015-04-23 13:59:08 -070043 exit $status
44else
45 exit 0
Thomas Vachuska87994d02015-04-23 11:55:24 -070046fi