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 0a5d16defe1..42ea34ea97e 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 @@ -26,6 +26,7 @@ import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.dynamic.scaffold.inline.MethodNameTransformer; import net.bytebuddy.utility.QueueFactory; +import net.bytebuddy.utility.nullability.MaybeNull; import org.gradle.api.Action; import org.gradle.api.DefaultTask; import org.gradle.api.GradleException; @@ -46,7 +47,13 @@ import java.io.Closeable; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -160,7 +167,7 @@ public void execute() { try { buildLogger = (BuildLogger) Class.forName("net.bytebuddy.build.gradle.GradleBuildLogger") .getConstructor(Logger.class) - .newInstance(LOGGER); + .newInstance(getProject().getLogger()); } catch (Exception exception) { throw new GradleException("Failed to resolve Gradle build logger", exception); } @@ -181,7 +188,7 @@ public void execute() { } } Plugin.Engine.Summary summary = Plugin.Engine.Default.of(new EntryPoint.Unvalidated(EntryPoint.Default.DECORATE), - classFileVersion,Logger + classFileVersion, MethodNameTransformer.Suffixing.withRandomSuffix()) .with(classFileLocator) .apply(new Plugin.Engine.Source.Compound(sources), new TargetForAndroidAppJarFile(getOutputFile().get().getAsFile()), factories); diff --git a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidPlugin.java b/byte-buddy/src/main/resources/ByteBuddyAndroidPlugin.java similarity index 94% rename from byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidPlugin.java rename to byte-buddy/src/main/resources/ByteBuddyAndroidPlugin.java index da9d9c4d4cc..64bec71daec 100644 --- a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidPlugin.java +++ b/byte-buddy/src/main/resources/ByteBuddyAndroidPlugin.java @@ -323,7 +323,7 @@ protected ByteBuddyTransformationConfiguration(Project project, * {@inheritDoc} */ public Unit invoke(ByteBuddyInstrumentationParameters parameters) { - parameters.getByteBuddyClasspath().from(getByteBuddyClasspath(project, configuration)); + parameters.getByteBuddyClasspath().from(ByteBuddyViewConfiguration.toClassPath(project, configuration)); parameters.getAndroidBootClasspath().from(project.getExtensions().getByType(BaseExtension.class).getBootClasspath()); parameters.getRuntimeClasspath().from(classPath); parameters.getByteBuddyService().set(byteBuddyAndroidServiceProvider); @@ -482,7 +482,9 @@ enum ForLegacyAndroid implements TransformationDispatcher { public void accept(Project project, Variant variant, Configuration configuration, FileCollection classPath) { TaskProvider provider = project.getTasks().register(variant.getName() + "BytebuddyLocalTransform", LegacyByteBuddyLocalClassesEnhancerTask.class, - new LegacyByteBuddyLocalClassesEnhancerTask.ConfigurationAction(getByteBuddyClasspath(project, configuration), project.getExtensions().getByType(BaseExtension.class), classPath)); + new LegacyByteBuddyLocalClassesEnhancerTask.ConfigurationAction(ByteBuddyViewConfiguration.toClassPath(project, configuration), + project.getExtensions().getByType(BaseExtension.class), + classPath)); variant.getArtifacts() .use(provider) .wiredWith(GetLocalClassesFunction.INSTANCE, GetOutputDirFunction.INSTANCE) @@ -579,7 +581,7 @@ protected ForApk74CompatibleAndroid(Method forScope, Method use, Method toTransf public void accept(Project project, Variant variant, Configuration configuration, FileCollection classPath) { TaskProvider provider = project.getTasks().register(variant.getName() + "BytebuddyTransform", ByteBuddyLocalClassesEnhancerTask.class, - new ByteBuddyLocalClassesEnhancerTask.ConfigurationAction(getByteBuddyClasspath(project, configuration), project.getExtensions().getByType(BaseExtension.class))); + new ByteBuddyLocalClassesEnhancerTask.ConfigurationAction(ByteBuddyViewConfiguration.toClassPath(project, configuration), project.getExtensions().getByType(BaseExtension.class))); try { toTransform.invoke(use.invoke(forScope.invoke(variant.getArtifacts(), scope), provider), artifact, @@ -660,19 +662,32 @@ public RegularFileProperty invoke(ByteBuddyLocalClassesEnhancerTask task) { } /** - * For external dependencies, it provides their JAR files. For local project's dependencies, it provides their local - * build dirs for both classes and resources. The latter allows for faster and more reliable (up-to-date) compilation processes - * when using local plugins. + * A view configuration for creating the Byte Buddy class path. */ - private static FileCollection getByteBuddyClasspath(Project project, Configuration byteBuddyConfiguration) { - FileCollection resources = byteBuddyConfiguration.getIncoming().artifactView(viewConfiguration -> { - viewConfiguration.lenient(false); - viewConfiguration.getAttributes().attribute(ARTIFACT_TYPE_ATTRIBUTE, BYTE_BUDDY_RESOURCES_TYPE); - }).getFiles(); - FileCollection classes = byteBuddyConfiguration.getIncoming().artifactView(viewConfiguration -> { - viewConfiguration.lenient(false); - viewConfiguration.getAttributes().attribute(ARTIFACT_TYPE_ATTRIBUTE, BYTE_BUDDY_CLASSES_TYPE); - }).getFiles(); - return project.files(classes, resources); + protected enum ByteBuddyViewConfiguration implements Action { + + /** + * The singleton instance. + */ + INSTANCE; + + /** + * For external dependencies, it provides their JAR files. For local project's dependencies, it provides their local + * build dirs for both classes and resources. The latter allows for faster and more reliable (up-to-date) compilation processes + * when using local plugins. + */ + protected static FileCollection toClassPath(Project project, Configuration configuration) { + return project.files( + configuration.getIncoming().artifactView(INSTANCE).getFiles(), + configuration.getIncoming().artifactView(INSTANCE).getFiles()); + } + + /** + * {@inheritDoc} + */ + public void execute(ArtifactView.ViewConfiguration configuration) { + configuration.lenient(false); + configuration.getAttributes().attribute(ARTIFACT_TYPE_ATTRIBUTE, BYTE_BUDDY_RESOURCES_TYPE); + } } }