KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > ant > BaseExportTask


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.ant;
12
13 import org.apache.tools.ant.BuildException;
14 import org.apache.tools.ant.Task;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.core.runtime.jobs.Job;
22 import org.eclipse.pde.internal.core.PDECoreMessages;
23 import org.eclipse.pde.internal.core.exports.FeatureExportOperation;
24
25 public abstract class BaseExportTask extends Task {
26     
27     protected String JavaDoc fDestination;
28     protected String JavaDoc fZipFilename;
29     protected boolean fToDirectory;
30     protected boolean fUseJarFormat;
31     protected boolean fExportSource;
32     protected String JavaDoc fQualifier;
33
34     public BaseExportTask() {
35     }
36     
37     /* (non-Javadoc)
38      * @see org.apache.tools.ant.Task#execute()
39      */

40     public void execute() throws BuildException {
41         if (fDestination == null)
42             throw new BuildException("No destination is specified"); //$NON-NLS-1$
43

44         if (!fToDirectory && fZipFilename == null)
45             throw new BuildException("No zip file is specified"); //$NON-NLS-1$
46

47         Job job = new Job(PDECoreMessages.BaseExportTask_pdeExport) {
48             protected IStatus run(IProgressMonitor monitor) {
49                 try {
50                     getExportOperation().run(new NullProgressMonitor());
51                 } catch (CoreException e) {
52                     e.printStackTrace();
53                 }
54                 return Status.OK_STATUS;
55             }
56         };
57         
58         // if running in ant runner, block until job is done. Prevents Exiting before completed
59
// blocking will cause errors if done when running in regular runtime.
60
if (isAntRunner()) {
61             try {
62                 job.schedule();
63                 job.join();
64             } catch (InterruptedException JavaDoc e) {
65             }
66         } else
67             job.schedule(2000);
68     }
69     
70     public void setExportType(String JavaDoc type) {
71         fToDirectory = !"zip".equals(type); //$NON-NLS-1$
72
}
73     
74     public void setUseJARFormat(String JavaDoc useJarFormat) {
75         fUseJarFormat = "true".equals(useJarFormat); //$NON-NLS-1$
76
}
77     
78     public void setExportSource(String JavaDoc doExportSource) {
79         fExportSource = "true".equals(doExportSource); //$NON-NLS-1$
80
}
81     
82     public void setDestination(String JavaDoc destination) {
83         fDestination = destination;
84     }
85     
86     public void setFilename(String JavaDoc filename) {
87         fZipFilename = filename;
88     }
89     
90     public void setQualifier(String JavaDoc qualifier) {
91         fQualifier = qualifier;
92     }
93     
94     public boolean isAntRunner() {
95         String JavaDoc args [] = Platform.getCommandLineArgs();
96         for (int i = 0; i < args.length; i++) {
97             if (args[i].equals("-application")) //$NON-NLS-1$
98
return args[i+1].equals("org.eclipse.ant.core.antRunner"); //$NON-NLS-1$
99
}
100         return false;
101     }
102     
103     protected abstract FeatureExportOperation getExportOperation();
104 }
105
Popular Tags