diff --git a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyLocalClassesEnhancerTask.java b/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyLocalClassesEnhancerTask.java index 96ff3bd411..ae2c31f4ab 100644 --- a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyLocalClassesEnhancerTask.java +++ b/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyLocalClassesEnhancerTask.java @@ -29,8 +29,8 @@ import org.gradle.api.DefaultTask; import org.gradle.api.GradleException; import org.gradle.api.JavaVersion; +import org.gradle.api.Project; import org.gradle.api.file.*; -import org.gradle.api.logging.Logger; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.*; @@ -226,7 +226,7 @@ public void execute() throws IOException { try { Class discovery = Class.forName("net.bytebuddy.build.gradle.Discovery"); Class.forName("net.bytebuddy.build.gradle.AbstractByteBuddyTask").getMethod("apply", - Logger.class, + Project.class, ClassLoader.class, List.class, discovery, @@ -245,7 +245,7 @@ public void execute() throws IOException { boolean.class, Plugin.Engine.Source.class, Plugin.Engine.Target.class).invoke(null, - getLogger(), + getProject(), classLoader, transformations, discovery.getMethod("valueOf", String.class).invoke(null, getDiscovery().get().name()), diff --git a/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTask.java b/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTask.java index 9ca194df3b..071208e6c9 100644 --- a/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTask.java +++ b/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTask.java @@ -27,6 +27,7 @@ import net.bytebuddy.utility.nullability.UnknownNull; import org.gradle.api.Action; import org.gradle.api.DefaultTask; +import org.gradle.api.Project; import org.gradle.api.logging.Logger; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Internal; @@ -399,7 +400,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target) classFileVersion = this.classFileVersion; getLogger().debug("Java version was configured: {}", classFileVersion.getJavaVersion()); } - apply(getLogger(), + apply(getProject(), getClass().getClassLoader(), new ArrayList(getTransformations()), getDiscovery(), @@ -423,7 +424,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target) /** * Dispatches a Byte Buddy instrumentation Gradle task. * - * @param logger The logger to use. + * @param project The current project. * @param rootLoader The class loader that is used for searching types and applying plugins. * @param transformations The transformations to apply. * @param discovery The discovery for plugins to use. @@ -444,7 +445,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target) * @param target The target to use for instrumenting. * @throws IOException If an I/O error occurs. */ - public static void apply(Logger logger, + public static void apply(Project project, ClassLoader rootLoader, List transformations, Discovery discovery, @@ -484,16 +485,20 @@ public static void apply(Logger logger, } catch (ClassNotFoundException exception) { throw new IllegalStateException("Discovered plugin is not available: " + name, exception); } - logger.debug("Registered discovered plugin: {}", name); + project.getLogger().debug("Registered discovered plugin: {}", name); } else { - logger.info("Skipping discovered plugin {} which was previously discovered or registered", name); + project.getLogger().info("Skipping discovered plugin {} which was previously discovered or registered", name); } } } if (transformations.isEmpty()) { - logger.warn("No transformations are specified or discovered. Application will be non-operational."); + project.getLogger().warn("No transformations are specified or discovered. Application will be non-operational."); } else { - logger.debug("{} plugins are being applied via configuration and discovery", transformations.size()); + project.getLogger().debug("{} plugins are being applied via configuration and discovery", transformations.size()); + } + List classPath = new ArrayList(); + for (File file : artifacts) { + classPath.add(file); } List factories = new ArrayList(transformations.size()); for (Transformation transformation : transformations) { @@ -501,10 +506,12 @@ public static void apply(Logger logger, factories.add(new Plugin.Factory.UsingReflection(transformation.toPlugin(classLoader)) .with(transformation.makeArgumentResolvers()) .with(rootLocationResolver, - Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, logger), - Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, logger), - Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(logger)))); - logger.info("Resolved plugin: {}", transformation.toPluginName()); + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, project.getLogger()), + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, project.getLogger()), + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(project.getLogger())), + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Project.class, project), + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, classPath.toArray(new File[0])))); + project.getLogger().info("Resolved plugin: {}", transformation.toPluginName()); } catch (Throwable throwable) { throw new IllegalStateException("Cannot resolve plugin: " + transformation.toPluginName(), throwable); } @@ -526,7 +533,7 @@ public static void apply(Logger logger, : Plugin.Engine.PoolStrategy.Default.FAST) .with(classFileLocator) .with(multiReleaseClassFileVersion) - .with(new TransformationLogger(logger)) + .with(new TransformationLogger(project.getLogger())) .withErrorHandlers(Plugin.Engine.ErrorHandler.Enforcing.ALL_TYPES_RESOLVED, failOnLiveInitializer ? Plugin.Engine.ErrorHandler.Enforcing.NO_LIVE_INITIALIZERS : Plugin.Engine.Listener.NoOp.INSTANCE, failFast @@ -547,9 +554,9 @@ public static void apply(Logger logger, if (!summary.getFailed().isEmpty()) { throw new IllegalStateException(summary.getFailed() + " type transformation(s) have failed"); } else if (warnOnEmptyTypeSet && summary.getTransformed().isEmpty()) { - logger.warn("No types were transformed during plugin execution"); + project.getLogger().warn("No types were transformed during plugin execution"); } else { - logger.info("Transformed {} type(s)", summary.getTransformed().size()); + project.getLogger().info("Transformed {} type(s)", summary.getTransformed().size()); } } diff --git a/byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java b/byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java index 2f7296eefe..edc43d10e0 100644 --- a/byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java +++ b/byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java @@ -374,6 +374,10 @@ protected Plugin.Engine.Summary transform(List classPath, stalenessFilter = null; getLog().debug("Did not discover previous staleness file"); } + List artifacts = new ArrayList(classPath.size()); + for (String element : classPath) { + artifacts.add(new File(element)); + } ClassLoaderResolver classLoaderResolver = new ClassLoaderResolver(getLog(), repositorySystem, repositorySystemSession == null ? MavenRepositorySystemUtils.newSession() : repositorySystemSession, project.getRemotePluginRepositories()); try { List factories = new ArrayList(transformers.size()); @@ -384,7 +388,9 @@ protected Plugin.Engine.Summary transform(List classPath, .with(transformer.toArgumentResolvers()) .with(Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File.class, file), Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Log.class, getLog()), - Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new MavenBuildLogger(getLog())))); + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new MavenBuildLogger(getLog())), + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(MavenProject.class, project), + Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, artifacts.toArray(new File[0])))); getLog().info("Resolved plugin: " + plugin); } catch (Throwable throwable) { throw new MojoExecutionException("Cannot resolve plugin: " + plugin, throwable); @@ -408,10 +414,9 @@ protected Plugin.Engine.Summary transform(List classPath, ClassFileVersion multiReleaseClassFileVersion = multiReleaseVersion == null ? classFileVersion : ClassFileVersion.ofJavaVersion(multiReleaseVersion); - List classFileLocators = new ArrayList(classPath.size()); + List classFileLocators = new ArrayList(artifacts.size()); classFileLocators.add(ClassFileLocator.ForClassLoader.ofPlatformLoader()); - for (String element : classPath) { - File artifact = new File(element); + for (File artifact : artifacts) { classFileLocators.add(artifact.isFile() ? ClassFileLocator.ForJarFile.of(artifact, multiReleaseClassFileVersion) : ClassFileLocator.ForFolder.of(artifact, multiReleaseClassFileVersion));