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  // TBD: use new dependency on slf4j
30  // import com.jcabi.log.Logger;
31  // import org.slf4j.impl.StaticLoggerBinder;
32  
33  import java.io.File;
34  
35  /**
36   * Abstract base class for all mojos.
37   *
38   */
39  abstract class AbstractLatexMojo extends AbstractMojo
40      implements ParameterAdapter {
41  
42    /**
43     * The base directory of this maven project. 
44     * Reinitializes {@link Settings#baseDirectory} via {@link #initialize()}. 
45     */
46    @Parameter(name = "baseDirectory", defaultValue = "${basedir}",
47        readonly = true)
48    protected File baseDirectory;
49  
50    /**
51     * The target directory of this maven project. 
52     * Reinitializes {@link Settings#targetDirectory} 
53     * via {@link #initialize()}. 
54     */
55    @Parameter(name = "targetDirectory",
56        defaultValue = "${project.build.directory}", readonly = true)
57    protected File targetDirectory;
58  
59    /**
60     * The target site directory of this maven project. 
61     * Reinitializes {@link Settings#baseDirectory} via {@link #initialize()}. 
62     */
63    // is adapted for tests in pom4pdf.xml 
64    @Parameter(name = "targetSiteDirectory",
65        defaultValue = "${project.reporting.outputDirectory}")//, readonly = true
66    protected File targetSiteDirectory;
67  
68  
69    /**
70     * Comprises all parameters for executing this maven plugin. 
71     * If not set in the pom prior to execution, 
72     * is set in {@link #initialize()}. 
73     */
74    // for help plugin this does not fit. 
75    // also not ideal that settings is all the same independent of target. 
76    // also for help plugin this is not detailed enough. 
77    @Parameter(name = "settings")
78    protected Settings settings;
79  
80    // set by {@link #initialize()}. 
81    protected LatexProcessor latexProcessor;
82  
83  
84    // api-docs inherited from ParameterAdapter 
85    public final void initialize() {
86      if (this.settings == null) {
87        // Here, no configuration is defined in pom, 
88        // i.e. object is not created by Maven
89        this.settings = new Settings();
90      }
91      this.settings.setBaseDirectory(this.baseDirectory);
92      this.settings.setTargetSiteDirectory(this.targetSiteDirectory);
93      this.settings.setTargetDirectory(this.targetDirectory);
94  
95      this.latexProcessor =
96          new LatexProcessor(this.settings, new MavenLogWrapper(this.getClass()), this);
97    }
98  }