org.eclipse.debug.core.sourcelookup.ISourceContainer Java Examples

The following examples show how to use org.eclipse.debug.core.sourcelookup.ISourceContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodewindSourcePathComputer.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration config, IProgressMonitor monitor)
		throws CoreException {

	// Get the project name from the launch configuration, look up the IProject, and return that IProject as a
	// source container.

	// CodewindLaunchConfigDelegate sets this attribute in the launch config.
	final String projectName = config.getAttribute(CodewindLaunchConfigDelegate.PROJECT_NAME_ATTR, "");
	if (!projectName.isEmpty()) {
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);

		if (project == null || !project.exists()) {
			Logger.logError("Could not find project with name " + projectName + " to add to source path");
			return new ISourceContainer[0];
		}

		// What does the second boolean parameter 'referenced' mean ?
		ISourceContainer projectSourceContainer = new ProjectSourceContainer(project, true);
		Logger.log("Adding source container from project " + project.getName());
		return new ISourceContainer[] { projectSourceContainer };
	}

	Logger.logError("Could not retrieve project name from launch config " + config.getName());
	return new ISourceContainer[0];
}
 
Example #2
Source File: LangSourceLookupDirector.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a stack frame, find the target java project that the associated source file belongs to.
 *
 * @param stackFrame
 *                  the stack frame.
 * @param containers
 *                  the source container list.
 * @return the java project.
 */
public static IJavaProject findProject(StackFrame stackFrame, ISourceContainer[] containers) {
    Location location = stackFrame.location();
    try {
        Object sourceElement = findSourceElement(location.sourcePath(), containers);
        if (sourceElement instanceof IResource) {
            return JavaCore.create(((IResource) sourceElement).getProject());
        } else if (sourceElement instanceof IClassFile) {
            IJavaProject javaProject = ((IClassFile) sourceElement).getJavaProject();
            if (javaProject != null) {
                return javaProject;
            }
        }
    } catch (AbsentInformationException e) {
        // When the compiled .class file doesn't contain debug source information, return null.
    }
    return null;
}
 
Example #5
Source File: LangSourceLookupDirector.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: SourceLookupDirector.java    From corrosion with Eclipse Public License 2.0 6 votes vote down vote up
@Override public ISourcePathComputer getSourcePathComputer() {
	ISourcePathComputer computer = super.getSourcePathComputer();
	if (computer != null) {
		return computer;
	}
	return new ISourcePathComputer() {

		CSourcePathComputerDelegate langSourcePathComputer = new CSourcePathComputerDelegate();

		@Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
			return langSourcePathComputer.computeSourceContainers(configuration, monitor);
		}

		@Override public String getId() {
			return CorrosionPlugin.PLUGIN_ID + ".SourceLocator"; //$NON-NLS-1$
		}
	};
}
 
Example #7
Source File: LangSourceLookupDirector.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@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;
		}
	};
}
 
Example #8
Source File: MyMvnSourceContainer.java    From m2e.sourcelookup with Eclipse Public License 1.0 6 votes vote down vote up
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[] {};
}
 
Example #9
Source File: MyMvnSourceContainer.java    From m2e.sourcelookup with Eclipse Public License 1.0 6 votes vote down vote up
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);
  }
 
Example #10
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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]);
}
 
Example #11
Source File: ScriptSourcePathComputerDelegate.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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( )] );
}
 
Example #12
Source File: MyMvnSourceContainerBrowser.java    From m2e.sourcelookup with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: MyMvnSourceContainerTypeDelegate.java    From m2e.sourcelookup with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: MyMvnSourceContainerTypeDelegate.java    From m2e.sourcelookup with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #15
Source File: JdtSourceLookUpProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the project associated source containers.
 * @return the initialized source container list
 */
public synchronized ISourceContainer[] getSourceContainers() {
    if (sourceContainers == null) {
        sourceContainers = JdtUtils.getSourceContainers((String) options.get(Constants.PROJECT_NAME));
    }

    return sourceContainers;
}
 
Example #16
Source File: ReportLaunchConfigurationDelegate.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param launch
 */
private void configLaunch( ILaunch launch,
		ILaunchConfiguration configuration )
{
	if ( launch.getSourceLocator( ) instanceof JavaSourceLookupDirector )
	{
		JavaSourceLookupDirector director = (JavaSourceLookupDirector) launch.getSourceLocator( );
		ISourceContainer[] contains = director.getSourceContainers( );
		List list = new ArrayList( );

		if ( contains != null && contains.length != 0 )
		{
			for ( int i = 0; i < contains.length; i++ )
			{
				list.add( contains[i] );
			}
		}

		try
		{
			List sourcePaths = getAllProjectSourcePaths( configuration.getAttribute( IMPORTPROJECTNAMES,
					"" ) ); //$NON-NLS-1$
			for ( int i = 0; i < sourcePaths.size( ); i++ )
			{
				// String source = ( String ) sourcePaths.get( i );
				// ISourceContainer temp = new DirectorySourceContainer(
				// new Path( source ), true );
				// list.add( temp );

				IJavaProject source = (IJavaProject) sourcePaths.get( i );
				ISourceContainer temp = new JavaProjectSourceContainer( source );
				list.add( i, temp );
			}
		}
		catch ( CoreException e )
		{

		}

		ISourceContainer[] retValue = new ISourceContainer[list.size( )];
		retValue = (ISourceContainer[]) list.toArray( retValue );
		director.setSourceContainers( retValue );
	}
}
 
Example #17
Source File: MyMvnSourceContainer.java    From m2e.sourcelookup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ISourceContainer[] createSourceContainers() throws CoreException {
  return fromMavenSourcePathProvider();
  // return fromJavaRuntimeResolver();
}
 
Example #18
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
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];
}
 
Example #19
Source File: LangSourceLookupDirector.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unused") 
protected void customizeDefaultSourceContainers(ArrayList2<ISourceContainer> containers) {
}