View Javadoc
1   /*
2    * Copyright 2004 Diogo Quintela (dquintela@users.sourceforge.net)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.whatsnew.ant;
17  
18  import net.sf.whatsnew.WhatsNew;
19  import net.sf.whatsnew.exceptions.AppException;
20  import net.sf.whatsnew.mode.Mode;
21  import net.sf.whatsnew.options.Options;
22  
23  import org.apache.tools.ant.BuildException;
24  import org.apache.tools.ant.Task;
25  
26  
27  /***
28   * <p>
29   * Jakarta Ant Task Plugin for WhatsNew File Creator application.
30   * </p>
31   *
32   * @author <a href="mailto:dquintela@users.sourceforge.net">Diogo Quintela</a>
33   * @version $Id: WhatsNewTask.java,v 1.1 2004/05/13 01:22:40 dquintela Exp $
34   */
35  public class WhatsNewTask extends Task {
36      /*** External config file properties */
37      private String configProperties;
38  
39      /*** File name */
40      private String file;
41  
42      /*** Quick Change version */
43      private String message;
44  
45      /*** Release version */
46      private String releaseVersion;
47  
48      /*** Change mode */
49      private boolean change;
50  
51      /*** Release mode */
52      private boolean release;
53  
54      /***
55       * Setter for property {@link #change}
56       *
57       * @param change The value for property
58       */
59      public void setChange(boolean change) {
60          this.change = change;
61      }
62  
63      /***
64       * Setter for property {@link #configProperties}
65       *
66       * @param configProperties The value for property
67       */
68      public void setConfigProperties(String configProperties) {
69          this.configProperties = configProperties;
70      }
71  
72      /***
73       * Setter for property {@link #file}
74       *
75       * @param file The value for property
76       */
77      public void setFile(String file) {
78          this.file = file;
79      }
80  
81      /***
82       * Setter for property {@link #message}
83       *
84       * @param message The value for property
85       */
86      public void setMessage(String message) {
87          this.message = message;
88      }
89  
90      /***
91       * Setter for property {@link #release}
92       *
93       * @param release The value for property
94       */
95      public void setRelease(boolean release) {
96          this.release = release;
97      }
98  
99      /***
100      * Setter for property {@link #releaseVersion}
101      *
102      * @param releaseVersion The value for property
103      */
104     public void setReleaseVersion(String releaseVersion) {
105         this.releaseVersion = releaseVersion;
106     }
107 
108     /***
109      * Main task exec method
110      *
111      * @throws BuildException in case of error
112      */
113     public void execute()
114     throws BuildException {
115         try {
116             // Generate options
117             Options appOptions = WhatsNew.getConfigOptions(configProperties);
118             appOptions.setValue(Options.MODE, resolveMode());
119             if (file != null) {
120                 appOptions.setValue(Options.FILE, file);
121             }
122             if (releaseVersion != null) {
123                 appOptions.setValue(Options.RELEASE_VERSION, releaseVersion);
124             }
125             if (message != null) {
126                 appOptions.setValue(Options.CHANGE_MESSAGE, message);
127             }            
128 
129             // Instanciate 
130             WhatsNew prog = new WhatsNew(appOptions);
131 
132             // Unleash it
133             prog.run();
134 
135             // Display message
136             System.out.println("WhatsNew File Creator sucessfully");
137         } catch (AppException e) {
138             throw new BuildException(e);
139         }
140     }
141 
142     /***
143      * Init
144      *
145      * @throws BuildException in case of error
146      */
147     public void init()
148     throws BuildException {
149     }
150 
151     /***
152      * Auxiliar method to resolve the running mode for the application
153      *
154      * @return The mode to use
155      *
156      * @throws AppException in case of error
157      */
158     private Integer resolveMode()
159     throws AppException {
160         if (change && !release) {
161             return Mode.CHANGE;
162         } else if (!change && release) {
163             return Mode.RELEASE;
164         } else if (change && release) {
165             throw new AppException("error.only.one.mode", true);
166         }
167 
168         // Will use default mode
169         // It is Mode.CHANGE
170         return null;
171     }
172 }
173 
174 
175 // EOF