01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *****************************************/package org.eclipse.pde.internal.build.properties;
11:
12: import java.io.IOException;
13: import java.net.URL;
14: import java.util.HashMap;
15: import java.util.Map;
16: import org.eclipse.ant.core.IAntPropertyValueProvider;
17: import org.eclipse.core.runtime.*;
18: import org.eclipse.osgi.util.NLS;
19: import org.eclipse.pde.internal.build.*;
20:
21: public class PDEProperties implements IAntPropertyValueProvider {
22: static private final String PREFIX = "eclipse.pdebuild"; //$NON-NLS-1$
23: static private final String HOME = PREFIX + ".home"; //$NON-NLS-1$
24: static private final String SCRIPTS = PREFIX + ".scripts"; //$NON-NLS-1$
25: static private final String TEMPLATES = PREFIX + ".templates"; //$NON-NLS-1$
26: static private final Map cache = new HashMap();
27:
28: public String getAntPropertyValue(String antPropertyName) {
29: String searchedEntry = null;
30: if (HOME.equals(antPropertyName))
31: searchedEntry = "."; //$NON-NLS-1$
32:
33: if (SCRIPTS.equals(antPropertyName))
34: searchedEntry = "scripts"; //$NON-NLS-1$
35:
36: if (TEMPLATES.equals(antPropertyName))
37: searchedEntry = "templates"; //$NON-NLS-1$
38:
39: if (searchedEntry == null)
40: return null; //TODO Throw an exception or log an error
41:
42: try {
43: String result = (String) cache.get(searchedEntry);
44: if (result == null) {
45: URL foundEntry = Platform.getBundle(
46: IPDEBuildConstants.PI_PDEBUILD).getEntry(
47: searchedEntry);
48: if (foundEntry == null) {
49: BundleHelper
50: .getDefault()
51: .getLog()
52: .log(
53: new Status(
54: IStatus.ERROR,
55: IPDEBuildConstants.PI_PDEBUILD,
56: IPDEBuildConstants.WARNING_PLUGIN_ALTERED,
57: NLS
58: .bind(
59: Messages.exception_missing_pdebuild_folder,
60: antPropertyName),
61: null));
62: } else {
63: result = FileLocator.toFileURL(foundEntry)
64: .getPath();
65: cache.put(searchedEntry, result);
66: }
67: }
68: return result;
69: } catch (IOException e) {
70: return null;
71: }
72:
73: }
74:
75: }
|