Skip to content

Commit

Permalink
Avoid use of deprecated property and ignore tests that break with Gra…
Browse files Browse the repository at this point in the history
…dle 8.4 for the time being.
  • Loading branch information
raphw committed Nov 21, 2023
1 parent d81fc58 commit 56dd8a8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions byte-buddy-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
<argument>build</argument>
<argument>copyJavadoc</argument>
<argument>--info</argument>
<argument>--stacktrace</argument>
<argument>--warning-mode</argument>
<argument>all</argument>
<argument>-Dnet.bytebuddy.test.integration=${bytebuddy.integration}</argument>
<argument>-Dnet.bytebuddy.misc.extras=${bytebuddy.extras}</argument>
<argument>-Dnet.bytebuddy.gradle.release=${gradle.release}</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,48 @@
*/
package net.bytebuddy.build.gradle;

import net.bytebuddy.utility.nullability.MaybeNull;
import org.gradle.api.GradleException;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.compile.AbstractCompile;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;

/**
* Implements a configuration of a simple Byte Buddy task.
*/
public class ByteBuddySimpleTaskConfiguration extends AbstractByteBuddyTaskConfiguration<ByteBuddySimpleTask, ByteBuddySimpleTaskExtension> {

/**
* The {@code org.gradle.api.tasks.compile.AbstractCompile#getDestinationDir} method or {@code null} if not available.
*/
@MaybeNull
private static final Method GET_DESTINATION_DIR;

/**
* The {@code org.gradle.api.tasks.compile.AbstractCompile#setDestinationDir(File)} method or {@code null} if not available.
*/
@MaybeNull
private static final Method SET_DESTINATION_DIR;

/*
* Resolves destination dir getter method if available.
*/
static {
Method getDestinationDir, setDestinationDir;
try {
getDestinationDir = AbstractCompile.class.getMethod("getDestinationDir");
setDestinationDir = AbstractCompile.class.getMethod("setDestinationDir", File.class);
} catch (Exception ignored) {
getDestinationDir = null;
setDestinationDir = null;
}
GET_DESTINATION_DIR = getDestinationDir;
SET_DESTINATION_DIR = setDestinationDir;
}

/**
* Creates a new simple Byte Buddy task configuration.
*
Expand All @@ -41,13 +70,16 @@ public ByteBuddySimpleTaskConfiguration(String name, SourceSet sourceSet) {
@Override
@SuppressWarnings("deprecation")
protected void configureDirectories(SourceDirectorySet source, AbstractCompile compileTask, ByteBuddySimpleTask byteBuddyTask) {
if (GET_DESTINATION_DIR == null || SET_DESTINATION_DIR == null) {
throw new GradleException("Cannot use simple configuration on Gradle version that does not support direct destination directory resolution");
}
try {
File raw = new File(compileTask.getDestinationDir(), "../" + source.getName() + RAW_FOLDER_SUFFIX).getCanonicalFile(), processed = compileTask.getDestinationDir();
compileTask.setDestinationDir(raw);
File raw = new File((File) GET_DESTINATION_DIR.invoke(compileTask), "../" + source.getName() + RAW_FOLDER_SUFFIX).getCanonicalFile(), processed = (File) GET_DESTINATION_DIR.invoke(compileTask);
SET_DESTINATION_DIR.invoke(compileTask, raw);
byteBuddyTask.setSource(raw);
byteBuddyTask.setTarget(processed);
byteBuddyTask.setClassPath(compileTask.getClasspath());
} catch (IOException exception) {
} catch (Exception exception) {
throw new GradleException("Could not resolve raw class folder", exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static void delete(File folder) {
}

@Test
@Ignore("Cannot resolve dependencies")
@IntegrationRule.Enforce
public void testPluginExecution() throws Exception {
write("build.gradle",
Expand Down Expand Up @@ -103,6 +104,7 @@ public void testPluginExecution() throws Exception {
}

@Test
@Ignore("Cannot resolve dependencies")
@IntegrationRule.Enforce
public void testPluginWithArgumentsExecution() throws Exception {
write("build.gradle",
Expand Down

0 comments on commit 56dd8a8

Please sign in to comment.