21
21
import com .facebook .buck .core .model .BuildTarget ;
22
22
import com .facebook .buck .core .rules .BuildRule ;
23
23
import com .facebook .buck .core .rules .BuildRuleParams ;
24
+ import com .facebook .buck .core .rules .SourcePathRuleFinder ;
24
25
import com .facebook .buck .core .rules .impl .AbstractBuildRuleWithDeclaredAndExtraDeps ;
25
26
import com .facebook .buck .core .sourcepath .ExplicitBuildTargetSourcePath ;
26
27
import com .facebook .buck .core .sourcepath .SourcePath ;
37
38
import com .google .common .collect .ImmutableList ;
38
39
import com .google .common .collect .ImmutableSet ;
39
40
import com .google .common .collect .ImmutableSortedSet ;
41
+ import com .google .common .collect .ImmutableSortedSet .Builder ;
40
42
import com .google .common .collect .Ordering ;
41
43
import com .google .common .collect .Sets ;
42
44
import java .nio .file .Path ;
@@ -70,10 +72,13 @@ private MavenUberJar(
70
72
this .mavenPomTemplate = mavenPomTemplate ;
71
73
}
72
74
73
- private static BuildRuleParams adjustParams (BuildRuleParams params , TraversedDeps traversedDeps ) {
75
+ private static BuildRuleParams adjustParams (
76
+ BuildRuleParams params ,
77
+ TraversedDeps traversedDeps ,
78
+ ImmutableSortedSet <BuildRule > extras ) {
74
79
return params
75
80
.withDeclaredDeps (ImmutableSortedSet .copyOf (Ordering .natural (), traversedDeps .packagedDeps ))
76
- .withoutExtraDeps ( );
81
+ .withExtraDeps ( extras );
77
82
}
78
83
79
84
/**
@@ -84,18 +89,23 @@ private static BuildRuleParams adjustParams(BuildRuleParams params, TraversedDep
84
89
* published item.
85
90
*/
86
91
public static MavenUberJar create (
92
+ SourcePathRuleFinder resolver ,
87
93
JavaLibrary rootRule ,
88
94
BuildTarget buildTarget ,
89
95
ProjectFilesystem projectFilesystem ,
90
96
BuildRuleParams params ,
91
97
Optional <String > mavenCoords ,
92
98
Optional <SourcePath > mavenPomTemplate ) {
93
99
TraversedDeps traversedDeps = TraversedDeps .traverse (ImmutableSet .of (rootRule ));
100
+
101
+ Builder <BuildRule > templateRule = ImmutableSortedSet .naturalOrder ();
102
+ mavenPomTemplate .ifPresent (path -> resolver .getRule (path ).ifPresent (templateRule ::add ));
103
+
94
104
return new MavenUberJar (
95
105
traversedDeps ,
96
106
buildTarget ,
97
107
projectFilesystem ,
98
- adjustParams (params , traversedDeps ),
108
+ adjustParams (params , traversedDeps , templateRule . build () ),
99
109
mavenCoords ,
100
110
mavenPomTemplate );
101
111
}
@@ -195,6 +205,7 @@ private static TraversedDeps traverse(
195
205
196
206
Set <JavaLibrary > difference = Sets .difference (candidates .build (), removals .build ());
197
207
Set <? extends BuildRule > mandatoryRules = alwaysPackageRoots ? roots : Collections .emptySet ();
208
+
198
209
return new TraversedDeps (
199
210
/* mavenDeps */ depsCollector .build (),
200
211
/* packagedDeps */ Sets .union (mandatoryRules , difference ));
0 commit comments