/** * Given a source name info, search the associated source file or class file from the source container list. * * @param sourcePath * the target source name (e.g. com\microsoft\java\debug\xxx.java). * @param containers * the source container list. * @return the associated source file or class file. */ public static Object findSourceElement(String sourcePath, ISourceContainer[] containers) { if (containers == null) { return null; } for (ISourceContainer container : containers) { try { Object[] objects = container.findSourceElements(sourcePath); if (objects.length > 0 && (objects[0] instanceof IResource || objects[0] instanceof IClassFile)) { return objects[0]; } } catch (CoreException e) { // do nothing. } } return null; }
/** * Given a stack frame, find the target project that the associated source file belongs to. * * @param stackFrame * the stack frame. * @param containers * the source container list. * @return the context project. */ public static IProject findProject(StackFrame stackFrame, ISourceContainer[] containers) { Location location = stackFrame.location(); try { Object sourceElement = findSourceElement(location.sourcePath(), containers); if (sourceElement instanceof IResource) { return ((IResource) sourceElement).getProject(); } else if (sourceElement instanceof IClassFile) { IJavaProject javaProject = ((IClassFile) sourceElement).getJavaProject(); if (javaProject != null) { return javaProject.getProject(); } } } catch (AbsentInformationException e) { // When the compiled .class file doesn't contain debug source information, return null. } return null; }
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { List<IRuntimeClasspathEntry> entries = new ArrayList<IRuntimeClasspathEntry>(); IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration); if (jreEntry != null) { entries.add(jreEntry); } String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ if (projectName == null) { return null; } for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.isOpen() && ("".equals(projectName) || projectName.equals(javaProject.getElementName()))) { //$NON-NLS-1$ entries.add(JavaRuntime.newDefaultProjectClasspathEntry(javaProject)); } } IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath( // entries.toArray(new IRuntimeClasspathEntry[entries.size()]), configuration); return JavaRuntime.getSourceContainers(resolved); }
private ISourceContainer[] fromJavaRuntimeResolver() throws CoreException { for (final IClasspathEntry cpe : jp.getRawClasspath()) { if (IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind() && // IClasspathManager.CONTAINER_ID.equals(cpe.getPath().toString())) { final IRuntimeClasspathEntry newRuntimeContainerClasspathEntry = JavaRuntime.newRuntimeContainerClasspathEntry(cpe.getPath(), IRuntimeClasspathEntry.USER_CLASSES, jp); final IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry = JavaRuntime.resolveRuntimeClasspathEntry( newRuntimeContainerClasspathEntry, jp); // there is only one maven2 classpath container in a project return return JavaRuntime.getSourceContainers(resolveRuntimeClasspathEntry); } } return new ISourceContainer[] {}; }
private ISourceContainer[] fromMavenSourcePathProvider() throws CoreException { final IRuntimeClasspathEntry mavenEntry = JavaRuntime.newRuntimeContainerClasspathEntry(new Path(IClasspathManager.CONTAINER_ID), IRuntimeClasspathEntry.USER_CLASSES); final ILaunchConfiguration launchConfiguration = getDirector().getLaunchConfiguration(); // final ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy(); // wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, getProjectName()); // final ILaunchConfiguration doSave = wc.doSave(); final ILaunchConfiguration javaProjectLaunchConfiguration = new JavaProjectLaunchConfiguration(launchConfiguration, this); final IRuntimeClasspathEntry[] resolved = mavenRuntimeClasspathProvider.resolveClasspath(new IRuntimeClasspathEntry[] { mavenEntry }, javaProjectLaunchConfiguration); // final IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedSourceLookupPath(doSave); // final IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, doSave); return JavaRuntime.getSourceContainers(resolved); }
private ILaunchConfiguration getRunningLaunchConfiguration() { Set<IProject> projects = new HashSet<IProject>( Arrays.asList(ProjectUtil.getProjects(repository))); ILaunchManager launchManager = DebugPlugin.getDefault() .getLaunchManager(); ILaunch[] launches = launchManager.getLaunches(); for (ILaunch launch : launches) { if (launch.isTerminated()) continue; ISourceLocator locator = launch.getSourceLocator(); if (locator instanceof ISourceLookupDirector) { ISourceLookupDirector director = (ISourceLookupDirector) locator; ISourceContainer[] containers = director.getSourceContainers(); if (isAnyProjectInSourceContainers(containers, projects)) return launch.getLaunchConfiguration(); } } return null; }
private boolean isAnyProjectInSourceContainers( ISourceContainer[] containers, Set<IProject> projects) { for (ISourceContainer container : containers) { if (container instanceof ProjectSourceContainer) { ProjectSourceContainer projectContainer = (ProjectSourceContainer) container; if (projects.contains(projectContainer.getProject())) return true; } try { boolean found = isAnyProjectInSourceContainers( container.getSourceContainers(), projects); if (found) return true; } catch (CoreException e) { // Ignore the child source containers, continue search } } return false; }
@Override Object[] findSourceElements(Object object, LookupParticipant.SuperClassAccess superClass) throws CoreException { ArrayList<Object> result = new ArrayList<Object>(); JavascriptVmEmbedder vmEmbedder = superClass.getChromiumSourceDirector().javascriptVmEmbedder; ScriptNameManipulator.FilePath scriptName = getParsedScriptFileName(object, vmEmbedder.getScriptNameManipulator()); if (scriptName != null) { for (ISourceContainer container : superClass.getSourceContainers()) { try { findSourceElements(container, object, scriptName, result); } catch (CoreException e) { ChromiumDebugPlugin.log(e); continue; } // If one container returned one file -- that's a single uncompromised result. IFile oneFile = getSimpleResult(result); if (oneFile != null) { return new Object[] { oneFile }; } } } return result.toArray(); }
private VmResourceId tryForContainer(IFile sourceFile, ISourceContainer container) throws CoreException { if (container.isComposite() && isSupportedCompositeContainer(container)) { ISourceContainer[] subContainers = container.getSourceContainers(); for (ISourceContainer subContainer : subContainers) { VmResourceId res = tryForContainer(sourceFile, subContainer); if (res != null) { return res; } } return null; } else if (container instanceof VProjectSourceContainer) { VProjectSourceContainer projectSourceContainer = (VProjectSourceContainer) container; return projectSourceContainer.findScriptId(sourceFile); } else { String name = tryForNonVirtualContainer(sourceFile, container); if (name == null) { return null; } return new VmResourceId(name, null); } }
public ISourceContainer createSourceContainer(String memento) throws CoreException { MementoFormat.Parser parser = new MementoFormat.Parser(memento); String prefix; String typeId; String subContainerMemento; try { prefix = parser.nextComponent(); typeId = parser.nextComponent(); subContainerMemento = parser.nextComponent(); } catch (MementoFormat.ParserException e) { throw new CoreException(new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, "Failed to parse memento", e)); //$NON-NLS-1$ } ISourceContainerType subContainerType = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType(typeId); ISourceContainer subContainer = subContainerType.createSourceContainer(subContainerMemento); return new SourceNameMapperContainer(prefix, subContainer); }
@Override public ISourcePathComputer getSourcePathComputer() { ISourcePathComputer sourcePathComputer = super.getSourcePathComputer(); if(sourcePathComputer != null) { return sourcePathComputer; } return new ISourcePathComputer() { LangSourcePathComputer langSourcePathComputer = new LangSourcePathComputer(); @Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { return langSourcePathComputer.computeSourceContainers(configuration, monitor); } @Override public String getId() { return LangDebug.LANG_SOURCE_LOOKUP_DIRECTOR; } }; }
@Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { ISourceContainer[] common = getSourceLookupDirector().getSourceContainers(); ISourceContainer[] containers = new ISourceContainer[common.length]; for (int i = 0; i < common.length; i++) { ISourceContainer container = common[i]; ISourceContainerType type = container.getType(); // Clone the container to make sure that the original can be safely disposed. if(container instanceof AbsolutePathSourceContainer) { // LANG: Ensure our modifications are propagated. container = new LangAbsolutePathSourceContainer(); } else { container = type.createSourceContainer(type.getMemento(container)); } containers[i] = container; } return containers; }
protected ISourceLookupDirector getSourceLookupDirector() { ISourceLookupDirector commonSourceLookupDirector = new AbstractSourceLookupDirector() { @Override public void initializeParticipants() { } }; ArrayList2<ISourceContainer> containers = new ArrayList2<>(); containers.add(new LangAbsolutePathSourceContainer()); containers.add(new ProgramRelativePathSourceContainer()); customizeDefaultSourceContainers(containers); commonSourceLookupDirector.setSourceContainers(containers.toArray(ISourceContainer.class)); return commonSourceLookupDirector; }
/** * Compute the possible source containers that the specified project could be associated with. * <p> * If the project name is specified, it will put the source containers parsed from the specified project's * classpath entries in the front of the result, then the other projects at the same workspace. * </p> * <p> * Otherwise, just loop every projects at the current workspace and combine the parsed source containers directly. * </p> * @param projectName * the project name. * @return the possible source container list. */ public static ISourceContainer[] getSourceContainers(String projectName) { Set<ISourceContainer> containers = new LinkedHashSet<>(); List<IProject> projects = new ArrayList<>(); // If the project name is specified, firstly compute the source containers from the specified project's // classpath entries so that they can be placed in the front of the result. IProject targetProject = JdtUtils.getProject(projectName); if (targetProject != null) { projects.add(targetProject); } List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()); projects.addAll(workspaceProjects); Set<IRuntimeClasspathEntry> calculated = new LinkedHashSet<>(); projects.stream().distinct().map(project -> JdtUtils.getJavaProject(project)) .filter(javaProject -> javaProject != null && javaProject.exists()) .forEach(javaProject -> { // Add source containers associated with the project's runtime classpath entries. containers.addAll(Arrays.asList(getSourceContainers(javaProject, calculated))); // Add source containers associated with the project's source folders. containers.add(new JavaProjectSourceContainer(javaProject)); }); return containers.toArray(new ISourceContainer[0]); }
private synchronized ISourceContainer[] getSourceContainers() { if (sourceContainers == null) { sourceContainers = JdtUtils.getSourceContainers((String) options.get(Constants.PROJECTNAME)); } return sourceContainers; }
@Override public ISourceContainer createSourceContainer(final String memento) throws CoreException { final Node node = parseDocument(memento); if (node.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) node; if (MVNCONTAINER.equals(element.getNodeName())) { final String string = element.getAttribute(PROJECT_NAME); if (string == null || string.length() == 0) { abort(SourceLookupMessages.MyMvnSourceContainerTypeDelegate_ProjectNameIsMissing, null); } final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(string); final IJavaProject javaProject = JavaCore.create(project); return new MyMvnSourceContainer(javaProject); } abort(SourceLookupMessages.myMvnSourceContainerTypeDelegate_ContainerIsMissing, null); } abort(SourceLookupMessages.MyMvnSourceContainerTypeDelegate_InvalidFormat, null); return null; }
@Override public String getMemento(final ISourceContainer container) throws CoreException { final MyMvnSourceContainer sourceContainer = (MyMvnSourceContainer) container; final Document document = newDocument(); final Element element = document.createElement(MVNCONTAINER); element.setAttribute(PROJECT_NAME, sourceContainer.getProjectName()); document.appendChild(element); return serializeDocument(document); }
private static List<IJavaProject> getPossibleAdditions0(final ISourceLookupDirector director) { final List<IProject> mavenProjects = new ArrayList<IProject>(); for (final IMavenProjectFacade mavenProject : MavenPlugin.getMavenProjectRegistry().getProjects()) { mavenProjects.add(mavenProject.getProject()); } final List<IJavaProject> javaProjects = new ArrayList<IJavaProject>(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); try { for (final IJavaProject javaProject : JavaCore.create(root).getJavaProjects()) { if (mavenProjects.contains(javaProject.getProject())) { javaProjects.add(javaProject); } } } catch (final JavaModelException e) { final IStatus status = new Status(IStatus.ERROR, SourceLookupPlugin.getInstance().getBundle().getSymbolicName(), "Can't retrieve Java projects.", e); SourceLookupPlugin.getInstance().getLog().log(status); } for (final ISourceContainer container : director.getSourceContainers()) { if (container.getType().getId().equals(MyMvnSourceContainerTypeDelegate.TYPE_ID)) { javaProjects.remove(((MyMvnSourceContainer) container).getJavaProject()); } } return javaProjects; }
@Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { String projectName = configuration.getAttribute(BfLaunchConfigurationDelegate.PROJECT_ATTR, ""); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project != null) { return new ISourceContainer[]{new ProjectSourceContainer(project, false)}; } else { return new ISourceContainer[]{new WorkspaceSourceContainer()}; } }
private void findSourceElements(ISourceContainer container, Object object, ScriptNameManipulator.FilePath scriptName, ArrayList<Object> output) throws CoreException { Object[] objects = container.findSourceElements(scriptName.getLastComponent()); if (objects.length == 0) { return; } int outputStartPos = output.size(); for (Object obj : objects) { if (obj instanceof IFile) { IFile file = (IFile) obj; if (matchFileAccurateness(file, scriptName)) { output.add(obj); } } else if (obj instanceof VProjectSourceContainer.LookupResult) { VProjectSourceContainer.LookupResult vprojectResult = (VProjectSourceContainer.LookupResult) obj; expandVProjectResult(vprojectResult, object, output); } else { output.add(obj); } } int outputEndPos = output.size(); if (outputEndPos - outputStartPos > 1) { // Put short name last. They cannot be filtered out by our rules, so they may // be parasite. Collections.sort(output.subList(outputStartPos, outputEndPos), SHORT_NAME_LAST); } }
/** * Tries to find a corresponding script for a file from a user workspace. The method uses * the file name and current source lookup rules to retrieve a resource id, regardless of * whether the resource has actually been loaded into the VM (you may want to set a breakpoint * on resource before it is actually loaded). */ public VmResourceId findVmResource(IFile sourceFile) throws CoreException { for (ISourceContainer container : sourceDirector.getSourceContainers()) { VmResourceId scriptName = tryForContainer(sourceFile, container); if (scriptName != null) { return scriptName; } } return null; }
/** * @param container that may not wrap VProjectSourceContainer */ private String tryForNonVirtualContainer(IFile resource, ISourceContainer container) { ContainerWrapper wrapper = wrapNonVirtualContainer(container); if (wrapper == null) { return null; } return wrapper.lookup(resource); }
public ISourceContainer[] editSourceContainers(Shell shell, ISourceLookupDirector director, ISourceContainer[] containers) { final SourceNameMapperContainer originalContainer = (SourceNameMapperContainer) containers[0]; SourceNameMapperContainerDialog.PresetFieldValues params = new SourceNameMapperContainerDialog.PresetFieldValues() { public ISourceContainer getContainer() { return originalContainer.getTargetContainer(); } public String getPrefix() { return originalContainer.getPrefix(); } }; return openDialog(shell, director, params); }
private ISourceContainer[] openDialog(Shell shell, ISourceLookupDirector director, SourceNameMapperContainerDialog.PresetFieldValues params) { SourceNameMapperContainerDialog dialog = new SourceNameMapperContainerDialog(shell, director, params); dialog.open(); SourceNameMapperContainerDialog.Result dialogResult = dialog.getResult(); if (dialogResult == null) { return new ISourceContainer[0]; } ISourceContainer result = new SourceNameMapperContainer(dialogResult.getResultPrefix(), dialogResult.getResultContainer()); return new ISourceContainer[] { result }; }
/** * {@inheritDoc} */ public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { IServer server = ServerUtil.getServer(configuration); SourcePathComputerVisitor visitor = new SourcePathComputerVisitor(configuration); IModule[] modules = server.getModules(); for (int i = 0; i < modules.length; i++) { ModuleTraverser.traverse(modules[i],visitor,monitor); } return visitor.getSourceContainers(); }
ISourceContainer[] getSourceContainers() throws CoreException { runtimeClasspath.addAll(Arrays.asList(JavaRuntime.computeUnresolvedSourceLookupPath(configuration))); IRuntimeClasspathEntry[] entries = (IRuntimeClasspathEntry[])runtimeClasspath.toArray(new IRuntimeClasspathEntry[runtimeClasspath.size()]); IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries,configuration); return JavaRuntime.getSourceContainers(resolved); }
public ISourceContainer[] computeSourceContainers( ILaunchConfiguration configuration, IProgressMonitor monitor ) throws CoreException { List containers = new ArrayList( ); String path = getPath( configuration ); if ( path != null ) { containers.add( new ScriptDirectorySourceContainer( new File( path ), false ) ); } // always use standard source path provider to avoid PDE setting overwritten IRuntimeClasspathProvider scp = new StandardSourcePathProvider( ); IRuntimeClasspathEntry[] entries = scp.computeUnresolvedClasspath( configuration ); IRuntimeClasspathEntry[] resolved = scp.resolveClasspath( entries, configuration ); ISourceContainer[] cts = JavaRuntime.getSourceContainers( resolved ); if ( cts != null ) { for ( int i = 0; i < cts.length; i++ ) { containers.add( cts[i] ); } } return (ISourceContainer[]) containers.toArray( new ISourceContainer[containers.size( )] ); }
@Override public void sourceContainersChanged(ISourceLookupDirector director) { delegateContainers.clear(); ISourceContainer[] containers = director.getSourceContainers(); for (int i = 0; i < containers.length; i++) { ISourceContainer container = containers[i]; if (container.getType().getId().equals(ArchiveSourceContainer.TYPE_ID)) { IFile file = ((ArchiveSourceContainer)container).getFile(); IProject project = file.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { try { IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int j = 0; j < roots.length; j++) { IPackageFragmentRoot root = roots[j]; if (file.equals(root.getUnderlyingResource())) { delegateContainers.put(container, new PackageFragmentRootSourceContainer(root)); } else { IPath path = root.getSourceAttachmentPath(); if (path != null) { if (file.getFullPath().equals(path)) { delegateContainers.put(container, new PackageFragmentRootSourceContainer(root)); } } } } } catch (JavaModelException e) { } } } } }
@Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { return new ISourceContainer[] { new AbsolutePathSourceContainer() }; }
private static ISourceContainer[] getSourceContainers(IJavaProject project, Set<IRuntimeClasspathEntry> calculated) { if (project == null || !project.exists()) { return new ISourceContainer[0]; } try { IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project); List<IRuntimeClasspathEntry> resolved = new ArrayList<>(); for (IRuntimeClasspathEntry entry : unresolved) { for (IRuntimeClasspathEntry resolvedEntry : JavaRuntime.resolveRuntimeClasspathEntry(entry, project)) { if (!calculated.contains(resolvedEntry)) { calculated.add(resolvedEntry); resolved.add(resolvedEntry); } } } Set<ISourceContainer> containers = new LinkedHashSet<>(); containers.addAll(Arrays.asList( JavaRuntime.getSourceContainers(resolved.toArray(new IRuntimeClasspathEntry[0])))); // Due to a known jdt java 9 support bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=525840, // it would miss some JRE libraries source containers when the debugger is running on JDK9. // As a workaround, recompute the possible source containers for JDK9 jrt-fs.jar libraries. IRuntimeClasspathEntry jrtFs = resolved.stream().filter(entry -> { return entry.getType() == IRuntimeClasspathEntry.ARCHIVE && entry.getPath().lastSegment().equals("jrt-fs.jar"); }).findFirst().orElse(null); if (jrtFs != null && project.isOpen()) { IPackageFragmentRoot[] allRoots = project.getPackageFragmentRoots(); for (IPackageFragmentRoot root : allRoots) { if (root.getPath().equals(jrtFs.getPath()) && isSourceAttachmentEqual(root, jrtFs)) { containers.add(new PackageFragmentRootSourceContainer(root)); } } } return containers.toArray(new ISourceContainer[0]); } catch (CoreException ex) { // do nothing. } return new ISourceContainer[0]; }
@Override protected ISourceContainer[] createSourceContainers() throws CoreException { return fromMavenSourcePathProvider(); // return fromJavaRuntimeResolver(); }
ISourceContainer[] getSourceContainers() { return LookupParticipant.this.getSourceContainers(); }
public ISourceContainer[] getSourceContainers() { return null; }
public ISourceContainer createSourceContainer(String memento) throws CoreException { return new VProjectSourceContainer(); }
public String getMemento(ISourceContainer container) throws CoreException { return "VProjectSourceContainer.memento.stub"; //$NON-NLS-1$ }
public static boolean isGoodTargetContainer(ISourceContainer container) { return wrapNonVirtualContainer(container) != null; }
public SourceNameMapperContainer(String prefix, ISourceContainer targetContainer) { this.targetContainer = targetContainer; this.prefix = prefix; }
public ISourceContainer getTargetContainer() { return targetContainer; }
public ISourceContainer[] getSourceContainers() { return new ISourceContainer[] { targetContainer }; }