Skip to content

Commit

Permalink
Clean up build and remove access to projects from Maven and Gradle pl…
Browse files Browse the repository at this point in the history
…ugins as this breaks configuration cache.
  • Loading branch information
raphw committed Dec 14, 2024
1 parent efbd6cb commit c15c880
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.JavaVersion;
import org.gradle.api.Project;
import org.gradle.api.file.*;
import org.gradle.api.logging.Logger;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.*;
Expand Down Expand Up @@ -226,7 +226,7 @@ public void execute() throws IOException {
try {
Class<?> discovery = Class.forName("net.bytebuddy.build.gradle.Discovery");
Class.forName("net.bytebuddy.build.gradle.AbstractByteBuddyTask").getMethod("apply",
Project.class,
Logger.class,
ClassLoader.class,
List.class,
discovery,
Expand All @@ -245,7 +245,7 @@ public void execute() throws IOException {
boolean.class,
Plugin.Engine.Source.class,
Plugin.Engine.Target.class).invoke(null,
getProject(),
getLogger(),
classLoader,
transformations,
discovery.getMethod("valueOf", String.class).invoke(null, getDiscovery().get().name()),
Expand Down
2 changes: 1 addition & 1 deletion byte-buddy-gradle-plugin/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if (Boolean.getBoolean('net.bytebuddy.misc.extras')) {
}
javadoc {
options {
links 'https://docs.oracle.com/javase/1.5.0/docs/api'
links 'https://docs.oracle.com/javase/6/docs/api'
links 'https://docs.gradle.org/7.5/javadoc'
linksOffline "https://javadoc.io/doc/net.bytebuddy/byte-buddy/${pom.parent.version.text().toString()}", '../byte-buddy/target/apidocs'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import net.bytebuddy.utility.nullability.UnknownNull;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
Expand Down Expand Up @@ -400,7 +399,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
classFileVersion = this.classFileVersion;
getLogger().debug("Java version was configured: {}", classFileVersion.getJavaVersion());
}
apply(getProject(),
apply(getLogger(),
getClass().getClassLoader(),
new ArrayList<Transformation>(getTransformations()),
getDiscovery(),
Expand All @@ -424,7 +423,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
/**
* Dispatches a Byte Buddy instrumentation Gradle task.
*
* @param project The current project.
* @param logger The logger to use.
* @param rootLoader The class loader that is used for searching types and applying plugins.
* @param transformations The transformations to apply.
* @param discovery The discovery for plugins to use.
Expand All @@ -445,7 +444,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
* @param target The target to use for instrumenting.
* @throws IOException If an I/O error occurs.
*/
public static void apply(Project project,
public static void apply(Logger logger,
ClassLoader rootLoader,
List<Transformation> transformations,
Discovery discovery,
Expand Down Expand Up @@ -485,16 +484,16 @@ public static void apply(Project project,
} catch (ClassNotFoundException exception) {
throw new IllegalStateException("Discovered plugin is not available: " + name, exception);
}
project.getLogger().debug("Registered discovered plugin: {}", name);
logger.debug("Registered discovered plugin: {}", name);
} else {
project.getLogger().info("Skipping discovered plugin {} which was previously discovered or registered", name);
logger.info("Skipping discovered plugin {} which was previously discovered or registered", name);
}
}
}
if (transformations.isEmpty()) {
project.getLogger().warn("No transformations are specified or discovered. Application will be non-operational.");
logger.warn("No transformations are specified or discovered. Application will be non-operational.");
} else {
project.getLogger().debug("{} plugins are being applied via configuration and discovery", transformations.size());
logger.debug("{} plugins are being applied via configuration and discovery", transformations.size());
}
List<File> classPath = new ArrayList<File>();
for (File file : artifacts) {
Expand All @@ -506,12 +505,11 @@ public static void apply(Project project,
factories.add(new Plugin.Factory.UsingReflection(transformation.toPlugin(classLoader))
.with(transformation.makeArgumentResolvers())
.with(rootLocationResolver,
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, project.getLogger()),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, project.getLogger()),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(project.getLogger())),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Project.class, project),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, logger),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, logger),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(logger)),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, classPath.toArray(new File[0]))));
project.getLogger().info("Resolved plugin: {}", transformation.toPluginName());
logger.info("Resolved plugin: {}", transformation.toPluginName());
} catch (Throwable throwable) {
throw new IllegalStateException("Cannot resolve plugin: " + transformation.toPluginName(), throwable);
}
Expand All @@ -533,7 +531,7 @@ public static void apply(Project project,
: Plugin.Engine.PoolStrategy.Default.FAST)
.with(classFileLocator)
.with(multiReleaseClassFileVersion)
.with(new TransformationLogger(project.getLogger()))
.with(new TransformationLogger(logger))
.withErrorHandlers(Plugin.Engine.ErrorHandler.Enforcing.ALL_TYPES_RESOLVED, failOnLiveInitializer
? Plugin.Engine.ErrorHandler.Enforcing.NO_LIVE_INITIALIZERS
: Plugin.Engine.Listener.NoOp.INSTANCE, failFast
Expand All @@ -554,9 +552,9 @@ public static void apply(Project project,
if (!summary.getFailed().isEmpty()) {
throw new IllegalStateException(summary.getFailed() + " type transformation(s) have failed");
} else if (warnOnEmptyTypeSet && summary.getTransformed().isEmpty()) {
project.getLogger().warn("No types were transformed during plugin execution");
logger.warn("No types were transformed during plugin execution");
} else {
project.getLogger().info("Transformed {} type(s)", summary.getTransformed().size());
logger.info("Transformed {} type(s)", summary.getTransformed().size());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ protected void configure(T task) {
doConfigure(task);
}

/**
* Defines the discovery set to use.
*
* @param fileCollection The file collection that represents the discovery set.
*/
protected abstract void discoverySet(FileCollection fileCollection);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ protected Plugin.Engine.Summary transform(List<? extends String> classPath,
.with(Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File.class, file),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Log.class, getLog()),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new MavenBuildLogger(getLog())),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(MavenProject.class, project),
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, artifacts.toArray(new File[0]))));
getLog().info("Resolved plugin: " + plugin);
} catch (Throwable throwable) {
Expand Down

0 comments on commit c15c880

Please sign in to comment.