KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > model > AntDefiningTaskNode


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

11
12 package org.eclipse.ant.internal.ui.editor.model;
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.net.URL JavaDoc;
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 JavaDoc label) {
34         super(task, label);
35     }
36     
37     protected ImageDescriptor getBaseImageDescriptor() {
38         String JavaDoc taskName= getTask().getTaskName();
39         if ("taskdef".equalsIgnoreCase(taskName) || "typedef".equalsIgnoreCase(taskName)) { //$NON-NLS-1$//$NON-NLS-2$
40
return super.getBaseImageDescriptor();
41         }
42         return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_MACRODEF);
43     }
44     
45     /**
46      * Execute the defining task.
47      */

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 JavaDoc 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     /*
73      * Sets the Java class path in org.apache.tools.ant.types.Path
74      * so that the classloaders defined by these "definer" tasks will have the
75      * correct classpath.
76      */

77     public static void setJavaClassPath() {
78         
79         AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
80         URL JavaDoc[] antClasspath= prefs.getURLs();
81         
82         StringBuffer JavaDoc buff= new StringBuffer JavaDoc();
83         File JavaDoc file= null;
84         for (int i = 0; i < antClasspath.length; i++) {
85             try {
86                 file = new File JavaDoc(Platform.asLocalURL(antClasspath[i]).getPath());
87             } catch (IOException JavaDoc e) {
88                 continue;
89             }
90             buff.append(file.getAbsolutePath());
91             buff.append("; "); //$NON-NLS-1$
92
}
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     /* (non-Javadoc)
99      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#setParent(org.eclipse.ant.internal.ui.editor.model.AntElementNode)
100      */

101     protected void setParent(AntElementNode node) {
102         super.setParent(node);
103         getProjectNode().addDefiningTaskNode(this);
104     }
105 }
106
Popular Tags