blob: 351c53ac319551d716f327e5749e9c65d9a75d0b [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
Charles Chan2ff12e22015-10-28 17:42:36 -070018 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 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' | \
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 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