1
1
package org .javamodularity .moduleplugin .tasks ;
2
2
3
3
import org .gradle .api .Project ;
4
+ import org .gradle .api .file .FileCollection ;
4
5
import org .gradle .api .tasks .compile .AbstractCompile ;
5
6
import org .gradle .api .tasks .compile .JavaCompile ;
7
+ import org .javamodularity .moduleplugin .extensions .CompileModuleOptions ;
6
8
7
9
import java .util .ArrayList ;
8
10
import java .util .List ;
@@ -11,27 +13,48 @@ class CompileJavaTaskMutator {
11
13
12
14
private static final String COMPILE_KOTLIN_TASK_NAME = "compileKotlin" ;
13
15
14
- static void mutateJavaCompileTask (Project project , JavaCompile compileJava ) {
15
- ModuleOptions moduleOptions = compileJava .getExtensions ().getByType (ModuleOptions .class );
16
+ private final Project project ;
17
+ /**
18
+ * {@linkplain JavaCompile#getClasspath() Classpath} of {@code compileJava} task.
19
+ */
20
+ private final FileCollection compileJavaClasspath ;
21
+ /**
22
+ * {@link CompileModuleOptions} of {@code compileJava} task.
23
+ */
24
+ private final CompileModuleOptions moduleOptions ;
25
+
26
+ CompileJavaTaskMutator (Project project , FileCollection compileJavaClasspath , CompileModuleOptions moduleOptions ) {
27
+ this .project = project ;
28
+ this .compileJavaClasspath = compileJavaClasspath ;
29
+ this .moduleOptions = moduleOptions ;
30
+ }
31
+
32
+ /**
33
+ * The argument is a {@link JavaCompile} task whose modularity is to be configured.
34
+ *
35
+ * @param javaCompile {@code compileJava} if {@link CompileModuleOptions#getCompileModuleInfoSeparately()}
36
+ * is {@code false}, {@code compileModuleInfoJava} if it is {@code true}
37
+ */
38
+ void modularizeJavaCompileTask (JavaCompile javaCompile ) {
16
39
PatchModuleExtension patchModuleExtension = project .getExtensions ().getByType (PatchModuleExtension .class );
17
40
18
- var compilerArgs = new ArrayList <>(compileJava .getOptions ().getCompilerArgs ());
41
+ var compilerArgs = new ArrayList <>(javaCompile .getOptions ().getCompilerArgs ());
19
42
20
- compilerArgs .addAll (List .of ("--module-path" , compileJava . getClasspath ()
43
+ compilerArgs .addAll (List .of ("--module-path" , compileJavaClasspath
21
44
.filter (patchModuleExtension ::isUnpatched )
22
45
.getAsPath ()));
23
46
24
47
String moduleName = (String ) project .getExtensions ().findByName ("moduleName" );
25
48
moduleOptions .mutateArgs (moduleName , compilerArgs );
26
49
27
- compilerArgs .addAll (patchModuleExtension .configure (compileJava . getClasspath () ));
28
- compileJava .getOptions ().setCompilerArgs (compilerArgs );
29
- compileJava .setClasspath (project .files ());
50
+ compilerArgs .addAll (patchModuleExtension .configure (compileJavaClasspath ));
51
+ javaCompile .getOptions ().setCompilerArgs (compilerArgs );
52
+ javaCompile .setClasspath (project .files ());
30
53
31
54
// https://github.com/java9-modularity/gradle-modules-plugin/issues/45
32
55
AbstractCompile compileKotlin = (AbstractCompile ) project .getTasks ().findByName (COMPILE_KOTLIN_TASK_NAME );
33
56
if (compileKotlin != null ) {
34
- compileJava .setDestinationDir (compileKotlin .getDestinationDir ());
57
+ javaCompile .setDestinationDir (compileKotlin .getDestinationDir ());
35
58
}
36
59
}
37
60
0 commit comments