View | Details | Raw Unified | Return to bug 198641
Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/PDEClasspathContainer.java (-1 / +106 lines)
Lines 13-23 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.List;
16
18
19
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IResourceChangeEvent;
23
import org.eclipse.core.resources.IResourceChangeListener;
19
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.Path;
22
import org.eclipse.jdt.core.IAccessRule;
28
import org.eclipse.jdt.core.IAccessRule;
23
import org.eclipse.jdt.core.IClasspathAttribute;
29
import org.eclipse.jdt.core.IClasspathAttribute;
Lines 27-32 Link Here
27
import org.eclipse.pde.core.plugin.IPluginLibrary;
33
import org.eclipse.pde.core.plugin.IPluginLibrary;
28
import org.eclipse.pde.core.plugin.IPluginModelBase;
34
import org.eclipse.pde.core.plugin.IPluginModelBase;
29
import org.eclipse.pde.core.plugin.PluginRegistry;
35
import org.eclipse.pde.core.plugin.PluginRegistry;
36
import org.eclipse.pde.internal.build.Utils;
30
37
31
public class PDEClasspathContainer {
38
public class PDEClasspathContainer {
32
	
39
	
Lines 44-51 Link Here
44
		}
51
		}
45
	}
52
	}
46
	
53
	
54
	private static class PrebuildActions implements IResourceChangeListener {
55
		private List actions = new ArrayList() ;
56
57
		public void resourceChanged(IResourceChangeEvent event) {
58
			for (Iterator iterator = actions.iterator(); iterator.hasNext();) {
59
				Runnable action = (Runnable) iterator.next();
60
				action.run();
61
			}
62
			actions.clear();
63
		}
64
		
65
		public void addAction(Runnable runnable) {
66
			actions.add(runnable);
67
		}
68
	}
69
	
47
	private static HashMap ACCESSIBLE_RULES = new HashMap();
70
	private static HashMap ACCESSIBLE_RULES = new HashMap();
48
	private static HashMap DISCOURAGED_RULES = new HashMap();
71
	private static HashMap DISCOURAGED_RULES = new HashMap();
72
	private static PrebuildActions workspaceRunnable ;
49
	
73
	
50
	private static final IAccessRule EXCLUDE_ALL_RULE = 
74
	private static final IAccessRule EXCLUDE_ALL_RULE = 
51
		JavaCore.newAccessRule(new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE|IAccessRule.IGNORE_IF_BETTER); //$NON-NLS-1$
75
		JavaCore.newAccessRule(new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE|IAccessRule.IGNORE_IF_BETTER); //$NON-NLS-1$
Lines 76-82 Link Here
76
	}
100
	}
77
	
101
	
78
	protected static void addExternalPlugin(IPluginModelBase model, Rule[] rules, ArrayList entries) throws CoreException {
102
	protected static void addExternalPlugin(IPluginModelBase model, Rule[] rules, ArrayList entries) throws CoreException {
79
		if (new File(model.getInstallLocation()).isFile()) {
103
		// bug# 198641
104
		String[] devPaths = DevEntryHelper.getDevClassPath(model.getBundleDescription().getSymbolicName());
105
		if (devPaths.length > 0) {
106
			addDevPluginPaths(entries, devPaths);
107
		} else if (new File(model.getInstallLocation()).isFile()) {
80
			IPath srcPath = ClasspathUtilCore.getSourceAnnotation(model, "."); //$NON-NLS-1$
108
			IPath srcPath = ClasspathUtilCore.getSourceAnnotation(model, "."); //$NON-NLS-1$
81
			if (srcPath == null)
109
			if (srcPath == null)
82
				srcPath = new Path(model.getInstallLocation());			
110
				srcPath = new Path(model.getInstallLocation());			
Lines 100-106 Link Here
100
			}		
128
			}		
101
		}
129
		}
102
	}
130
	}
131
132
	protected static void addDevPluginPaths(ArrayList entries, String[] paths) {
133
		for (int i = 0; i < paths.length; i++) {
134
			IClasspathEntry entry ;
135
			File file = new File(paths[i]);
136
			if (file.isFile()) {
137
				entry = JavaCore.newLibraryEntry(Path.fromPortableString(paths[i]), null, null);
138
			} else {
139
				entry = getFolderEntry(paths[i]);
140
			}
141
142
			if (entry != null)
143
				entries.add(entry);
144
		}
145
		return ;
146
	}
103
	
147
	
148
	private static IClasspathEntry getFolderEntry(String path) {
149
		final IPath ipath = Path.fromPortableString(path);
150
		IProject project ;
151
		project = getLinkedFolder();
152
		if (project == null)
153
			return null ;
154
		String[] segments = ipath.segments();
155
		String linkedFolder = Utils.getStringFromArray(segments, "_");
156
		final IFolder folder = project.getFolder(linkedFolder);
157
		if (!folder.exists()) {
158
			workspaceRunnable.addAction(new Runnable() {
159
				public void run() {
160
					try {
161
						if (!folder.exists()) {
162
							folder.createLink(ipath, IResource.REPLACE, new NullProgressMonitor());
163
						}
164
					} catch (CoreException e) {
165
						e.printStackTrace();
166
					}
167
				}
168
			});
169
		}
170
		return JavaCore.newLibraryEntry(folder.getFullPath(), null, null);
171
	}
172
173
	private static IProject getLinkedFolder() {
174
		final IProject project = PDECore.getWorkspace().getRoot().getProject("__host_plugins__");
175
		if (!project.exists() || !project.isOpen())
176
			workspaceRunnable.addAction(new Runnable() {
177
				public void run() {
178
					try {
179
						if (!project.exists()) {
180
							project.create(new NullProgressMonitor());
181
						}
182
						if (!project.isOpen()) {
183
							project.open(new NullProgressMonitor());
184
						}
185
					} catch (CoreException e) {
186
						e.printStackTrace();
187
					}
188
				}
189
			});
190
		return project ;
191
	}
192
104
	protected static void addLibraryEntry(IPath path, IPath srcPath, Rule[] rules, IClasspathAttribute[] attributes, ArrayList entries) {
193
	protected static void addLibraryEntry(IPath path, IPath srcPath, Rule[] rules, IClasspathAttribute[] attributes, ArrayList entries) {
105
		IClasspathEntry entry = null;
194
		IClasspathEntry entry = null;
106
		if (rules != null) {
195
		if (rules != null) {
Lines 176-180 Link Here
176
		}
265
		}
177
		return null;
266
		return null;
178
	}
267
	}
268
269
	public static void start() {
270
		if (workspaceRunnable == null) {
271
			workspaceRunnable = new PrebuildActions();
272
			JavaCore.addPreProcessingResourceChangedListener(
273
					workspaceRunnable,
274
					IResourceChangeEvent.PRE_BUILD);
275
		}
276
	}
277
278
	public static void stop() {
279
		if (workspaceRunnable != null) {
280
			JavaCore.removePreProcessingResourceChangedListener(workspaceRunnable);
281
			workspaceRunnable = null ;
282
		}
283
	}
179
	
284
	
180
}
285
}
(-)src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java (+3 lines)
Lines 144-149 Link Here
144
				}
144
				}
145
			}
145
			}
146
146
147
			// add default classpath passed through -dev argument bug# 198641
148
			addDevPluginPaths(entries, DevEntryHelper.getDevDefaultPath());
149
			
147
			// add dependencies
150
			// add dependencies
148
			BundleSpecification[] required = desc.getRequiredBundles();
151
			BundleSpecification[] required = desc.getRequiredBundles();
149
			for (int i = 0; i < required.length; i++) {
152
			for (int i = 0; i < required.length; i++) {
(-)src/org/eclipse/pde/internal/core/PDECore.java (+2 lines)
Lines 250-255 Link Here
250
		fPluginRebuilder.start();
250
		fPluginRebuilder.start();
251
		fFeatureRebuilder = new FeatureRebuilder();
251
		fFeatureRebuilder = new FeatureRebuilder();
252
		fFeatureRebuilder.start();
252
		fFeatureRebuilder.start();
253
		PDEClasspathContainer.start(); // bug# 198641
253
	}
254
	}
254
255
255
	public BundleContext getBundleContext() {
256
	public BundleContext getBundleContext() {
Lines 288-292 Link Here
288
			fExtensionRegistry.stop();
289
			fExtensionRegistry.stop();
289
			fExtensionRegistry = null;
290
			fExtensionRegistry = null;
290
		}
291
		}
292
		PDEClasspathContainer.stop(); // bug# 198641
291
	}
293
	}
292
}
294
}
(-)src/org/eclipse/pde/internal/core/ClasspathHelper.java (+2 lines)
Lines 59-64 Link Here
59
			}
59
			}
60
		}
60
		}
61
		Properties properties = new Properties();
61
		Properties properties = new Properties();
62
		properties.putAll(DevEntryHelper.getDevProperties()); // bug# 198641
62
		IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
63
		IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
63
		for (int i = 0; i < models.length; i++) {
64
		for (int i = 0; i < models.length; i++) {
64
			String id = models[i].getPluginBase().getId();
65
			String id = models[i].getPluginBase().getId();
Lines 97-102 Link Here
97
            }
98
            }
98
        }
99
        }
99
        Properties properties = new Properties();
100
        Properties properties = new Properties();
101
		properties.putAll(DevEntryHelper.getDevProperties()); // bug# 198641
100
        Iterator iter = map.values().iterator();
102
        Iterator iter = map.values().iterator();
101
        while (iter.hasNext()) {
103
        while (iter.hasNext()) {
102
            IPluginModelBase model = (IPluginModelBase)iter.next();
104
            IPluginModelBase model = (IPluginModelBase)iter.next();
(-)src/org/eclipse/pde/internal/core/PluginPathFinder.java (-1 / +1 lines)
Lines 90-96 Link Here
90
	}
90
	}
91
	
91
	
92
	public static URL[] getPluginPaths(String platformHome) {
92
	public static URL[] getPluginPaths(String platformHome) {
93
		if (new Path(platformHome).equals(new Path(TargetPlatform.getDefaultLocation())) && !isDevLaunchMode())
93
		if (new Path(platformHome).equals(new Path(TargetPlatform.getDefaultLocation()))) // bug# 198641
94
			return ConfiguratorUtils.getCurrentPlatformConfiguration().getPluginPath();
94
			return ConfiguratorUtils.getCurrentPlatformConfiguration().getPluginPath();
95
		
95
		
96
		File file = new File(platformHome, "configuration/org.eclipse.update/platform.xml"); //$NON-NLS-1$
96
		File file = new File(platformHome, "configuration/org.eclipse.update/platform.xml"); //$NON-NLS-1$
(-)src/org/eclipse/pde/internal/core/DevEntryHelper.java (+109 lines)
Added Link Here
1
// bug# 198641
2
package org.eclipse.pde.internal.core;
3
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.net.MalformedURLException;
7
import java.net.URL;
8
import java.util.Enumeration;
9
import java.util.Properties;
10
11
import org.eclipse.core.runtime.FileLocator;
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.core.runtime.Status;
15
import org.eclipse.osgi.util.NLS;
16
import org.eclipse.pde.internal.build.BundleHelper;
17
import org.eclipse.pde.internal.build.IPDEBuildConstants;
18
import org.eclipse.pde.internal.build.Messages;
19
import org.eclipse.pde.internal.build.Utils;
20
import org.osgi.framework.Bundle;
21
22
public class DevEntryHelper {
23
	private Properties devProperties = new Properties();
24
	private String[] devDefaultPath ;
25
	
26
	private static DevEntryHelper instance ;
27
	
28
	private static DevEntryHelper getInstance() {
29
		if (instance == null) {
30
			instance = new DevEntryHelper(System.getProperty("osgi.dev"));
31
		}
32
		return instance;
33
	}
34
	
35
	private DevEntryHelper(String osgiDev) {
36
		// Check the osgi.dev property to see if dev classpath entries have been defined.
37
		if (osgiDev != null) {
38
			try {
39
				URL location = new URL(osgiDev);
40
				load(location);
41
			} catch (MalformedURLException e) {
42
				devDefaultPath = Utils.getArrayFromString(osgiDev);
43
			}
44
		}
45
	}
46
47
	public static String[] getDevDefaultPath() {
48
		String[] path = getInstance().devDefaultPath;
49
		if (path == null)
50
			path = getDevClassPath("*");
51
		return path ;
52
	}
53
	
54
	public static Properties getDevProperties() {
55
		return getInstance().devProperties;
56
	}
57
	
58
	/*
59
	 * Load the given properties file
60
	 */
61
	private void load(URL url) {
62
		Properties props = new Properties();
63
		try {
64
			InputStream 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 e) {
73
			String 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
		convertRelativePaths(props);
77
	}
78
79
	private void convertRelativePaths(Properties props) {
80
		Enumeration keys = props.keys();
81
		while (keys.hasMoreElements()) {
82
			String bundleName = (String) keys.nextElement();
83
			String path = props.getProperty(bundleName);
84
			Bundle bundle = Platform.getBundle(bundleName);
85
			if (bundle != null) {
86
				addAbsolutePath(bundle, path);
87
			}
88
		}
89
	}
90
91
	private void addAbsolutePath(Bundle bundle, String pathList) {
92
		String[] paths = Utils.getArrayFromString(pathList);
93
		for (int i = 0; i < paths.length; i++) {
94
			URL convertedPathURL = bundle.getEntry(paths[i]);
95
			if (convertedPathURL != null) {
96
				try {
97
					paths[i] = FileLocator.toFileURL(convertedPathURL).getFile();
98
				} catch (IOException e) {
99
				}
100
			}
101
		}
102
		devProperties.setProperty(bundle.getSymbolicName(), Utils.getStringFromArray(paths, ","));
103
	}
104
105
	public static String[] getDevClassPath(String symbolicName) {
106
		String devPath = getInstance().devProperties.getProperty(symbolicName);
107
		return Utils.getArrayFromString(devPath);
108
	}
109
}

Return to bug 198641