1 11 package org.eclipse.pde.internal.ui.views.plugins; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IWorkspaceRoot; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.SubProgressMonitor; 20 import org.eclipse.jdt.core.IClasspathEntry; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.JavaCore; 23 import org.eclipse.jdt.core.JavaModelException; 24 import org.eclipse.jdt.launching.JavaRuntime; 25 import org.eclipse.jface.operation.IRunnableWithProgress; 26 import org.eclipse.pde.core.plugin.IPluginModelBase; 27 import org.eclipse.pde.internal.core.PDECore; 28 import org.eclipse.pde.internal.core.SearchablePluginsManager; 29 import org.eclipse.pde.internal.core.util.CoreUtility; 30 31 public class JavaSearchOperation implements IRunnableWithProgress { 32 33 private IPluginModelBase[] fModels; 34 private boolean fAdd; 35 36 public JavaSearchOperation(IPluginModelBase[] models, boolean add) { 37 fModels = models; 38 fAdd = add; 39 } 40 41 public void run(IProgressMonitor monitor) throws InvocationTargetException { 42 try { 43 createProxyProject(monitor); 44 SearchablePluginsManager manager = PDECore.getDefault().getSearchablePluginsManager(); 45 if (fAdd) 46 manager.addToJavaSearch(fModels); 47 else 48 manager.removeFromJavaSearch(fModels); 49 } catch (CoreException e) { 50 throw new InvocationTargetException (e); 51 } finally { 52 monitor.done(); 53 } 54 } 55 56 public IProject createProxyProject(IProgressMonitor monitor) throws CoreException { 57 IWorkspaceRoot root = PDECore.getWorkspace().getRoot(); 58 IProject project = root.getProject(SearchablePluginsManager.PROXY_PROJECT_NAME); 59 if (project.exists()) 60 return project; 61 62 monitor.beginTask("", 5); project.create(new SubProgressMonitor(monitor, 1)); 64 project.open(new SubProgressMonitor(monitor, 1)); 65 CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, new SubProgressMonitor(monitor, 1)); 66 IJavaProject jProject = JavaCore.create(project); 67 jProject.setOutputLocation(project.getFullPath(), new SubProgressMonitor(monitor, 1)); 68 computeClasspath(jProject, new SubProgressMonitor(monitor, 1)); 69 return project; 70 } 71 72 private void computeClasspath(IJavaProject project, IProgressMonitor monitor) throws CoreException { 73 IClasspathEntry[] classpath = new IClasspathEntry[2]; 74 classpath[0] = JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath()); 75 classpath[1] = JavaCore.newContainerEntry(PDECore.JAVA_SEARCH_CONTAINER_PATH); 76 try { 77 project.setRawClasspath(classpath, monitor); 78 } catch (JavaModelException e) { 79 } 80 } 81 82 } 83 | Popular Tags |