01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 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.builder;
11:
12: import java.io.IOException;
13: import java.io.InputStream;
14: import java.net.MalformedURLException;
15: import java.net.URL;
16: import java.util.Properties;
17: import org.eclipse.core.runtime.*;
18: import org.eclipse.osgi.util.NLS;
19: import org.eclipse.pde.internal.build.*;
20:
21: public class DevClassPathHelper {
22: protected boolean inDevelopmentMode = false;
23: protected String[] devDefaultClasspath;
24: protected Properties devProperties = null;
25:
26: public DevClassPathHelper(String devInfo) {
27: // Check the osgi.dev property to see if dev classpath entries have been defined.
28: String osgiDev = devInfo;
29: if (osgiDev != null) {
30: try {
31: inDevelopmentMode = true;
32: URL location = new URL(osgiDev);
33: devProperties = load(location);
34: devDefaultClasspath = Utils
35: .getArrayFromString(devProperties
36: .getProperty("*")); //$NON-NLS-1$
37: } catch (MalformedURLException e) {
38: devDefaultClasspath = Utils.getArrayFromString(osgiDev);
39: }
40: }
41: }
42:
43: public String[] getDevClassPath(String id) {
44: String[] result = null;
45: if (id != null && devProperties != null) {
46: String entry = devProperties.getProperty(id);
47: if (entry != null)
48: result = Utils.getArrayFromString(entry);
49: }
50: if (result == null)
51: result = devDefaultClasspath;
52: return result;
53: }
54:
55: public boolean inDevelopmentMode() {
56: return inDevelopmentMode;
57: }
58:
59: /*
60: * Load the given properties file
61: */
62: private static Properties load(URL url) {
63: Properties props = new Properties();
64: try {
65: InputStream is = null;
66: try {
67: is = url.openStream();
68: props.load(is);
69: } finally {
70: if (is != null)
71: is.close();
72: }
73: } catch (IOException e) {
74: String message = NLS.bind(Messages.exception_missingFile,
75: url.toExternalForm());
76: BundleHelper.getDefault().getLog().log(
77: new Status(IStatus.WARNING,
78: IPDEBuildConstants.PI_PDEBUILD,
79: IPDEBuildConstants.EXCEPTION_READING_FILE,
80: message, null));
81: }
82: return props;
83: }
84: }
|