Skip to content

Commit

Permalink
Make source code Java 5 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 13, 2023
1 parent 0ba8c9e commit 2faeefa
Showing 1 changed file with 90 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.gradle.api.attributes.CompatibilityCheckDetails;
import org.gradle.api.attributes.Usage;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
Expand Down Expand Up @@ -150,26 +151,26 @@ protected VariantAction(Project project, Configuration configuration) {
*/
public void execute(Variant variant) {
Provider<ByteBuddyAndroidService> byteBuddyAndroidServiceProvider = project.getGradle().getSharedServices().registerIfAbsent(variant.getName() + "ByteBuddyAndroidService",
ByteBuddyAndroidService.class,
new ByteBuddyAndroidService.ConfigurationAction(project.getExtensions().getByType(BaseExtension.class)));
ByteBuddyAndroidService.class,
new ByteBuddyAndroidService.ConfigurationAction(project.getExtensions().getByType(BaseExtension.class)));
if (variant.getBuildType() == null) {
throw new GradleException("Build type for " + variant + " was null");
}
Configuration configuration = configurations.get(variant.getBuildType());
if (configuration == null) {
configuration = project.getConfigurations().create(variant.getBuildType() + "ByteBuddy", new VariantConfigurationConfigurationAction(project,
this.configuration,
variant.getBuildType()));
this.configuration,
variant.getBuildType()));
Configuration previous = configurations.putIfAbsent(variant.getBuildType(), configuration);
if (previous != null) {
configuration = previous;
}
}
FileCollection classPath = RuntimeClassPathResolver.INSTANCE.apply(variant);
variant.getInstrumentation().transformClassesWith(ByteBuddyAsmClassVisitorFactory.class, InstrumentationScope.ALL, new ByteBuddyTransformationConfiguration(project,
configuration,
byteBuddyAndroidServiceProvider,
classPath));
configuration,
byteBuddyAndroidServiceProvider,
classPath));
TRANSFORMATION_DISPATCHER.accept(project, variant, configuration, classPath);
}
}
Expand Down Expand Up @@ -217,8 +218,8 @@ protected FileCollection apply(Variant variant) {
throw new GradleException("Cannot resolve runtime class path for " + variant);
}
return ((ComponentCreationConfig) variant).getVariantDependencies().getArtifactFileCollection(AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH,
AndroidArtifacts.ArtifactScope.ALL,
AndroidArtifacts.ArtifactType.CLASSES_JAR);
AndroidArtifacts.ArtifactScope.ALL,
AndroidArtifacts.ArtifactType.CLASSES_JAR);
}
}

Expand Down Expand Up @@ -464,12 +465,12 @@ enum ForLegacyAndroid implements TransformationDispatcher {
*/
public void accept(Project project, Variant variant, Configuration configuration, FileCollection classPath) {
TaskProvider<LegacyByteBuddyLocalClassesEnhancerTask> provider = project.getTasks().register(variant.getName() + "BytebuddyLocalTransform",
LegacyByteBuddyLocalClassesEnhancerTask.class,
new LegacyByteBuddyLocalClassesEnhancerTask.ConfigurationAction(configuration, project.getExtensions().getByType(BaseExtension.class), classPath));
LegacyByteBuddyLocalClassesEnhancerTask.class,
new LegacyByteBuddyLocalClassesEnhancerTask.ConfigurationAction(configuration, project.getExtensions().getByType(BaseExtension.class), classPath));
variant.getArtifacts()
.use(provider)
.wiredWith(LegacyByteBuddyLocalClassesEnhancerTask::getLocalClassesDirs, LegacyByteBuddyLocalClassesEnhancerTask::getOutputDir)
.toTransform(MultipleArtifact.ALL_CLASSES_DIRS.INSTANCE);
.use(provider)
.wiredWith(GetLocalJarsFunction.INSTANCE, GetOutputDirFunction.INSTANCE)
.toTransform(MultipleArtifact.ALL_CLASSES_DIRS.INSTANCE);
}
}

Expand Down Expand Up @@ -530,9 +531,9 @@ public void accept(Project project, Variant variant, Configuration configuration
try {
toTransform.invoke(use.invoke(forScope.invoke(variant.getArtifacts(), scope), provider),
artifact,
(Function1<ByteBuddyLocalClassesEnhancerTask, ListProperty<RegularFile>>) ByteBuddyLocalClassesEnhancerTask::getLocalJars,
(Function1<ByteBuddyLocalClassesEnhancerTask, ListProperty<Directory>>) ByteBuddyLocalClassesEnhancerTask::getLocalClassesDirs,
(Function1<ByteBuddyLocalClassesEnhancerTask, RegularFileProperty>) ByteBuddyLocalClassesEnhancerTask::getOutputFile);
GetLocalJarsFunction.INSTANCE,
GetLocalClassesDirsFunction.INSTANCE,
GetOutputFileFunction.INSTANCE);
} catch (IllegalAccessException exception) {
throw new IllegalStateException("Failed to variant scope", exception);
} catch (InvocationTargetException exception) {
Expand All @@ -550,5 +551,77 @@ public void accept(Project project, Variant variant, Configuration configuration
* @param classPath The class path to use.
*/
void accept(Project project, Variant variant, Configuration configuration, FileCollection classPath);

/**
* A function representation of resolving local jars.
*/
enum GetLocalJarsFunction implements Function1<ByteBuddyLocalClassesEnhancerTask, ListProperty<RegularFile>> {

/**
* The singleton instance.
*/
INSTANCE;

/**
* {@inheritDoc}
*/
public ListProperty<RegularFile> invoke(ByteBuddyLocalClassesEnhancerTask task) {
return task.getLocalJars();
}
}

/**
* A function representation of getting the local classes directory.
*/
enum GetLocalClassesDirsFunction implements Function1<ByteBuddyLocalClassesEnhancerTask, ListProperty<Directory>> {

/**
* The singleton instance.
*/
INSTANCE;

/**
* {@inheritDoc}
*/
public ListProperty<Directory> invoke(ByteBuddyLocalClassesEnhancerTask task) {
return task.getLocalClassesDirs();
}
}

/**
* A function representation of getting the output directory.
*/
enum GetOutputDirFunction implements Function1<LegacyByteBuddyLocalClassesEnhancerTask, DirectoryProperty> {

/**
* The singleton instance.
*/
INSTANCE;

/**
* {@inheritDoc}
*/
public DirectoryProperty invoke(LegacyByteBuddyLocalClassesEnhancerTask task) {
return task.getOutputDir();
}
}

/**
* A function representation of getting the output file.
*/
enum GetOutputFileFunction implements Function1<ByteBuddyLocalClassesEnhancerTask, RegularFileProperty> {

/**
* The singleton instance.
*/
INSTANCE;

/**
* {@inheritDoc}
*/
public RegularFileProperty invoke(ByteBuddyLocalClassesEnhancerTask task) {
return task.getOutputFile();
}
}
}
}

0 comments on commit 2faeefa

Please sign in to comment.