1 11 12 package org.eclipse.ant.internal.ui.model; 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.net.URL ; 17 import java.util.ArrayList ; 18 import java.util.Hashtable ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.ComponentHelper; 24 import org.apache.tools.ant.Task; 25 import org.apache.tools.ant.UnknownElement; 26 import org.eclipse.ant.core.AntCorePlugin; 27 import org.eclipse.ant.core.AntCorePreferences; 28 import org.eclipse.ant.core.AntSecurityException; 29 import org.eclipse.ant.internal.ui.AntUIImages; 30 import org.eclipse.ant.internal.ui.AntUIPlugin; 31 import org.eclipse.ant.internal.ui.IAntUIConstants; 32 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 33 import org.eclipse.core.runtime.FileLocator; 34 import org.eclipse.jface.preference.IPreferenceStore; 35 import org.eclipse.jface.resource.ImageDescriptor; 36 import org.xml.sax.Attributes ; 37 38 public class AntDefiningTaskNode extends AntTaskNode { 39 private String fIdentifier= null; 40 41 public AntDefiningTaskNode(Task task, Attributes attributes) { 42 super(task); 43 String label= attributes.getValue(IAntModelConstants.ATTR_NAME); 44 if (label == null) { 45 label= task.getTaskName(); 46 47 String file= attributes.getValue(IAntModelConstants.ATTR_FILE); 48 if(file != null) { 49 label= label + " " + file; fIdentifier= file; 51 } else { 52 String resource= attributes.getValue(IAntModelConstants.ATTR_RESOURCE); 53 if (resource != null) { 54 label= label + " " + resource; fIdentifier= resource; 56 } 57 } 58 } else { 59 fIdentifier= label; 60 } 61 62 setBaseLabel(label); 63 } 64 65 protected ImageDescriptor getBaseImageDescriptor() { 66 String taskName= getTask().getTaskName(); 67 if ("taskdef".equalsIgnoreCase(taskName) || "typedef".equalsIgnoreCase(taskName)) { return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TASKDEF); 69 } 70 return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_MACRODEF); 71 } 72 73 76 public boolean configure(boolean validateFully) { 77 if (fConfigured) { 78 return false; 79 } 80 if (shouldConfigure()) { 81 try { 82 ComponentHelper helper= ComponentHelper.getComponentHelper(getProjectNode().getProject()); 83 ((AntModel) getAntModel()).removeDefinerTasks(getIdentifier(), helper.getAntTypeTable()); 84 Hashtable old= new Hashtable (helper.getAntTypeTable()); 85 getTask().maybeConfigure(); 86 getTask().execute(); 87 Iterator newNames= helper.getAntTypeTable().keySet().iterator(); 88 List defined= new ArrayList (); 89 while (newNames.hasNext()) { 90 String name = (String ) newNames.next(); 91 if (old.get(name) == null) { 92 defined.add(name); 93 } 94 } 95 ((AntModel) getAntModel()).addDefinedTasks(defined, this); 96 return false; 97 } catch (BuildException be) { 98 ((AntModel)getAntModel()).removeDefiningTaskNodeInfo(this); 99 handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_CLASSPATH); 100 } catch (LinkageError e) { 101 ((AntModel)getAntModel()).removeDefiningTaskNodeInfo(this); 105 handleBuildException(new BuildException(AntModelMessages.AntDefiningTaskNode_0), AntEditorPreferenceConstants.PROBLEM_CLASSPATH); 106 } catch (AntSecurityException se) { 107 ((AntModel)getAntModel()).removeDefiningTaskNodeInfo(this); 109 handleBuildException(new BuildException(AntModelMessages.AntDefiningTaskNode_1), AntEditorPreferenceConstants.PROBLEM_SECURITY); 110 } 111 } 112 return false; 113 } 114 115 public Object getRealTask() { 116 Task task= getTask(); 117 if (task instanceof UnknownElement) { 118 task.maybeConfigure(); 119 return ((UnknownElement)task).getRealThing(); 120 } 121 return task; 122 } 123 124 protected String getIdentifier() { 125 return fIdentifier; 126 } 127 128 133 public static void setJavaClassPath() { 134 135 AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences(); 136 URL [] antClasspath= prefs.getURLs(); 137 138 setJavaClassPath(antClasspath); 139 } 140 141 146 public static void setJavaClassPath(URL [] antClasspath) { 147 148 StringBuffer buff= new StringBuffer (); 149 File file= null; 150 for (int i = 0; i < antClasspath.length; i++) { 151 try { 152 file = new File (FileLocator.toFileURL(antClasspath[i]).getPath()); 153 } catch (IOException e) { 154 continue; 155 } 156 buff.append(file.getAbsolutePath()); 157 buff.append("; "); } 159 160 org.apache.tools.ant.types.Path systemClasspath= new org.apache.tools.ant.types.Path(null, buff.substring(0, buff.length() - 2)); 161 org.apache.tools.ant.types.Path.systemClasspath= systemClasspath; 162 } 163 164 public boolean collapseProjection() { 165 IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore(); 166 if (store.getBoolean(AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING)) { 167 return true; 168 } 169 return false; 170 } 171 172 175 public void setLength(int length) { 176 super.setLength(length); 177 if (shouldConfigure()) { 178 getAntModel().setDefiningTaskNodeText(this); 179 } 180 } 181 182 private boolean shouldConfigure() { 183 IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore(); 184 return store.getBoolean(AntEditorPreferenceConstants.CODEASSIST_USER_DEFINED_TASKS); 185 } 186 187 protected void setNeedsToBeConfigured(boolean configure) { 188 fConfigured= !configure; 189 } 190 } 191 | Popular Tags |