Skip to content

Commit

Permalink
Simplify AspectJ Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgrefer committed Oct 8, 2023
1 parent 852ff21 commit 17891e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.internal.tasks.DefaultSourceSet;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.plugins.internal.JvmPluginsHelper;
Expand All @@ -27,6 +26,8 @@ public class AspectJPlugin implements Plugin<Project> {

private Provider<JavaLauncher> defaultLauncher;

private JavaPluginExtension javaExtension;

@Override
public void apply(Project project) {
if (project.getPlugins().hasPlugin(AspectJPostCompileWeavingPlugin.class)) {
Expand All @@ -42,27 +43,32 @@ public void apply(Project project) {

this.project = project;
project.getPlugins().apply(AspectJBasePlugin.class);
project.getPlugins().apply(JavaBasePlugin.class);
project.getPlugins().apply(JavaPlugin.class);

configureJavaBasePlugin(project);

configureJavaPlugin(project);
}

JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
private void configureJavaBasePlugin(Project project) {
javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);

JavaToolchainService service = project.getExtensions().getByType(JavaToolchainService.class);
defaultLauncher = service.launcherFor(javaExtension.getToolchain());

javaExtension.getSourceSets().all(this::configureSourceSet);
}

project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

SourceSet main = javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet test = javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
private void configureJavaPlugin(Project project) {
SourceSet main = javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet test = javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

Configuration aspectpath = project.getConfigurations().getByName(WeavingSourceSet.getAspectConfigurationName(main));
Configuration testAspectpath = project.getConfigurations().getByName(WeavingSourceSet.getAspectConfigurationName(test));
Configuration aspectpath = project.getConfigurations().getByName(WeavingSourceSet.getAspectConfigurationName(main));
Configuration testAspectpath = project.getConfigurations().getByName(WeavingSourceSet.getAspectConfigurationName(test));

testAspectpath.extendsFrom(aspectpath);
testAspectpath.extendsFrom(aspectpath);

WeavingSourceSet.getAspectPath(test).setFrom(main.getOutput(), testAspectpath);
});
WeavingSourceSet.getAspectPath(test).setFrom(main.getOutput(), testAspectpath);
}

private void configureSourceSet(SourceSet sourceSet) {
Expand Down
2 changes: 0 additions & 2 deletions examples/aspectj/aspect/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
apply plugin: "java"
apply plugin: "groovy"
apply plugin: "io.freefair.aspectj"

dependencies {
Expand Down

0 comments on commit 17891e0

Please sign in to comment.