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:
23: import org.apache.tools.ant.BuildException;
24: import org.apache.tools.ant.Task;
25: import org.java.plugin.ObjectFactory;
26: import org.java.plugin.registry.ManifestProcessingException;
27: import org.java.plugin.tools.PluginArchiver;
28: import org.java.plugin.util.IoUtil;
29:
30: /**
31: * The ant task for extracting plug-ins from archive.
32: * @version $Id$
33: */
34: public final class UnpackTask extends Task {
35: private File destDir;
36: private File srcFile;
37:
38: /**
39: * @param aSrcFile archive file to be unpacked
40: */
41: public void setSrcFile(final File aSrcFile) {
42: this .srcFile = aSrcFile;
43: }
44:
45: /**
46: * @param aDestFolder folder where to extract archived plug-ins
47: */
48: public void setDestDir(final File aDestFolder) {
49: this .destDir = aDestFolder;
50: }
51:
52: /**
53: * @see org.apache.tools.ant.Task#execute()
54: */
55: @Override
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: try {
66: PluginArchiver.unpack(IoUtil.file2url(srcFile),
67: ObjectFactory.newInstance().createRegistry(),
68: destDir);
69: log("Plug-ins archive unpacked to folder " + destDir); //$NON-NLS-1$
70: } catch (IOException ioe) {
71: throw new BuildException(ioe);
72: } catch (ManifestProcessingException mpe) {
73: throw new BuildException(mpe);
74: } catch (ClassNotFoundException cnfe) {
75: throw new BuildException(cnfe);
76: }
77: }
78: }
|