KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > core > AntPropertyValueProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 BBDO Detroit and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Thierry Lach (thierry.lach@bbdodetroit.com) - initial API and implementation for bug 40502
10  * IBM Corporation - added eclipse.running property, bug 65655
11  *******************************************************************************/

12 package org.eclipse.ant.internal.core;
13
14 import java.io.File JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.ant.core.AntCorePlugin;
18 import org.eclipse.ant.core.IAntPropertyValueProvider;
19 import org.eclipse.core.runtime.FileLocator;
20
21 /**
22  * Dynamic provider for Ant properties.
23  *
24  * Provides the dynamic values for the following Ant properties:
25  *
26  * <ul>
27  * <li><code>eclipse.home</code> - set to the Eclipse installation directory</li>
28  * </ul>
29  * * <ul>
30  * <li><code>eclipse.running</code> - set (to "true") when Eclipse is running</li>
31  * </ul>
32  *
33  * @since 3.0
34  */

35 public class AntPropertyValueProvider implements IAntPropertyValueProvider {
36     /**
37      * Returns the dynamic property values for Ant properties.
38      *
39      * @param propertyName The name of the property to resolve the value for
40      * @return The resolved value for the property
41      * @see org.eclipse.ant.core.IAntPropertyValueProvider#getAntPropertyValue(String)
42      */

43     public String JavaDoc getAntPropertyValue(String JavaDoc propertyName) {
44         String JavaDoc value = null;
45         if ("eclipse.running".equals(propertyName)){ //$NON-NLS-1$
46
return "true"; //$NON-NLS-1$
47
} else if ("eclipse.home".equals(propertyName)) { //$NON-NLS-1$
48
try {
49                 value = new File JavaDoc(FileLocator.resolve(new URL JavaDoc("platform:/base/")).getPath()).getAbsolutePath(); //$NON-NLS-1$
50
if (value.endsWith("/")) { //$NON-NLS-1$
51
value = value.substring(0, value.length() - 1);
52                 }
53             } catch (Exception JavaDoc e) {
54                 AntCorePlugin.log(e);
55             }
56         }
57         return value;
58     }
59 }
Popular Tags