Skip to content

Commit

Permalink
Merge branch '2.4.x'
Browse files Browse the repository at this point in the history
Closes gh-24527
  • Loading branch information
wilkinsona committed Dec 16, 2020
2 parents 5bd5ca5 + 5fdb2ae commit 4dd0e9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,15 +47,8 @@ private void enableJavaParametersOption(Project project) {
}

@Override
@SuppressWarnings("unchecked")
public Class<? extends Plugin<? extends Project>> getPluginClass() {
try {
return (Class<? extends Plugin<? extends Project>>) Class
.forName("org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper");
}
catch (Throwable ex) {
return null;
}
return KotlinPluginWrapper.class;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,9 +30,11 @@ interface PluginApplicationAction extends Action<Project> {

/**
* The class of the {@code Plugin} that, when applied, will trigger the execution of
* this action. May return {@code null} if the plugin class is not on the classpath.
* @return the plugin class or {@code null}
* this action.
* @return the plugin class
* @throws ClassNotFoundException if the plugin class cannot be found
* @throws NoClassDefFoundError if an error occurs when defining the plugin class
*/
Class<? extends Plugin<? extends Project>> getPluginClass();
Class<? extends Plugin<? extends Project>> getPluginClass() throws ClassNotFoundException, NoClassDefFoundError;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
Expand Down Expand Up @@ -119,10 +120,18 @@ private void registerPluginActions(Project project, Configuration bootArchives)
new WarPluginAction(singlePublishedArtifact), new MavenPluginAction(bootArchives.getUploadTaskName()),
new DependencyManagementPluginAction(), new ApplicationPluginAction(), new KotlinPluginAction());
for (PluginApplicationAction action : actions) {
Class<? extends Plugin<? extends Project>> pluginClass = action.getPluginClass();
if (pluginClass != null) {
project.getPlugins().withType(pluginClass, (plugin) -> action.execute(project));
}
withPluginClassOfAction(action,
(pluginClass) -> project.getPlugins().withType(pluginClass, (plugin) -> action.execute(project)));
}
}

private void withPluginClassOfAction(PluginApplicationAction action,
Consumer<Class<? extends Plugin<? extends Project>>> consumer) {
try {
consumer.accept(action.getPluginClass());
}
catch (Throwable ex) {
// Plugin class unavailable. Continue.
}
}

Expand Down

0 comments on commit 4dd0e9a

Please sign in to comment.