Skip to content

Commit

Permalink
Avoid deprecation on task configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 13, 2024
1 parent 8e1acc6 commit f3a68e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public class ByteBuddyPlugin implements Plugin<Project> {
Dispatcher<?, ?> dispatcher;
try {
Class.forName("org.gradle.work.InputChanges"); // Make sure that at least Gradle 6 is available.
dispatcher = new Dispatcher.ForApi6CapableGradle(SourceDirectorySet.class.getMethod("getDestinationDirectory"),
AbstractCompile.class.getMethod("setDestinationDir", Class.forName("org.gradle.api.provider.Provider")));
dispatcher = new Dispatcher.ForApi6CapableGradle(
SourceDirectorySet.class.getMethod("getDestinationDirectory"),
AbstractCompile.class.getMethod("getDestinationDirectory"));
} catch (Throwable ignored) {
dispatcher = Dispatcher.ForLegacyGradle.INSTANCE;
}
Expand Down Expand Up @@ -191,22 +192,22 @@ class ForApi6CapableGradle implements Dispatcher<ByteBuddyTask, ByteBuddyTaskExt
/**
* The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
*/
private final Method getDestinationDirectory;
private final Method getDestinationDirectorySource;

/**
* The {@code org.gradle.api.tasks.compile.AbstractCompile#setDestinationDir} method.
* The {@code org.gradle.api.file.AbstractCompile#getDestinationDirectory} method.
*/
private final Method setDestinationDir;
private final Method getDestinationDirectoryTarget;

/**
* Creates a new dispatcher for a Gradle version of at least 6.
*
* @param getDestinationDirectory The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
* @param setDestinationDir The {@code org.gradle.api.tasks.compile.AbstractCompile#setDestinationDir} method.
* @param getDestinationDirectorySource The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
* @param getDestinationDirectoryTarget The {@code org.gradle.api.file.AbstractCompile#getDestinationDirectory} method.
*/
protected ForApi6CapableGradle(Method getDestinationDirectory, Method setDestinationDir) {
this.getDestinationDirectory = getDestinationDirectory;
this.setDestinationDir = setDestinationDir;
protected ForApi6CapableGradle(Method getDestinationDirectorySource, Method getDestinationDirectoryTarget) {
this.getDestinationDirectorySource = getDestinationDirectorySource;
this.getDestinationDirectoryTarget = getDestinationDirectoryTarget;
}

/**
Expand All @@ -227,7 +228,7 @@ public ByteBuddyTaskExtension toExtension(Project project) {
* {@inheritDoc}
*/
public ByteBuddyTaskConfiguration toAction(String name, SourceSet sourceSet) {
return new ByteBuddyTaskConfiguration(name, sourceSet, getDestinationDirectory, setDestinationDir);
return new ByteBuddyTaskConfiguration(name, sourceSet, getDestinationDirectorySource, getDestinationDirectoryTarget);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,34 @@ public class ByteBuddyTaskConfiguration extends AbstractByteBuddyTaskConfigurati
/**
* The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
*/
private final Method getDestinationDirectory;
private final Method getDestinationDirectorySource;

/**
* The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
* The {@code org.gradle.api.file.AbstractCompile#getDestinationDirectory} method.
*/
private final Method setDestinationDir;
private final Method getDestinationDirectoryTarget;

/**
* Creates a new Byte Buddy task configuration.
*
* @param name The name of the task.
* @param sourceSet The source set for which the task chain is being configured.
* @param getDestinationDirectory The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
* @param setDestinationDir The {@code org.gradle.api.tasks.compile.AbstractCompile#setDestinationDir} method.
* @param name The name of the task.
* @param sourceSet The source set for which the task chain is being configured.
* @param getDestinationDirectorySource The {@code org.gradle.api.file.SourceSetDirectory#getDestinationDirectory} method.
* @param getDestinationDirectoryTarget The {@code org.gradle.api.file.AbstractCompile#getDestinationDirectory} method.
*/
public ByteBuddyTaskConfiguration(String name, SourceSet sourceSet, Method getDestinationDirectory, Method setDestinationDir) {
public ByteBuddyTaskConfiguration(String name, SourceSet sourceSet, Method getDestinationDirectorySource, Method getDestinationDirectoryTarget) {
super(name, sourceSet);
this.getDestinationDirectory = getDestinationDirectory;
this.setDestinationDir = setDestinationDir;
this.getDestinationDirectorySource = getDestinationDirectorySource;
this.getDestinationDirectoryTarget = getDestinationDirectoryTarget;
}

@Override
protected void configureDirectories(SourceDirectorySet source, AbstractCompile compileTask, ByteBuddyTask byteBuddyTask) {
try {
DirectoryProperty directory = (DirectoryProperty) getDestinationDirectory.invoke(source);
setDestinationDir.invoke(compileTask, directory.dir("../" + source.getName() + RAW_FOLDER_SUFFIX).map(ToFileMapper.INSTANCE));
DirectoryProperty directory = (DirectoryProperty) getDestinationDirectorySource.invoke(source);
((DirectoryProperty) getDestinationDirectoryTarget.invoke(compileTask)).set((File) directory.dir("../"
+ source.getName()
+ RAW_FOLDER_SUFFIX).map(ToFileMapper.INSTANCE));
byteBuddyTask.getSource().set(directory.dir("../" + source.getName() + RAW_FOLDER_SUFFIX));
byteBuddyTask.getTarget().set(directory);
byteBuddyTask.getClassPath().from(compileTask.getClasspath());
Expand Down

0 comments on commit f3a68e0

Please sign in to comment.