1 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 fDestination; 28 protected String fZipFilename; 29 protected boolean fToDirectory; 30 protected boolean fUseJarFormat; 31 protected boolean fExportSource; 32 protected String fQualifier; 33 34 public BaseExportTask() { 35 } 36 37 40 public void execute() throws BuildException { 41 if (fDestination == null) 42 throw new BuildException("No destination is specified"); 44 if (!fToDirectory && fZipFilename == null) 45 throw new BuildException("No zip file is specified"); 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 (isAntRunner()) { 61 try { 62 job.schedule(); 63 job.join(); 64 } catch (InterruptedException e) { 65 } 66 } else 67 job.schedule(2000); 68 } 69 70 public void setExportType(String type) { 71 fToDirectory = !"zip".equals(type); } 73 74 public void setUseJARFormat(String useJarFormat) { 75 fUseJarFormat = "true".equals(useJarFormat); } 77 78 public void setExportSource(String doExportSource) { 79 fExportSource = "true".equals(doExportSource); } 81 82 public void setDestination(String destination) { 83 fDestination = destination; 84 } 85 86 public void setFilename(String filename) { 87 fZipFilename = filename; 88 } 89 90 public void setQualifier(String qualifier) { 91 fQualifier = qualifier; 92 } 93 94 public boolean isAntRunner() { 95 String args [] = Platform.getCommandLineArgs(); 96 for (int i = 0; i < args.length; i++) { 97 if (args[i].equals("-application")) return args[i+1].equals("org.eclipse.ant.core.antRunner"); } 100 return false; 101 } 102 103 protected abstract FeatureExportOperation getExportOperation(); 104 } 105 | Popular Tags |