1 17 package org.eclipse.emf.ant.taskdefs; 18 19 import org.apache.tools.ant.BuildException; 20 import org.apache.tools.ant.Task; 21 22 import org.eclipse.ant.core.AntCorePlugin; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.NullProgressMonitor; 25 26 27 33 public abstract class EMFTask extends Task 34 { 35 41 public static void assertTrue(String message, boolean expression) throws BuildException 42 { 43 if (!expression) 44 { 45 throw new BuildException(message); 46 } 47 } 48 49 protected IProgressMonitor getProgressMonitor() 50 { 51 try 52 { 53 IProgressMonitor progressMonitor = (IProgressMonitor)getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR); 54 if (progressMonitor != null) 55 { 56 return progressMonitor; 57 } 58 } 59 catch (Exception e) 60 { 61 } 62 return new NullProgressMonitor(); 63 } 64 65 public final void execute() throws BuildException 66 { 67 checkAttributes(); 68 69 try 70 { 71 doExecute(); 72 } 73 catch (Exception e) 74 { 75 if (e instanceof BuildException) 76 { 77 throw (BuildException)e; 78 } 79 else 80 { 81 throw new BuildException(e); 82 } 83 } 84 } 85 86 90 protected void checkAttributes() throws BuildException 91 { 92 } 93 94 98 abstract protected void doExecute() throws Exception ; 99 } | Popular Tags |