KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > AntModelProject


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * Portions Copyright 2000-2004 The Apache Software Foundation
4  * All rights reserved. This program and the accompanying materials are made
5  * available under the terms of the Apache Software License v2.0 which
6  * accompanies this distribution and is available at
7  * http://www.apache.org/licenses/LICENSE-2.0.
8  *
9  * Contributors:
10  * IBM Corporation - derived implementation
11  *******************************************************************************/

12
13 package org.eclipse.ant.internal.ui.model;
14
15 import java.io.File JavaDoc;
16 import java.util.Enumeration JavaDoc;
17 import java.util.Hashtable JavaDoc;
18
19 import org.apache.tools.ant.AntClassLoader;
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.BuildListener;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.types.Path;
24
25 /**
26  * Derived from the original Ant Project class
27  * This class allows property values to be written multiple times.
28  * This facilitates incremental parsing of the Ant build file
29  * It also attempts to ensure that we clean up after ourselves and allows
30  * more manipulation of properties resulting from incremental parsing.
31  * Also allows the Eclipse additions to the Ant runtime classpath.
32  */

33 public class AntModelProject extends Project {
34     
35     private Hashtable JavaDoc fBaseProperties;
36     private Hashtable JavaDoc fCurrentProperties= new Hashtable JavaDoc();
37     private AntPropertyNode fCurrentConfiguringPropertyNode;
38     
39     /* (non-Javadoc)
40      * @see org.apache.tools.ant.Project#setNewProperty(java.lang.String, java.lang.String)
41      */

42     public void setNewProperty(String JavaDoc name, String JavaDoc value) {
43         
44         if (fCurrentProperties.get(name) != null) {
45             return;
46         }
47         //allows property values to be over-written for this parse session
48
//there is currently no way to remove properties from the Apache Ant project
49
//the project resets it properties for each parse...see reset()
50
fCurrentProperties.put(name, value);
51         if (fCurrentConfiguringPropertyNode != null) {
52             fCurrentConfiguringPropertyNode.addProperty(name, value);
53         }
54         super.setProperty(name, value);
55     }
56     
57     /* (non-Javadoc)
58      * @see org.apache.tools.ant.Project#fireBuildFinished(java.lang.Throwable)
59      */

60     public void fireBuildFinished(Throwable JavaDoc exception) {
61         super.fireBuildFinished(exception);
62         Enumeration JavaDoc e= getBuildListeners().elements();
63         while (e.hasMoreElements()) {
64             BuildListener listener = (BuildListener) e.nextElement();
65             removeBuildListener(listener);
66         }
67     }
68     
69     public void reset() {
70         getTargets().clear();
71         setDefault(null);
72         setDescription(null);
73         setName(""); //$NON-NLS-1$
74
//reset the properties to the initial set
75
fCurrentProperties= new Hashtable JavaDoc(fBaseProperties);
76     }
77     
78     /* (non-Javadoc)
79      * @see org.apache.tools.ant.Project#getProperty(java.lang.String)
80      */

81     public String JavaDoc getProperty(String JavaDoc name) {
82         //override as we cannot remove properties from the Apache Ant project
83
String JavaDoc result= (String JavaDoc)fCurrentProperties.get(name);
84         if (result == null) {
85             result= getUserProperty(name);
86         }
87         return result;
88     }
89     
90     /* (non-Javadoc)
91      * @see org.apache.tools.ant.Project#getProperties()
92      */

93     public Hashtable JavaDoc getProperties() {
94         //override as we cannot remove properties from the Apache Ant project
95
Hashtable JavaDoc allProps= new Hashtable JavaDoc(fCurrentProperties);
96         allProps.putAll(getUserProperties());
97         allProps.put("basedir", getBaseDir().getPath()); //$NON-NLS-1$
98
return allProps;
99     }
100     
101     /* (non-Javadoc)
102      * @see org.apache.tools.ant.Project#init()
103      */

104     public void init() throws BuildException {
105         super.init();
106         fBaseProperties= super.getProperties();
107         fCurrentProperties= super.getProperties();
108     }
109     
110     /* (non-Javadoc)
111      * @see org.apache.tools.ant.Project#setBaseDir(java.io.File)
112      */

113     public void setBaseDir(File JavaDoc baseDir) throws BuildException {
114         super.setBaseDir(baseDir);
115         fCurrentProperties.put("basedir", getBaseDir().getPath()); //$NON-NLS-1$
116
}
117
118     /**
119      * @param node the property node that is currently being configured
120      */

121     public void setCurrentConfiguringProperty(AntPropertyNode node) {
122         fCurrentConfiguringPropertyNode= node;
123     }
124     
125      /* (non-Javadoc)
126      * @see org.apache.tools.ant.Project#createClassLoader(org.apache.tools.ant.types.Path)
127      */

128     public AntClassLoader createClassLoader(Path path) {
129         AntClassLoader loader= super.createClassLoader(path);
130         if (path == null) {
131             //use the "fake" Eclipse runtime classpath for Ant
132
loader.setClassPath(Path.systemClasspath);
133         }
134         
135         return loader;
136     }
137 }
Popular Tags