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