17
17
18
18
package org .apache .arrow .maven .plugins ;
19
19
20
- import java .io .File ;
21
- import java .io .IOException ;
22
- import java .io .InputStreamReader ;
23
- import java .io .OutputStream ;
24
- import java .io .Reader ;
25
- import java .nio .charset .StandardCharsets ;
26
- import java .nio .file .Files ;
27
- import java .nio .file .Path ;
28
- import java .nio .file .Paths ;
29
20
import java .util .ArrayList ;
30
21
import java .util .List ;
31
- import java .util .Optional ;
32
22
33
- import org .apache .maven .plugin .AbstractMojo ;
34
- import org .apache .maven .plugin .MojoExecutionException ;
35
23
import org .apache .maven .plugins .annotations .LifecyclePhase ;
36
24
import org .apache .maven .plugins .annotations .Mojo ;
37
25
import org .apache .maven .plugins .annotations .Parameter ;
38
26
import org .apache .maven .project .MavenProject ;
39
- import org .glavo .mic .ModuleInfoCompiler ;
40
27
41
28
/**
42
- * Compiles the first module-info.java file in the project purely syntactically .
29
+ * A maven plugin for compiler module-info files in main code with JDK8 .
43
30
*/
44
- @ Mojo (name = "module-info-compile" , defaultPhase = LifecyclePhase .COMPILE )
45
- public class ModuleInfoCompilerPlugin extends AbstractMojo {
46
- /**
47
- * Source directories.
48
- */
31
+ @ Mojo (name = "compile" , defaultPhase = LifecyclePhase .COMPILE )
32
+ public class ModuleInfoCompilerPlugin extends BaseModuleInfoCompilerPlugin {
33
+
49
34
@ Parameter (defaultValue = "${project.compileSourceRoots}" , property = "compileSourceRoots" ,
50
35
required = true )
51
36
private final List <String > compileSourceRoots = new ArrayList <>();
@@ -57,49 +42,17 @@ public class ModuleInfoCompilerPlugin extends AbstractMojo {
57
42
private MavenProject project ;
58
43
59
44
@ Override
60
- public void execute () throws MojoExecutionException {
61
- if (skip ) {
62
- getLog ().info ("Skipping module-info-compiler-maven-plugin" );
63
- return ;
64
- }
65
-
66
- Optional <File > moduleInfoFile = findFirstModuleInfo (compileSourceRoots );
67
- if (moduleInfoFile .isPresent ()) {
68
- // The compiled module-info.class file goes into target/classes/module-info/main
69
- Path outputDir = Paths .get (project .getBuild ().getOutputDirectory ());
70
-
71
- outputDir .toFile ().mkdirs ();
72
- Path targetPath = outputDir .resolve ("module-info.class" );
73
-
74
- // Invoke the compiler,
75
- ModuleInfoCompiler compiler = new ModuleInfoCompiler ();
76
- try (Reader reader = new InputStreamReader (Files .newInputStream (moduleInfoFile .get ().toPath ()),
77
- StandardCharsets .UTF_8 );
78
- OutputStream output = Files .newOutputStream (targetPath )) {
79
- compiler .compile (reader , output );
80
- getLog ().info ("Successfully wrote module-info.class file." );
81
- } catch (IOException ex ) {
82
- throw new MojoExecutionException ("Error compiling module-info.java" , ex );
83
- }
84
- } else {
85
- getLog ().info ("No module-info.java file found. module-info.class file was not generated." );
86
- }
45
+ protected List <String > getSourceRoots () {
46
+ return compileSourceRoots ;
87
47
}
88
48
89
- /**
90
- * Finds the first module-info.java file in the set of source directories.
91
- */
92
- private Optional <File > findFirstModuleInfo (List <String > sourceDirectories ) {
93
- if (sourceDirectories == null ) {
94
- return Optional .empty ();
95
- }
49
+ @ Override
50
+ protected boolean skip () {
51
+ return skip ;
52
+ }
96
53
97
- return sourceDirectories .stream ().map (Paths ::get )
98
- .map (sourcePath ->
99
- sourcePath .toFile ().listFiles (file ->
100
- file .getName ().equals ("module-info.java" )))
101
- .filter (matchingFiles -> matchingFiles != null && matchingFiles .length != 0 )
102
- .map (matchingFiles -> matchingFiles [0 ])
103
- .findAny ();
54
+ @ Override
55
+ protected String getOutputDirectory () {
56
+ return project .getBuild ().getOutputDirectory ();
104
57
}
105
58
}
0 commit comments