Skip to content

Commit f071a02

Browse files
committed
Add additional arguments to plugins.
1 parent 01d06f9 commit f071a02

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyLocalClassesEnhancerTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.gradle.api.DefaultTask;
3030
import org.gradle.api.GradleException;
3131
import org.gradle.api.JavaVersion;
32+
import org.gradle.api.Project;
3233
import org.gradle.api.file.*;
33-
import org.gradle.api.logging.Logger;
3434
import org.gradle.api.provider.ListProperty;
3535
import org.gradle.api.provider.Property;
3636
import org.gradle.api.tasks.*;
@@ -226,7 +226,7 @@ public void execute() throws IOException {
226226
try {
227227
Class<?> discovery = Class.forName("net.bytebuddy.build.gradle.Discovery");
228228
Class.forName("net.bytebuddy.build.gradle.AbstractByteBuddyTask").getMethod("apply",
229-
Logger.class,
229+
Project.class,
230230
ClassLoader.class,
231231
List.class,
232232
discovery,
@@ -245,7 +245,7 @@ public void execute() throws IOException {
245245
boolean.class,
246246
Plugin.Engine.Source.class,
247247
Plugin.Engine.Target.class).invoke(null,
248-
getLogger(),
248+
getProject(),
249249
classLoader,
250250
transformations,
251251
discovery.getMethod("valueOf", String.class).invoke(null, getDiscovery().get().name()),

byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTask.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.bytebuddy.utility.nullability.UnknownNull;
2828
import org.gradle.api.Action;
2929
import org.gradle.api.DefaultTask;
30+
import org.gradle.api.Project;
3031
import org.gradle.api.logging.Logger;
3132
import org.gradle.api.tasks.Input;
3233
import org.gradle.api.tasks.Internal;
@@ -399,7 +400,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
399400
classFileVersion = this.classFileVersion;
400401
getLogger().debug("Java version was configured: {}", classFileVersion.getJavaVersion());
401402
}
402-
apply(getLogger(),
403+
apply(getProject(),
403404
getClass().getClassLoader(),
404405
new ArrayList<Transformation>(getTransformations()),
405406
getDiscovery(),
@@ -423,7 +424,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
423424
/**
424425
* Dispatches a Byte Buddy instrumentation Gradle task.
425426
*
426-
* @param logger The logger to use.
427+
* @param project The current project.
427428
* @param rootLoader The class loader that is used for searching types and applying plugins.
428429
* @param transformations The transformations to apply.
429430
* @param discovery The discovery for plugins to use.
@@ -444,7 +445,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
444445
* @param target The target to use for instrumenting.
445446
* @throws IOException If an I/O error occurs.
446447
*/
447-
public static void apply(Logger logger,
448+
public static void apply(Project project,
448449
ClassLoader rootLoader,
449450
List<Transformation> transformations,
450451
Discovery discovery,
@@ -484,27 +485,33 @@ public static void apply(Logger logger,
484485
} catch (ClassNotFoundException exception) {
485486
throw new IllegalStateException("Discovered plugin is not available: " + name, exception);
486487
}
487-
logger.debug("Registered discovered plugin: {}", name);
488+
project.getLogger().debug("Registered discovered plugin: {}", name);
488489
} else {
489-
logger.info("Skipping discovered plugin {} which was previously discovered or registered", name);
490+
project.getLogger().info("Skipping discovered plugin {} which was previously discovered or registered", name);
490491
}
491492
}
492493
}
493494
if (transformations.isEmpty()) {
494-
logger.warn("No transformations are specified or discovered. Application will be non-operational.");
495+
project.getLogger().warn("No transformations are specified or discovered. Application will be non-operational.");
495496
} else {
496-
logger.debug("{} plugins are being applied via configuration and discovery", transformations.size());
497+
project.getLogger().debug("{} plugins are being applied via configuration and discovery", transformations.size());
498+
}
499+
List<File> classPath = new ArrayList<File>();
500+
for (File file : artifacts) {
501+
classPath.add(file);
497502
}
498503
List<Plugin.Factory> factories = new ArrayList<Plugin.Factory>(transformations.size());
499504
for (Transformation transformation : transformations) {
500505
try {
501506
factories.add(new Plugin.Factory.UsingReflection(transformation.toPlugin(classLoader))
502507
.with(transformation.makeArgumentResolvers())
503508
.with(rootLocationResolver,
504-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, logger),
505-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, logger),
506-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(logger))));
507-
logger.info("Resolved plugin: {}", transformation.toPluginName());
509+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, project.getLogger()),
510+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, project.getLogger()),
511+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(project.getLogger())),
512+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Project.class, project),
513+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, classPath.toArray(new File[0]))));
514+
project.getLogger().info("Resolved plugin: {}", transformation.toPluginName());
508515
} catch (Throwable throwable) {
509516
throw new IllegalStateException("Cannot resolve plugin: " + transformation.toPluginName(), throwable);
510517
}
@@ -526,7 +533,7 @@ public static void apply(Logger logger,
526533
: Plugin.Engine.PoolStrategy.Default.FAST)
527534
.with(classFileLocator)
528535
.with(multiReleaseClassFileVersion)
529-
.with(new TransformationLogger(logger))
536+
.with(new TransformationLogger(project.getLogger()))
530537
.withErrorHandlers(Plugin.Engine.ErrorHandler.Enforcing.ALL_TYPES_RESOLVED, failOnLiveInitializer
531538
? Plugin.Engine.ErrorHandler.Enforcing.NO_LIVE_INITIALIZERS
532539
: Plugin.Engine.Listener.NoOp.INSTANCE, failFast
@@ -547,9 +554,9 @@ public static void apply(Logger logger,
547554
if (!summary.getFailed().isEmpty()) {
548555
throw new IllegalStateException(summary.getFailed() + " type transformation(s) have failed");
549556
} else if (warnOnEmptyTypeSet && summary.getTransformed().isEmpty()) {
550-
logger.warn("No types were transformed during plugin execution");
557+
project.getLogger().warn("No types were transformed during plugin execution");
551558
} else {
552-
logger.info("Transformed {} type(s)", summary.getTransformed().size());
559+
project.getLogger().info("Transformed {} type(s)", summary.getTransformed().size());
553560
}
554561
}
555562

byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ protected Plugin.Engine.Summary transform(List<? extends String> classPath,
374374
stalenessFilter = null;
375375
getLog().debug("Did not discover previous staleness file");
376376
}
377+
List<File> artifacts = new ArrayList<File>(classPath.size());
378+
for (String element : classPath) {
379+
artifacts.add(new File(element));
380+
}
377381
ClassLoaderResolver classLoaderResolver = new ClassLoaderResolver(getLog(), repositorySystem, repositorySystemSession == null ? MavenRepositorySystemUtils.newSession() : repositorySystemSession, project.getRemotePluginRepositories());
378382
try {
379383
List<Plugin.Factory> factories = new ArrayList<Plugin.Factory>(transformers.size());
@@ -384,7 +388,9 @@ protected Plugin.Engine.Summary transform(List<? extends String> classPath,
384388
.with(transformer.toArgumentResolvers())
385389
.with(Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File.class, file),
386390
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Log.class, getLog()),
387-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new MavenBuildLogger(getLog()))));
391+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new MavenBuildLogger(getLog())),
392+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(MavenProject.class, project),
393+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, artifacts.toArray(new File[0]))));
388394
getLog().info("Resolved plugin: " + plugin);
389395
} catch (Throwable throwable) {
390396
throw new MojoExecutionException("Cannot resolve plugin: " + plugin, throwable);
@@ -408,10 +414,9 @@ protected Plugin.Engine.Summary transform(List<? extends String> classPath,
408414
ClassFileVersion multiReleaseClassFileVersion = multiReleaseVersion == null
409415
? classFileVersion
410416
: ClassFileVersion.ofJavaVersion(multiReleaseVersion);
411-
List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>(classPath.size());
417+
List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>(artifacts.size());
412418
classFileLocators.add(ClassFileLocator.ForClassLoader.ofPlatformLoader());
413-
for (String element : classPath) {
414-
File artifact = new File(element);
419+
for (File artifact : artifacts) {
415420
classFileLocators.add(artifact.isFile()
416421
? ClassFileLocator.ForJarFile.of(artifact, multiReleaseClassFileVersion)
417422
: ClassFileLocator.ForFolder.of(artifact, multiReleaseClassFileVersion));

0 commit comments

Comments
 (0)