@@ -48,13 +48,16 @@ protected JavaLibrary(JavaSemantics semantics) {
48
48
public ConfiguredTarget create (RuleContext ruleContext )
49
49
throws InterruptedException , RuleErrorException {
50
50
JavaCommon common = new JavaCommon (ruleContext , semantics );
51
- RuleConfiguredTargetBuilder builder =
52
- init (ruleContext , common , false /* includeGeneratedExtensionRegistry */ );
53
- return builder != null ? builder .build () : null ;
51
+ return init (
52
+ ruleContext ,
53
+ common ,
54
+ /* includeGeneratedExtensionRegistry = */ false ,
55
+ /* includeJavaPluginInfoProvider = */ false );
54
56
}
55
57
56
- final RuleConfiguredTargetBuilder init (
57
- RuleContext ruleContext , final JavaCommon common , boolean includeGeneratedExtensionRegistry )
58
+ final ConfiguredTarget init (
59
+ RuleContext ruleContext , final JavaCommon common , boolean includeGeneratedExtensionRegistry ,
60
+ boolean includeJavaPluginInfoProvider )
58
61
throws InterruptedException {
59
62
JavaTargetAttributes .Builder attributesBuilder = common .initCommon ();
60
63
@@ -211,13 +214,7 @@ protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
211
214
NestedSet <Artifact > proguardSpecs = new ProguardLibrary (ruleContext ).collectProguardSpecs ();
212
215
213
216
CcLinkParamsProvider ccLinkParamsProvider = new CcLinkParamsProvider (ccLinkParamsStore );
214
- JavaProvider javaProvider = JavaProvider .Builder .create ()
215
- .addProvider (JavaCompilationArgsProvider .class , compilationArgsProvider )
216
- .addProvider (JavaSourceJarsProvider .class , sourceJarsProvider )
217
- .addProvider (ProtoJavaApiInfoAspectProvider .class , protoAspectBuilder .build ())
218
- .addProvider (JavaRuleOutputJarsProvider .class , ruleOutputJarsProvider )
219
- // java_library doesn't need to return JavaRunfilesProvider
220
- .build ();
217
+
221
218
builder
222
219
.addSkylarkTransitiveInfo (
223
220
JavaSkylarkApiProvider .NAME , JavaSkylarkApiProvider .fromRuleContext ())
@@ -230,10 +227,8 @@ protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
230
227
.addProvider (new JavaNeverlinkInfoProvider (neverLink ))
231
228
.addProvider (transitiveCppDeps )
232
229
.addProvider (JavaCompilationArgsProvider .class , compilationArgsProvider )
233
- .addProvider (javaProvider )
234
230
.addProvider (ccLinkParamsProvider )
235
231
.addNativeDeclaredProvider (ccLinkParamsProvider )
236
- .addNativeDeclaredProvider (javaProvider )
237
232
.addProvider (new JavaNativeLibraryProvider (transitiveJavaNativeLibraries ))
238
233
.addProvider (JavaSourceInfoProvider .fromJavaTargetAttributes (attributes , semantics ))
239
234
// TODO(bazel-team): this should only happen for java_plugin
@@ -243,10 +238,25 @@ protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
243
238
.addOutputGroup (JavaSemantics .SOURCE_JARS_OUTPUT_GROUP , transitiveSourceJars )
244
239
.addOutputGroup (OutputGroupProvider .HIDDEN_TOP_LEVEL , proguardSpecs );
245
240
241
+ // java_library doesn't need to return JavaRunfilesProvider
242
+ JavaProvider .Builder javaProviderBuilder = JavaProvider .Builder .create ()
243
+ .addProvider (JavaCompilationArgsProvider .class , compilationArgsProvider )
244
+ .addProvider (JavaSourceJarsProvider .class , sourceJarsProvider )
245
+ .addProvider (ProtoJavaApiInfoAspectProvider .class , protoAspectBuilder .build ())
246
+ .addProvider (JavaRuleOutputJarsProvider .class , ruleOutputJarsProvider );
247
+ if (includeJavaPluginInfoProvider ) {
248
+ JavaPluginInfoProvider javaPluginInfoProvider = common .getJavaPluginInfoProvider (ruleContext );
249
+ javaProviderBuilder .addProvider (JavaPluginInfoProvider .class , javaPluginInfoProvider );
250
+ builder .addProvider (javaPluginInfoProvider );
251
+ }
252
+ JavaProvider javaProvider = javaProviderBuilder .build ();
253
+ builder .addProvider (javaProvider );
254
+ builder .addNativeDeclaredProvider (javaProvider );
255
+
246
256
if (ruleContext .hasErrors ()) {
247
257
return null ;
248
258
}
249
259
250
- return builder ;
260
+ return builder . build () ;
251
261
}
252
262
}
0 commit comments