|
22 | 22 | import org.gradle.api.tasks.SourceSet; |
23 | 23 | import org.gradle.api.tasks.compile.JavaCompile; |
24 | 24 |
|
25 | | -import java.lang.reflect.InvocationTargetException; |
26 | 25 | import java.lang.reflect.Method; |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.List; |
27 | 28 |
|
28 | 29 | public class JavaModuleDependenciesBridge { |
29 | 30 |
|
@@ -54,4 +55,29 @@ public static FileCollection addRequiresRuntimeSupport(Project project, JavaComp |
54 | 55 | throw new RuntimeException(e); |
55 | 56 | } |
56 | 57 | } |
| 58 | + |
| 59 | + public static List<String> getRuntimeClasspathModules(Project project, SourceSet sourceSet) { |
| 60 | + return getClasspathModules("getRuntimeClasspathModules", project, sourceSet); |
| 61 | + } |
| 62 | + |
| 63 | + public static List<String> getCompileClasspathModules(Project project, SourceSet sourceSet) { |
| 64 | + return getClasspathModules("getCompileClasspathModules", project, sourceSet); |
| 65 | + } |
| 66 | + |
| 67 | + public static List<String> getClasspathModules(String getter, Project project, SourceSet sourceSet) { |
| 68 | + Object moduleInfoDslExtension = project.getExtensions().findByName(sourceSet.getName() + "ModuleInfo"); |
| 69 | + if (moduleInfoDslExtension == null) { |
| 70 | + return Collections.emptyList(); |
| 71 | + } |
| 72 | + try { |
| 73 | + Method gav = moduleInfoDslExtension.getClass().getMethod(getter); |
| 74 | + @SuppressWarnings("unchecked") |
| 75 | + List<String> modules = (List<String>) gav.invoke(moduleInfoDslExtension); |
| 76 | + return modules; |
| 77 | + } catch (NoSuchMethodException e) { |
| 78 | + return Collections.emptyList(); |
| 79 | + } catch (ReflectiveOperationException e) { |
| 80 | + throw new RuntimeException(e); |
| 81 | + } |
| 82 | + } |
57 | 83 | } |
0 commit comments