1 11 12 package org.eclipse.ant.internal.ui.editor.model; 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.net.URL ; 17 18 import org.apache.tools.ant.BuildException; 19 import org.apache.tools.ant.Task; 20 import org.apache.tools.ant.UnknownElement; 21 import org.eclipse.ant.core.AntCorePlugin; 22 import org.eclipse.ant.core.AntCorePreferences; 23 import org.eclipse.ant.internal.ui.model.AntUIImages; 24 import org.eclipse.ant.internal.ui.model.AntUIPlugin; 25 import org.eclipse.ant.internal.ui.model.IAntUIConstants; 26 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 27 import org.eclipse.core.runtime.Platform; 28 import org.eclipse.jface.preference.IPreferenceStore; 29 import org.eclipse.jface.resource.ImageDescriptor; 30 31 public class AntDefiningTaskNode extends AntTaskNode { 32 33 public AntDefiningTaskNode(Task task, String label) { 34 super(task, label); 35 } 36 37 protected ImageDescriptor getBaseImageDescriptor() { 38 String taskName= getTask().getTaskName(); 39 if ("taskdef".equalsIgnoreCase(taskName) || "typedef".equalsIgnoreCase(taskName)) { return super.getBaseImageDescriptor(); 41 } 42 return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_MACRODEF); 43 } 44 45 48 public boolean configure(boolean validateFully) { 49 IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore(); 50 boolean enabled= store.getBoolean(AntEditorPreferenceConstants.CODEASSIST_USER_DEFINED_TASKS); 51 if (enabled) { 52 try { 53 getTask().maybeConfigure(); 54 getTask().execute(); 55 return false; 56 } catch (BuildException be) { 57 handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_CLASSPATH); 58 } 59 } 60 return false; 61 } 62 63 public Object getRealTask() { 64 Task task= getTask(); 65 if (task instanceof UnknownElement) { 66 task.maybeConfigure(); 67 return ((UnknownElement)task).getRealThing(); 68 } 69 return task; 70 } 71 72 77 public static void setJavaClassPath() { 78 79 AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences(); 80 URL [] antClasspath= prefs.getURLs(); 81 82 StringBuffer buff= new StringBuffer (); 83 File file= null; 84 for (int i = 0; i < antClasspath.length; i++) { 85 try { 86 file = new File (Platform.asLocalURL(antClasspath[i]).getPath()); 87 } catch (IOException e) { 88 continue; 89 } 90 buff.append(file.getAbsolutePath()); 91 buff.append("; "); } 93 94 org.apache.tools.ant.types.Path systemClasspath= new org.apache.tools.ant.types.Path(null, buff.substring(0, buff.length() - 2)); 95 org.apache.tools.ant.types.Path.systemClasspath= systemClasspath; 96 } 97 98 101 protected void setParent(AntElementNode node) { 102 super.setParent(node); 103 getProjectNode().addDefiningTaskNode(this); 104 } 105 } 106 | Popular Tags |