Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .mvn/checksums.sha256
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ net.bytebuddy:byte-buddy-agent:jar:1.17.8 5b17113e66e77ca6f8af07ff367c216df964a9
net.bytebuddy:byte-buddy-agent:jar:1.18.0 e0144f3fb59778df85f3fe693481173d15deb11dc5027c09d155223f0cab4b1a
net.bytebuddy:byte-buddy-agent:jar:1.18.1 d6edab86ae91111b853d9dd04389ad2c7dab9742ac76dd6aecd275cad5ed3dce
net.bytebuddy:byte-buddy-agent:jar:1.18.2 d91e2d6d1b777687ab14a52b18b08aca32c4c91274131c99907674c661402a76
net.bytebuddy:byte-buddy-agent:jar:1.18.3 3d4c6ff9a441306969ec223db1b37e986788f0b9e077be2a39e2fbbfc11b04e0
net.bytebuddy:byte-buddy-android:jar:1.12.19 bb73d3b9ace5a60a9a9aa1701761073b3df3baf79ff463aed6cd94b724fd3ba9
net.bytebuddy:byte-buddy-android:jar:1.12.20 f43b8b7eb840f6140135066224f0e6b565b9becb05345fdc572a66bfb92df0aa
net.bytebuddy:byte-buddy-android:jar:1.12.21 bf4ad1405c2fcaa8b179929f9a64c8ee66d04f34b0e3fe8a90b28c738f883fe9
Expand Down Expand Up @@ -781,6 +782,7 @@ net.bytebuddy:byte-buddy-android:jar:1.17.8 8368ccfb9a58bde8a83db1ca5a9c142227eb
net.bytebuddy:byte-buddy-android:jar:1.18.0 1dacad4a9557a5c6961ab894d19160723ec5d168d55754000dd18fd4c6f587eb
net.bytebuddy:byte-buddy-android:jar:1.18.1 85f9420e91ce0801f4646af9582f885980b614243e504b70457932f49538c45e
net.bytebuddy:byte-buddy-android:jar:1.18.2 9bf06f5a1ff1487a8f0c95d83189102c0aa830664f1a6705129f7bfcb251b4bb
net.bytebuddy:byte-buddy-android:jar:1.18.3 948bf5ea5b35dd08cd6fbbe0e07c476ff14cc872c64d7b0e091486fa0ee51742
net.bytebuddy:byte-buddy-dep:jar:1.12.19 a85bb853ec6ec156b10ea0b5b0e38ac0f89c6c2bc89dd0358772a0dff2eb85c9
net.bytebuddy:byte-buddy-dep:jar:1.12.20 d7e15d3ccc0508e78a146f1be420779eb3e2e9a537e3c8add3cd6d802c9a615e
net.bytebuddy:byte-buddy-dep:jar:1.12.21 116b320c1f3f8539978ea67989d94e9bfed3e9422beb5a76749d967439ec8f9d
Expand Down Expand Up @@ -832,6 +834,7 @@ net.bytebuddy:byte-buddy-dep:jar:1.17.8 43c225b000af23bfacd5e1d0293d8eef0be8c4ab
net.bytebuddy:byte-buddy-dep:jar:1.18.0 eac12098bd8449321a2bb0646bf5f384fa1a1efe10715dc6259f71b4d563b28a
net.bytebuddy:byte-buddy-dep:jar:1.18.1 3c38fb212713a27e183e058f30c0508811c2d06c942603b02b2184cd99658b8c
net.bytebuddy:byte-buddy-dep:jar:1.18.2 c437ae76a7fc23b60e6dad41e5c4b5efc585272123b3eba202298f1e90661cbe
net.bytebuddy:byte-buddy-dep:jar:1.18.3 4099a282280933c48dfbd09a8c1872ca8912013dc0e4f579535a1e6d3d5e2e1b
net.bytebuddy:byte-buddy-maven-plugin:jar:1.12.19 3419e2afbfac4f21ef709ee3f8f08fc1d71001e07ba2524a0bb2a3c28f3e1087
net.bytebuddy:byte-buddy-maven-plugin:jar:1.12.20 48a36e2e8c2dbe2b3673ef8bf6be22b021cfca35d6205a3d5e722f74db42d52b
net.bytebuddy:byte-buddy-maven-plugin:jar:1.12.21 cb3332f89cc6502e3637dbe509c08c55cb5ad528c675131858dda89eabf7c9fc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.UnknownDomainObjectException;
import org.gradle.api.artifacts.ArtifactView;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.attributes.Attribute;
Expand Down Expand Up @@ -196,7 +197,7 @@ public void execute(Variant variant) {
Provider<ByteBuddyAndroidService> byteBuddyAndroidServiceProvider = project.getGradle().getSharedServices().registerIfAbsent(
variantName + "ByteBuddyAndroidService",
ByteBuddyAndroidService.class,
new ByteBuddyAndroidService.ConfigurationAction(project.getExtensions().getByType(BaseExtension.class)));
ByteBuddyAndroidService.ConfigurationAction.of(project.getExtensions()));
FileCollection classPath = RuntimeClassPathResolver.INSTANCE.apply(variant);
variant.getInstrumentation().transformClassesWith(ByteBuddyAsmClassVisitorFactory.class, InstrumentationScope.ALL, new ByteBuddyTransformationConfiguration(project,
variantResolvableConfiguration,
Expand Down Expand Up @@ -346,7 +347,11 @@ protected ByteBuddyTransformationConfiguration(Project project,
*/
public Unit invoke(ByteBuddyInstrumentationParameters parameters) {
parameters.getByteBuddyClasspath().from(ByteBuddyViewConfiguration.toClassPath(project, configuration));
parameters.getAndroidBootClasspath().from(project.getExtensions().getByType(BaseExtension.class).getBootClasspath());
try {
parameters.getAndroidBootClasspath().from(project.getExtensions().getByType(AndroidComponentsExtension.class).getSdkComponents().getBootClasspath());
} catch (UnknownDomainObjectException ignored) {
parameters.getAndroidBootClasspath().from(project.getExtensions().getByType(BaseExtension.class).getBootClasspath());
}
parameters.getRuntimeClasspath().from(classPath);
parameters.getByteBuddyService().set(byteBuddyAndroidServiceProvider);
return Unit.INSTANCE;
Expand Down Expand Up @@ -607,9 +612,9 @@ public void accept(Project project, Variant variant, Configuration configuration
}
TaskProvider<ByteBuddyLocalClassesEnhancerTask> provider = project.getTasks().register(variant.getName() + "BytebuddyTransform",
ByteBuddyLocalClassesEnhancerTask.class,
new ByteBuddyLocalClassesEnhancerTask.ConfigurationAction(ByteBuddyViewConfiguration.toClassPath(project, configuration),
project.getExtensions().getByType(BaseExtension.class),
project.getExtensions().getByType(ByteBuddyAndroidTaskExtension.class)));
ByteBuddyLocalClassesEnhancerTask.ConfigurationAction.of(
ByteBuddyViewConfiguration.toClassPath(project, configuration),
project.getExtensions()));
try {
toTransform.invoke(use.invoke(forScope.invoke(variant.getArtifacts(), scope), provider),
artifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package net.bytebuddy.build.gradle.android;

import com.android.build.api.dsl.ApplicationExtension;
import com.android.build.gradle.BaseExtension;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.ClassFileVersion;
Expand All @@ -32,8 +33,10 @@
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.JavaVersion;
import org.gradle.api.UnknownDomainObjectException;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.provider.Property;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;
Expand Down Expand Up @@ -379,17 +382,31 @@ protected static class ConfigurationAction implements Action<BuildServiceSpec<Pa
/**
* The base extension.
*/
private final BaseExtension extension;
private final ApplicationExtension extension;

/**
* Creates a new configuration action.
*
* @param extension The base extension.
*/
protected ConfigurationAction(BaseExtension extension) {
protected ConfigurationAction(ApplicationExtension extension) {
this.extension = extension;
}

/**
* Resolves a configuration action for the current platform.
*
* @param container The extension container to query.
* @return An appropriate configuration action.
*/
protected static Action<BuildServiceSpec<Parameters>> of(ExtensionContainer container) {
try {
return new ConfigurationAction(container.getByType(ApplicationExtension.class));
} catch (UnknownDomainObjectException ignored) {
return new ForLegacyAndroid(container.getByType(BaseExtension.class));
}
}

/**
* {@inheritDoc}
*/
Expand All @@ -398,6 +415,36 @@ public void execute(BuildServiceSpec<Parameters> spec) {
.getJavaTargetCompatibilityVersion()
.set(extension.getCompileOptions().getTargetCompatibility());
}

/**
* A configuration action for the {@link BuildServiceSpec} of the {@link Parameters} of {@link ByteBuddyAndroidService}
* used on legacy Android platforms that do not support the current extension.
*/
protected static class ForLegacyAndroid implements Action<BuildServiceSpec<Parameters>> {

/**
* The base extension.
*/
private final BaseExtension extension;

/**
* Creates a new configuration action.
*
* @param extension The base extension.
*/
protected ForLegacyAndroid(BaseExtension extension) {
this.extension = extension;
}

/**
* {@inheritDoc}
*/
public void execute(BuildServiceSpec<Parameters> spec) {
spec.getParameters()
.getJavaTargetCompatibilityVersion()
.set(extension.getCompileOptions().getTargetCompatibility());
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package net.bytebuddy.build.gradle.android;

import com.android.build.api.dsl.ApplicationExtension;
import com.android.build.api.variant.AndroidComponentsExtension;
import com.android.build.gradle.BaseExtension;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.ClassFileVersion;
Expand All @@ -29,12 +31,14 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.JavaVersion;
import org.gradle.api.UnknownDomainObjectException;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.Directory;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -312,38 +316,109 @@ public static class ConfigurationAction implements Action<ByteBuddyLocalClassesE
/**
* The current variant's Byte Buddy configuration.
*/
private final FileCollection byteBuddyConfiguration;
private final FileCollection byteBuddyClassPath;

/**
* The Android gradle extension.
* The Android Gradle extension.
*/
private final BaseExtension androidExtension;
private final ApplicationExtension applicationExtension;

/**
* The Android components extension.
*/
private final AndroidComponentsExtension<?, ?, ?> androidComponentsExtension;

/**
* The Byte Buddy task extension.
*/
private final ByteBuddyAndroidTaskExtension byteBuddyExtension;

/**
* @param byteBuddyConfiguration The current variant Byte Buddy configuration.
* @param androidExtension The Android gradle extension.
* @param byteBuddyExtension The Byte Buddy task extension.
* @param byteBuddyClassPath The current variant Byte Buddy configuration.
* @param applicationExtension The Android Gradle extension.
* @param androidComponentsExtension The Android components extension.
* @param byteBuddyExtension The Byte Buddy task extension.
*/
public ConfigurationAction(FileCollection byteBuddyConfiguration,
BaseExtension androidExtension,
ByteBuddyAndroidTaskExtension byteBuddyExtension) {
this.byteBuddyConfiguration = byteBuddyConfiguration;
this.androidExtension = androidExtension;
protected ConfigurationAction(FileCollection byteBuddyClassPath,
ApplicationExtension applicationExtension,
AndroidComponentsExtension<?, ?, ?> androidComponentsExtension,
ByteBuddyAndroidTaskExtension byteBuddyExtension) {
this.byteBuddyClassPath = byteBuddyClassPath;
this.applicationExtension = applicationExtension;
this.androidComponentsExtension = androidComponentsExtension;
this.byteBuddyExtension = byteBuddyExtension;
}

/**
* Resolves an appropriate configuration action for the current Android platform.
* @param byteBuddyClassPath The current variant Byte Buddy configuration.
* @param container The extensions container to use.
* @return An appropriate configuration action.
*/
@SuppressWarnings("unchecked")
public static Action<ByteBuddyLocalClassesEnhancerTask> of(FileCollection byteBuddyClassPath, ExtensionContainer container) {
try {
return new ConfigurationAction(byteBuddyClassPath,
container.getByType(ApplicationExtension.class),
container.getByType(AndroidComponentsExtension.class),
container.getByType(ByteBuddyAndroidTaskExtension.class));
} catch (UnknownDomainObjectException ignored) {
return new ForLegacyAndroid(byteBuddyClassPath,
container.getByType(BaseExtension.class),
container.getByType(ByteBuddyAndroidTaskExtension.class));
}
}

@Override
public void execute(ByteBuddyLocalClassesEnhancerTask task) {
task.getByteBuddyClasspath().from(byteBuddyConfiguration);
task.getAndroidBootClasspath().from(androidExtension.getBootClasspath());
task.getJavaTargetCompatibilityVersion().set(androidExtension.getCompileOptions().getTargetCompatibility());
task.getByteBuddyClasspath().from(byteBuddyClassPath);
task.getAndroidBootClasspath().from(androidComponentsExtension.getSdkComponents().getBootClasspath());
task.getJavaTargetCompatibilityVersion().set(applicationExtension.getCompileOptions().getTargetCompatibility());
byteBuddyExtension.configure(task);
}

/**
* A configuration action for the {@link ByteBuddyLocalClassesEnhancerTask} task for
* legacy Android platforms.
*/
protected static class ForLegacyAndroid implements Action<ByteBuddyLocalClassesEnhancerTask> {

/**
* The current variant's Byte Buddy configuration.
*/
private final FileCollection byteBuddyClassPath;

/**
* The Android Gradle extension.
*/
private final BaseExtension baseExtension;

/**
* The Byte Buddy task extension.
*/
private final ByteBuddyAndroidTaskExtension byteBuddyExtension;

/**
* @param byteBuddyClassPath The current variant Byte Buddy configuration.
* @param baseExtension The Android Gradle extension.
* @param byteBuddyExtension The Byte Buddy task extension.
*/
protected ForLegacyAndroid(FileCollection byteBuddyClassPath,
BaseExtension baseExtension,
ByteBuddyAndroidTaskExtension byteBuddyExtension) {
this.byteBuddyClassPath = byteBuddyClassPath;
this.baseExtension = baseExtension;
this.byteBuddyExtension = byteBuddyExtension;
}

@Override
public void execute(ByteBuddyLocalClassesEnhancerTask task) {
task.getByteBuddyClasspath().from(byteBuddyClassPath);
task.getAndroidBootClasspath().from(baseExtension.getBootClasspath());
task.getJavaTargetCompatibilityVersion().set(baseExtension.getCompileOptions().getTargetCompatibility());
byteBuddyExtension.configure(task);
}
}
}

/**
Expand Down