KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Task;
26 import org.java.plugin.ObjectFactory;
27 import org.java.plugin.registry.ManifestProcessingException;
28 import org.java.plugin.tools.PluginArchiver;
29 import org.java.plugin.util.IoUtil;
30
31 /**
32  * The ant task for extracting plug-ins from archive.
33  * @version $Id: UnpackTask.java,v 1.6 2006/08/26 15:14:09 ddimon Exp $
34  */

35 public final class UnpackTask extends Task {
36     private File JavaDoc destDir;
37     private File JavaDoc srcFile;
38
39     /**
40      * @param aSrcFile archive file to be unpacked
41      */

42     public void setSrcFile(final File JavaDoc aSrcFile) {
43         this.srcFile = aSrcFile;
44     }
45
46     /**
47      * @param aDestFolder folder where to extract archived plug-ins
48      */

49     public void setDestDir(final File JavaDoc aDestFolder) {
50         this.destDir = aDestFolder;
51     }
52     
53     /**
54      * @see org.apache.tools.ant.Task#execute()
55      */

56     public void execute() {
57         if (srcFile == null) {
58             throw new BuildException("srcfile attribute must be set!", //$NON-NLS-1$
59
getLocation());
60         }
61         if (destDir == null) {
62             throw new BuildException("destdir attribute must be set!", //$NON-NLS-1$
63
getLocation());
64         }
65         log("Extracting plug-ins from archive..."); //$NON-NLS-1$
66
try {
67             PluginArchiver.unpack(IoUtil.file2url(srcFile),
68                     ObjectFactory.newInstance().createRegistry(), destDir);
69             log("... plug-ins archive unpacked to folder " + destDir); //$NON-NLS-1$
70
} catch (IOException JavaDoc ioe) {
71             throw new BuildException(ioe);
72         } catch (ManifestProcessingException mpe) {
73             throw new BuildException(mpe);
74         } catch (ClassNotFoundException JavaDoc cnfe) {
75             throw new BuildException(cnfe);
76         }
77     }
78 }
79
Popular Tags