01: /*****************************************************************************
02: * Java Plug-in Framework (JPF)
03: * Copyright (C) 2004-2007 Dmitry Olshansky
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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: *****************************************************************************/package org.java.plugin.tools.ant;
19:
20: import java.io.File;
21: import java.io.IOException;
22: import org.apache.tools.ant.BuildException;
23: import org.java.plugin.registry.PluginDescriptor;
24: import org.java.plugin.registry.PluginFragment;
25: import org.java.plugin.tools.PluginArchiver;
26:
27: /**
28: * The Ant task to create "single file" plug-ins.
29: *
30: * @version $Id$
31: */
32: public class SingleFilePluginTask extends BaseJpfTask {
33: private File destDir;
34:
35: /**
36: * @param aDestDir folder, where to put generated plug-in file(s)
37: */
38: public void setDestDir(final File aDestDir) {
39: destDir = aDestDir;
40: }
41:
42: /**
43: * @see org.apache.tools.ant.Task#execute()
44: */
45: @Override
46: public void execute() throws BuildException {
47: if (destDir == null) {
48: throw new BuildException("destdir attribute must be set!", //$NON-NLS-1$
49: getLocation());
50: }
51: initRegistry(true);
52: int count = 0;
53: for (PluginDescriptor descr : getRegistry()
54: .getPluginDescriptors()) {
55: File destFile = new File(destDir, descr.getId() + "-" //$NON-NLS-1$
56: + descr.getVersion() + ".zip"); //$NON-NLS-1$
57: try {
58: PluginArchiver.pack(descr, getPathResolver(), destFile);
59: } catch (IOException ioe) {
60: throw new BuildException(
61: "failed building plug-in file " //$NON-NLS-1$
62: + destFile, ioe, getLocation());
63: }
64: if (getVerbose()) {
65: log("Created plug-in file " + destFile); //$NON-NLS-1$
66: }
67: count++;
68: }
69: for (PluginFragment fragment : getRegistry()
70: .getPluginFragments()) {
71: File destFile = new File(destDir, fragment.getId() + "-" //$NON-NLS-1$
72: + fragment.getVersion() + ".zip"); //$NON-NLS-1$
73: try {
74: PluginArchiver.pack(fragment, getPathResolver(),
75: destFile);
76: } catch (IOException ioe) {
77: throw new BuildException(
78: "failed building plug-in fragment file " //$NON-NLS-1$
79: + destFile, ioe, getLocation());
80: }
81: if (getVerbose()) {
82: log("Created plug-in fragment file " + destFile); //$NON-NLS-1$
83: }
84: count++;
85: }
86: log("Plug-in files created " + count); //$NON-NLS-1$
87: }
88: }
|