KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > builder > DevClassPathHelper


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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.builder;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.Properties JavaDoc;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.pde.internal.build.*;
21
22 public class DevClassPathHelper {
23     protected boolean inDevelopmentMode = false;
24     protected String JavaDoc[] devDefaultClasspath;
25     protected Properties JavaDoc devProperties = null;
26
27     public DevClassPathHelper(String JavaDoc devInfo) {
28         // Check the osgi.dev property to see if dev classpath entries have been defined.
29
String JavaDoc osgiDev = devInfo;
30         if (osgiDev != null) {
31             try {
32                 inDevelopmentMode = true;
33                 URL JavaDoc location = new URL JavaDoc(osgiDev);
34                 devProperties = load(location);
35                 devDefaultClasspath = Utils.getArrayFromString(devProperties.getProperty("*")); //$NON-NLS-1$
36
} catch (MalformedURLException JavaDoc e) {
37                 devDefaultClasspath = Utils.getArrayFromString(osgiDev);
38             }
39         }
40     }
41
42     public String JavaDoc[] getDevClassPath(String JavaDoc id) {
43         String JavaDoc[] result = null;
44         if (id != null && devProperties != null) {
45             String JavaDoc entry = devProperties.getProperty(id);
46             if (entry != null)
47                 result = Utils.getArrayFromString(entry);
48         }
49         if (result == null)
50             result = devDefaultClasspath;
51         return result;
52     }
53
54     public boolean inDevelopmentMode() {
55         return inDevelopmentMode;
56     }
57
58     /*
59      * Load the given properties file
60      */

61     private static Properties JavaDoc load(URL JavaDoc url) {
62         Properties JavaDoc props = new Properties JavaDoc();
63         try {
64             InputStream JavaDoc is = null;
65             try {
66                 is = url.openStream();
67                 props.load(is);
68             } finally {
69                 if (is != null)
70                     is.close();
71             }
72         } catch (IOException JavaDoc e) {
73             String JavaDoc message = NLS.bind(Messages.exception_missingFile, url.toExternalForm());
74             BundleHelper.getDefault().getLog().log(new Status(IStatus.WARNING, IPDEBuildConstants.PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, message, null));
75         }
76         return props;
77     }
78 }
79
Popular Tags