KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > properties > PDEProperties


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *****************************************/

11 package org.eclipse.pde.internal.build.properties;
12
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17 import org.eclipse.ant.core.IAntPropertyValueProvider;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.pde.internal.build.*;
21
22 public class PDEProperties implements IAntPropertyValueProvider {
23     static private final String JavaDoc PREFIX = "eclipse.pdebuild"; //$NON-NLS-1$
24
static private final String JavaDoc HOME = PREFIX + ".home"; //$NON-NLS-1$
25
static private final String JavaDoc SCRIPTS = PREFIX + ".scripts"; //$NON-NLS-1$
26
static private final String JavaDoc TEMPLATES = PREFIX + ".templates"; //$NON-NLS-1$
27
static private final Map JavaDoc cache = new HashMap JavaDoc();
28
29     public String JavaDoc getAntPropertyValue(String JavaDoc antPropertyName) {
30         String JavaDoc searchedEntry = null;
31         if (HOME.equals(antPropertyName))
32             searchedEntry = "."; //$NON-NLS-1$
33

34         if (SCRIPTS.equals(antPropertyName))
35             searchedEntry = "scripts"; //$NON-NLS-1$
36

37         if (TEMPLATES.equals(antPropertyName))
38             searchedEntry = "templates"; //$NON-NLS-1$
39

40         if (searchedEntry == null)
41             return null; //TODO Throw an exception or log an error
42

43         try {
44             String JavaDoc result = (String JavaDoc) cache.get(searchedEntry);
45             if (result == null) {
46                 URL JavaDoc foundEntry = Platform.getBundle(IPDEBuildConstants.PI_PDEBUILD).getEntry(searchedEntry);
47                 if (foundEntry == null) {
48                     BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, IPDEBuildConstants.PI_PDEBUILD, IPDEBuildConstants.WARNING_PLUGIN_ALTERED, NLS.bind(Messages.exception_missing_pdebuild_folder, antPropertyName), null));
49                 } else {
50                     result = FileLocator.toFileURL(foundEntry).getPath();
51                     cache.put(searchedEntry, result);
52                 }
53             }
54             return result;
55         } catch (IOException JavaDoc e) {
56             return null;
57         }
58
59     }
60
61 }
62
Popular Tags