View Javadoc
1   /*
2    * The akquinet maven-latex-plugin project
3    *
4    * Copyright (c) 2011 by akquinet tech@spree GmbH
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package eu.simuline.m2latex.mojo;
20  
21  import eu.simuline.m2latex.core.LatexProcessor;
22  import eu.simuline.m2latex.core.ParameterAdapter;
23  import eu.simuline.m2latex.core.Settings;
24  
25  import org.apache.maven.plugin.AbstractMojo;
26  
27  import org.apache.maven.plugins.annotations.Parameter;
28  
29  import java.io.File;
30  
31  /**
32   * Abstract base class for all mojos. 
33   *
34   */
35  abstract class AbstractLatexMojo extends AbstractMojo 
36      implements ParameterAdapter {
37  
38      /**
39       * The base directory of this maven project. 
40       * Reinitializes {@link Settings#baseDirectory} via {@link #initialize()}. 
41       */
42      @Parameter(name = "baseDirectory", 
43  	       defaultValue = "${basedir}", 
44  	       readonly = true)
45      protected File baseDirectory;
46  
47      /**
48       * The target directory of this maven project. 
49       * Reinitializes {@link Settings#targetDirectory} 
50       * via {@link #initialize()}. 
51       */
52      @Parameter(name = "targetDirectory", 
53  	       defaultValue = "${project.build.directory}", 
54  	       readonly = true)
55      protected File targetDirectory;
56  
57      /**
58       * The target site directory of this maven project. 
59       * Reinitializes {@link Settings#baseDirectory} via {@link #initialize()}. 
60       */
61      @Parameter(name = "targetSiteDirectory", 
62  	       defaultValue = "${project.reporting.outputDirectory}", 
63  	       readonly = true)
64      protected File targetSiteDirectory;
65  
66      /**
67       * Comrpises all parameters for executing this maven plugin. 
68       * If not set in the pom prior to execution, 
69       * is set in {@link #initialize()}. 
70       */
71      // for help plugin this does not fit. 
72      // also not ideal that settings is all the same independent of target. 
73      // also for help plugin this is not detailed enough. 
74      @Parameter(name = "settings")
75      protected Settings settings;
76  
77      // set by {@link #initialize()}. 
78      protected LatexProcessor latexProcessor;
79  
80  
81      // api-docs inherited from ParameterAdapter 
82      public final void initialize() {
83  	if (this.settings == null) {
84  	    // Here, no configuration is defined in pom, 
85  	    // i.e. object is not created by Maven
86  	    this.settings = new Settings();
87  	}
88  	this.settings.setBaseDirectory(this.baseDirectory);
89  	this.settings.setTargetSiteDirectory(this.targetSiteDirectory);
90  	this.settings.setTargetDirectory(this.targetDirectory);
91  
92  	this.latexProcessor = new LatexProcessor(this.settings,  
93  						 new MavenLogWrapper(getLog()), 
94  						 this);
95      }
96  }