blob: ac2dec8e5b487b430244deb02bceddd2e184a07b [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 {} \; | \
Thomas Vachuska87994d02015-04-23 11:55:24 -070010 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')
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
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 Vachuskafcd61142015-04-23 13:59:08 -070038 status=$?
Thomas Vachuska87994d02015-04-23 11:55:24 -070039
40 [ -n "$appProjects" ] && echo "App staging required for projects $appProjects"
Thomas Vachuskafcd61142015-04-23 13:59:08 -070041 exit $status
42else
43 exit 0
Thomas Vachuska87994d02015-04-23 11:55:24 -070044fi