KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > tools > ant > SingleFilePluginTask


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2006 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.tools.ant;
20
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.apache.tools.ant.BuildException;
26 import org.java.plugin.registry.PluginDescriptor;
27 import org.java.plugin.registry.PluginFragment;
28 import org.java.plugin.tools.PluginArchiver;
29
30 /**
31  * The Ant task to create "single file" plug-ins.
32  *
33  * @version $Id: SingleFilePluginTask.java,v 1.2 2006/08/26 15:14:09 ddimon Exp $
34  */

35 public class SingleFilePluginTask extends BaseJpfTask {
36     private File JavaDoc destDir;
37
38     /**
39      * @param aDestDir folder, where to put generated plug-in file(s)
40      */

41     public void setDestDir(final File JavaDoc aDestDir) {
42         destDir = aDestDir;
43     }
44
45     /**
46      * @see org.apache.tools.ant.Task#execute()
47      */

48     public void execute() throws BuildException {
49         if (destDir == null) {
50             throw new BuildException("destdir attribute must be set!", //$NON-NLS-1$
51
getLocation());
52         }
53         initRegistry(true);
54         log("Creating plug-in files..."); //$NON-NLS-1$
55
int count = 0;
56         for (Iterator JavaDoc it = getRegistry().getPluginDescriptors().iterator();
57                 it.hasNext(); count++) {
58             PluginDescriptor descr = (PluginDescriptor) it.next();
59             File JavaDoc destFile = new File JavaDoc(destDir, descr.getId() + "-" //$NON-NLS-1$
60
+ descr.getVersion() + ".zip"); //$NON-NLS-1$
61
try {
62                 PluginArchiver.pack(descr, getPathResolver(), destFile);
63             } catch (IOException JavaDoc ioe) {
64                 throw new BuildException("failed building plug-in file " //$NON-NLS-1$
65
+ destFile, ioe, getLocation());
66             }
67             if (getVerbose()) {
68                 log("Created plug-in file " + destFile); //$NON-NLS-1$
69
}
70         }
71         for (Iterator JavaDoc it = getRegistry().getPluginFragments().iterator();
72                 it.hasNext(); count++) {
73             PluginFragment fragment = (PluginFragment) it.next();
74             File JavaDoc destFile = new File JavaDoc(destDir, fragment.getId() + "-" //$NON-NLS-1$
75
+ fragment.getVersion() + ".zip"); //$NON-NLS-1$
76
try {
77                 PluginArchiver.pack(fragment, getPathResolver(), destFile);
78             } catch (IOException JavaDoc ioe) {
79                 throw new BuildException("failed building plug-in fragment file " //$NON-NLS-1$
80
+ destFile, ioe, getLocation());
81             }
82             if (getVerbose()) {
83                 log("Created plug-in fragment file " + destFile); //$NON-NLS-1$
84
}
85         }
86         log("... " + count + " plug-in files created"); //$NON-NLS-1$ //$NON-NLS-2$
87
}
88 }
89
Popular Tags