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.BuildFailureException;
22  import eu.simuline.m2latex.core.Injection;
23  import eu.simuline.m2latex.core.Settings;
24  
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.plugins.annotations.LifecyclePhase;
28  import java.util.Set;
29  import org.apache.maven.plugin.MojoFailureException;
30  
31  // documentation occurs in latex:help
32  /**
33   * Creates rc file <code>.latexmkrc</code> for latexmk 
34   * and <code>.chktexrc</code> for chktex and further files for various use cases. 
35   * The goal is tied to the lifecycle phase <code>validate</code> by default.  
36   */
37  @Mojo(name = "inj", defaultPhase = LifecyclePhase.VALIDATE)
38  // TBD: maybe verify
39  // in fact, Metainfo can give more info than just versioning 
40  public class InjectionMojo extends AbstractLatexMojo {
41  
42    /**
43     * Indicates the files injected by the goal <code>inj</code>. 
44     * This is a comma separated list of {@link Injection}s 
45     * without blanks. 
46     * The injections are in one of three categories: representing 
47     * <ul>
48     * <li>configuration files: 
49     *  <ul>
50     *  <li><code>latexmkrc</code> represents the config file <code>.latexmkrc</code> 
51     *      of <code>latexmk</code></li>
52     *  <li><code>chktexrc</code> represents the config file <code>.chktexrc</code> 
53     *      of <code>chktex</code></li>
54     *  </ul></li>
55     * <li>header files to be input into TEX files: 
56     *  <ul>
57     *  <li><code>header</code> represents the file <code>header.tex</code> 
58     *      which is intended to be included in any latex main file. </li>
59     *  <li><code>headerGrp</code> represents the file <code>headerGrp.tex</code> 
60     *      which shall be included in latex main files using the <code>graphicx</code> pacakge. </li>
61     *  <li><code>headerSuppressMetaPDF</code> represents the file <code>headerSuppressMetaPDF.tex</code> 
62     *      which serves to suppress meta info of a latex main file  
63     *      which may be considered a safety risk. </li>
64     *  </ul></li>
65     * <li>script files: 
66     *  <ul>
67     *  <li><code>vscodeExt</code> represents the file <code>instVScode4tex.sh</code> 
68     *      installing all extensions on VS Code recommended for development of latex documents. </li>
69     *  <li><code>ntlatex</code> represents the file <code>ntlatex</code> 
70     *      performing latex compilation with epoch time 0. </li>
71     *  <li><code>pythontexW</code> represents the file <code>pythontexW</code> 
72     *      which essentially invokes <code>pythontex</code> 
73     *      and redirects output to a log file</li>
74     *  <li><code>vmdiff</code> represents the file <code>vmdiff</code> 
75     *      which performs a diff based on 
76     *      the visual diff <code>diff-pdf-visually</code> and 
77     *      on the diff on meta-data given by <code>pdfinfo</code>. </li>
78     *  </ul></li>
79     * </ul>
80     * <p>
81     * The default value is <code>latexmkrc,chktexrc</code>. 
82     */
83    @Parameter(name = "injections", defaultValue = "latexmkrc,chktexrc",
84        property = Settings.PARAM_PROP)
85    private Set<Injection> injections;
86  
87    /**
88     * Creates rc file <code>.latexmkrc</code> for latexmk 
89     * and <code>.chktexrc</code> for chktex 
90     * and moves to base directory of tex sources {@link Settings#texSrcDirectory}. 
91     *
92     * @throws MojoFailureException
93     *    <ul>
94     *    <li>TMI01: if the stream to a template for an rc file could not be created. </li>
95     *    <li>TLP03: if the rc file cannot be written completely and reliably for some reason. </li>
96     *    </ul>
97     */
98    public void execute() throws MojoFailureException {
99      // TBD: redesign 
100     initialize();
101     try {
102       // TBD: update 
103       // warnings: WMI01, WMI02, 
104       // may throw build failure exception TLP03, TMI01
105       this.latexProcessor.processFileInjections(this.injections);
106     } catch (BuildFailureException e) {
107       // may throw Exception TBD
108       throw new MojoFailureException(e.getMessage(), e.getCause());
109     }
110   }
111 
112 }