1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.rwx.maven.asciidoc;
18
19 import net.rwx.maven.asciidoc.configuration.Document;
20 import com.google.inject.Guice;
21 import com.google.inject.Injector;
22 import java.io.File;
23 import java.util.List;
24 import net.rwx.maven.asciidoc.services.ServiceOrchestrator;
25 import net.rwx.maven.asciidoc.services.modules.AsciidocModule;
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28
29
30
31
32
33
34
35
36 public class AsciidocMojo extends AbstractMojo {
37
38
39
40
41
42
43 private String defaultDocumentType;
44
45
46
47
48
49 private String defaultOutputPath;
50
51
52
53
54
55 private String defaultBackend;
56
57
58
59
60 private File projectFile;
61
62
63
64
65
66
67 private List<Document> documents;
68
69 @Override
70 public void execute() throws MojoExecutionException {
71
72 getLog().info( "Starting asciidoc compilation" );
73 getLog().info( "Default document type : " + defaultDocumentType );
74 getLog().info( "Default output path : " + defaultOutputPath );
75 getLog().info( "Default backend : " + defaultBackend );
76
77 if( documents == null ) {
78 getLog().info( "Nothing to be done" );
79 return;
80 }
81
82 ServiceOrchestrator orchestrator = getServiceOrchestrator();
83 orchestrator.setLogger( getLog() );
84
85 for ( Document document : documents ) {
86 computeDocument( document );
87 orchestrator.execute( document );
88 }
89 }
90
91 private String determineValue( String inputValue, String defaultValue ) {
92 return (inputValue == null)?defaultValue:inputValue;
93 }
94
95 private void computeDocument( Document document ) {
96 document.setBackend( determineValue( document.getBackend(), defaultBackend) );
97 document.setDocumentType( determineValue( document.getDocumentType(), defaultDocumentType ) );
98 document.setOutputPath( determineValue( document.getOutputPath(), defaultOutputPath ) );
99
100 String realPath = projectFile.getParent() + File.separator + document.getPath();
101 document.setPath( realPath );
102 }
103
104 private ServiceOrchestrator getServiceOrchestrator() throws MojoExecutionException {
105 Injector injector = Guice.createInjector( new AsciidocModule() );
106 return injector.getInstance( ServiceOrchestrator.class );
107 }
108
109 public String getDefaultDocumentType() {
110 return defaultDocumentType;
111 }
112
113 public void setDefaultDocumentType(String defaultDocumentType) {
114 this.defaultDocumentType = defaultDocumentType;
115 }
116
117 public String getDefaultOutputPath() {
118 return defaultOutputPath;
119 }
120
121 public void setDefaultOutputPath(String defaultOutputPath) {
122 this.defaultOutputPath = defaultOutputPath;
123 }
124
125 public String getDefaultBackend() {
126 return defaultBackend;
127 }
128
129 public void setDefaultBackend(String defaultBackend) {
130 this.defaultBackend = defaultBackend;
131 }
132
133 public File getProjectFile() {
134 return projectFile;
135 }
136
137 public void setProjectFile(File projectFile) {
138 this.projectFile = projectFile;
139 }
140
141 public List<Document> getDocuments() {
142 return documents;
143 }
144
145 public void setDocuments(List<Document> documents) {
146 this.documents = documents;
147 }
148
149
150 }