Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / ant / IzPackTask.java @ 15280

History | View | Annotate | Download (5.42 KB)

1 15280 rgaitan
/*
2
 *  $Id: IzPackTask.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPackTask
4
 *  Copyright (C) 2002 Paul Wilkinson
5
 *
6
 *  File :               IzPacktask.java
7
 *  Description :        An ant task to invoke the IZPack compiler.
8
 *  Author's email :     paulw@wilko.com
9
 *
10
 *  This program is free software; you can redistribute it and/or
11
 *  modify it under the terms of the GNU General Public License
12
 *  as published by the Free Software Foundation; either version 2
13
 *  of the License, or any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program; if not, write to the Free Software
22
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
package com.izforge.izpack.ant;
25
26
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.Project;
28
import org.apache.tools.ant.types.EnumeratedAttribute;
29
30
import com.izforge.izpack.compiler.Compiler;
31
32
/**
33
 *  A IzPack Ant task.
34
 *
35
 * @author     Paul Wilkinson
36
 */
37
public class IzPackTask extends org.apache.tools.ant.Task
38
   implements com.izforge.izpack.compiler.PackagerListener
39
{
40
41
  /**  Holds value of property input. */
42
  private String input;
43
44
  /**  Holds value of property basedir. */
45
  private String basedir;
46
47
  /**  Holds value of property output. */
48
  private String output;
49
50
  /**  Holds value of property installerType. */
51
  private InstallerType installerType;
52
53
  /**  Holds value of property izPackDir. This should point at the IzPack directory */
54
  private String izPackDir;
55
56
57
  /**  Creates new IZPackTask */
58
  public IzPackTask()
59
  {
60
    basedir = null;
61
    input = null;
62
    output = null;
63
    installerType = null;
64
    izPackDir = null;
65
  }
66
67
68
  /**
69
   *  Logs a message to the Ant log.
70
   *
71
   * @param  str  The message to log.
72
   */
73
  public void packagerMsg(java.lang.String str)
74
  {
75
    log(str);// Log the message to the Ant log
76
  }
77
78
79
  /**  Called when the packaging starts. */
80
  public void packagerStart()
81
  {
82
    log(java.util.ResourceBundle.getBundle("com/izforge/izpack/ant/langpacks/messages").getString("Packager_starting"), Project.MSG_DEBUG);
83
  }
84
85
86
  /**  Called when the packaging stops. */
87
  public void packagerStop()
88
  {
89
    log(java.util.ResourceBundle.getBundle("com/izforge/izpack/ant/langpacks/messages").getString("Packager_ended"), Project.MSG_DEBUG);
90
  }
91
92
93
  /**
94
   *  Packages.
95
   *
96
   * @exception  org.apache.tools.ant.BuildException  Description of the
97
   *      Exception
98
   */
99
  public void execute() throws org.apache.tools.ant.BuildException
100
  {
101
    if (input == null)
102
      throw new BuildException(java.util.ResourceBundle.getBundle("com/izforge/izpack/ant/langpacks/messages").getString("input_must_be_specified"));
103
104
    if (output == null)
105
      throw new BuildException(java.util.ResourceBundle.getBundle("com/izforge/izpack/ant/langpacks/messages").getString("output_must_be_specified"));
106
107
    // if (installerType == null) now optional
108
109
    if (basedir == null)
110
      throw new BuildException(java.util.ResourceBundle.getBundle("com/izforge/izpack/ant/langpacks/messages").getString("basedir_must_be_specified"));
111
112
    //if (izPackDir == null)
113
    //  throw new BuildException(java.util.ResourceBundle.getBundle("com/izforge/izpack/ant/langpacks/messages").getString("izPackDir_must_be_specified"));
114
115
    String kind = (installerType == null ? null : installerType.getValue());
116
    Compiler c = new Compiler(input, basedir, kind, output);// Create the compiler
117
    Compiler.IZPACK_HOME = izPackDir;
118
119
    c.setPackagerListener(this);// Listen to the compiler messages
120
121
    try
122
    {
123
      c.executeCompiler();
124
    }
125
    catch (Exception e)
126
    {
127
      throw new org.apache.tools.ant.BuildException(e);// Throw an exception if compilation failed
128
    }
129
  }
130
131
132
  /**
133
   *  Setter for property input.
134
   *
135
   * @param  input  New value of property input.
136
   */
137
  public void setInput(String input)
138
  {
139
    this.input = input;
140
  }
141
142
143
  /**
144
   *  Setter for property basedir.
145
   *
146
   * @param  basedir  New value of property basedir.
147
   */
148
  public void setBasedir(String basedir)
149
  {
150
    this.basedir = basedir;
151
  }
152
153
154
  /**
155
   *  Setter for property output.
156
   *
157
   * @param  output  New value of property output.
158
   */
159
  public void setOutput(String output)
160
  {
161
    this.output = output;
162
  }
163
164
165
  /**
166
   *  Setter for property installerType.
167
   *
168
   * @param  installerType  New value of property installerType.
169
   */
170
  public void setInstallerType(InstallerType installerType)
171
  {
172
    this.installerType = installerType;
173
  }
174
175
176
  /**
177
   *  Setter for property izPackDir.
178
   *
179
   * @param  izPackDir  New value of property izPackDir.
180
   */
181
  public void setIzPackDir(String izPackDir)
182
  {
183
    if (!(izPackDir.endsWith("/")))
184
      izPackDir += "/";
185
    this.izPackDir = izPackDir;
186
  }
187
188
189
  /**
190
   *  Enumerated attribute with the values "asis", "add" and "remove".
191
   *
192
   * @author     Paul Wilkinson
193
   */
194
  public static class InstallerType extends EnumeratedAttribute
195
  {
196
    public String[] getValues()
197
    {
198
      return new String[]{Compiler.STANDARD, Compiler.WEB};
199
    }
200
  }
201
}