Skip to content

Commit c46b100

Browse files
committed
melting-pot: add flag to prune unaffected deps
The default behavior of the melting pot is to create a multi-module build of all project components which match the inclusion criteria (i.e., the includes and excludes), minus any changed components specified by the '--changes' flag. However, when the set of changes is small, and the main interest is in testing breakages relating to those changes, then it is nice to limit the build to only those components which depend on the changed components (either directly or transitively). Hence, the new '--prune' flag does exactly that! Be warned that even if a component does not explicitly depend on a changed component, it might still be affected by changes in that component. One example is components which use dependency injection at runtime, using resources discovered on the classpath (e.g., plugins).
1 parent 522f493 commit c46b100

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

melting-pot.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ parseArguments() {
126126
outputDir="$2"
127127
shift
128128
;;
129+
-p|--prune)
130+
prune=1
131+
;;
129132
-v|--verbose)
130133
verbose=1
131134
;;
@@ -154,7 +157,7 @@ parseArguments() {
154157
if [ "$usage" ]
155158
then
156159
echo "Usage: $(basename "$0") <project> [-c <GAVs>] \\
157-
[-i <GAs>] [-e <GAs>] [-r <URLs>] [-l <dir>] [-o <dir>] [-vfsh]
160+
[-i <GAs>] [-e <GAs>] [-r <URLs>] [-l <dir>] [-o <dir>] [-pvfsh]
158161
159162
<project>
160163
The project to build, including dependencies, with consistent versions.
@@ -174,6 +177,10 @@ parseArguments() {
174177
Overrides the directory of the Maven local repository cache.
175178
-o, --outputDir
176179
Overrides the output directory. The default is \"melting-pot\".
180+
-p, --prune
181+
Build only the components which themselves depend on a changed
182+
artifact. This will make the build much faster, at the expense of
183+
not fully testing runtime compatibility across all components.
177184
-v, --verbose
178185
Enable verbose/debugging output.
179186
-f, --force
@@ -337,6 +344,32 @@ isIncluded() {
337344
done
338345
}
339346

347+
# Deletes components which do not depend on a changed GAV.
348+
pruneReactor() {
349+
local dir
350+
for dir in */*
351+
do
352+
debug "Checking relevance of component $dir"
353+
local deps="$(deps "$dir")"
354+
355+
# Determine whether the component depends on a changed GAV.
356+
local keep
357+
unset keep
358+
local dep
359+
for dep in $deps
360+
do
361+
test "$(isChanged "$dep")" && keep=1 && break
362+
done
363+
364+
# If the component is irrelevant, prune it.
365+
if [ -z "$keep" ]
366+
then
367+
debug "Pruning irrelevant component: $dir"
368+
rm -rf "$dir"
369+
fi
370+
done
371+
}
372+
340373
# Generates an aggregator POM for all modules in the current directory.
341374
generatePOM() {
342375
echo '<?xml version="1.0" encoding="UTF-8"?>' > pom.xml
@@ -411,6 +444,9 @@ meltDown() {
411444
done
412445
unset TLS
413446

447+
# Prune the build, if applicable.
448+
test "$prune" && pruneReactor
449+
414450
# Generate the aggregator POM.
415451
debug "Generating aggregator POM"
416452
generatePOM

tests/melting-pot-prune.t

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Test that the '--prune' flag works as intended:
2+
3+
$ sh "$TESTDIR/../melting-pot.sh" net.imagej:imagej-common:0.15.1 -r http://maven.imagej.net/content/groups/public -c org.scijava:scijava-common:2.44.2 -i 'org.scijava:*,net.imagej:*,net.imglib2:*' -p -v -f -s
4+
[DEBUG] net.imagej:imagej-common:0.15.1: fetching project source
5+
[DEBUG] net.imagej:imagej-common:0.15.1: determining project dependencies
6+
[DEBUG] net.imagej:imagej-common:0.15.1: processing project dependencies
7+
[DEBUG] net.imagej:imagej-common:0.15.1: imglib2-roi: fetching component source
8+
[DEBUG] net.imagej:imagej-common:0.15.1: imglib2: fetching component source
9+
[DEBUG] net.imagej:imagej-common:0.15.1: processing changed components
10+
[DEBUG] Checking relevance of component net.imagej/imagej-common
11+
[DEBUG] Checking relevance of component net.imglib2/imglib2
12+
[DEBUG] Pruning irrelevant component: net.imglib2/imglib2
13+
[DEBUG] Checking relevance of component net.imglib2/imglib2-roi
14+
[DEBUG] Pruning irrelevant component: net.imglib2/imglib2-roi
15+
[DEBUG] Generating aggregator POM
16+
[DEBUG] Skipping the build; the command would have been:
17+
[DEBUG] mvn -Denforcer.skip -Dimglib2-roi.version=0.3.0 -Djunit.version=4.11 -Dhamcrest-core.version=1.3 -Dimglib2.version=2.2.1 -Dtrove4j.version=3.0.3 -Dgentyref.version=1.1.0 -Dudunits.version=4.3.18 -Deventbus.version=1.4 -Dscijava-common.version=2.44.2 test
18+
[DEBUG] net.imagej:imagej-common:0.15.1: complete
19+
20+
$ find melting-pot -maxdepth 2
21+
melting-pot
22+
melting-pot/net.imagej
23+
melting-pot/net.imagej/imagej-common
24+
melting-pot/net.imglib2
25+
melting-pot/pom.xml

0 commit comments

Comments
 (0)