View Javadoc
1   package eu.simuline.m2latex.antTask;
2   
3   import org.apache.tools.ant.Task;
4   
5   import eu.simuline.m2latex.core.Settings;
6   import eu.simuline.m2latex.core.LatexProcessor;
7   import eu.simuline.m2latex.core.ParameterAdapter;
8   
9   import java.io.File;
10  
11  /**
12   * Abstract base class of all tasks provided by this latex converter. 
13   * @author ernst
14   *
15   */
16  abstract class AbstractLatexTask extends Task implements ParameterAdapter {
17  
18    /**
19     * Contains all parameters for executing this task. 
20     */
21    protected Settings settings;
22  
23    // set by {@link #initialize()}. 
24    protected LatexProcessor latexProcessor;
25  
26    /**
27     * Invoked by ant returning a container for all parameters 
28     * and initializing {@link #settings}. 
29     */
30    public Settings createSettings() {
31      return this.settings = new Settings();
32    }
33  
34    private File getPropertyFile(String prop) {
35      return new File(getProject().getProperty(prop));
36    }
37  
38    // api-docs inherited from ParameterAdapter 
39    public final void initialize() {
40      // use of the reference to Project-instance
41      //String message = getProperty("ant.project.name");
42      // Task's log method
43      //log("Here is project '" + message + "'. ");
44      // almost the same as getProject().log(this, msg, msgLevel)
45  
46      // where this task is used?
47      //log("I am used in: " + getLocation() + "'. ");
48      if (this.settings == null) {
49        // Here, no configuration is defined in build file, 
50        // i.e. object is not created by ant
51        this.settings = new Settings();
52      }
53      this.settings.setBaseDirectory(getPropertyFile("basedir"));
54      this.settings.setTargetSiteDirectory(getPropertyFile("targetSiteDir"));
55      this.settings.setTargetDirectory(getPropertyFile("targetDir"));
56  
57      //log("settings: \n" + this.settings);
58  
59      this.latexProcessor = new LatexProcessor(this.settings,
60          new AntLogWrapper(getProject()), this);
61    }
62  
63  }